GameState

model.entities.games.GameState
case class GameState(currentPlayers: Int, maxAllowedPlayers: Int, playersId: List[String])

Represents the current state of player occupancy for a game.

Tracks the number of players currently engaged with a game, enforces capacity limits, and maintains a list of player identifiers. This immutable data structure ensures thread-safe state management and provides methods for adding and removing players with proper validation.

Value parameters

currentPlayers

the number of players currently in the game

maxAllowedPlayers

the maximum capacity of players for this game

playersId

the list of unique identifiers for all current players

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def addPlayer(id: String): Result[GameState, GameState]

Attempts to add a new player to the game.

Attempts to add a new player to the game.

Validates that the game has available capacity before adding the player. If successful, returns a new GameState with incremented player count and the player's ID added to the list. If the game is full, returns the current state as a failure.

Value parameters

id

the unique identifier of the player to add

Attributes

Returns

Success with updated GameState if space available, Failure with current state if full

def isFull: Boolean

Checks if the game has reached its maximum player capacity.

Checks if the game has reached its maximum player capacity.

Attributes

Returns

true if the game is at full capacity, false otherwise

def removePlayer(id: String): Result[GameState, GameState]

Attempts to remove a player from the game.

Attempts to remove a player from the game.

Validates that there are players to remove before proceeding. If successful, returns a new GameState with decremented player count and the player's ID removed from the list. If no players are present, returns the current state as a failure.

Value parameters

id

the unique identifier of the player to remove

Attributes

Returns

Success with updated GameState if players exist, Failure with current state if empty

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product