|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.common.model.FreeColGameObject
net.sf.freecol.common.model.Game
public class Game
The main component of the game model.
If an object of this class returns a non-null result to getViewOwner()
,
then this object just represents a view of the game from a single player's
perspective. In that case, some information might be missing from the model.
Field Summary |
---|
Fields inherited from class net.sf.freecol.common.model.FreeColObject |
---|
ID_ATTRIBUTE_TAG |
Constructor Summary | |
---|---|
Game(ModelController modelController,
javax.xml.stream.XMLStreamReader in,
java.lang.String viewOwnerUsername)
Initiate a new Game object from an XML-representation. |
Method Summary | |
---|---|
void |
addPlayer(Player player)
Adds the specified player to the game. |
boolean |
canAddNewPlayer()
Checks if a new Player can be added. |
boolean |
checkIntegrity()
Checks the integrity of this Game uninitialized objects . |
boolean |
equals(java.lang.Object o)
Need to overwrite behavior of equals inherited from FreeColGameObject, since two games are not the same if the have the same id. |
CombatModel |
getCombatModel()
Get the CombatModel value. |
Player |
getCurrentPlayer()
Gets the current player. |
java.util.List<Player> |
getEuropeanPlayers()
Returns all the European players known by the player of this game. |
Player |
getFirstPlayer()
Gets the first player in this game. |
FreeColGameObject |
getFreeColGameObject(java.lang.String id)
Gets the FreeColGameObject with the specified ID. |
java.util.Iterator<FreeColGameObject> |
getFreeColGameObjectIterator()
Gets an Iterator of every registered
FreeColGameObject . |
FreeColGameObjectListener |
getFreeColGameObjectListener()
|
FreeColGameObject |
getFreeColGameObjectSafely(java.lang.String id)
Get the FreeColGameObject with the given id or null. |
GameOptions |
getGameOptions()
Gets the GameOptions that is associated with this
Game . |
java.util.HashMap<java.lang.String,java.lang.Long> |
getGameStatistics()
Computes how many objects of each class have been created, to track memory leaks over time |
static int |
getInciteAmount(Player payingPlayer,
Player targetPlayer,
Player attackingPlayer)
Gets the amount of gold needed for inciting. |
Map |
getMap()
Gets the Map that is being used in this game. |
java.util.HashMap<java.lang.String,java.lang.Long> |
getMemoryStatistics()
|
ModelController |
getModelController()
Returns the Game's ModelController. |
NationOptions |
getNationOptions()
Get the NationOptions value. |
Player |
getNextPlayer()
Gets the next current player. |
int |
getNumberOfPlayers()
|
Player |
getPlayer(java.lang.String nationID)
Return a Player identified by it's nation. |
Player |
getPlayerAfter(Player beforePlayer)
Gets the player after the given player. |
Player |
getPlayerByName(java.lang.String name)
Gets a Player specified by a name. |
java.util.Iterator<Player> |
getPlayerIterator()
Gets an Iterator of every Player in this
game. |
java.util.List<Player> |
getPlayers()
Gets an Vector containing every Player in
this game. |
Settlement |
getSettlement(java.lang.String name)
Returns the first Settlement with the given name. |
boolean |
getSpanishSuccession()
Get the SpanishSuccession value. |
Turn |
getTurn()
|
Player |
getUnknownEnemy()
Returns the "Unknown Enemy" Player, which is used for privateers. |
Nation |
getVacantNation()
Returns a vacant nation. |
java.util.List<Nation> |
getVacantNations()
Get the VacantNations value. |
Player |
getViewOwner()
Returns the owner of this view of the game, or null if
this game has all the information. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
boolean |
isAllPlayersReadyToLaunch()
Checks if all players are ready to launch. |
boolean |
isClientTrusted()
Check if the clients are trusted or if the server should keep secrets in order to prevent cheating. |
boolean |
isNextPlayerInNewTurn()
Checks if the next player is in a new turn. |
boolean |
playerNameInUse(java.lang.String username)
Checks if the specified name is in use. |
FreeColGameObject |
removeFreeColGameObject(java.lang.String id)
Removes the FreeColGameObject with the specified ID. |
void |
removePlayer(Player player)
Removes the specified player from the game. |
void |
setCombatModel(CombatModel newCombatModel)
Set the CombatModel value. |
void |
setCurrentPlayer(Player newCp)
Sets the current player. |
void |
setFreeColGameObject(java.lang.String id,
FreeColGameObject freeColGameObject)
Registers a new FreeColGameObject with the specified ID. |
void |
setFreeColGameObjectListener(FreeColGameObjectListener freeColGameObjectListener)
|
void |
setMap(Map map)
Sets the Map that is going to be used in this game. |
void |
setNationOptions(NationOptions newNationOptions)
Set the NationOptions value. |
void |
setSpanishSuccession(boolean newSpanishSuccession)
Set the SpanishSuccession value. |
void |
setTurn(Turn newTurn)
|
void |
setUnknownEnemy(Player player)
Sets the "Unknown Enemy" Player, which is used for privateers. |
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject |
---|
addToRemoveElement, dispose, equals, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, setGame, setId, toSavedXML, toString, toXML, updateFreeColGameObject, updateID |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Game(ModelController modelController, javax.xml.stream.XMLStreamReader in, java.lang.String viewOwnerUsername) throws javax.xml.stream.XMLStreamException
Game
object from an XML-representation.
Note that this is used on the client side; the game is really a partial view of the server-side game.
modelController
- A controller object the model can use to make
actions not allowed from the model (generate random numbers
etc).in
- The XML stream to read the data from.viewOwnerUsername
- The username of the owner of this view of the
game.
javax.xml.stream.XMLStreamException
- if an error occured during parsing.ConnectController.login(String,
String, int)
Method Detail |
---|
public ModelController getModelController()
ModelController
valuepublic Player getUnknownEnemy()
Player
valuepublic void setUnknownEnemy(Player player)
player
- a Player
valuepublic final java.util.List<Nation> getVacantNations()
VacantNations
value.
List
valuepublic boolean isClientTrusted()
public Player getViewOwner()
null
if
this game has all the information. null
, then it means that this
Game
object has access to all information (ie is the
server model).
Player
using this Game
-object
as a view.public Settlement getSettlement(java.lang.String name)
Settlement
with the given name.
name
- The name of the Settlement
.
Settlement
or null
if there is no
known Settlement
with the specified name (the settlement
might not be visible to a client).public Turn getTurn()
public void setTurn(Turn newTurn)
public final CombatModel getCombatModel()
CombatModel
value.
CombatModel
valuepublic final void setCombatModel(CombatModel newCombatModel)
CombatModel
value.
newCombatModel
- The new CombatModel value.public void addPlayer(Player player)
player
- The Player
that shall be added to this
Game
.public void removePlayer(Player player)
player
- The Player
that shall be removed from this
Game
.public void setFreeColGameObject(java.lang.String id, FreeColGameObject freeColGameObject)
FreeColGameObject
with the specified ID.
id
- The unique ID of the FreeColGameObject
.freeColGameObject
- The FreeColGameObject
that shall
be added to this Game
.
java.lang.IllegalArgumentException
- If either id
or freeColGameObject
are
null.public void setFreeColGameObjectListener(FreeColGameObjectListener freeColGameObjectListener)
public FreeColGameObjectListener getFreeColGameObjectListener()
public FreeColGameObject getFreeColGameObject(java.lang.String id)
FreeColGameObject
with the specified ID.
id
- The identifier of the FreeColGameObject
.
FreeColGameObject
.
java.lang.IllegalArgumentException
- If id == null
, or id = ""
.public FreeColGameObject getFreeColGameObjectSafely(java.lang.String id)
FreeColGameObject
with the given id or null. This method
does NOT throw if the id is invalid.
id
- The id, may be null or invalid.
public FreeColGameObject removeFreeColGameObject(java.lang.String id)
FreeColGameObject
with the specified ID.
id
- The identifier of the FreeColGameObject
that
shall be removed from this Game
.
FreeColGameObject
that has been removed.
java.lang.IllegalArgumentException
- If id == null
, or id = ""
.public Map getMap()
Map
that is being used in this game.
Map
that is being used in this game or
null if no Map
has been created.public void setMap(Map map)
Map
that is going to be used in this game.
map
- The Map
that is going to be used in this game.public final NationOptions getNationOptions()
NationOptions
value.
NationOptions
valuepublic final void setNationOptions(NationOptions newNationOptions)
NationOptions
value.
newNationOptions
- The new NationOptions value.public Nation getVacantNation()
public Player getPlayer(java.lang.String nationID)
Player
identified by it's nation.
nationID
- The nation.
Player
of the given nation.public void setCurrentPlayer(Player newCp)
newCp
- The new current player.public Player getCurrentPlayer()
Player
currently
playing the Game
.
public Player getNextPlayer()
getCurrentPlayer()
public Player getPlayerAfter(Player beforePlayer)
beforePlayer
- The Player
before the
Player
to be returned.
Player
after the beforePlayer
in the list which determines the order each player becomes the
current player.getNextPlayer()
public boolean isNextPlayerInNewTurn()
true
if changing to the Player
given by getNextPlayer()
would increase the current
number of turns by one.public Player getFirstPlayer()
Player
that was first added to this
Game
.public java.util.Iterator<FreeColGameObject> getFreeColGameObjectIterator()
Iterator
of every registered
FreeColGameObject
.
This Iterator
should be iterated at least once
in a while since it cleans the FreeColGameObject
cache.
Iterator
containing every registered
FreeColGameObject
.setFreeColGameObject(java.lang.String, net.sf.freecol.common.model.FreeColGameObject)
public Player getPlayerByName(java.lang.String name)
Player
specified by a name.
name
- The name identifying the Player
.
Player
.public boolean playerNameInUse(java.lang.String username)
username
- The name.
public java.util.Iterator<Player> getPlayerIterator()
Iterator
of every Player
in this
game.
Iterator
.public java.util.List<Player> getPlayers()
Vector
containing every Player
in
this game.
Vector
.public int getNumberOfPlayers()
public java.util.List<Player> getEuropeanPlayers()
public boolean canAddNewPlayer()
Player
can be added.
public boolean isAllPlayersReadyToLaunch()
public final boolean getSpanishSuccession()
SpanishSuccession
value.
boolean
valuepublic final void setSpanishSuccession(boolean newSpanishSuccession)
SpanishSuccession
value.
newSpanishSuccession
- The new SpanishSuccession value.public boolean checkIntegrity()
Game
uninitialized objects
.
Detected problems gets written to the log.
true
if the Game
has
been loaded properly.public GameOptions getGameOptions()
GameOptions
that is associated with this
Game
.
getGameOptions
in class FreeColGameObject
GameOptions
-object as returned
by getGame().getGameOptions()
.public static int getInciteAmount(Player payingPlayer, Player targetPlayer, Player attackingPlayer)
payingPlayer
- The Player
paying for the incite.targetPlayer
- The Player
to be attacked by the
attackingPlayer
.attackingPlayer
- The player that would be receiving the money for
incite.
payingPlayer
to attackingPlayer
in
order for attackingPlayer
to attack
targetPlayer
.public static java.lang.String getXMLElementTagName()
public boolean equals(java.lang.Object o)
equals
in class FreeColGameObject
o
- The FreeColGameObject
to compare against this object.
FreeColGameObject
are equal and false otherwise.public java.util.HashMap<java.lang.String,java.lang.Long> getGameStatistics()
public java.util.HashMap<java.lang.String,java.lang.Long> getMemoryStatistics()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |