|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.cvut.agents.rph.core.GameController
cz.cvut.agents.rph.reversi.ReversiController
public class ReversiController
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 |
---|
protected int afterMoveDelay
protected ReversiModel reversiModel
private long timeoutInMilis
protected ReversiPlayerInterface player1
protected ReversiPlayerInterface player2
protected ReversiPlayerInterface currentPlayer
static final java.lang.String PLAY_PAUSE_ACTION_COMMAND
static final java.lang.String AFTER_MOVE_DELAY_CHANGED
public static final java.lang.String RESTART_ACTION_COMMAND
Constructor Detail |
---|
public ReversiController(ReversiModel model, long timeoutInMilis, ReversiPlayerInterface player1, ReversiPlayerInterface player2) throws java.lang.Exception
model
- Reversi game model.timeoutInMilis
- Timeout per moveplayer1
- Player 1.player2
- Player 2.
java.lang.Exception
- Of course, something can go wrong - catch this guy to know what was it!Method Detail |
---|
public void actionPerformed(java.awt.event.ActionEvent e)
public void restartGame() throws java.lang.Exception
java.lang.Exception
public ReversiGameResult run() throws java.lang.Exception
GameController
run
in class GameController
java.lang.Exception
public ReversiGameResult run(boolean autostart) throws java.lang.Exception
autostart
- set to true if you want the game to start immediately - typically, when no view is used.
java.lang.Exception
- - if something goes wrong, catch it!public ReversiGameResult endGame(ReversiPlayerInterface timeoutPlayer, ReversiPlayerInterface errorPlayer) throws java.lang.Exception
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.
java.lang.Exception
- well, you know...protected void changeCurrentPlayer()
protected void switchPlayers() throws java.lang.Exception
java.lang.Exception
protected ReversiMove makeNextMove(ReversiPlayerInterface currentPlayer) throws java.util.concurrent.TimeoutException, java.util.concurrent.ExecutionException, java.lang.InterruptedException
Future
to get the move after given timeout or sooner
currentPlayer
- who is playing.
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.protected void afterMoveDelay() throws java.lang.InterruptedException
java.lang.InterruptedException
public void setAfterMoveDelay(int afterMoveDelay)
afterMoveDelay
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |