Browse Source

Fix: Forgoten copy semantict to tiles and color

tags/v1.0
Christos Houtouridis 5 years ago
parent
commit
f89d442dcc
2 changed files with 22 additions and 15 deletions
  1. +3
    -3
      src/net/hoo2/auth/dsproject/snake/Apple.java
  2. +19
    -12
      src/net/hoo2/auth/dsproject/snake/Board.java

+ 3
- 3
src/net/hoo2/auth/dsproject/snake/Apple.java View File

@@ -35,7 +35,7 @@ public class Apple {
Apple (int appleId, int appleTileId, String color, int points) {
this.appleId = appleId;
this.appleTileId = appleTileId;
this.color = color;
this.color = new String(color);
this.points = points;
}
/** Copy constructor
@@ -44,7 +44,7 @@ public class Apple {
Apple (Apple a) {
appleId = a.getAppleId ();
appleTileId = a.getAppleTileId ();
color = a.getColor ();
color = new String (a.getColor ());
points = a.getPoints ();
}
/** @} */
@@ -92,7 +92,7 @@ public class Apple {
* }</pre>
* would be better and far less error prone.
* In order to support this style of color encoding we have to strict the
* color names to lower case letters and also convert user input.
* color names to lower case letters and also "low case-convert" the user input.
* We also update the points sign to make calculations easier.
* @see setColor
*/


+ 19
- 12
src/net/hoo2/auth/dsproject/snake/Board.java View File

@@ -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


Loading…
Cancel
Save