1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| public boolean tilt(Side side) { boolean changed; changed = false; int size = board.size(); if(side != Side.NORTH) board.setViewingPerspective(side); for(int col = 0; col < size; col ++) { for (int row = size - 2; row >= 0; row--) { int nulltile = 0; Tile t = board.tile(col, row); if(t != null) { for(int row_before = row + 1; row_before < size; row_before ++){ if(tile(col, row_before) == null) nulltile ++; } board.move(col, row + nulltile, t); changed = true; } } } for(int col = 0; col < size; col ++){ for (int row = size - 2; row >= 0; row--) { Tile t1 = board.tile(col, row); if(t1 != null){ Tile t2 = board.tile(col, row + 1); if(t2 != null && t1.value() == t2.value()){ board.move(col, row + 1, t1); changed = true; score += 2 * t2.value(); } } } } for(int col = 0; col < size; col ++) { for (int row = size - 2; row >= 0; row--) { int nulltile = 0; Tile t = board.tile(col, row); if(t != null) { for(int row_before = row + 1; row_before < size; row_before ++){ if(tile(col, row_before) == null) nulltile ++; } board.move(col, row + nulltile, t); changed = true; } } } if(side != Side.NORTH) board.setViewingPerspective(Side.NORTH); if (changed) { setChanged(); } return changed; }
|