es.ucm.fdi.hysteria.gui
Class Controller

java.lang.Object
  extended by es.ucm.fdi.hysteria.gui.Controller

public class Controller
extends java.lang.Object

This class provides an interface to communicate a given Game with any number of GUIs. It also provides with methods to represent the old Commands.

Author:
MiniSandor

Field Summary
protected  java.util.Properties _config
           
protected  java.util.Deque<Game> _future
           
protected  Game _game
           
protected  java.util.Set<GUIHandler> _guis
           
protected  java.util.Deque<Game> _history
           
protected  Item _key
           
protected  Message _lastMessage
           
protected  boolean _online
           
protected  java.io.ObjectInputStream _onlineIos
           
protected  java.io.ObjectOutputStream _onlineOos
           
protected  java.net.Socket _socket
           
 
Constructor Summary
Controller(Game theGame, GUIHandler gui)
          Builds a controller with a given game and an initial GUI
Controller(Game theGame, java.util.Properties config, GUIHandler gui)
          Creates a controller with a given game, a given config and an initial GUI
 
Method Summary
 void addGUI(GUIHandler gui)
          Adds a new gui to the list of guis
 void clearEvents()
           
 void commandClose(GUIHandler owner, Game.Direction dir)
          Tries to close an obstacle in a given direction
 void commandCloseWith(GUIHandler owner, Game.Direction dir, Item item)
          Tries to close an obstacle in a given direction with a given item
 void commandDrop(Item item)
          Tries to drop an item
 void commandGo(GUIHandler owner, Game.Direction dir)
          Tries to move in a given direction
 void commandOpen(GUIHandler owner, Game.Direction dir)
          Tries to open an obstacle in a given direction
 void commandOpenWith(GUIHandler owner, Game.Direction dir, Item item)
          Tries to open an obstacle in a given direction with a given item
 void commandPresent(GUIHandler owner, Item item)
           
 void commandRedo(GUIHandler owner)
          Tries to redo an action
 void commandTake(GUIHandler owner, Item item)
          Tries to take an item
 void commandTalk(java.lang.String topic)
           
 void commandUndo(GUIHandler owner)
          Tries to undo an action
 void commandUse(GUIHandler owner, Item item)
           
 void commandUseWith(GUIHandler owner, Item item1, Item item2)
           
 void connect(java.lang.String user, java.lang.String pass)
           
 void disconnect()
           
 java.lang.String getEvents()
           
 java.lang.String getGameTitle()
           
 java.lang.String getInfo()
           
 java.util.Vector<java.lang.String> getTopics()
           
 java.util.Vector<UserFileData> getUserFilesVector()
           
 boolean hasEvents()
           
 boolean isOnline()
           
 boolean loadGame(java.lang.String path)
          Loads a new game
 boolean saveGame(java.lang.String path)
          Tries to save the game
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_game

protected Game _game

_config

protected java.util.Properties _config

_guis

protected java.util.Set<GUIHandler> _guis

_key

protected Item _key

_socket

protected java.net.Socket _socket

_online

protected boolean _online

_onlineOos

protected java.io.ObjectOutputStream _onlineOos

_onlineIos

protected java.io.ObjectInputStream _onlineIos

_lastMessage

protected Message _lastMessage

_history

protected java.util.Deque<Game> _history

_future

protected java.util.Deque<Game> _future
Constructor Detail

Controller

public Controller(Game theGame,
                  GUIHandler gui)
Builds a controller with a given game and an initial GUI

Parameters:
theGame - The game
gui - The Gui

Controller

public Controller(Game theGame,
                  java.util.Properties config,
                  GUIHandler gui)
Creates a controller with a given game, a given config and an initial GUI

Parameters:
theGame - The game
config - The config
gui - The Gui
Method Detail

addGUI

public void addGUI(GUIHandler gui)
Adds a new gui to the list of guis

Parameters:
gui - The new gui

hasEvents

public boolean hasEvents()

getEvents

public java.lang.String getEvents()

clearEvents

public void clearEvents()

isOnline

public boolean isOnline()

saveGame

public boolean saveGame(java.lang.String path)
Tries to save the game

Parameters:
path - The path where to save the game

loadGame

public boolean loadGame(java.lang.String path)
Loads a new game

Parameters:
path - The path to the savegame

connect

public void connect(java.lang.String user,
                    java.lang.String pass)

disconnect

public void disconnect()

getUserFilesVector

public java.util.Vector<UserFileData> getUserFilesVector()
                                                  throws java.io.IOException,
                                                         java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getGameTitle

public java.lang.String getGameTitle()
Returns:
The game title

getInfo

public java.lang.String getInfo()
Returns:
The game info

commandGo

public void commandGo(GUIHandler owner,
                      Game.Direction dir)
Tries to move in a given direction

Parameters:
owner - The GUI owner of the command
dir - The direction

commandOpen

public void commandOpen(GUIHandler owner,
                        Game.Direction dir)
Tries to open an obstacle in a given direction

Parameters:
owner - The GUI owner of the command
dir - The direction

commandOpenWith

public void commandOpenWith(GUIHandler owner,
                            Game.Direction dir,
                            Item item)
Tries to open an obstacle in a given direction with a given item

Parameters:
owner - The GUI owner of the command
dir - The direction
item - The item

commandClose

public void commandClose(GUIHandler owner,
                         Game.Direction dir)
Tries to close an obstacle in a given direction

Parameters:
owner - The GUI owner of the command
dir - The direction

commandCloseWith

public void commandCloseWith(GUIHandler owner,
                             Game.Direction dir,
                             Item item)
Tries to close an obstacle in a given direction with a given item

Parameters:
owner - The GUI owner of the command
dir - The direction
item - The item

commandUndo

public void commandUndo(GUIHandler owner)
Tries to undo an action

Parameters:
owner - The GUI owner of the command

commandRedo

public void commandRedo(GUIHandler owner)
Tries to redo an action

Parameters:
owner - The GUI owner of the command

commandTake

public void commandTake(GUIHandler owner,
                        Item item)
Tries to take an item

Parameters:
owner - The GUI owner of the command
item - The item

commandDrop

public void commandDrop(Item item)
Tries to drop an item

Parameters:
item - The item

commandUse

public void commandUse(GUIHandler owner,
                       Item item)

commandUseWith

public void commandUseWith(GUIHandler owner,
                           Item item1,
                           Item item2)

getTopics

public java.util.Vector<java.lang.String> getTopics()

commandTalk

public void commandTalk(java.lang.String topic)

commandPresent

public void commandPresent(GUIHandler owner,
                           Item item)