This will be your last lab of the year before we start reviewing for AP tests. This lab is due by 11:59pm on Tuesday, March 26th. We will have two weeks to work on this assignment and I would recommend spending around half an hour per day outside of class on this project. There will be no revisions or late work allowed on this lab.
In this major project, you will design one of the following games using GridWorld. You will create a full, functional Bejeweled, Minesweeper or 2048 game (if you have another game you would like to try, please talk to me on an individual basis). I have completed all three projects already and found them to be similar in difficulty and to take almost the exact same amount of time to code. If you are curious, I found Bejeweled to be a bit more difficult but I found Minesweeper and 2048 to be slightly more annoying at times. I would recommend coding whichever game you think you would enjoy more! If you cannot decide, you should probably read this document for ideas. Here are some sites you can play each game for free online (they may be blocked at school):
Minesweeper: http://minesweeperonline.com/#
2048: https://2048game.com/
Bejeweled: https://www.digbejeweled.com/
I have attached some starter code for each project at the bottom of this page. All three are challenging but I know that all of you can complete any of these given enough time and effort. Get after it!
OPTION 1:
In this program, you will use GridWorld to create a version of the classic game Minesweeper (which comes with Windows and may have eaten up a significant portion of your childhood).
In my example, a 9 x 9 board is filled up with 12 bombs (set it up so you can easily change these numbers in your driver). The point of the game is to correctly identify the locations of all 12 bombs. You can click on a space to reveal what it is – if it is a bomb, you lose! Otherwise it should tell you how many bombs are adjacent to that space. If you click on a space with zero neighboring bombs, it will also basically “click” on all of the neighboring spaces, revealing their number of neighbors (and possibly doing this over and over if you hit another zero… sounds like recursion to me!). You may also mark a space as a bomb by planting a flag on it (this is like right clicking in the windows version).
The game ends when you click on a bomb (you lose!) or when you have correctly marked the locations of all bombs and not marked any other locations (you win!). When the game ends either way, it should reveal all spaces on the board to show where the bombs are and what numbers are under the other spaces.
Harder Option: Create your own Minesweeper game from scratch using the GridWorld interface. The class design is up to you.
Regular Option: Use my organization scheme to set up your game by creating the following classes.
-A Space class which will have some kind of instance variable detailing whether it is a bomb or not. It should have different methods to "mark" as a flag and to "reveal" its properties (possibly blowing up and ending the game, possibly detailing how many bomb neighbors it has).
-A Flag class to represent a spot you have marked as a bomb.
-When you mark a Space object, you will replace that object with a Flag – make sure to keep track of whether it was originally a bomb! You should be able to unmark this and return it to a regular Space.
-Different classes for space, flag, and one, two, three, four, five, six, seven, eight so the user can easily see how many bomb neighbors an empty space had. (I have attached an example of these)
-Different .gifs for each class (one of which is provided). Make sure to give the .gif the exact same name as the class file to get the picture to show up!
-A driver class to set up the board initially (a skeleton of which is provided for you at the bottom of this page)
Extra credit opportunities:
-Create different difficulty levels
-Allow for the user to mark spots with a question mark as in the windows version.
-Create a reset button and put it at the top of your game
-Add the "double-click" functionality
-Other upgrades/options you talk to me about
OPTION 2:
In this program, you will use GridWorld to create 2048, the phone game from several years ago. In this game a 4x4 board begins with two "2" objects in two random locations. You can swipe all tiles either left, right, up, or down. This slides all the tiles in that direction, combining like tiles into their sum. So if you swipe a 4 into a 4, they will merge into an 8. Every time you swipe, a new 2 or 4 will appear in a random empty location in the grid. If swiping one way would not merge or move anything, you are not allowed to swipe in that direction and no new tile should be placed in the board.
The point of the game is to get a 2048 tile somewhere on the board. If the board is full and you are unable to make any matches by swiping in any direction, the game is over and you lose.
You will need to make your own classes for Two, Four, Eight, etc. to get the images to show up correctly. I should be able to click on any number tile on the board to swipe them all in one direction.
Extra Credit Opportunities
-Implement keyboard controls so that you can slide the tiles using the arrow keys - it's not too difficult, you just have to extend ActorWorld and override the KeyPressed method. Check the KeyWorldExample class I have written and attached below for an example.
-Have it keep track of your score like the app does. You can just use System.out.println() to show the score.
OPTION 3 (probably the more challenging option):
In this program, you will use GridWorld to create a version of the classic tile game Bejeweled (you may have also played a variant called Candy Crush Saga or countless other knockoffs). In this case, an 8x8 board fills up with tiles (jewels) of 8 different colors at random. The point is to swap the location of two tiles to try to match together 3 or more of the same color tile along a line. Once matches are found, they are removed from the board, and all tiles above them slide down into place (possibly creating more matches), with new tiles filling up empty spots at the top of the board.
You may not swap a tile if it does not create a match. The game is over when there are no more possible matches.
Create your own Bejeweled game from scratch using the GridWorld framework. I recommend just starting with the following 2 classes.
-a Jewel class (which would probably extend Actor) - this class will contain the vast majority of your code. Even methods to refill the grid with new objects and slide them down can be written in this class!
-a driver class (a skeleton of which is provided for you) to set up the board initially
-HINT: when replacing the jewels after a match, first create a list of all locations on the board with a match, THEN remove all of the jewels in those spots. After everything is cleared, then slide jewels down and put in new ones at the top.
Extra Credit opportunities:
-Create a score counter that keeps track of the current score. You can put this in a corner or just use System.out.println(). You can decide on a scoring scheme for the user.
-Create other objects with different effects that might fall down or be created throughout the game, such as the striped candies, bombs, or blocks from Candy Crush Saga.
-Other upgrades/options you come up with and talk to me about
OPTION 4: You can also propose an alternative idea for a project to me - please check in with me briefly before doing this option. In the past, students have created Tetris, Pac-Man, Bomberman, Galaga, Chess, Tower Defense, Donkey Kong, and more. HOWEVER, be aware that if you choose one of these, it may be significantly harder and I may not be able to help you if you get stuck!
TIPS FOR ALL OPTIONS:
-Have fun!
-Think about a plan to build and test your program in chunks. You may want to implement some of the harder features at the end after the first part works. In Minesweeper, you might want to make sure everything gets set up right and counts nearby bombs correctly before working on 0s or determining if the player has won. In Bejeweled, make sure your program sets up the board, swaps tiles, and erases matches before refilling the grid or checking to see if you have lost.
-You will include your own .gif in your project folder to represent the items on the grid. To make this happen, download/create a picture, then save it with the same name as your class (so if you have Two.java, you need a Two.gif). If you have a .jpg or .png, open it in paint and save it as a .gif file (here is a video on how to do this: https://www.youtube.com/watch?v=OlOMrYfraKo). If you want to maintain the original color of your image for an object, call setColor(null) in the constructor of your object.
-Break things up into smaller methods. For instance, swapping two tiles in Bejeweled should be in a separate method from clearing all the matches on the board. In Minesweeper, you should count how many bombs are nearby in a separate method before going through the code to “reveal” a bomb.
-Allocate at least 1/3 of your time to testing your program. There will likely be a lot of errors and issues. This is NOT an easy assignment (it is one of your most challenging assignments of the year). It took me about 3-4 hours to put each one together. Half of that time was spent testing and debugging.
-When you get a runtime error, read the error message and click on the link to find where and why it is occurring! Try to troubleshoot yourself as much as possible.
-To place objects in the grid via your driver, call world.add(new One()) to add your object to a random location. Once your program is running and you are in the class of one of the actors and you want to add or remove Actors from the grid, make sure to use the .putSelfInGrid() and .removeSelfFromGrid() methods, NOT the .put and .remove method in Grid. They will give you errors and should be avoided.
-If you want a method to not show up when you click on an object, change it to be protected instead of public.
-When removing objects from the grid, you may want to store the grid as a variable (like Grid<Actor> gr = getGrid()) BEFORE you remove it so you can still access that grid later on, as getGrid() will be null as soon as the current object is no longer in a grid.
-It is likely that blueJ will give some warnings (not errors) when you compile your code due to casting issues or your forgetting to put the <Actor> after a Grid or ArrayList. Don’t worry about them unless you are getting runtime errors.
-The act method should do nothing in each case, having GridWorld “step” will not do anything meaningful. You should be able to play the game by clicking on tiles and selecting methods.
-Do you want more extra credit? Make more than one of these games... (you will not get a full 30 points of extra credit, but if both work perfectly, it should be worth an extra 10).
When you are done, please submit your entire project folder so I can open it up in BlueJ and test your code easily. Here is the rubric I will use to grade your projects, which are out of 30 points.
Bejeweled:
_/6 Board sets up correctly with no matches.
_/8 I can swap to make a match and I cannot swap if it doesn't result in a match.
_/3 Multiple combos are all removed.
_/10 After matching, tiles fall and new tiles fill in, clearing any new matches
_/3 Game ends when I have no more matches.
__/30 total
__/10 extra credit points (variable)
Minesweeper:
_/5 Board sets up correctly
_/10 I can correctly call mark or reveal on a space to reveal the number in that spot or mark it as a bomb.
_/5 Clicking on a blank space will correctly reveal all of its neighbors.
_/10 Game ends at the appropriate time (win or lose), reveals the whole board.
_/30 total
__/10 extra credit points (variable)
2048:
_/8 I can swipe in any direction, moving all tiles
_/10 Combining works properly, gives the new number
_/5 New tile is added randomly and correctly (and only if a swipe actually occured)
_/7 Game ends when I lose and prints out a fun message if I get a 2048
__/30 Total
__/10 extra credit points (variable)
In the following folder (https://drive.google.com/drive/folders/1CBOZVeZaIZR5pjZNxp_El9-y_0tEeEX9?usp=sharing), I have attached some code you can use to start your project.
MINESWEEPER:
Driver class, code and .gif for class "One"
2048:
Driver class (for pictures - same idea as the One.gif in MineSweeper)
BEJEWELED:
Driver class (same tip with pictures)