add game start to lobby

This commit is contained in:
Branden J Brown 2024-01-21 12:48:29 -06:00
parent 98a45e2680
commit 8aff29e0b8
1 changed files with 15 additions and 0 deletions

View File

@ -3,7 +3,10 @@ package lobby
import ( import (
"sync" "sync"
"github.com/google/uuid"
"git.sunturtle.xyz/studio/shotgun/game" "git.sunturtle.xyz/studio/shotgun/game"
"git.sunturtle.xyz/studio/shotgun/player"
"git.sunturtle.xyz/studio/shotgun/serve" "git.sunturtle.xyz/studio/shotgun/serve"
) )
@ -29,6 +32,18 @@ func (l *Lobby) Game(id GameID) *game.Game {
return l.games[id] return l.games[id]
} }
// Start begins a new game in the lobby.
// The caller must be able to distinguish the dealer's and challenger's conns
// in order to provide correct game start DTOs to each.
func (l *Lobby) Start(dealer, challenger player.ID) GameID {
id := uuid.New()
g := game.New(dealer, challenger)
l.mu.Lock()
defer l.mu.Unlock()
l.games[id] = g
return id
}
// Finish removes a game from the lobby. // Finish removes a game from the lobby.
func (l *Lobby) Finish(id GameID) { func (l *Lobby) Finish(id GameID) {
l.mu.Lock() l.mu.Lock()