2022-12-14 21:19:47 +00:00
|
|
|
package server
|
|
|
|
|
2023-04-18 20:47:51 +00:00
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
2022-12-14 21:19:47 +00:00
|
|
|
|
2023-04-18 20:47:51 +00:00
|
|
|
type Lobby map[uuid.UUID]Player
|
2022-12-14 21:19:47 +00:00
|
|
|
|
2023-04-18 20:54:32 +00:00
|
|
|
var lobbyInstance Lobby = nil
|
2022-12-14 21:19:47 +00:00
|
|
|
|
2023-04-18 20:54:32 +00:00
|
|
|
func GetLobby() Lobby {
|
2022-12-14 21:19:47 +00:00
|
|
|
if lobbyInstance == nil {
|
|
|
|
lobbyInstance = newLobby()
|
|
|
|
}
|
|
|
|
|
|
|
|
return lobbyInstance
|
|
|
|
}
|
|
|
|
|
2023-04-18 20:54:32 +00:00
|
|
|
func newLobby() Lobby {
|
|
|
|
lobby := make(map[uuid.UUID]Player, 0)
|
|
|
|
return lobby
|
2022-12-14 21:19:47 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 20:47:51 +00:00
|
|
|
func (lobby Lobby) RegisterPlayer(player *Player) {
|
|
|
|
lobby[player.uuid] = *player
|
|
|
|
|
|
|
|
if len(lobby)%2 == 0 {
|
|
|
|
var players [2]Player
|
|
|
|
var index int = 0
|
2022-12-14 21:19:47 +00:00
|
|
|
|
2023-04-18 20:47:51 +00:00
|
|
|
for _, player := range lobby {
|
|
|
|
players[index] = player
|
|
|
|
index += 1
|
|
|
|
}
|
2022-12-14 21:19:47 +00:00
|
|
|
|
2023-04-22 17:23:46 +00:00
|
|
|
game := NewGame()
|
|
|
|
|
|
|
|
game.addPlayersToGame(players)
|
2022-12-14 21:19:47 +00:00
|
|
|
}
|
|
|
|
}
|