40 lines
718 B
Go
40 lines
718 B
Go
|
package usher
|
||
|
|
||
|
import (
|
||
|
"local/m/mchess_server/chess"
|
||
|
lobbies "local/m/mchess_server/lobby_registry"
|
||
|
)
|
||
|
|
||
|
type Usher struct {
|
||
|
}
|
||
|
|
||
|
var instance *Usher
|
||
|
|
||
|
func NewUsher() *Usher {
|
||
|
return &Usher{}
|
||
|
}
|
||
|
|
||
|
func GetUsher() *Usher {
|
||
|
if instance == nil {
|
||
|
instance = NewUsher()
|
||
|
}
|
||
|
return instance
|
||
|
}
|
||
|
|
||
|
func (u *Usher) WelcomeNewPlayer(player *chess.Player) *lobbies.Lobby {
|
||
|
lobby := lobbies.GetLobbyRegistry().GetLobbyForPlayer()
|
||
|
return lobby
|
||
|
}
|
||
|
|
||
|
func (u *Usher) AddPlayerToLobby(player *chess.Player, lobby *lobbies.Lobby) {
|
||
|
lobby.AddPlayer(player)
|
||
|
}
|
||
|
|
||
|
func (u *Usher) WaitForTwoPlayersInLobby(lobby *lobbies.Lobby) {
|
||
|
player1 := lobby.GetPlayer1()
|
||
|
<-player1.JoinedLobby
|
||
|
|
||
|
player2 := lobby.GetPlayer2()
|
||
|
<-player2.JoinedLobby
|
||
|
}
|