For your final lab of the year, you will make a copy of the classic phone game 2048 (if you are unfamiliar, you can play a version here: https://www.mathsisfun.com/games/2048.html). This lab will be due on 11:59pm at Monday 3/30.
Here is a basic structure of how the game works:
-There is a 4x4 grid of numbers. Some of these spots will be blank. I recommend creating a class to represent the board. It would store the number data in a 2d array and have several other methods to move and combine tiles.
-The grid 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 (there is a 90 percent chance of a 2 being added and a 10 percent chance of a 4 being added). 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.
-A player has "won" the game when a 2048 tile appears on the board. They may still keep playing after that point.
-The game ends in a loss when the board is full AND there are no possible moves in any direction that will make a merge.
-The game will keep score as you play. Every time you merge, you get points for every new tile created by the merge. For example, if you merge a 4 and a 4, you will end up with an 8 and get 8 points added to your total. After the game ends, it will compare your score to a HighScores.txt file (which you should create in notepad or something similar) and determine in which place your current score would put you on the list.
My HighScores.txt file (which you can copy) looked like this:
genius gena, 2000
super steve, 1000
silly sammy, 850
mediocre mandy, 500
mikey moron, 100
Instead of moving in real time, your game will work within blueJ. The user will type in w,a,s, or d (or type "quit" to end the game) and then hit enter to shift everything in the appropriate direction.
Here are some hints you might find useful:
-Your board class is a good place to store the data and have methods to move and merge the numbers. It is also a good place to keep score, add a new tile, and check for wins and losses.
-A good place to start is by creating the board, having it print out properly, and then starting to add tiles to random empty locations.
-When thinking about merging, I would consider having one method to move everything, then another method to check and process merges.
-Merges go in the order starting at the side you are merging. For example, if you have 4 4 4 and swipe left, it should be 8 4. If you have 4 4 4 and swipe right, it should be 4 8. However, if you swipe 2 2 2 2 together, it should only merge once into 4 4. Use this when you think about which order to do your loops.
-To help your board print out in a clean alignment, use "\t" inside your lines to print out the board to ensure your columns are lined up.
EXTRA CREDIT OPTION: For a couple points of extra credit, look up how to use .write to actually add the user's score to the txt file with the high scores!
When you turn in your project, please remove all other files from your turn in folder besides your 2048 project.
Have fun!!