Class GameInfo

java.lang.Object
net.sf.colossus.webcommon.GameInfo

public class GameInfo extends Object
One object of this this class represents a game for which players/users have enrolled to play it together. It starts in state "PROPOSED" as type either instantly or scheduled. Then its state will change along the sequence of states PROPOSED, DUE, ACTIVATED, STARTING, READY_TO_CONNECT, RUNNING, ENDING as denoted in the GameState enum. The actual running/starting of the game will be handled by different classes, namely GameOnServer and (to be done) GameOnClient. The same class is also used at client side, but only part of the data is used there (e.g. the user has only a name, not a socket).
Author:
Clemens Katzer
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • nextFreeGameId

      private static int nextFreeGameId
    • gameId

      private String gameId
    • type

      private GameInfo.GameType type
    • state

      private GameInfo.GameState state
    • oldState

      private GameInfo.GameState oldState
      temporary backup during startingAttempt
    • startingUser

      private User startingUser
    • portNr

      private int portNr
    • hostingHost

      private String hostingHost
    • gameRunner

      private IGameRunner gameRunner
    • initiator

      private String initiator
    • variant

      private String variant
    • viewmode

      private String viewmode
    • autosave

      private final boolean autosave
      See Also:
    • eventExpiring

      private String eventExpiring
    • unlimitedMulligans

      private boolean unlimitedMulligans
    • balancedTowers

      private boolean balancedTowers
    • min

      private int min
    • target

      private int target
    • max

      private int max
    • onlineCount

      private int onlineCount
    • startTime

      private long startTime
    • duration

      private int duration
    • summary

      private String summary
    • enrolledPlayers

      private int enrolledPlayers
    • players

      private ArrayList<User> players
  • Constructor Details

    • GameInfo

      private GameInfo(GameInfo.GameType type)
    • GameInfo

      public GameInfo(String initiator, String variant, String viewmode, long startTime, int duration, String summary, String expire, boolean unlimitedMulligans, boolean balancedTowers, int min, int target, int max)
    • GameInfo

      public GameInfo(String gameId, boolean onServer)
  • Method Details

    • setNextFreeGameId

      public static void setNextFreeGameId(int id)
      Server calls this to set it high enough that existing directories in games work directory are not overwritten
      Parameters:
      id - Next games should have higher number than given id
    • getNextFreeGameId

      private static int getNextFreeGameId()
    • wouldBeInstantGame

      public static boolean wouldBeInstantGame(long startTime)
    • makeTypeFromStarttime

      private static GameInfo.GameType makeTypeFromStarttime(long startTime)
    • fromString

      public static GameInfo fromString(String[] tokens, HashMap<String,GameInfo> games, boolean fromFile)
    • toString

      public String toString(String sep)
    • setState

      public void setState(GameInfo.GameState state)
    • getGameState

      public GameInfo.GameState getGameState()
    • isScheduledGame

      public boolean isScheduledGame()
    • getStateString

      public String getStateString()
    • getGameId

      public String getGameId()
    • setGameId

      public void setGameId(String val)
    • setGameRunner

      public void setGameRunner(IGameRunner gr)
    • getGameRunner

      public IGameRunner getGameRunner()
    • getPort

      public int getPort()
    • setPort

      public void setPort(int nr)
    • setHostingHost

      public void setHostingHost(String host)
    • getHostingHost

      public String getHostingHost()
    • getInitiator

      public String getInitiator()
    • setInitiator

      public void setInitiator(String val)
    • getStartTime

      public Long getStartTime()
    • setStartTime

      public void setStartTime(String val)
    • getDuration

      public Integer getDuration()
    • setDuration

      public void setDuration(String val)
    • getSummary

      public String getSummary()
    • setSummary

      public void setSummary(String val)
    • getVariant

      public String getVariant()
    • setVariant

      public void setVariant(String val)
    • getViewmode

      public String getViewmode()
    • getAutosave

      public boolean getAutosave()
    • setViewmode

      public void setViewmode(String val)
    • getEventExpiring

      public String getEventExpiring()
    • setEventExpiring

      public void setEventExpiring(String val)
    • getUnlimitedMulligans

      public boolean getUnlimitedMulligans()
    • setUnlimitedMulligans

      public void setUnlimitedMulligans(boolean val)
    • getBalancedTowers

      public boolean getBalancedTowers()
    • setBalancedTowers

      public void setBalancedTowers(boolean val)
    • hasEnoughPlayers

      public boolean hasEnoughPlayers()
      Have enough players enrolled (at least "min")
      Returns:
      true or false whether enough (at least 'min') players are already enrolled to this game
    • allEnrolledOnline

      public boolean allEnrolledOnline()
      Have enough players enrolled (at least "min")
      Returns:
      true or false whether all enrolled players are online
    • isDue

      public boolean isDue()
      Has the scheduled time come?
      Returns:
      true if the game can be started according to schedule
    • getMin

      public Integer getMin()
    • setMin

      public void setMin(Integer val)
    • getTargetInteger

      public Integer getTargetInteger()
    • getTarget

      public int getTarget()
    • setTarget

      public void setTarget(Integer val)
    • getMax

      public Integer getMax()
    • setMax

      public void setMax(Integer val)
    • getEnrolledCount

      public Integer getEnrolledCount()
    • enoughPlayersEnrolled

      public boolean enoughPlayersEnrolled()
    • getOnlineCount

      public int getOnlineCount()
    • setOnlineCount

      public void setOnlineCount(int count)
    • setEnrolledCount

      public void setEnrolledCount(Integer val)
    • getPlayers

      public ArrayList<User> getPlayers()
    • getPlayerListAsString

      public String getPlayerListAsString()
    • isFirstInEnrolledList

      public boolean isFirstInEnrolledList(String name)
    • reEnrollIfNecessary

      public boolean reEnrollIfNecessary(User newUser)
    • removeIfEnrolled

      public boolean removeIfEnrolled(String newName)
      TODO remove overlap with isEnrolled If user with name "newName" is found, remove it from game, so that it can be safely enrolled again. E.g. after user reconnected or accidental double click to enroll button
      Parameters:
      newName -
      Returns:
      Whether user was found
    • isEnrolled

      public boolean isEnrolled(String searchName)
    • setPlayerList

      public void setPlayerList(ArrayList<User> playerlist)
    • updateOnlineCount

      public boolean updateOnlineCount(int newCount)
    • enroll

      public String enroll(User user)
    • unenroll

      public String unenroll(User user)
    • storeToOptionsObject

      public void storeToOptionsObject(Options gameOptions, String localPlayerName, boolean noAIs)
    • relevantForSaving

      public boolean relevantForSaving()
    • isStartable

      public boolean isStartable()
    • isRunning

      public boolean isRunning()
    • wasAlreadyStarted

      public boolean wasAlreadyStarted()
    • markStarting

      public void markStarting(User starter)
    • isStarting

      public boolean isStarting()
    • cancelStarting

      public void cancelStarting()
    • getStartingUser

      public User getStartingUser()