From 8aff29e0b8568cc0379805da782690835e3f8272 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Sun, 21 Jan 2024 12:48:29 -0600 Subject: [PATCH] add game start to lobby --- lobby/lobby.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lobby/lobby.go b/lobby/lobby.go index e352676..7fe5f4b 100644 --- a/lobby/lobby.go +++ b/lobby/lobby.go @@ -3,7 +3,10 @@ package lobby import ( "sync" + "github.com/google/uuid" + "git.sunturtle.xyz/studio/shotgun/game" + "git.sunturtle.xyz/studio/shotgun/player" "git.sunturtle.xyz/studio/shotgun/serve" ) @@ -29,6 +32,18 @@ func (l *Lobby) Game(id GameID) *game.Game { 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. func (l *Lobby) Finish(id GameID) { l.mu.Lock()