mchess-server/server/lobby.go

40 lines
587 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 {
var lobby Lobby
return &lobby
}
func (lobby Lobby) RegisterPlayer(player *Player) {
lobby[player.uuid] = *player
if len(lobby)%2 == 0 {
var players [2]Player
var index int = 0
for _, player := range lobby {
players[index] = player
index += 1
}
addPlayersToGame(players)
removePlayersFromLobby(players)
}
}