public abstract class GameMaster extends ObservableGame
HeartsGameMaster
, which is
a specialization of this class.
It provides core features such as:
jpleal@fc.up.pt
Modifier and Type | Class and Description |
---|---|
(package private) static class |
GameMaster.GameStage
Enumeration representing the stages of the game.
|
Modifier and Type | Field and Description |
---|---|
(package private) static java.util.Map<java.lang.String,java.lang.Integer> |
COUNTER |
Modifier | Constructor and Description |
---|---|
protected |
GameMaster()
Create a game and assign it an id.
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsPlayers()
Is this game still accepting players?
|
void |
addPlayer(Player player)
Adds given player to this game.
|
protected abstract void |
beforeRoundConclusion()
This method is invoked before concluding the round,
after all players have played.
|
protected abstract void |
checkCards(java.lang.String nick,
java.util.List<Card> cards)
Check if these cards can be played at this moment.
|
(package private) void |
concludeRound()
Conclude round by
broadcasting the conclusion event,
updating points for all players,
setting turn for the next round
|
(package private) void |
dealCards()
Deal cards to each player, set turn (if needed) and notify all players
|
boolean |
expired()
Has this game expired? I.e.
|
protected CardComparator |
getCardComparator()
The card comparator used in this game.
|
protected abstract GamePlayingStrategy |
getCardGameStrategy()
A game playing strategy for this kind of game.
|
protected Card |
getCardOnTable(java.lang.String nick)
Convenience method to retrieve the single card on table
of player with given nick.
|
protected CardCollection |
getCardsOnTable(java.lang.String nick)
Retrieve cards on table of player with given nick.
|
protected abstract int |
getCardsPerPlayer()
Number of cards each player receives at the start
|
protected CardCollection |
getDeck()
The deck of cards used by this game, backed by the defined card comparator.
|
static long |
getExpirationtime()
Time in milliseconds for a game to expire.
|
java.lang.String |
getGameId()
A string to identify this particular game instance.
|
protected abstract java.lang.String |
getGameName()
The name of this kind of game.
|
protected CardCollection |
getHand(java.lang.String nick)
Get a cards in given player's hand.
|
GameInfo |
getInfo()
Information describing this game.
|
protected java.lang.String |
getMode()
Retrieve current game mode.
|
protected java.lang.String |
getNickWithTurn()
The nick of the player currently with the turn to play.
|
protected abstract int |
getNumberOfPlayers()
Number of players in this game.
|
protected java.util.List<java.lang.String> |
getPlayerNicks()
A list with the nicks of players in this game.
|
protected abstract int |
getRoundPoints(java.lang.String nick)
Points collected by the player with given nick
in the last round.
|
protected int |
getRoundsCompleted()
Number of rounds completed in this game.
|
CardSuit |
getSuitToFollow()
Convenience method with suit to follow: the suit of the
first card played in this round.
|
protected abstract java.lang.String |
getWinner()
Who is the winner of this game?
This method is invoked if game
hasEnded() . |
protected abstract boolean |
hasEnded()
Has this games ended?
|
protected abstract java.lang.String |
initialTurnInRound()
In turn based games, provides the nick of the player player
to play in the next round.
|
protected abstract boolean |
isWithTurns()
Do players play in turn, one after the other,
in the order they were given in the constructor?
Or can they play in any order?
|
(package private) java.lang.String |
makeGameId()
Generate a string id for a game instance
using the game name as prefix and a counter.
|
protected CardCollection |
newCardCollection()
Convenience method to create a new empty card collection backed by the
this games's
CardComparator . |
(package private) java.lang.String |
nextInTurn()
Return the next nick in the list of players.
|
protected java.lang.String |
nickWithMostPoints()
Nick of player with most points, usually the winner.
|
void |
playCard(java.lang.String nick,
Card card)
Convenience method to play a single card.
|
void |
playCards(java.lang.String nick,
java.util.List<Card> cards)
Play your cards.
|
protected void |
sendCards(java.lang.String nick,
CardCollection cards)
Send to player with the given nick the given card collection.
|
static void |
setExpirationtime(long expirationTime)
Change time in milliseconds for a game to expire.
|
protected void |
setMode(java.lang.String mode)
Change current game mode.
|
protected abstract void |
startGame()
Method invoked when all players joined the game.
|
(package private) void |
startPlaying()
Start playing this game: change stage to PLAYING, start the game
and update players.
|
addObserver, broadcast, broadcast, broadcast, notify
public static long getExpirationtime()
public static void setExpirationtime(long expirationTime)
expirationTime
- to set.public java.lang.String getGameId()
public final GameInfo getInfo()
public final boolean expired()
true
if expired; false
otherwise.protected CardComparator getCardComparator()
DefaultCardComparator
but may be redefined by concrete game rules.protected CardCollection getDeck()
CardCollection.getDeck()
but
concrete game rules may redefine this method to remove some card values, add
other cards such as jokers, or use a double deck.public boolean acceptsPlayers()
true
if accepting, false
otherwisepublic final void addPlayer(Player player) throws CardGameException
player
- to add.CardGameException
- if not in preparing stage or if player already in game.final void startPlaying()
final void dealCards()
protected final void sendCards(java.lang.String nick, CardCollection cards)
nick
- of player.cards
- to send.public final void playCard(java.lang.String nick, Card card) throws CardGameException
playCards(String, List)
.nick
- of player.card
- to be played.CardGameException
- if some game rule is violated.public final void playCards(java.lang.String nick, java.util.List<Card> cards) throws CardGameException
nick
- of player.cards
- to be played.CardGameException
- if some game rule is violatedjava.lang.String nextInTurn()
void concludeRound()
protected CardCollection newCardCollection()
CardComparator
.protected java.util.List<java.lang.String> getPlayerNicks()
protected java.lang.String getNickWithTurn()
protected java.lang.String getMode()
protected void setMode(java.lang.String mode)
mode
- to set.protected CardCollection getHand(java.lang.String nick)
nick
- holding cards.protected CardCollection getCardsOnTable(java.lang.String nick)
nick
- of player.protected Card getCardOnTable(java.lang.String nick)
nick
- of playerpublic CardSuit getSuitToFollow()
null
if there are no cards on the table.null
.protected int getRoundsCompleted()
protected java.lang.String nickWithMostPoints()
protected abstract GamePlayingStrategy getCardGameStrategy()
protected abstract java.lang.String getGameName()
protected abstract int getNumberOfPlayers()
protected abstract int getCardsPerPlayer()
protected abstract boolean isWithTurns()
true
if game is with turns; false
otherwise.protected abstract void startGame()
protected abstract void checkCards(java.lang.String nick, java.util.List<Card> cards) throws CardGameException
nick
- of player.cards
- to check.CardGameException
- if a rule was violated.protected abstract void beforeRoundConclusion()
protected abstract int getRoundPoints(java.lang.String nick)
nick
- of player.protected abstract java.lang.String initialTurnInRound()
protected abstract boolean hasEnded()
true
if game ended; false
otherwise.protected abstract java.lang.String getWinner()
hasEnded()
.java.lang.String makeGameId()