gvprojects.igel.model
Class IgelGameKurmas

java.lang.Object
  extended by gvprojects.igel.model.IgelGameKurmas
All Implemented Interfaces:
IGameState, IIgelGame

public class IgelGameKurmas
extends java.lang.Object
implements IIgelGame, IGameState

Game engine for Igel Argern

Author:
Zachary Kurmas

Nested Class Summary
 
Nested classes/interfaces inherited from interface gvprojects.igel.model.IIgelGame
IIgelGame.GameEventListener
 
Constructor Summary
IgelGameKurmas(IgelGameParameters parameters)
          Constructor
IgelGameKurmas(IgelGameParameters parameters, java.io.InputStream input)
          Constructor allowing configuration from a file (or other stream source).
 
Method Summary
 void addGameEventListener(IIgelGame.GameEventListener listener)
          Add a IIgelGame.GameEventListener
 boolean canMoveHedgehog(int fromRow, int fromColumn)
          Return whether the the top hedgehog at [fromRow, fromColumn] can be moved forward.
 boolean canMoveHedgehog(int fromRow, int fromColumn, int toColumn)
          Return whether the the top hedgehog at [fromRow, fromColumn] can be moved to column toColumn.
 boolean canPlaceHedgehog(int row)
          returns true if the current player can place a hedgehog in row (applies to initial hedgehog placement only).
 boolean canSlideHedgehog(int fromRow, int fromColumn)
          Return true if the current player can slide the hedgehog at [fromRow, fromColumn]
 boolean canSlideHedgehog(int fromRow, int fromColumn, int toRow)
          Return true if the current player can slide the hedgehog at [fromRow, fromColumn] to [toRow, fromColumn].
 int currentDieValue()
          return the current value of the die
 java.lang.String currentMessage()
          Get the current message.
 int currentPlayer()
          Return the current player's number.
 ICellState getCell(int row, int column)
          return the ICellState object at the given location
 IGameState getState()
          get a read-only view of the game's current state.
 int hedgehogsPerPlayer()
          Return the number of hedgehogs per player.
 void moveHedgehog(int fromRow, int fromColumn, int toColumn)
          Move the top hedgehog at [fromRow, fromColumn] to column toColumn.
 int numColumns()
          return the number of columns on the board.
 int numPlayers()
          Return the number of players.
 int numRows()
          return the number of rows on the board.
 void passSidewaysMove()
          Pass the current user's sideways move.
 Phase phase()
          Return the current game phase.
 void placeHedgehog(int row)
          Make an initial placement of one of the current player's hedgehogs in row and increment the current player.
 void quickLayout()
          Make an initial placement of all hedgehogs in round-robin order.
 void setNextRolls(java.lang.Integer i)
          Set the value of the die rolls.
 void slideHedgehog(int fromRow, int fromColumn, int toRow)
          Slide the hedgehog at the top of the specified cell to the specified row.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IgelGameKurmas

public IgelGameKurmas(IgelGameParameters parameters)
Constructor

Parameters:
parameters - an object containing all of the game parameters (num players, number of hedgehogs, etc.)
Throws:
java.lang.IllegalArgumentException - if parameters is null, or any parameter has an illegal value.

IgelGameKurmas

public IgelGameKurmas(IgelGameParameters parameters,
                      java.io.InputStream input)
Constructor allowing configuration from a file (or other stream source).

Note: Not all parameters may be used. Typically, values specified in input override those values in parameters

Parameters:
parameters - game parameters specified by the current user (e.g., from the configuration dialog).
input - game parameters contained in a file (or other data stream).
Throws:
java.lang.IllegalArgumentException - if any parameter is null or has an illegal value
Method Detail

numRows

public int numRows()
Description copied from interface: IGameState
return the number of rows on the board.

Specified by:
numRows in interface IGameState
Returns:
the number of rows on the board.

numColumns

public int numColumns()
Description copied from interface: IGameState
return the number of columns on the board.

Specified by:
numColumns in interface IGameState
Returns:
the number of columns on the board.

numPlayers

public int numPlayers()
Description copied from interface: IGameState
Return the number of players.

Specified by:
numPlayers in interface IGameState
Returns:
the number of players

hedgehogsPerPlayer

public int hedgehogsPerPlayer()
Description copied from interface: IGameState
Return the number of hedgehogs per player.

Specified by:
hedgehogsPerPlayer in interface IGameState
Returns:
the number of hedgehogs per player.

phase

public Phase phase()
Description copied from interface: IGameState
Return the current game phase.

Specified by:
phase in interface IGameState
Returns:
the current game phase.

currentPlayer

public int currentPlayer()
Description copied from interface: IGameState
Return the current player's number.

Specified by:
currentPlayer in interface IGameState
Returns:
the current player's number

getCell

public ICellState getCell(int row,
                          int column)
return the ICellState object at the given location

Specified by:
getCell in interface IGameState
Parameters:
row - the row (indexed beginning at 0)
column - the column (indexed beginning at 0)
Returns:
the ICellState object at the given location
Throws:
java.lang.IllegalArgumentException - if row or column is invalid

canPlaceHedgehog

public boolean canPlaceHedgehog(int row)
Description copied from interface: IIgelGame
returns true if the current player can place a hedgehog in row (applies to initial hedgehog placement only).

Specified by:
canPlaceHedgehog in interface IIgelGame
Parameters:
row - the desired row
Returns:
true if the current player can place a hedgehog in row, false otherwise.

getState

public IGameState getState()
Description copied from interface: IIgelGame
get a read-only view of the game's current state.

Specified by:
getState in interface IIgelGame
Returns:
a read-only view of the game's current state.

placeHedgehog

public void placeHedgehog(int row)
Description copied from interface: IIgelGame
Make an initial placement of one of the current player's hedgehogs in row and increment the current player.

Specified by:
placeHedgehog in interface IIgelGame
Parameters:
row - the row

addGameEventListener

public void addGameEventListener(IIgelGame.GameEventListener listener)
Description copied from interface: IIgelGame
Add a IIgelGame.GameEventListener

Specified by:
addGameEventListener in interface IIgelGame
Parameters:
listener - the MessageChangeListener to add

currentDieValue

public int currentDieValue()
return the current value of the die

Specified by:
currentDieValue in interface IGameState
Returns:
the current value of the die

currentMessage

public java.lang.String currentMessage()
Get the current message.

Specified by:
currentMessage in interface IGameState
Returns:
the current message

canSlideHedgehog

public boolean canSlideHedgehog(int fromRow,
                                int fromColumn)
Description copied from interface: IIgelGame
Return true if the current player can slide the hedgehog at [fromRow, fromColumn]

Specified by:
canSlideHedgehog in interface IIgelGame
Parameters:
fromRow - the current row of the player's hedgehog.
fromColumn - the current column of the player's hedgehog.
Returns:
true if the current player can slide the hedgehog at [fromRow, fromColumn].

canSlideHedgehog

public boolean canSlideHedgehog(int fromRow,
                                int fromColumn,
                                int toRow)
Description copied from interface: IIgelGame
Return true if the current player can slide the hedgehog at [fromRow, fromColumn] to [toRow, fromColumn].

Specified by:
canSlideHedgehog in interface IIgelGame
Parameters:
fromRow - the current row of the player's hedgehog.
fromColumn - the current column of the player's hedgehog.
toRow - the destination row
Returns:
true if the current player can slide the hedgehog at [fromRow, fromColumn] to [toRow, fromColumn]

slideHedgehog

public void slideHedgehog(int fromRow,
                          int fromColumn,
                          int toRow)
Slide the hedgehog at the top of the specified cell to the specified row.

Specified by:
slideHedgehog in interface IIgelGame
Parameters:
fromRow - the current row of the player's hedgehog.
fromColumn - the current column of the player's hedgehog.
toRow - the destination row.
Throws:
java.lang.IllegalArgumentException - if any of the parameters are out of range.
IllegalMoveException - if the move is not valid.

canMoveHedgehog

public boolean canMoveHedgehog(int fromRow,
                               int fromColumn)
Description copied from interface: IIgelGame
Return whether the the top hedgehog at [fromRow, fromColumn] can be moved forward. Note, the implementation in IgelGameKurmas checks only that the hedgehog at [fromRow, fromColumn] may be moved. It does not check whether the hedgehog may move into [fromRow, fromColumn + 1]

Specified by:
canMoveHedgehog in interface IIgelGame
Parameters:
fromRow - the row
fromColumn - the column
Returns:
true if the the top hedgehog at [fromRow, fromColumn] can be moved forward.

canMoveHedgehog

public boolean canMoveHedgehog(int fromRow,
                               int fromColumn,
                               int toColumn)
Description copied from interface: IIgelGame
Return whether the the top hedgehog at [fromRow, fromColumn] can be moved to column toColumn.

Specified by:
canMoveHedgehog in interface IIgelGame
Parameters:
fromRow - the row
fromColumn - the column
toColumn - the proposed new column
Returns:
true if the the top hedgehog at [fromRow, fromColumn] can be moved to column toColumn

moveHedgehog

public void moveHedgehog(int fromRow,
                         int fromColumn,
                         int toColumn)
Description copied from interface: IIgelGame
Move the top hedgehog at [fromRow, fromColumn] to column toColumn.

Specified by:
moveHedgehog in interface IIgelGame
Parameters:
fromRow - the row
fromColumn - the column
toColumn - the proposed new column

passSidewaysMove

public void passSidewaysMove()
Description copied from interface: IIgelGame
Pass the current user's sideways move.

Specified by:
passSidewaysMove in interface IIgelGame

setNextRolls

public void setNextRolls(java.lang.Integer i)
Set the value of the die rolls. If i is null, roll a random value. If i is not null, then the die should return i

Specified by:
setNextRolls in interface IIgelGame
Parameters:
i - fix the die roll at i, or roll normally if i is null

quickLayout

public void quickLayout()
Make an initial placement of all hedgehogs in round-robin order. This method is used during development only as a shortcut for testing.