|
|
@@ -6,9 +6,9 @@ import java.lang.Math; |
|
|
|
* @class Board
|
|
|
|
* @brief The game's board representation.
|
|
|
|
*
|
|
|
|
* The board in a square collection of tiles numbered in a
|
|
|
|
* The board is a square collection of tiles numbered in a
|
|
|
|
* boustrophedon (zig-zag) way. A number of snakes, ladders
|
|
|
|
* and apples which called elements are placed on the board
|
|
|
|
* and apples which we called elements are placed on the board
|
|
|
|
* for each game.
|
|
|
|
*
|
|
|
|
* @author Christos Choutouridis 8997
|
|
|
@@ -82,7 +82,7 @@ public class Board { |
|
|
|
ladders = new Ladder[B.getLadders().length];
|
|
|
|
apples = new Apple[B.getApples().length];
|
|
|
|
// Copy B's guts into new memory
|
|
|
|
setTiles(B.getTiles()); // primitive
|
|
|
|
copyTiles(B.getTiles());
|
|
|
|
copySnakes(B.getSnakes());
|
|
|
|
copyLadders(B.getLadders());
|
|
|
|
copyApples(B.getApples());
|
|
|
@@ -110,15 +110,7 @@ public class Board { |
|
|
|
* @param tiles Source of tiles to use
|
|
|
|
* @note This has to be called if the board is default constructed
|
|
|
|
*/
|
|
|
|
void setTiles (int[][] tiles) {
|
|
|
|
// Check if we need allocation
|
|
|
|
if (this.tiles == null)
|
|
|
|
this.tiles = new int[N][M];
|
|
|
|
// Assign values
|
|
|
|
for (int i =0 ; i<N ; ++i)
|
|
|
|
for (int j =0 ; j<M ; ++j)
|
|
|
|
this.tiles[i][j] = tiles[i][j];
|
|
|
|
}
|
|
|
|
void setTiles (int[][] tiles) { this.tiles = tiles; }
|
|
|
|
|
|
|
|
/** Get reference to snakes */
|
|
|
|
Snake[] getSnakes() { return snakes; }
|
|
|
@@ -147,6 +139,21 @@ public class Board { |
|
|
|
*/
|
|
|
|
void setApples(Apple[] apples) { this.apples = apples; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy tiles
|
|
|
|
* @param tiles Source of tiles to use
|
|
|
|
* @note This has to be called if the board is default constructed
|
|
|
|
*/
|
|
|
|
void copyTiles (int[][] tiles) {
|
|
|
|
// Check if we need allocation
|
|
|
|
if (this.tiles == null)
|
|
|
|
this.tiles = new int[N][M];
|
|
|
|
// Copy-assign the values
|
|
|
|
for (int i =0 ; i<N ; ++i)
|
|
|
|
for (int j =0 ; j<M ; ++j)
|
|
|
|
this.tiles[i][j] = tiles[i][j];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy snakes (deep copy)
|
|
|
|
* @param snakes Source of snakes to use
|
|
|
|