cz.cvut.agents.rph.reversi
Class ReversiController

java.lang.Object
  extended by cz.cvut.agents.rph.core.GameController
      extended by cz.cvut.agents.rph.reversi.ReversiController
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class ReversiController
extends GameController

Controller of the Reversi game. Author: Ondrej Vanek Date: 10/3/12 Time: 10:04 AM


Field Summary
(package private) static java.lang.String AFTER_MOVE_DELAY_CHANGED
           
protected  int afterMoveDelay
          Delay in ms after each move.
protected  ReversiPlayerInterface currentPlayer
          Who is the first player.
(package private) static java.lang.String PLAY_PAUSE_ACTION_COMMAND
           
protected  ReversiPlayerInterface player1
          First player.
protected  ReversiPlayerInterface player2
          Second Player.
static java.lang.String RESTART_ACTION_COMMAND
           
protected  ReversiModel reversiModel
          Model of the game
private  long timeoutInMilis
          What is the timeout for one move?
 
Fields inherited from class cz.cvut.agents.rph.core.GameController
model
 
Constructor Summary
ReversiController(ReversiModel model, long timeoutInMilis, ReversiPlayerInterface player1, ReversiPlayerInterface player2)
          Constructs the controller for the Reversi game.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Something happened in the View - what was that?
protected  void afterMoveDelay()
          We should sleep a bit so that the user actually sees something from the game.
protected  void changeCurrentPlayer()
          PURE MAGIC! :)
 ReversiGameResult endGame(ReversiPlayerInterface timeoutPlayer, ReversiPlayerInterface errorPlayer)
          Method wrapping the endgame procedure - creation of result, update of model, etc.
protected  ReversiMove makeNextMove(ReversiPlayerInterface currentPlayer)
          Wrapping of next move calling.
 void restartGame()
          DUH, restart the game.
 ReversiGameResult run()
          Execute the game.
 ReversiGameResult run(boolean autostart)
          Runs the game
 void setAfterMoveDelay(int afterMoveDelay)
          sets the delay between moves to defined value in miliseconds.
protected  void switchPlayers()
          Switches first and second player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

afterMoveDelay

protected int afterMoveDelay
Delay in ms after each move.


reversiModel

protected ReversiModel reversiModel
Model of the game


timeoutInMilis

private long timeoutInMilis
What is the timeout for one move?


player1

protected ReversiPlayerInterface player1
First player.


player2

protected ReversiPlayerInterface player2
Second Player.


currentPlayer

protected ReversiPlayerInterface currentPlayer
Who is the first player.


PLAY_PAUSE_ACTION_COMMAND

static final java.lang.String PLAY_PAUSE_ACTION_COMMAND
See Also:
Constant Field Values

AFTER_MOVE_DELAY_CHANGED

static final java.lang.String AFTER_MOVE_DELAY_CHANGED
See Also:
Constant Field Values

RESTART_ACTION_COMMAND

public static final java.lang.String RESTART_ACTION_COMMAND
See Also:
Constant Field Values
Constructor Detail

ReversiController

public ReversiController(ReversiModel model,
                         long timeoutInMilis,
                         ReversiPlayerInterface player1,
                         ReversiPlayerInterface player2)
                  throws java.lang.Exception
Constructs the controller for the Reversi game.

Parameters:
model - Reversi game model.
timeoutInMilis - Timeout per move
player1 - Player 1.
player2 - Player 2.
Throws:
java.lang.Exception - Of course, something can go wrong - catch this guy to know what was it!
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Something happened in the View - what was that?


restartGame

public void restartGame()
                 throws java.lang.Exception
DUH, restart the game.

Throws:
java.lang.Exception

run

public ReversiGameResult run()
                      throws java.lang.Exception
Description copied from class: GameController
Execute the game.

Specified by:
run in class GameController
Returns:
return a game result.
Throws:
java.lang.Exception

run

public ReversiGameResult run(boolean autostart)
                      throws java.lang.Exception
Runs the game

Parameters:
autostart - set to true if you want the game to start immediately - typically, when no view is used.
Returns:
result of the game.
Throws:
java.lang.Exception - - if something goes wrong, catch it!

endGame

public ReversiGameResult endGame(ReversiPlayerInterface timeoutPlayer,
                                 ReversiPlayerInterface errorPlayer)
                          throws java.lang.Exception
Method wrapping the endgame procedure - creation of result, update of model, etc.

Parameters:
timeoutPlayer - who was the timeout player? Set to null if there wasn't one.
errorPlayer - who was the error player? Set to null if there wasn't one.
Returns:
result of the game.
Throws:
java.lang.Exception - well, you know...

changeCurrentPlayer

protected void changeCurrentPlayer()
PURE MAGIC! :)


switchPlayers

protected void switchPlayers()
                      throws java.lang.Exception
Switches first and second player. (typically after game restart).

Throws:
java.lang.Exception

makeNextMove

protected ReversiMove makeNextMove(ReversiPlayerInterface currentPlayer)
                            throws java.util.concurrent.TimeoutException,
                                   java.util.concurrent.ExecutionException,
                                   java.lang.InterruptedException
Wrapping of next move calling. Using Future to get the move after given timeout or sooner

Parameters:
currentPlayer - who is playing.
Returns:
Move of the currentPlayer.
Throws:
java.util.concurrent.TimeoutException - thrown if the player didn't decide in time
java.util.concurrent.ExecutionException - thrown if the was an Exception/Error thrown by the player.
java.lang.InterruptedException - thrown when the FutureTask has been interrupted. Shouldn't been happening.

afterMoveDelay

protected void afterMoveDelay()
                       throws java.lang.InterruptedException
We should sleep a bit so that the user actually sees something from the game.

Throws:
java.lang.InterruptedException

setAfterMoveDelay

public void setAfterMoveDelay(int afterMoveDelay)
sets the delay between moves to defined value in miliseconds.

Parameters:
afterMoveDelay -