Class Map

java.lang.Object
  |
  +--java.util.Observable
        |
        +--Map
Direct Known Subclasses:
Tutorial

public class Map
extends java.util.Observable

The Map class represents the environment in which the robot will be able to move around in. It will hold the location of crates, walls, incinerators, & robots.


Field Summary
protected  Level level
          The name of the level.
protected  boolean loading
          The boolean to let sounds know if the game is loading or not
protected  java.util.Vector robots
          The robots is a Vector of up to 4 robots to represent each of the players in multiplayer mode.
 
Constructor Summary
Map(Game owner)
          Creates a new Map object with given coordinates of crates, walls and incinerators.
 
Method Summary
 void addRobot(Robot robot)
          Adds a Robot to the robot vector.
 int calculateScore(int robot)
          An algorithm will compute a score using a combination of game variables.
 void changeLevel(java.lang.String newlevel)
          Player choses a different level map to play.
 Square[][] getMap()
          Returns a 2-dimensional array containing the Squares representing the current map.
 Robot getRobot(int robotNum)
          Removes the Robot with a robotNumber equal to the passed robotNum from the robot vector.
 Robot[] getRobots()
          Returns an array of the Robots on the map.
 int getTime()
          Returns the current time spent solving the map in seconds.
 void instantReplay()
          Shows the sequence of movements a robot has taken up to the current point in the level.
 boolean isPaused()
          Returns true if the map is currently paused, false otherwise.
 void moveRobot(int robotNum, Direction direction)
          Moves the robot in the direction passed.
 void pauseTimer()
          Pauses the timer.
 void removeRobot(int robot)
          Removes the Robot with a robotNumber equal to the passed robotNum from the robot list.
 void restartLevel()
          Current level is reset.
 void setTimer(int newTime)
          Sets the timer to the value passed.
 void startTimer()
          Starts the timer.
 java.lang.String[] toStringArray()
          Returns a 2-dimensional array containing the values representing the current map.
 void undoMove(int robotNum)
          Updates the board to reflect the state before the robot's last move.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

level

protected Level level
The name of the level.

robots

protected java.util.Vector robots
The robots is a Vector of up to 4 robots to represent each of the players in multiplayer mode.

loading

protected boolean loading
The boolean to let sounds know if the game is loading or not
Constructor Detail

Map

public Map(Game owner)
Creates a new Map object with given coordinates of crates, walls and incinerators.
Method Detail

moveRobot

public void moveRobot(int robotNum,
                      Direction direction)
Moves the robot in the direction passed.
Parameters:
robotNum - the robot to move
dir - the direction to move
Pre-conditions: none
Post-conditions: robot moves in the direction passed

addRobot

public void addRobot(Robot robot)
Adds a Robot to the robot vector.
Parameters:
robot - the robot to be added to the robot vector
Pre-conditions: none
Post-conditions: a Robot is added to the robot vector

removeRobot

public void removeRobot(int robot)
Removes the Robot with a robotNumber equal to the passed robotNum from the robot list.
Parameters:
robot - the robot number to be removed from the robot vector
Pre-conditions: there are existing robots
Post-conditions: the robot with robotNumber = robotNum is removed

getRobot

public Robot getRobot(int robotNum)
Removes the Robot with a robotNumber equal to the passed robotNum from the robot vector.
Parameters:
robotNum - the robot number to be found in the robots vector
Returns:
the Robot with the passed robot number
Pre-conditions: there are existing robots
Post-conditions: the robot with robotNumber = robotNum is removed

restartLevel

public void restartLevel()
Current level is reset. All crates are in orginal positions and robot back at start location. All statistics are reset to 0.
Pre-conditions: none
Post-conditions: Current level is started from the beginning. crates and robot(s) are at orginal positions. stats for level are reset to zero.

instantReplay

public void instantReplay()
Shows the sequence of movements a robot has taken up to the current point in the level.
Pre-conditions: single-player with only 1 Robot on the robots vector; the Robot has moved at least once
Post-conditions: the level is returned to its state prior to the instant replay call

changeLevel

public void changeLevel(java.lang.String newlevel)
Player choses a different level map to play.
Parameters:
level - String value associated with name of the level
Pre-conditions: none
Post-conditions: new map object is loaded for play

calculateScore

public int calculateScore(int robot)
An algorithm will compute a score using a combination of game variables. The algorithm will compute the number of crates incinerated in the current level and multiply each crate by 100. The number of robot moves will be subtracted from that value, and then divided by time in seconds.
Parameters:
robot - int value associated with player's robot
Pre-conditions: Level is complete, no crates are present
Post-conditions: adds robot's level score to robot's cumulative game score.

pauseTimer

public void pauseTimer()
Pauses the timer.
Pre-conditions: timer is running
Post-conditions: timer stopped

startTimer

public void startTimer()
Starts the timer.
Pre-conditions: timer stopped
Post-conditions: timer is running

setTimer

public void setTimer(int newTime)
Sets the timer to the value passed.

isPaused

public boolean isPaused()
Returns true if the map is currently paused, false otherwise.
Returns:
returns whether the map is paused or not

undoMove

public void undoMove(int robotNum)
Updates the board to reflect the state before the robot's last move.
Parameters:
robotNum - the robot number who performed the undo
Precondition:MoveTracker is not empty
Postcondition:the board is updated to reflect the state of the board before the robot's last move

toStringArray

public java.lang.String[] toStringArray()

Returns a 2-dimensional array containing the values representing the current map.

Returns:
the values representing the current map

getMap

public Square[][] getMap()

Returns a 2-dimensional array containing the Squares representing the current map.

Returns:
Returns a copy of the current map

getRobots

public Robot[] getRobots()

Returns an array of the Robots on the map.

Returns:
the Robots playing on the current map

getTime

public int getTime()

Returns the current time spent solving the map in seconds.

Returns:
the amount of time spent in seconds