mchess-server/lobby_registry/lobby.go
Marco aac428baab First changes to move away from central registry of all players
1. Introduce 'usher' that opens lobbies and fills it and waits for them
   to be filled
2. Add global registry of all games
2023-05-31 23:55:40 +02:00

34 lines
561 B
Go

package lobby_registry
import (
"local/m/mchess_server/chess"
"github.com/google/uuid"
)
type Lobby struct {
uuid uuid.UUID
players []*chess.Player
}
func NewEmptyLobbyByUUID(uuid uuid.UUID) *Lobby {
return &Lobby{uuid: uuid}
}
func (w *Lobby) AddPlayer(player *chess.Player) {
w.players = append(w.players, player)
player.JoinedLobby <- true
}
func (w *Lobby) IsFull() bool {
return len(w.players) == 2
}
func (l *Lobby) GetPlayer1() *chess.Player {
return l.players[0]
}
func (l *Lobby) GetPlayer2() *chess.Player {
return l.players[1]
}