代做Oop | 代写Project | Gui代写 | Lab代写 | Java | 代写Javafx – JAVAFX Programming

Homework | 代做Oop | 代写Project | Gui代写 | Lab代写 | Java | 代写Javafx – 这是一个基于java的GUI程序的实现,通过javafx进行界面的编写,是比较典型的相关类型OOP面向对象任务

JAVAFX Programming project 5

I. Overview

The purpose of this homework is to give you practice designing and creating a complete program.

II. Code Readability (20% of your project grade)

To receive the full readability marks, your code must follow the following guideline:

All variables (fields, parameters, local variables) must be given appropriate and descriptive names.
All variable and method names must start with a lowercase letter. All class names must start with an
uppercase letter.
The class body should be organized so that all the fields are at the top of the file, the constructors are
next, the non-static methods next, and the static methods at the bottom with the main method last.
There should not be two statements on the same line.
All code must be properly indented (see Appendix F of the Lewis book for an example of good style).
The amount of indentation is up to you, but it should be at least 2 spaces, and it must be used
consistently throughout the code.
You must be consistent in your use of {, }. The closing } must be on its own line and indented the same
amount as the line containing the opening {.
There must be an empty line between each method.
There must be a space separating each operator from its operands as well as a space after each comma.
There must be a comment at the top of the file that is in proper JavaDoc format and includes both
your name and a description of what the class represents. The comment should include tags for the
author. (See Appendix J of the Lewis book of pages 226-234 if the Evans and Flanagan book.)
There must be a comment directly above each method (including constructors) that is in proper
JavaDoc format and states what task the method is doing, not how it is doing it. The comment should
include tags for any parameters, return values and exceptions, and the tags should include appropriate
comments that indicate the purpose of the inputs, the value returned, and the meaning of the
exceptions.
There must be a comment directly above each field that, in one line, states what the field is storing.
There must be a comment either above or to the right of each non-field variable indicating what the
variable is storing. Any comments placed to the right should be aligned so they start on the same
column.
There must be a comment above each l oop that indicates the purpose of the loop. Ideally, the comment
would consist of any preconditions (if they exist) and the subgoal for the loop iteration.
Any code that is complicated should have a short comment either above it or aligned to the right that
explains the logic of the code.

III. Program Testing (20% of your project grade)

You are to write a test report that indicates the types of tests needed to thoroughly test your project. The tests should demonstrate that all parts of your code behave correctly. Any unit of your program involving conditional statements will need tests that go through each branch of the execution. Any unit of your program involving loops will need tests that cover the "test 0, test 1, test many" and "test first, test middle, test last" guidelines. Your testing report should not list the actual tests and results.

You are to have a JUnit test class or classes that implement as many of the tests as you can. You should have comments, names, or other indicators in your JUnit tests that easily link the JUnit tests back to the testing report.

The testing report must be separate from the JUnit class. In most companies, the testing document will be written in a style that allows both programmers and non-programmers to read it and recognize whether all the needed test cases were included.

Note that you will not be able to (easily) test methods involving user input or screen output with JUnit. For these parts of your program, your testing report should indicate the specific tests you did to test these routines.

Hint 1: Make lots of helper methods for each of the different parts of the game. That will make it much easier to design tests for your game, and it will make the testing shorter! You can make the methods public or private. In Friday’s lecture, you will learn how to write tests specifically for private methods.

Hint 2: The javafx GUI components are not always simple to create outside of a JavaFX application. As a result, it will be easier to write JUnit tests if you have the game mechanics done in helper methods that do not directly use GUI components.

IV. java Programming (60% of your grade)

For this project you will implement a modified game of Bejeweled (variations include Jewel Quest and Candy Crush).

Rules of the game:

In our modified game, the game is played on a grid of "tiles". Each tile begins with a random jewel placed on the tile (we will represent the jewel type by the color of the tile). The base game will be 8 rows and 10 columns with 4 different types of jewels. For each legal move, you click a first tile and a second tile immediately next to it, either horizontally or vertically. The jewels in the tiles are switched. For every group of three or more tiles in a straight line, horizontally or vertically, that contain the same type of jewel and that contain the second clicked tile (i.e. the color of the first clicked tile), those tiles are marked with a *, the jewels in those tiles are removed, the jewels in the tiles above the removed jewels slide down, and new random jewels are placed in the now empty tiles at the top of the grid. Note that the jewels slide, but the tile markings stay in place. The object of the game is to get every square of the grid "marked". If the second clicked tile (after the swap) is not part of any group of three or more tiles in a straight line containing the same jewel type (color), then this was not a legal move and the jewels in this tile and the initial clicked tile are switched back.

For those who have played the "normal" Bejeweled game, the main difference is that in the normal game, all straight lines of three or more tiles with the same jewel are marked and removed, not just groups containing the second clicked tile, and any groupings of three or more that appear as a result of sliding jewels are also automatically marked and removed. In our version, no markings happen automatically, and the tile groups to be marked and removed must include the second clicked tile. Thus at most two lines of tiles will be marked and have jewels removed with each move in the game.

What you must do:

Important: Read the instructions for the testing part of this project. You need to design your code so that it is easy to test. If you put off writing the testing code to the end of the project, you may need to rewrite your code to get testing to work.

You are to create a class called Jewels. The Jewels class extend the JavaFX Appliction class.

Designing your program

Below the instructions provide the basic steps you need to accomplish to get your game to work. However, it is strongly recommended that you spend some time designing what you will be coding before you code. It is very strongly recommended that you employ helper methods and/or additional classes in the design of this game. Doing so will shorten the amount of work you need to do. As a hint, if you find yourself writing the same piece of code over and over, it might be easier to either write a helper method to do that operation or to write a class that extends the class you are working with so that the class a method that does what you need.

Create the board

You are to create a board by making a two-dimensional grid of Buttons. This simplest way to to that is to create a GridPane instance that will hold the buttons, and add the GridPane to the JavaFX Scene.

You can then create a 2-dimensional array of Buttons and add them to the GridPane using the add method of GridPane with the appropriate values so that the location of a button in the array corresponds to its location in the display grid.

Give each button a random color selected from a set of colors of your choice. You should also set the Insets and CorderRadii of the button so it looks reasonable on the screen

Hint: In the default game, you will be changing the text on the button, and that will resize the button. That may make the board look strange partway through the game. A simple way to avoid that is to give each button an initial text of two spaces. If you want, you can hunt through the API to see how to set the size of the button to avoid resizing.

Here is a picture of what your board should look like in the middle of a game: JewelsBoard.jpeg

Respond to button clicks

You should create an EventHandler for the buttons. Recall that an EventHandler has a method handle that is called every time the button is pressed. The handle method has a single parameter, ActionEvent e, and you can get the button that was pressed by using the code

Button b = (Button)e.getSource();

b is the button that was pressed.

When a button is pressed, the code should save the button (or its location), darken the color of the selected button so the user sees what they clicked, and wait for a second button press. On the second press, your code should restore the first button to its original color, get the second button, check to see if the two clicked buttons are adjacent, and swap the colors/jewels of those buttons if they are adjacent. It is not hard to determine if two buttons are adjacent because you get the button that was clicked from the ActionEvent parameter, and you have all the possible buttons stored in their appropriate location in a two-dimensional array. If the user did not click adjacent buttons, you start again waiting for the first button click.

You now need to see if there are at least three jewels in a straight line, horizontally or vertically, containing the second clicked tile and with the same color as this tile (following the swap). If there are, these tiles need to be marked and the jewels removed. Do not place all the code for this into the handle method. You need to have JUnit tests so you should create separate methods to handle these actions.

If there are not three in a row horizontally or vertically, the two swapped tiles should be restored, and we again wait for a first click.

Once all the tiles have been marked, you are to print a message indicating that the game is over and list the total number of legal moves it took to complete the game.

Add a main method

The Jewels class should have a main method that launches the Jewels game. With a main method, you should be able to play your game by typing:

java Jewels

in the Interactions pane. You should also allow the user to enter three arguments, the board size and the number of jewel types. For example: java Jewels should start a game with a 8×10 grid and 4 different jewel types (colors), and java Jewels 8 12 5 should start a game with 8 rows, 12 columns, and 5 different jewels. If the user enters something other than realistic numbers, your code should do something appropriate, but not crash.

There are two ways you can deal with the command line arguments. You can either process them directly in the main method. Of you can pass the arguments to the launch method, and then in the start method, you can access them using the getParameters().getRaw() method of Application. (See our lab 9 to recall how to do this.)

Hint: Do not try to code everything at once! First just get the game board displaying. Then add the ability to click on a button and have text appear on the button clicked. Then make it so that the correct button gets the text. Then write code to search for a win. Finally, get the main method working.

Extra Credit:

If you decide to do an extra credit, you must state in the Canvas comments what you did. Don’t make us hunt through your code to figure out what extra you did.

Extra Credit #

Create fancier Jewels game. Instead of using the button color to indicate the jewel type and a ‘*’ to indicate if the tile is marked, set all buttons to initially have the same background color. Use different shaped and colored icons for the jewels, change the background to yellow to indicate a tile being marked, and use a different color to indicate when a button is pressed.

Extra Credit #

Make further improvements to the aesthetics of the game. Here are three possible ideas: add fancy borders and extra areas to the game board that display useful information, animate the jewel movements, add a timer and instead of counting the number of moves the game goes until the timer runs out, or add obstacles to the board: tiles that do not contain jewels, do not slide, and will not be marked. For many of these ideas, you will need to hunt through the Java API.

Leave a Reply

Your email address will not be published. Required fields are marked *