framework
Class BattleField

java.lang.Object
  extended by framework.BattleField

public class BattleField
extends java.lang.Object

A rectangular grid in which battles take place. Each location in the grid may be empty, or may contain one of the following: A red soldier, a blue soldier, or an obstacle.

Author:
(C) Fawzi Emad, 2010

Field Summary
static int BLUE_TEAM
          Blue Team Member is in the location queried
static int EMPTY
          The location queried is empty
static int OBSTACLE
          An obstacle is in the location queried
static int OUT_OF_BOUNDS
          The location queried is outside of the battle field
static int RED_TEAM
          Red Team Member is in the location queried
 
Method Summary
 void attack(int row, int col)
          A soldier calls this method to attack another soldier on the enemy team.
 int get(int row, int col)
          Returns the contents of a particular location on the battlefield
 int getCols()
          Returns the width of the battle field.
 int getRows()
          Returns the height of the battle field.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RED_TEAM

public static final int RED_TEAM
Red Team Member is in the location queried

See Also:
Constant Field Values

BLUE_TEAM

public static final int BLUE_TEAM
Blue Team Member is in the location queried

See Also:
Constant Field Values

EMPTY

public static final int EMPTY
The location queried is empty

See Also:
Constant Field Values

OUT_OF_BOUNDS

public static final int OUT_OF_BOUNDS
The location queried is outside of the battle field

See Also:
Constant Field Values

OBSTACLE

public static final int OBSTACLE
An obstacle is in the location queried

See Also:
Constant Field Values
Method Detail

attack

public void attack(int row,
                   int col)
A soldier calls this method to attack another soldier on the enemy team. Preconditions: 1. The location being attacked must be adjacent to the soldier who is attacking. 2. The location being attacked must contain an enemy soldier.

Parameters:
row - row of grid coordinate under attack
col - column of grid coordinate under attack

get

public int get(int row,
               int col)
Returns the contents of a particular location on the battlefield

Parameters:
row - row of location being queried
col - column of location being queried
Returns:
BattleField.RED_TEAM, BattleField.BLUE_TEAM, BattleField.EMPTY, BattleField.OBSTACLE, or BattleField.OUT_OF_BOUNDS

getRows

public int getRows()
Returns the height of the battle field.

Returns:
number of rows in the grid

getCols

public int getCols()
Returns the width of the battle field.

Returns:
number of columns in the grid


Web Accessibility