|
|||||||||
| 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 | |
|---|---|
protected CombatModel |
combatModel
The combat model this game uses. |
protected Player |
currentPlayer
The name of the player whose turn it is. |
protected FreeColGameObjectListener |
freeColGameObjectListener
|
protected java.util.HashMap<java.lang.String,FreeColGameObject> |
freeColGameObjects
Contains references to all objects created in this game. |
protected GameOptions |
gameOptions
|
private static java.util.logging.Logger |
logger
|
private Map |
map
|
protected ModelController |
modelController
|
private NationOptions |
nationOptions
Describe nationOptions here. |
protected int |
nextId
The next available ID, that can be given to a new FreeColGameObject. |
protected java.util.List<Player> |
players
Contains all the players in the game. |
private boolean |
spanishSuccession
Whether the War of Spanish Succession has already taken place. |
private Turn |
turn
|
private Player |
unknownEnemy
A virtual player to use with enemy privateers |
protected Player |
viewOwner
The owner of this view of the game, or null if this game
has all the information. |
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE |
| Constructor Summary | |
|---|---|
protected |
Game(Game game)
Minimal constructor, Just necessary to call parent constructor |
protected |
Game(Game game,
javax.xml.stream.XMLStreamReader in)
Minimal constructor, Just necessary to call parent constructor |
|
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 Gameuninitialized 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. |
private boolean |
fixIntegrity(java.util.List<java.lang.String> list)
Try to fix integrity problems |
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. |
protected void |
readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
Initialize this object from an XML-representation of this object. |
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. |
protected void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
This method writes an XML-representation of this object to the given stream. |
| Methods inherited from class net.sf.freecol.common.model.FreeColGameObject |
|---|
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, dispose, equals, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toString, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject, updateID |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
private Player unknownEnemy
protected java.util.List<Player> players
private Map map
protected GameOptions gameOptions
protected Player currentPlayer
protected Player viewOwner
null if this game
has all the information.
protected java.util.HashMap<java.lang.String,FreeColGameObject> freeColGameObjects
protected int nextId
FreeColGameObject.
private Turn turn
private NationOptions nationOptions
private boolean spanishSuccession
protected ModelController modelController
protected FreeColGameObjectListener freeColGameObjectListener
protected CombatModel combatModel
| Constructor Detail |
|---|
protected Game(Game game)
game -
protected Game(Game game,
javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
game -
javax.xml.stream.XMLStreamException
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.
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()
Gameuninitialized objects.
Detected problems gets written to the log.
true if the Game has
been loaded properly.private boolean fixIntegrity(java.util.List<java.lang.String> list)
public GameOptions getGameOptions()
GameOptions that is associated with this
Game.
getGameOptions in class FreeColGameObjectGameOptions-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.
protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
Player will be added
to that representation if showAll is set to
false.
toXMLImpl in class FreeColGameObjectout - The target stream.player - The Player this XML-representation should be
made for, or null if
showAll == true.showAll - Only attributes visible to player will be
added to the representation if showAll is set
to false.toSavedGame - If true then information that is only
needed when saving a game is added.
javax.xml.stream.XMLStreamException - if there are any problems writing to the
stream.
protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readFromXMLImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.public static java.lang.String getXMLElementTagName()
public boolean equals(java.lang.Object o)
equals in class FreeColGameObjecto - 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 | ||||||||