mchess-server/server/lobby.go

44 lines
619 B
Go

package server
import (
"github.com/google/uuid"
)
type Lobby map[uuid.UUID]Player
var lobbyInstance Lobby = nil
func GetLobby() Lobby {
if lobbyInstance == nil {
lobbyInstance = newLobby()
}
return lobbyInstance
}
func newLobby() Lobby {
lobby := make(map[uuid.UUID]Player, 0)
return lobby
}
func (lobby Lobby) RegisterPlayer(player *Player) {
lobby[player.Uuid] = *player
var players []Player
for _, player := range lobby {
if !player.InGame {
players = append(players, player)
}
}
if len(players) < 2 {
return
}
game := NewGame()
game.addPlayersToGame([2]Player(players[:2]))
}