package lobby_registry import ( "local/m/mchess_server/chess" "github.com/google/uuid" ) type Lobby struct { Uuid uuid.UUID Game *chess.Game PlayerJoined chan bool } func NewEmptyLobbyWithUUID(uuid uuid.UUID) *Lobby { return &Lobby{ Uuid: uuid, Game: chess.NewGame(), PlayerJoined: make(chan bool), } } func (w *Lobby) AddPlayerAndStartGameIfFull(player *chess.Player) { w.Game.AddPlayersToGame(player) if w.IsFull() { go w.Game.Handle() } } func (w *Lobby) IsFull() bool { return len(w.Game.GetPlayers()) == 2 } func (l *Lobby) GetPlayerByUUID(uuid uuid.UUID) (*chess.Player, bool) { for _, player := range l.Game.GetPlayers() { if player.Uuid == uuid { return player, true } } return nil, false } func (l *Lobby) GetPlayer1() *chess.Player { return l.Game.GetPlayer1() } func (l *Lobby) GetPlayer2() *chess.Player { return l.Game.GetPlayer2() }