|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Game
The Game Class is the central core of the the Sokoban game. The Game class is a link between the user interface, the networking and the map.
Field Summary | |
protected SGui |
gui
The link to the Sokoban user interface. |
Constructor Summary | |
Game(SGui sokobanGUI)
Constructor - initializes the game class |
Method Summary | |
void |
changeLevel(java.lang.String level)
Processes a request to change the current level being played. |
protected void |
checkChangeLevelVotes(java.lang.String level)
Checks to see if the change level vote has completed. |
protected void |
checkRestartVotes()
Checks to see if the restart level vote has completed. |
void |
connectionClosed()
Informs the multiplayer dialog to display a connection closed dialog message. |
void |
doChangeLevel(java.lang.String level)
Tells the map class to load the level passed. |
void |
doRestartMap()
Perform the restart map operation. |
void |
endGame()
Closes any connection that is present and clears the map. |
java.lang.String |
getCurrentLevel()
Returns the name of the current level being played |
java.lang.String |
getFirstLevel()
Returns the name of the first level in the level list. |
java.lang.String[] |
getLevelList()
Returns a String array of the names of the levels in the level list. |
Robot |
getLocalRobot()
Returns the local Robot |
Square[][] |
getMap()
Returns the current Map. |
java.lang.String[] |
getMapString()
Returns the current Map. |
java.lang.String |
getNextLevel()
Returns the name of the next level. |
java.lang.String |
getPrevLevel()
Returns the name of the previous level. |
Robot[] |
getRobots()
Returns the robots currently in the map |
static java.lang.String[] |
getSaveDescriptions()
Returns a String array containing the save game descriptions. |
int |
getTime()
Returns the cumulative time spent on solving the current map (in seconds). |
int |
getTotalScore()
Returns the current totalScore |
java.lang.String |
getUserName()
Returns the current username |
void |
instantReplay()
Sends instantReplay message to the Map class Precondition: The game is in single player mode. |
boolean |
isActive()
Returns whether the game is active or not. |
boolean |
isClientConnected()
Indicates whether or not the client is connected to a multiplayer game. |
boolean |
isHosting()
Indicates whether or not the client is connected to a multiplayer game. |
boolean |
isMultiplayer()
Indicates whether or not the game is a multiplayer game. |
boolean |
isPaused()
Returns true if the map is currently paused, false otherwise. |
void |
levelCompleted()
This function tells the system that level has been completed and to therefore proceed to next level. |
void |
loadGame(int loadSlot)
This function allows the user to load a game from a previously saved game Precondition:none Postcondition:The previously played game is loaded and the map is set to the saved state |
void |
pauseTimer()
Sends pauseTimer message to the Map class Precondition: The game is not multiplayer Postcondition: The timer is paused. |
void |
postAcceptedChangeLevel(java.lang.String level,
int robotNum,
boolean accepted)
Sets a robot's change level flag to the accepted boolean passed. |
void |
postAcceptedRestart(int robotNum,
boolean accepted)
Sets a robot's restart level flag to the accepted boolean passed. |
void |
postChat(java.lang.String user,
java.lang.String msg)
This function displays the chat messages sent by the users. |
void |
postDisconnect(int robotNum)
Informs other users connected to a server of a client disconnecting and removes the client's robot from the map |
void |
postMove(int robotNum,
Direction dir)
This function posts the move made by the user on the map. |
void |
postNewUser(java.lang.String userName,
int robotNum)
Adds a user to the current game. |
void |
requestChangeLevel(java.lang.String levelName,
int nRobot)
Allows the user to agree or disagree to a change level request. |
void |
requestRestart(int nRobot)
Allows the user to agree or disagree to a restart level request. |
void |
restartMap()
Sends restartMap message to the Map class Precondition: None. |
void |
saveGame(int saveSlot,
java.lang.String description)
This function allows the user to save his progress in the game Precondition:User is engaged in a game Postcondition:The game is saved |
void |
setDebugMode(boolean mode)
Sets whether the getTime() method reports time as always 1 or if it returns the correct value. |
void |
setMapObserver(java.util.Observer obs)
Adds an observer to the current map |
void |
setUserName(java.lang.String name)
Sets the current userName to the passed name |
void |
startClient(java.lang.String ip,
int port,
MultiplayerDialog multiDiag)
Initilizes the client to connect to the server. |
void |
startMap(java.lang.String levelName)
This function initializes the map, adds the robot(s) to the map and then loads the level to be played. |
void |
startServer(int port,
MultiplayerDialog multiDiag)
Tells the Server to begin listening for connections. |
void |
startTimer()
Sends startTimer message to the Map class Precondition: The game is not multiplayer Postcondition: The timer is started. |
void |
stopMultiplayer()
Disconnects the client and sends the disconnect message if this game is a client or disconnects all clients connected to the server if this game is a server. |
void |
undoMove(int robotNum)
Sends undoMove message to the Map class. |
void |
updateDisplay()
Informs the GUI to update the window preconditons: none. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected SGui gui
Constructor Detail |
public Game(SGui sokobanGUI)
Method Detail |
public void levelCompleted()
public void saveGame(int saveSlot, java.lang.String description)
saveSlot
- the saved game slot to save todescription
- the description entered by the user describing the current
saved game.public void loadGame(int loadSlot)
loadSlot
- the saved game slot to be loaded frompublic void startMap(java.lang.String levelName)
levelName
- the name of the initial level to play
public void changeLevel(java.lang.String level)
level
- the name of the level to change to
public void doChangeLevel(java.lang.String level)
level
- String value associated with name of the level
public void requestChangeLevel(java.lang.String levelName, int nRobot)
levelName
- the name of the level to change tonRobot
- the robot number requesting the change
public void postAcceptedChangeLevel(java.lang.String level, int robotNum, boolean accepted)
level
- the name of the level to change torobotNum
- the robotnum of the user accepting or decliningaccepted
- true if the user accepts, false if not
protected void checkChangeLevelVotes(java.lang.String level)
level
- the name of the level to change to
public void postChat(java.lang.String user, java.lang.String msg)
user
- The name of the user sending the messagemsg
- The message sent by user
public void postDisconnect(int robotNum)
robotNum
- The robot number of the user disconnecting
public void postMove(int robotNum, Direction dir)
robotNum
- The id of the robot being moveddir
- The direction in which the robot moved
public void undoMove(int robotNum)
robotNum
- The id of the robot undoing a move
public void postNewUser(java.lang.String userName, int robotNum)
userName
- the name of the new userrobotNum
- the robot number of the new user
precondition: there is a multiplayer game running
postcondition: the new user has been added to the gamepublic java.lang.String[] getMapString()
Returns the current Map.
public Square[][] getMap()
Returns the current Map.
public Robot[] getRobots()
Returns the robots currently in the map
public void pauseTimer()
public void startTimer()
public boolean isPaused()
public void restartMap()
public void doRestartMap()
public void requestRestart(int nRobot)
nRobot
- the robot number requesting the change
public void postAcceptedRestart(int robotNum, boolean accepted)
robotNum
- the robotnum of the user accepting or decliningaccepted
- true if the user accepts, false if not
protected void checkRestartVotes()
public void instantReplay()
public void startServer(int port, MultiplayerDialog multiDiag)
public void stopMultiplayer()
public void startClient(java.lang.String ip, int port, MultiplayerDialog multiDiag)
ip
- The IP address to connect to.port
- The port to use in the connection.
public boolean isMultiplayer()
public boolean isHosting()
public boolean isClientConnected()
public java.lang.String getUserName()
public void setUserName(java.lang.String name)
name
- the name of a userpublic int getTotalScore()
public Robot getLocalRobot()
public void updateDisplay()
public void connectionClosed()
public boolean isActive()
public void endGame()
public int getTime()
public void setMapObserver(java.util.Observer obs)
obs
- the Observer to be added to the mappublic static java.lang.String[] getSaveDescriptions()
public java.lang.String[] getLevelList()
public java.lang.String getNextLevel()
public java.lang.String getPrevLevel()
public java.lang.String getFirstLevel()
public java.lang.String getCurrentLevel()
public void setDebugMode(boolean mode)
mode
- turns debug mode on or off
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |