34 lines
524 B
Go
34 lines
524 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 {
|
||
|
player1 := lobby.players[0]
|
||
|
player2 := lobby.players[1]
|
||
|
addPlayersToGame([2]Player{player1, player2})
|
||
|
}
|
||
|
}
|