Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i'm trying to code the game 2048 using 2-D arrays but i need help with the last method. pls code in java Overview 2048 is

i'm trying to code the game 2048 using 2-D arrays but i need help with the last method. pls code in java
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Overview 2048 is a puzzle game where you use the arrow keys to move left, right, up or down to merge tiles of the same number together. Check it out if you never played it before. The goal of the game is to keep merging numbered (non-zero) tiles until you get one 2048 tle. If two tiles with the same number touch each other, they are merged together in the direction swiped into a new tile with twice the value. (ex: if you move up, the topmost value doubles and the bottom value becomes 0 ). Be careful with your moves - it the board is full at the end of a turn and there are no other valid moves, it's game over! In this assignment, we will represent the 2048 grid as a 44 array of integers, with 0 's representing empty tiles. Note that we will grade your individual operations - not your score or ability to get to 2048. Implementation Overview of files provided We provide two drivers (text and graphic) to help you test the individual methods. We suggest that you start with the text driver but once you have a good understanding of the assignment then you may use the graphic driver. - Board: The Board class contains all methods needed to construct a functioning 2048 game, Edit the empty methods with you solution, but DO NOT edit the provided ones or the methods signatures of any method. This is the file you submit. - BoardSpot: An object used to represent a location on the board. It houses a row and a column, along with getters and setters. Don't edit or submit to Autolab. - TextDriver: A tool to test your 2048 board interactively using only text-based boards. This driver is equivalent to AnimatedDriver and functions in the same way - you are free to use this driver to test all of your methods. Feel tree to edit this class, as it is provided only to help you test. It is not submitted and/or graded. - To use this driver, pick whether you want to test individual methods or play the full game (this option requires all methods to be completed) by selecting the number that appears for each option. - To test individual methods, first type in the full file name for an input file. Then, select a method to test by typing in the number that appears for each method in the list. Additionally, for makeMove, moves are represented by using the WASD keys like arrow keys ( w is up, a is left, s is down, and d is right). Type in the letter corresponding to the move you want to test. a Playing the full game makes use of the WASD keys like arrow keys ( W is up, A is left, S is down, and D is right). Press " Q ' to quit. - AnimatedDriver: A tool to test your 2048 board interactively through rendered images. This driver is equivalent to TextDriver and functions in the same way - you are free to use this driver to test all of your methods. Feel free to edit this class, as it is provided only to help you test. It is not submitted and/or graded. - To use this driver, pick whether you want to test individual methods or play the full game (this option requires all methods to be completed) by selecting the number that appears for each option. - To test individual methods, first type in the full file name for an input file. Then, select a method to test by typing in the number that appears for each mothod in the list. You will then see the board stored in the input file. For all methods besides makeMove, press any key to test your method. Press any key again to exit testing that method. - For makeMove, moves are represented by using the WASD keys like arrow keys (w is up, a is left, s is down, and d is right). Type in the letter corresponding to the move you want to test when you see the board stored in the input file. Once you type that letter, the move you want to test will be made. Press any key afterward to exit testing that method. - Playing the full game makes use of the WASD keys like arrow keys (w is up, a is lett, 5 is down, and d is right). Press " q " to quit. - Stdin and StdOut: libraries to handie input and output. Do not edit these classes. - StdRandom: Provides methods for generating random numbers. Don't edit or submit to Autolab. - Collage, Picture, StdDraw: Helper ibraries to support AnimatedDriver. Don't edit or submit to Autolab. - Input Files: Preset boards you're able to use to test your 2048 board in the drivers (intput1, in, input2,in,...). You can use all input files to test all methods. Each input file contains 4 lines, each with 4 space separated numbers. Each number is either 0 (represents an empty space) or a power of 2 (represents a normal tile). Feel free to make your own input files, as they will not be submitted to Autolab. Putting everything together by calling previous methods to construct 2048 moves in all directions. Rotate as necessary to complete this method using different directions. Swipe left, merge neighbors, and swipe left again to re-fill blank spaces. - The method input parameter is a character that indicates which direction to move ( U=up, ' R=right, 'D' = down, ' L= lett). Assume that you will only receive these characters, case-sensitive, as arguments in the makeMove method. - Be sure to have transpose, tliphoss, swipetett, and mergeleft completed before doing this method and all previous methods completed before testing. - As stated earlier, call rotateboard to help with non-left directions. This allows for MUCH better code reuse than redoing your awipeteft and aergeteft in 3 now directions. - To test this method, select the "makeMove' option in either driver and enter a character. You can use the W, A, S, and D keys like arrow keys (w = up, a = left, s= down and d= right). Even though you will be using the WASD keys like arrow keys, these keys still map to U, L, D, and R respectively; for instance, pressing W will call makeMove with ' U ' as the letter parameter. - Watch this video to leam more about this method. Here is the expected output atter testing makeMove with input1. in, moving up: Implementation Notes - YOU MAY only update the methods updateOpenSpaces(), addRandomTile(), swipeLeft(), mergeLett(), transpose(), fipRows(), and makeMove(). - COMMENT all printing statements from Board.java - DO NOT add any instance variables to the Board class. - DO NOT add any public methods to the Board class. - DO NOT add/rename the project or package statements. - DO NOT change the class Board name. - YOU MAY add private methods to the Board class. - YOU MAY use any of the libraries provided in the zip file. - DO NOT use System.exit0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started