34 lines
564 B
Go
34 lines
564 B
Go
package server
|
|
|
|
import "log"
|
|
|
|
type Lobby struct {
|
|
players []Player
|
|
}
|
|
|
|
var lobbyInstance *Lobby = nil
|
|
|
|
func GetLobby() *Lobby {
|
|
if lobbyInstance == nil {
|
|
lobbyInstance = newLobby()
|
|
}
|
|
|
|
return lobbyInstance
|
|
}
|
|
|
|
func newLobby() *Lobby {
|
|
return &Lobby{}
|
|
}
|
|
|
|
func (lobby *Lobby) RegisterPlayer(player *Player) {
|
|
lobby.players = append(lobby.players, *player)
|
|
|
|
log.Println(lobby)
|
|
|
|
if len(lobby.players)%2 == 0 {
|
|
player1 := lobby.players[len(lobby.players)-2]
|
|
player2 := lobby.players[len(lobby.players)-1]
|
|
addPlayersToGame([2]Player{player1, player2})
|
|
}
|
|
}
|