Package org.swtpra1.amazongame
Class Board
- java.lang.Object
-
- org.swtpra1.amazongame.Board
-
- All Implemented Interfaces:
java.io.Serializable
public class Board extends java.lang.Object implements java.io.Serializable
Describes the state of the pieces on the board at a given time.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int[][]
generateInitialBoard(int rows, int cols)
Generates the array representation of a board of size rows x cols.int
getGameSizeColumns()
Getter method for the number of columns.int
getGameSizeRows()
Getter method for the number of rows.int[][]
getSquares()
Getter method for the int array representing the current board.void
move(Square start, Square end, Player player)
Frees the source square and takes the target square and marks it with player id.void
movePiece(Turn turn)
Executes a given turn on a board by moving the players piece accordingly and blocking the shot square.void
setSquares(int[][] squares)
Setter method for the int array representing the current board.void
shoot(Square shot)
Blocks a given square.java.lang.String
toString()
-
-
-
Constructor Detail
-
Board
public Board(int rows, int columns)
Represents a Board of size pRows x pColumns.- Parameters:
rows
- how many rows the board hascolumns
- how many columns the board has
-
Board
public Board(Board originalBoard)
Dummy constructor to reliably clone a Board object.- Parameters:
originalBoard
- the Board to be cloned
-
-
Method Detail
-
getGameSizeColumns
public int getGameSizeColumns()
Getter method for the number of columns.- Returns:
- number of columns
-
getGameSizeRows
public int getGameSizeRows()
Getter method for the number of rows.- Returns:
- number of rows
-
getSquares
public int[][] getSquares()
Getter method for the int array representing the current board.- Returns:
- two dimensional integer array
-
setSquares
public void setSquares(int[][] squares)
Setter method for the int array representing the current board.- Parameters:
squares
- the new board
-
movePiece
public void movePiece(Turn turn)
Executes a given turn on a board by moving the players piece accordingly and blocking the shot square. Does NOT check for validity and may mess up the state if turn is invalid- Parameters:
turn
-
-
move
public void move(Square start, Square end, Player player)
Frees the source square and takes the target square and marks it with player id.- Parameters:
start
- starting squareend
- target squareplayer
- player who's moving
-
shoot
public void shoot(Square shot)
Blocks a given square.- Parameters:
shot
- target square
-
generateInitialBoard
public static int[][] generateInitialBoard(int rows, int cols)
Generates the array representation of a board of size rows x cols.- Parameters:
rows
- number of rowscols
- number of columns- Returns:
- 2-dimensional integer array
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-