gizmoball.gui
Class GamePlayModel

java.lang.Object
  extended by java.util.Observable
      extended by gizmoball.gui.GamePlayModel
All Implemented Interfaces:
CameraChanger

public class GamePlayModel
extends java.util.Observable
implements CameraChanger


Nested Class Summary
static class GamePlayModel.GameMode
          These values are the different modes the game can be in.
 
Field Summary
 double CAMERA_AMOUNT
          Increment of camera movement.
 int cameraPositionLimit
          The maximum allowed value of cameraPosition.
 java.lang.String currentDirectory
          The most recent file directory that was used to load / save.
 java.lang.String titleMessage
           
 
Method Summary
 void addKeyForGizmo(java.lang.Integer key, Gizmo giz)
          Adds link between specified key and specified Gizmo.
 void addToKeyDown(java.lang.Integer key)
          Adds key to keyDown.
 void changeCameraPosition(int index, int dir)
           
 void changeKeyForGameObject(java.lang.Integer key, GameObject go)
          This function links a key to a GameObject if no such link exists.
 void clearActives()
          Clear gizmos and triggers.
 GameObject closest(Vect3 initPos, Vect3 dir)
           
 void doKeyMapping(java.lang.Integer ke)
          Runs the UserActions mapped by ke.
 void edit()
          Changes back and forth between edit mode and play paused mode.
 void endDialog()
          Returns game mode to a previous mode upon end of dialog.
 void errorMessage(java.lang.String message)
          Notifies user of error.
 void escape()
          Either quit or exits to main menu.
 boolean findOutYesNo(java.lang.String message)
          Asks user whether he wants to do a certain action.
 Vect3 getCameraCoordinates()
           
 Vect3 getCameraLookAt()
          Returns the point at which the camera is looking.
 Vect3 getCameraPosition()
          Gets the current position of the camera (ignoring any transitory effects that the worlddrawer does)
 int getCameraPosition(int index)
           
 java.util.List<java.lang.Integer> getDownKeysForGameObject(GameObject g)
          Returns all keys (key down) associated to activate g.
 int getFrameRate()
           
 GamePlayModel.GameMode getGameMode()
           
 java.util.List<Gizmo> getGizmosForKey(java.lang.Integer ke)
          Returns all Gizmos activated by key.
 java.util.Set<java.lang.Integer> getKeyDown()
           
 java.util.List<java.lang.Integer> getKeysForGameObject(GameObject g)
          Returns all keys associated to activate g.
 boolean getShowWireframe()
           
 java.util.List<java.lang.Integer> getUpKeysForGameObject(GameObject g)
          Returns all keys (key up) associated to activate g.
 WorldModel getWorldModel()
           
 boolean hasKeyForGizmo(java.lang.Integer key, Gizmo giz)
          Returns t
 void init()
          Prepares to start game and shows the welcome screen.
 boolean isXMLFile(java.io.File file)
           
 java.util.Set<java.lang.Integer> keySet()
          Returns the key set of the key mapping.
 void load()
          Brings up a JFileChooser.
 void loadFromFile(java.io.File filename)
          Loads from file named filename.
 void loadKeyMappingsFromWorldModel()
          Loads key-to-action assignments from loaded WorldModel wm.
 void loadWM(WorldModel wm)
          Loads WorldModel.
 void newGame()
          Loads a default WorldModel.
 void pause()
          Pauses the game if unpaused, unpauses the game otherwise.
 void quit()
          Calls quit(true).
 void quit(boolean ask)
           
 void removeFromKeyDown(java.lang.Integer key)
          Removes key from keyDown.
 void removeKeyForGizmo(java.lang.Integer key, Gizmo go)
          Removes the link between specified key and specified Gizmo.
 void removeKeysForGizmo(Gizmo go)
          Removes all keys linked to specified Gizmo.
 void resetCameraPosition()
          Resets cameraPosition.
 void resetKeyPushNano()
          Resets counter for repushing keys.
 void resetWM()
          Resets wm, gr, default key mappings, and the list of Gizmos to activate.
 void runGame()
          Runs game.
 void save()
          Saves to currentFile if it exists.
 void saveAs()
          Brings up a JFileChooser.
 void saveToFile(java.io.File filename)
          Saves WorldModel contents to filename.
 void setCamera(Vect3 camera)
          Sets camera to the argument.
 void setCameraLookAt(Vect3 newLookAt)
          Sets camera's look to argument.
 void setFrameRate(int framerate)
           
 void setKeyMappingsToWorldModel()
          Sends the current key-to-actions mapping to the current WorldModel wm.
 void setMessage(java.lang.String msg)
          Sets title message.
 void setWalls()
          Sets currentWalls.
 void startDialog()
          Saves current mode and pauses game in preparation for a dialog box.
 void stopCamera()
          Confirms camera movement.
 void translateCamera(Vect3 translate)
          Translates camera by the argument.
 void updateCurrentFile(java.io.File filename)
          Updates currentFile and currentDirectory so that they reflect the most recent file and directory that was saved/loaded.
 boolean updateScreen()
          Notifies of whether game screen needs to be updated.
 double updatingInterval()
           
 void welcome()
          Opens welcome screen.
 void wireframe()
          Shows / hides wireframe.
 
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

titleMessage

public java.lang.String titleMessage

cameraPositionLimit

public final int cameraPositionLimit
The maximum allowed value of cameraPosition.

See Also:
Constant Field Values

CAMERA_AMOUNT

public final double CAMERA_AMOUNT
Increment of camera movement.

See Also:
Constant Field Values

currentDirectory

public java.lang.String currentDirectory
The most recent file directory that was used to load / save.

Method Detail

init

public void init()
Prepares to start game and shows the welcome screen.


keySet

public java.util.Set<java.lang.Integer> keySet()
Returns the key set of the key mapping.

Returns:
Unmodifiable copy of keyMapping.keySet()

getDownKeysForGameObject

public java.util.List<java.lang.Integer> getDownKeysForGameObject(GameObject g)
Returns all keys (key down) associated to activate g.

Parameters:
g -
Returns:
List of keys associated to activate g.

getGizmosForKey

public java.util.List<Gizmo> getGizmosForKey(java.lang.Integer ke)
Returns all Gizmos activated by key.

Parameters:
ke -
Returns:
All Gizmos activated by key

getKeysForGameObject

public java.util.List<java.lang.Integer> getKeysForGameObject(GameObject g)
Returns all keys associated to activate g.

Parameters:
g -
Returns:
List of keys associated to activate g.

getUpKeysForGameObject

public java.util.List<java.lang.Integer> getUpKeysForGameObject(GameObject g)
Returns all keys (key up) associated to activate g.

Parameters:
g -
Returns:
List of keys associated to activate g.

changeKeyForGameObject

public void changeKeyForGameObject(java.lang.Integer key,
                                   GameObject go)
This function links a key to a GameObject if no such link exists. If such a link exists, the link is removed. Since Balls cannot be activated, the GameObject must be instance of Gizmo.

Parameters:
key -
go -

removeKeysForGizmo

public void removeKeysForGizmo(Gizmo go)
Removes all keys linked to specified Gizmo.

Parameters:
go -

removeKeyForGizmo

public void removeKeyForGizmo(java.lang.Integer key,
                              Gizmo go)
Removes the link between specified key and specified Gizmo.

Parameters:
go -

addKeyForGizmo

public void addKeyForGizmo(java.lang.Integer key,
                           Gizmo giz)
Adds link between specified key and specified Gizmo.

Parameters:
go -

hasKeyForGizmo

public boolean hasKeyForGizmo(java.lang.Integer key,
                              Gizmo giz)
Returns t

Parameters:
key -
giz -
Returns:
key that returns KeyableAction that contains giz.

doKeyMapping

public void doKeyMapping(java.lang.Integer ke)
Runs the UserActions mapped by ke.

Parameters:
ke -

stopCamera

public void stopCamera()
Confirms camera movement.

Effects:
cameraMoving is set to false.

getCameraPosition

public Vect3 getCameraPosition()
Description copied from interface: CameraChanger
Gets the current position of the camera (ignoring any transitory effects that the worlddrawer does)

Specified by:
getCameraPosition in interface CameraChanger

resetCameraPosition

public void resetCameraPosition()
Resets cameraPosition.

Effects:
cameraPosition[0] = 0, cameraPosition[1] = 0

getCameraPosition

public int getCameraPosition(int index)
Returns:
cameraPosition
Requires:
0 <= index <= cameraPosition.length-1

changeCameraPosition

public void changeCameraPosition(int index,
                                 int dir)
Requires:
0 <= index <= cameraPosition.length-1
Effects:
cameraPosition

translateCamera

public void translateCamera(Vect3 translate)
Translates camera by the argument.

Specified by:
translateCamera in interface CameraChanger
Parameters:
translate -

setCamera

public void setCamera(Vect3 camera)
Sets camera to the argument.

Specified by:
setCamera in interface CameraChanger
Parameters:
camera -

setCameraLookAt

public void setCameraLookAt(Vect3 newLookAt)
Sets camera's look to argument.

Specified by:
setCameraLookAt in interface CameraChanger
Parameters:
newLookAt -

getCameraCoordinates

public Vect3 getCameraCoordinates()
Returns:
cameraCoordinates

getCameraLookAt

public Vect3 getCameraLookAt()
Returns the point at which the camera is looking.

Specified by:
getCameraLookAt in interface CameraChanger

setFrameRate

public void setFrameRate(int framerate)
Parameters:
framerate -
Effects:
Sets this.framerate to framerate.
Modifies:
this.framerate

getFrameRate

public int getFrameRate()
Returns:
framerate

getKeyDown

public java.util.Set<java.lang.Integer> getKeyDown()
Returns:
Unmodifiable copy of keyDown.

addToKeyDown

public void addToKeyDown(java.lang.Integer key)
Adds key to keyDown.

Parameters:
key -

removeFromKeyDown

public void removeFromKeyDown(java.lang.Integer key)
Removes key from keyDown.

Parameters:
key -

getGameMode

public GamePlayModel.GameMode getGameMode()
Returns:
mode

updateScreen

public boolean updateScreen()
Notifies of whether game screen needs to be updated. Screen should be updated if and only if at least one of the following holds - mode is PLAY - mode is PLAY_PAUSED - the camera is moving - the title is nontrivial

Returns:
true if and only if mode==GameMode.PLAY|| mode==GameMode.PLAY_PAUSED|| cameraMoving|| titleMessage != ""

getWorldModel

public WorldModel getWorldModel()
Returns:
wm

runGame

public void runGame()
Runs game.


resetKeyPushNano

public void resetKeyPushNano()
Resets counter for repushing keys.


welcome

public void welcome()
Opens welcome screen.


escape

public void escape()
Either quit or exits to main menu.


quit

public void quit()
Calls quit(true).

See Also:
void quit(boolean ask)

quit

public void quit(boolean ask)
Parameters:
ask - Exits the application. Asks user for confirmation if and only if ask is true.

findOutYesNo

public boolean findOutYesNo(java.lang.String message)
Asks user whether he wants to do a certain action.

Returns:
true if and only if the user answers yes.

startDialog

public void startDialog()
Saves current mode and pauses game in preparation for a dialog box.


endDialog

public void endDialog()
Returns game mode to a previous mode upon end of dialog.


errorMessage

public void errorMessage(java.lang.String message)
Notifies user of error.


wireframe

public void wireframe()
Shows / hides wireframe.


getShowWireframe

public boolean getShowWireframe()
Returns:
showWireframe

pause

public void pause()
Pauses the game if unpaused, unpauses the game otherwise.


edit

public void edit()
Changes back and forth between edit mode and play paused mode.


isXMLFile

public boolean isXMLFile(java.io.File file)
Parameters:
file -
Returns:
True if and only if file has extension ".xml"

save

public void save()
Saves to currentFile if it exists. Otherwise, it invokes saveAs().


saveAs

public void saveAs()
Brings up a JFileChooser.


saveToFile

public void saveToFile(java.io.File filename)
Saves WorldModel contents to filename.

Parameters:
filename -
Modifies:
currentFile, currentDirectory

newGame

public void newGame()
Loads a default WorldModel.


load

public void load()
Brings up a JFileChooser.

Effects:
Loaded chosen XML file or does nothing if no file was chosen.

loadFromFile

public void loadFromFile(java.io.File filename)
Loads from file named filename.

Parameters:
filename -
Requires:
filename to be a valid XML file.
Effects:
Updates WorldModel to the loaded file and starts a game based on that WorldModel.
Modifies:
WorldModel, currentFile, currentDirectory

updateCurrentFile

public void updateCurrentFile(java.io.File filename)
Updates currentFile and currentDirectory so that they reflect the most recent file and directory that was saved/loaded.

Parameters:
filename -
Modifies:
currentFile, currentDirectory

loadWM

public void loadWM(WorldModel wm)
Loads WorldModel.

Parameters:
this.wm -

setMessage

public void setMessage(java.lang.String msg)
Sets title message.

Parameters:
msg -
Effects:
titleMessage, messageStart

setWalls

public void setWalls()
Sets currentWalls.


loadKeyMappingsFromWorldModel

public void loadKeyMappingsFromWorldModel()
Loads key-to-action assignments from loaded WorldModel wm.

Requires:
wm!=null

setKeyMappingsToWorldModel

public void setKeyMappingsToWorldModel()
Sends the current key-to-actions mapping to the current WorldModel wm.


resetWM

public void resetWM()
Resets wm, gr, default key mappings, and the list of Gizmos to activate.

Parameters:
wm -
Modifies:
wm, keyMapping, toActivate

clearActives

public void clearActives()
Clear gizmos and triggers.


updatingInterval

public double updatingInterval()
Returns:
A number corresponding to the number of times per second an update should occur.

closest

public GameObject closest(Vect3 initPos,
                          Vect3 dir)
Returns:
the visible GameObject in ws closest to initPos in direction dir returns null if no visible object found