gui
Class RushHourDomain

java.lang.Object
  extended by gui.RushHourDomain

public class RushHourDomain
extends java.lang.Object

The domain of the Rush Hour GUI handles intermediate communication not directly with the GUI but imperative to GUI functionality. These methods can only be called by classes within the gui package and are helper methods to the GUIs functionality.


Constructor Summary
RushHourDomain()
           
 
Method Summary
static void loadGame(java.lang.Object file, RushHourGameBoard gameBoard)
          Loads a saved game from the given input file.
static void recurseThroughSolution(java.util.Vector<java.lang.String> buildDirections, java.util.HashMap<java.lang.String,java.lang.String> validMoves, java.util.HashMap<java.lang.String,java.lang.String> directionsForValidMoves, java.lang.String nextState)
          Since the instructions will be in reverse order, recurse backward through all instructions and then add them to the vector of directions.
static void saveGame(java.io.File file, RushHourGameBoard gameBoard)
          Saves the current game board to the specified file.
static java.awt.Point simplifyPoint(java.awt.Point clicked, int guiWidth, int width, int guiHeight, int height)
          Simplifies the three-digit (x, y) coordinate retrieved from a location on the GUI to a single-digit (x, y) coordinate that corresponds to coordinates within the game board object.
static java.awt.Point unsimplifyPoint(java.awt.Point coordinates, int guiWidth, int width, int guiHeight, int height)
          Unsimplifies the single-digit (x, y) coordinate retrieved from a coordinate within the game board object to a three-digit (x, y) location that corresponds to the GUI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RushHourDomain

public RushHourDomain()
Method Detail

loadGame

public static void loadGame(java.lang.Object file,
                            RushHourGameBoard gameBoard)
                     throws RushHourException,
                            java.io.IOException,
                            java.lang.NumberFormatException
Loads a saved game from the given input file.

Parameters:
file - The file to be read from.
gameBoard - The empty game board to load into.
Throws:
RushHourException - A characteristic of the vehicle given in the data file is invalid.
java.lang.ArrayIndexOutOfBoundsException - The coordinate given in the data file for placing this vehicle is invalid.
java.io.IOException - An error occured when reading the next line from the data file.
java.lang.NumberFormatException - A number given in the data file was not an integer greater than zero.

saveGame

public static void saveGame(java.io.File file,
                            RushHourGameBoard gameBoard)
                     throws java.io.IOException
Saves the current game board to the specified file.

Parameters:
file - The file to be written to.
gameBoard - The game board to be written to the file.
Throws:
java.io.IOException - An error occured when reading the next line from the data file.

recurseThroughSolution

public static void recurseThroughSolution(java.util.Vector<java.lang.String> buildDirections,
                                          java.util.HashMap<java.lang.String,java.lang.String> validMoves,
                                          java.util.HashMap<java.lang.String,java.lang.String> directionsForValidMoves,
                                          java.lang.String nextState)
Since the instructions will be in reverse order, recurse backward through all instructions and then add them to the vector of directions.

Parameters:
buildDirections - The vector that the directions will be added to for output to the console.
validMoves - The hash map that contains board states for attaining valid moves.
directionsForValidMoves - The hash map that contains directions for valid moves.
nextState - The next state to follow on the hash map.

unsimplifyPoint

public static java.awt.Point unsimplifyPoint(java.awt.Point coordinates,
                                             int guiWidth,
                                             int width,
                                             int guiHeight,
                                             int height)
Unsimplifies the single-digit (x, y) coordinate retrieved from a coordinate within the game board object to a three-digit (x, y) location that corresponds to the GUI.

Parameters:
coordinates - The single-digit point from the GUI.
guiWidth - The width of the GUI board.
width - The width of the board. param guiHeight the height of the GUI board.
height - The height of the board.
Returns:
The unsimplified point.

simplifyPoint

public static java.awt.Point simplifyPoint(java.awt.Point clicked,
                                           int guiWidth,
                                           int width,
                                           int guiHeight,
                                           int height)
Simplifies the three-digit (x, y) coordinate retrieved from a location on the GUI to a single-digit (x, y) coordinate that corresponds to coordinates within the game board object.

Parameters:
clicked - The three-digit point from the GUI.
guiWidth - The width of the GUI board.
width - The width of the board. param guiHeight the height of the GUI board.
height - The height of the board.
Returns:
The simplified point.