jrummikub.control
Class RoundControl

java.lang.Object
  extended by jrummikub.control.RoundControl
Direct Known Subclasses:
NetworkRoundControl

public class RoundControl
extends java.lang.Object

Controller that manages a single round of rummikub


Nested Class Summary
static class RoundControl.InvalidTurnInfo
          Table, stone sets and type of an invalid turn to allow a user to track his own errors
static class RoundControl.InvalidTurnType
          Enum summarizing the different types of invalid turns to set the correct panel message
 
Field Summary
protected  java.util.List<Connection> connections
           
private  Event1<Score> endOfRoundEvent
           
private  boolean mayPause
           
private  Event1<PlayerSettings> restartRoundEvent
           
protected  IRoundState roundState
           
private  Event1<IRoundState> roundStateUpdateEvent
           
private  ITurnControl turnControl
           
private  IView view
           
 
Constructor Summary
  RoundControl(IRoundState roundState, IView view)
          Create a new RoundControl using the given roundState and view
protected RoundControl(IRoundState roundState, IView view, boolean mayPause)
          Create a new RoundControl using the given roundState and view
 
Method Summary
 void abortRound()
          Abort round if a new one is started or a saved one is loaded
protected  void addTurnControlListeners(ITurnControl turnControl)
          Override this
 void continueRound()
          Continue a saved round after loading
protected  ITurnControl createTurnControl()
          Creates new turn control of the specified type
protected  void deal()
          Deal each player the number of stones specified in the game settings (numberOfStonesDealt)
protected  void doPrepareTurn()
          Prepare turn by setting the view components
(package private)  void endOfRound()
          Ends the current round and emits an event setting the score
protected  void endOfTurn(RoundControl.InvalidTurnInfo invalidTurnInfo)
          End the players turn
 IEvent1<Score> getEndOfRoundEvent()
          End the round
 IEvent1<PlayerSettings> getRestartRoundEvent()
          Emitted when the round is aborted and needs to be restarted
 IEvent1<IRoundState> getRoundStateUpdateEvent()
          Is emitted in network when a new turn starts
protected  void nextPlayer()
          Set the next player as active player if the round is not finished
protected  void prepareTurn()
          Prepare a player's turn by checking the player types and setting the correct turn control
protected  void redeal()
          Redeal stones and restart round if a player was allowed to redeal and chose to do so
private  void removeListeners()
          Removes all listeners form the connections
private  Score score()
          Calculate the score for the current round and the total game score
protected  void setRoundState(IRoundState state)
          Sets the current round state
protected  IView.BottomPanelType showStartTurnPanel()
           
 void startRound()
          Begin the round
protected  void startTurn()
          Start a players turn with the correct turn control
private static Pair<java.lang.Integer,java.lang.Integer> updateBestScore(Pair<java.lang.Integer,java.lang.Integer> bestScore, int stonePoints, int size)
          Update the best score to find the winner in case of special game end (everybody still has stones on hand)
private  void updateSidePanel()
          Update the side panel to show correct player order and heap size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

turnControl

private ITurnControl turnControl

roundState

protected IRoundState roundState

view

private IView view

restartRoundEvent

private Event1<PlayerSettings> restartRoundEvent

roundStateUpdateEvent

private Event1<IRoundState> roundStateUpdateEvent

endOfRoundEvent

private Event1<Score> endOfRoundEvent

connections

protected java.util.List<Connection> connections

mayPause

private boolean mayPause
Constructor Detail

RoundControl

public RoundControl(IRoundState roundState,
                    IView view)
Create a new RoundControl using the given roundState and view

Parameters:
roundState - initial round state
view - view used for user interaction

RoundControl

protected RoundControl(IRoundState roundState,
                       IView view,
                       boolean mayPause)
Create a new RoundControl using the given roundState and view

Parameters:
roundState - initial round state
view - view used for user interaction
mayPause - true when players are allowed to pause
Method Detail

getRoundStateUpdateEvent

public IEvent1<IRoundState> getRoundStateUpdateEvent()
Is emitted in network when a new turn starts

Returns:
the event

getEndOfRoundEvent

public IEvent1<Score> getEndOfRoundEvent()
End the round

Returns:
endOfRoundEvent

startRound

public void startRound()
Begin the round


continueRound

public void continueRound()
Continue a saved round after loading


abortRound

public void abortRound()
Abort round if a new one is started or a saved one is loaded


setRoundState

protected void setRoundState(IRoundState state)
Sets the current round state

Parameters:
state - to be set

showStartTurnPanel

protected IView.BottomPanelType showStartTurnPanel()

prepareTurn

protected void prepareTurn()
Prepare a player's turn by checking the player types and setting the correct turn control


doPrepareTurn

protected void doPrepareTurn()
Prepare turn by setting the view components


startTurn

protected void startTurn()
Start a players turn with the correct turn control


updateSidePanel

private void updateSidePanel()
Update the side panel to show correct player order and heap size


addTurnControlListeners

protected void addTurnControlListeners(ITurnControl turnControl)
Override this

Parameters:
turnControl - current turn control

createTurnControl

protected ITurnControl createTurnControl()
Creates new turn control of the specified type

Returns:
the new turn control

deal

protected void deal()
Deal each player the number of stones specified in the game settings (numberOfStonesDealt)


endOfTurn

protected void endOfTurn(RoundControl.InvalidTurnInfo invalidTurnInfo)
End the players turn

Parameters:
invalidTurnInfo - info about the player's last turn

nextPlayer

protected void nextPlayer()
Set the next player as active player if the round is not finished


endOfRound

void endOfRound()
Ends the current round and emits an event setting the score


removeListeners

private void removeListeners()
Removes all listeners form the connections


score

private Score score()
Calculate the score for the current round and the total game score

Returns:
the new score

updateBestScore

private static Pair<java.lang.Integer,java.lang.Integer> updateBestScore(Pair<java.lang.Integer,java.lang.Integer> bestScore,
                                                                         int stonePoints,
                                                                         int size)
Update the best score to find the winner in case of special game end (everybody still has stones on hand)

Parameters:
bestScore - of previous rounds
stonePoints - sum of points still left on hands
size - number of players in game (= size of score list in columns)
Returns:
Pair of maximum points and hand size

getRestartRoundEvent

public IEvent1<PlayerSettings> getRestartRoundEvent()
Emitted when the round is aborted and needs to be restarted

Returns:
the event

redeal

protected void redeal()
Redeal stones and restart round if a player was allowed to redeal and chose to do so