Marco
aac428baab
1. Introduce 'usher' that opens lobbies and fills it and waits for them to be filled 2. Add global registry of all games
34 lines
561 B
Go
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]
|
|
}
|