Introduction :
This application is a kind of game named “Boooom!” . We are asked to do this by using JavaFX framework, which is a set of graphics that programmers use to create complex applications.
In this game, there are 5 levels and each of them includes several types of rectangles. The aim is to destroy rectangles by considering their durability and clicking as few as possible. When all the rectangles are destroyed, next level becomes available. The usage of the game will be explained in more detail in the implementation part.
Implementation :
In this program, there are 6 main classes. One of them is for the main menu, the others are for the levels. When we open project.java class in eclipse and start the program, The main menu is shown like this. At the top of the menu, there is the title which has a constant motion. At left, there is a simple example of a game board. It has a constant motion as well. At right, there are separate buttons to reach the levels one by one. When the previous level is done, the button for the next level becomes active. If we try to reach next level without completing the previous one, A warning text occurs just under of the buttons. When we click a button, a different window arises. For each level, there is a specific stage and window.
Main Menu :
In the main menu, there is a border pane which has three other panes named menu_top, menu_center and menu_right. Each of them is created with different types of pane according to their purposes.
In menu_top, there is just a label to show the title of the game. But it is more than that. There is an animation in this part. The get_bigger property depends on the size of the title “Boooom!”. When it becomes 30, get_bigger becomes true and activate an if statement which provides the title is getting bigger until it is 50. Then get_bigger becomes false and title is getting smaller until it is 30 and so on.
The creation of the title :
The creation of the animation :
In the menu_right , there is a title “Levels” and 5 buttons for each level. There is an also warning label which occurs when we try to reach levels without doing the previous one.
Each button has an action. When level_x button is pressed, level_x_stage.show() method becomes active and the window for level_x arises. Also we check if the previous level is done or not in setOnAction method as in the fallowing figure.
In the menu_left, There is a for loop. This loop creates 10x10 rectangles and put them to a specific position. Then it gives them random numbers from 0 to 4 to fill them in different random colors. The colors change every second thanks to a TimeLine animation as in the figure.
Level Stages:
As it is stated, there are separate stages for each level. Each level is a copy of each other. There are just small changes according to the unique properties of the levels like filled rectangles. In this part, the details about level-2 will be shared.
-BorderPane_for_L2 Class Hierarchy
-Border Pane for level-2
As we stated, all level classes are actually a border pane. Level-2 border pane contains three other panes in itself as in the fallowing figure, which are the top pane, the bottom pane and the game board. We created and add them to the border pane.
There are also four other properties in the border pane. Counter simply counts the number of the rectangles destroyed. Points take the point of the user by considering counter. High_score take the high score depends on the point of the user. Is_it_done property determines if the all rectangles are destroyed or not by considering their colors. More explanation will be given.
Rectangle Class :
We decided to create a rectangle class which extends the Rectangle class. The aim was to add new properties to make coding easier and also using the Rectangle class properties at the same time. It has destroyable, x and y properties. When a rectangle is brown or white, destroyable property is set as false and vice versa for blue and purple.
In the constructer of the rectangle, a default rectangle is created with a specific x and y property and also a default size and color. It is better to use new x and y properties than default x and y properties because they give us the pixel count. But new x and y properties give us a coordinate.
Also, the rectangle class has a method named destroy(). In destroy function, The color and the destroyable property changes as in the fallowing figure. The destroyable property is determined in the game_board2 according to the level-2 filling rules. If a rectangle is purple, destroy function makes it blue. If it is blue, then it will be white an also “not destroyable.”
Top Board :
In top board, there is just the name of the level, the point and also the high score . Additionaly, there is a small bug but it can be solved easily. More explanation will be given in the test cases. The build function of the class provides the class to have three labels as in the fallowing figure.
When we get a two-digit point, the point label does not show the point properly. But the point is stored correctly and there is a small solution. If we close the window and open it again in the main menu, we can see the point even if it is 2-digit and also can continue from where we left.
Bottom Board :
In this board, there are several labels. As in project guide, when we click on a rectangle, the coordinates of the destroyed rectangles are shown. At the end of the level, a label arises which says “the next level is available!”. The implementation of these are in the game_board2 class, so more detail will be given in that part.
Game Board :
In our game board ,we create a rectangle list to store the rectangles at first.
In the build() method, we create rectangles according to the i (row) and j (column) values in the first loop. Then , we activate the setOnMouseClicked event to destroy boxes .
We increment the points value in this loop according to the counter value.And also created high_score value.
In every mouseClicked event , we need to change the points and counter variables . So we used .clear() method and add them again.
In the destroy_all(rectangle r) method, First, we check the IsDestroyable() value of the rectangle which is clicked. Then we try to find any affected rectangle by using if statements.
Also we need to write the clicked box and affected box on the bottom page , so we create hit# and box variables.
We need to write gained or lost points according to each click event. So we add this code at the end of each if blocks.
At the end of the GameBoard part, we need to write next level message if the current level is completed.By this code , we ensure that the level is completed or not:
Test cases :
When we run the game, the main menu arises. If we want to open level-2 without complating level-1, it gives a warning as in the fallowing figure.
When we click the button level-1, the level-1 stage arises. At the end of the level, the next level becomes available.
When the point is two digit and not shown properly, we can close the window and open again.
When we complete the level, a label arises in the bottom pane which says “The next level is available!” However, when we complete the level-5, it says congratulations. It is shown in the fallowing figure.
How to run the code ?
Firstly download the project levels & main class files.
Then open the windows command prompt.
Change the current directory to the location of downloaded files. (cd ./..).
Type the javac Project.java to compile the code.
Then type java Project.
It will opens the menu.
Congrats !! You can play the game ...