Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * * * Moves the tile at position ( x , y ) as far up as possible. * * Rules for Tilt: *
Moves the tile at position x y as far up as possible.
Rules for Tilt:
If two Tiles are adjacent in the direction of motion and have
the same value, they are merged into one Tile of twice the original
value and that new value is added to the score instance variable
A tile that is the result of a merge will not merge again on that
tilt. So each move, every tile will only ever be part of at most one
merge perhaps zero
When three adjacent tiles in the direction of motion have the same
value, then the leading two tiles in the direction of motion merge,
and the trailing tile does not.
public void moveTileUpAsFarAsPossibleint x int y
Tile currTile board.tilex y;
int myValue currTile.value;
int targetY y;
TODO: Tasks and Fill in this function.
while targetY board.size && board.tilex targetY null
targetY;
if targetY y
Tile tileAbove board.tilex targetY ;
if tileAbove null && tileAbove.wasMerged && tileAbove.value currTile.value
Merge tiles
int mergedValue currTile.value;
Tile mergedTile Tile.createmergedValue x targetY ;
board.movex targetY mergedTile;
else
Move the tile up
board.movex targetY, currTile;
code isn't merging the tiles but moving them
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started