Get RobotChase at SourceForge.net. Fast, secure and Free Open Source software downloads

org.gcs.robot
Class RCModel

java.lang.Object
  extended by java.util.Observable
      extended by org.gcs.robot.RCModel

public class RCModel
extends Observable

The RCModel class models the game board as a two dimensional array. The array contains height rows and width columns. Public constants indicate the meaning of an array element; a value of two or more represents a collision. The player's position is a Point representing the current row & column. The player's moves are handled by the move() methods. Overloaded versions of move() are used for mouse input.

Author:
John B. Matthews

Field Summary
static int BOMB
          This cell contains a bomb
static int EMPTY
          This cell is empty
static int MINTILE
          The smallest permitted board is 8x8.
static int POST
          This cell contains an electified post
static int ROBOT
          This cell contains a robot
static int WRECK
          This cell is a collision among two or more robots
 
Constructor Summary
RCModel(int width, int height)
          Construct a game board with the given dimensions.
 
Method Summary
 int[][] getBoard()
          Return the game board array.
 int getDeadRobots()
          Return the curent score.
 int getHeight()
          Return the game board Height in Tiles.
 int getLevel()
          Return the curent game level.
 int getLiveRobots()
          Return the number of robots left on this level.
 Point getPosition()
          Return the player's current position as a java.awt.Point.
 int getSafeJumps()
          Return the number of safe jumps left.
 int getWidth()
          Return the game board Width in Tiles.
 void initLevel()
          Initialize the current level and notify any observers.
 boolean lost()
          Return true if the player has died; false otherwise.
 void move()
          Move by jumping to a random location.
 boolean move(int key)
          Move in the given direction.
 boolean move(int row, int col)
          Move toward the specified row and column.
 void newLevel()
          Advance to the next level and initialize it.
 void resetGame()
          Reset the game and initialize the first level.
 void resizeArray(int width, int height)
          Resize the game board array.
 void restoreGame(int level, int score, int jumps)
          Restore the game and initialize the current level.
 boolean won()
          Return true if the player has won; false otherwise.
 
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

MINTILE

public static final int MINTILE
The smallest permitted board is 8x8.

See Also:
Constant Field Values

POST

public static final int POST
This cell contains an electified post

See Also:
Constant Field Values

BOMB

public static final int BOMB
This cell contains a bomb

See Also:
Constant Field Values

EMPTY

public static final int EMPTY
This cell is empty

See Also:
Constant Field Values

ROBOT

public static final int ROBOT
This cell contains a robot

See Also:
Constant Field Values

WRECK

public static final int WRECK
This cell is a collision among two or more robots

See Also:
Constant Field Values
Constructor Detail

RCModel

public RCModel(int width,
               int height)
Construct a game board with the given dimensions.

Parameters:
width - board width measured in tiles
height - board height measured in tiles
Method Detail

resizeArray

public void resizeArray(int width,
                        int height)
Resize the game board array. Notification is deferred to give observers an opportunity to adjust. The observer may call initLevel() when ready.

Parameters:
width - board width measured in tiles
height - board height measured in tiles

resetGame

public void resetGame()
Reset the game and initialize the first level.


restoreGame

public void restoreGame(int level,
                        int score,
                        int jumps)
Restore the game and initialize the current level.

Parameters:
level - the previous level
score - the previous score
jumps - the previous jumps

newLevel

public void newLevel()
Advance to the next level and initialize it.


initLevel

public void initLevel()
Initialize the current level and notify any observers.


getLevel

public int getLevel()
Return the curent game level.


getDeadRobots

public int getDeadRobots()
Return the curent score.


getLiveRobots

public int getLiveRobots()
Return the number of robots left on this level.


getSafeJumps

public int getSafeJumps()
Return the number of safe jumps left.


getBoard

public int[][] getBoard()
Return the game board array.


getWidth

public int getWidth()
Return the game board Width in Tiles.


getHeight

public int getHeight()
Return the game board Height in Tiles.


getPosition

public Point getPosition()
Return the player's current position as a java.awt.Point. This point represents a two-dimensional array index: point.x holds the column index and point.y holds the row index.

Returns:
the player's board position in row, column order

lost

public boolean lost()
Return true if the player has died; false otherwise.


won

public boolean won()
Return true if the player has won; false otherwise.


move

public boolean move(int key)
Move in the given direction. Non-numeric values are ignored.

Parameters:
key - a numeric keypad key code (96-105)
Returns:
true if a safe move was possible

move

public boolean move(int row,
                    int col)
Move toward the specified row and column.

Parameters:
row - the given row
col - the given column
Returns:
true if a safe move was possible

move

public void move()
Move by jumping to a random location.


Get RobotChase at SourceForge.net. Fast, secure and Free Open Source software downloads

Copyright © 2007 Gem City Software. Distributed under the terms of the GPL