Package net.sf.colossus.game
Class Player
- java.lang.Object
-
- net.sf.colossus.game.Player
-
- Direct Known Subclasses:
PlayerClientSide
,PlayerServerSide
public class Player extends java.lang.Object
A player in a game. This class holds all information describing a player in a game, such as the current legions and the score. Instances of this class are always bound to an instance ofGame
. TODO there is an excessive amount of methods around the markersAvailable list.
-
-
Field Summary
Fields Modifier and Type Field Description private PlayerColor
color
The label of the color we use.private boolean
dead
Set to true if the player is dead.private boolean
deadBeforeSave
Only needed during loading of a game.private Game
game
The game this information belongs to.private java.util.List<Legion>
legions
The current legions owned by this player.private java.util.SortedSet<java.lang.String>
markersAvailable
Sorted set of available legion markers for this player.private int
mulligansLeft
private java.lang.String
name
A name for this player for UI purposes and as identifier.private int
number
The number of the player in the game.private java.lang.String
playersEliminated
A string representing all players eliminated by this player.private int
score
private MasterHex
startingTower
The starting tower of the player.private java.lang.String
type
The type of player: local human, AI or network.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLegion(Legion legion)
void
addMarkerAvailable(java.lang.String markerId)
void
addPlayerElim(Player player)
boolean
canTitanTeleport()
void
clearMarkersAvailable()
java.lang.String
getAngelBasename()
Return the full basename for an angel of this player.PlayerColor
getColor()
boolean
getDeadBeforeSave()
During loading of a game, this player was already dead in the game before saving.java.lang.String
getFirstAvailableMarker()
Game
getGame()
Legion
getLegionByMarkerId(java.lang.String markerId)
java.util.List<? extends Legion>
getLegions()
TODO should be List, but currently subclasses still use more specific types TODO should be unmodifiable, but at least PlayerServerSide.die(Player)
still removes itemsjava.util.Set<java.lang.String>
getMarkersAvailable()
int
getMulligansLeft()
java.lang.String
getName()
int
getNumber()
int
getNumCreatures()
int
getNumLegions()
int
getNumMarkersAvailable()
java.lang.String
getPlayersElim()
int
getScore()
java.lang.String
getShortColor()
MasterHex
getStartingTower()
java.lang.String
getTitanBasename()
Return the full basename for the titan of this player.Legion
getTitanLegion()
int
getTitanPower()
int
getTotalPointValue()
Return the total value of all of this player's creatures.java.lang.String
getType()
boolean
hasLegion(java.lang.String markerId)
boolean
hasMoved()
Check if the player has already moved.boolean
hasTeleported()
boolean
isAI()
boolean
isDead()
boolean
isHuman()
boolean
isLocalHuman()
boolean
isMarkerAvailable(java.lang.String markerId)
boolean
isNetwork()
boolean
isNone()
void
removeAllLegions()
void
removeLegion(Legion legion)
void
removeMarkerAvailable(java.lang.String markerId)
java.lang.String
selectMarkerId(java.lang.String markerId)
Removes the selected marker from the list of those available.void
setColor(PlayerColor color)
void
setDead(boolean dead)
void
setDeadBeforeSave(boolean val)
void
setMulligansLeft(int mulligansLeft)
void
setName(java.lang.String name)
void
setPlayersElim(java.lang.String playersEliminated)
void
setScore(int score)
void
setStartingTower(MasterHex startingTower)
void
setType(java.lang.String type)
java.lang.String
toString()
Overridden for debug/logging purposes.
-
-
-
Field Detail
-
game
private final Game game
The game this information belongs to.
-
name
private java.lang.String name
A name for this player for UI purposes and as identifier.
-
legions
private final java.util.List<Legion> legions
The current legions owned by this player.
-
number
private final int number
The number of the player in the game. TODO clarify if this is just an arbitrary number (in which case we might want to get rid of it) or the actual turn sequence
-
dead
private boolean dead
Set to true if the player is dead. TODO check if that isn't equivalent to not having legions anymore
-
deadBeforeSave
private boolean deadBeforeSave
Only needed during loading of a game. Pulled up to game anyway, getNumLivingLegions needs it during loading.
-
startingTower
private MasterHex startingTower
The starting tower of the player. TODO this should be kind-of final: once a tower has been assigned, it shouldn't change anymore -- but assigning the towers has probably to happen a while after all players are created. We could at least at an assertion into the setter that it is allowed to change the value only if it was not set before.
-
color
private PlayerColor color
The label of the color we use. TODO this should really be an object representing a markerset TODO similar tostartingTower
this should be set only once but probably can't be set in the constructor.
-
type
private java.lang.String type
The type of player: local human, AI or network. TODO make typesafe version TODO shouldn't this be final? It should be possible to set that in the constructor. Unless we have to allow changes e.g. for humans dropping out of the game (in which case the todo should be read as "add some documentation regarding that ;-) ).
-
playersEliminated
private java.lang.String playersEliminated
A string representing all players eliminated by this player. The format is just a sequence of the short, two-character versions of the colors, e.g. "BkRd". TODO this should really be a List
-
mulligansLeft
private int mulligansLeft
-
score
private int score
-
markersAvailable
private final java.util.SortedSet<java.lang.String> markersAvailable
Sorted set of available legion markers for this player.
-
-
Constructor Detail
-
Player
public Player(Game game, java.lang.String playerName, int number)
-
-
Method Detail
-
getGame
public Game getGame()
-
getLegions
public java.util.List<? extends Legion> getLegions()
TODO should be List, but currently subclasses still use more specific types TODO should be unmodifiable, but at least PlayerServerSide.die(Player)
still removes items
-
getNumber
public int getNumber()
-
getName
public java.lang.String getName()
-
setName
public void setName(java.lang.String name)
-
isDead
public boolean isDead()
-
setDead
public void setDead(boolean dead)
-
getDeadBeforeSave
public boolean getDeadBeforeSave()
During loading of a game, this player was already dead in the game before saving. No client needs to be created for this player, and all legion activities/reveals are skipped.- Returns:
- True if player was dead
-
setDeadBeforeSave
public void setDeadBeforeSave(boolean val)
-
setType
public void setType(java.lang.String type)
-
getType
public java.lang.String getType()
-
isHuman
public boolean isHuman()
-
isLocalHuman
public boolean isLocalHuman()
-
isNetwork
public boolean isNetwork()
-
isNone
public boolean isNone()
-
isAI
public boolean isAI()
-
setStartingTower
public void setStartingTower(MasterHex startingTower)
-
getStartingTower
public MasterHex getStartingTower()
-
setColor
public void setColor(PlayerColor color)
-
getColor
public PlayerColor getColor()
-
getShortColor
public java.lang.String getShortColor()
-
getPlayersElim
public java.lang.String getPlayersElim()
-
setPlayersElim
public void setPlayersElim(java.lang.String playersEliminated)
-
addPlayerElim
public void addPlayerElim(Player player)
-
getLegionByMarkerId
public Legion getLegionByMarkerId(java.lang.String markerId)
-
hasLegion
public boolean hasLegion(java.lang.String markerId)
-
getTitanLegion
public Legion getTitanLegion()
-
addLegion
public void addLegion(Legion legion)
-
removeLegion
public void removeLegion(Legion legion)
-
removeAllLegions
public void removeAllLegions()
-
addMarkerAvailable
public void addMarkerAvailable(java.lang.String markerId)
-
removeMarkerAvailable
public void removeMarkerAvailable(java.lang.String markerId)
-
clearMarkersAvailable
public void clearMarkersAvailable()
-
getMarkersAvailable
public java.util.Set<java.lang.String> getMarkersAvailable()
-
getNumMarkersAvailable
public int getNumMarkersAvailable()
-
getFirstAvailableMarker
public java.lang.String getFirstAvailableMarker()
-
isMarkerAvailable
public boolean isMarkerAvailable(java.lang.String markerId)
-
selectMarkerId
public java.lang.String selectMarkerId(java.lang.String markerId)
Removes the selected marker from the list of those available. Returns the markerId if it was present, or null if it was not.
-
getNumCreatures
public int getNumCreatures()
-
toString
public java.lang.String toString()
Overridden for debug/logging purposes.- Overrides:
toString
in classjava.lang.Object
-
setMulligansLeft
public void setMulligansLeft(int mulligansLeft)
-
getMulligansLeft
public int getMulligansLeft()
-
setScore
public void setScore(int score)
-
getScore
public int getScore()
-
getTitanPower
public int getTitanPower()
-
canTitanTeleport
public boolean canTitanTeleport()
-
getTotalPointValue
public int getTotalPointValue()
Return the total value of all of this player's creatures.
-
hasTeleported
public boolean hasTeleported()
-
hasMoved
public boolean hasMoved()
Check if the player has already moved.- Returns:
- true iff at least one legion of the player has been moved
-
getNumLegions
public int getNumLegions()
-
getTitanBasename
public java.lang.String getTitanBasename()
Return the full basename for the titan of this player.
-
getAngelBasename
public java.lang.String getAngelBasename()
Return the full basename for an angel of this player.
-
-