diff --git a/game/lobby.go b/game/lobby.go index af03b81..d278f40 100644 --- a/game/lobby.go +++ b/game/lobby.go @@ -78,6 +78,14 @@ func (l *Lobby) ListRooms() []*LobbyRoom { return result } +func (l *Lobby) StartRoom(code string) { + l.mu.Lock() + defer l.mu.Unlock() + if room, ok := l.rooms[code]; ok { + room.Status = RoomPlaying + } +} + func (l *Lobby) RemoveRoom(code string) { l.mu.Lock() defer l.mu.Unlock() diff --git a/game/lobby_test.go b/game/lobby_test.go index 25b6b7d..5a60040 100644 --- a/game/lobby_test.go +++ b/game/lobby_test.go @@ -27,6 +27,25 @@ func TestJoinRoom(t *testing.T) { } } +func TestRoomStatusTransition(t *testing.T) { + l := NewLobby() + code := l.CreateRoom("Test") + l.JoinRoom(code, "Alice") + r := l.GetRoom(code) + if r.Status != RoomWaiting { + t.Errorf("new room should be Waiting, got %d", r.Status) + } + l.StartRoom(code) + r = l.GetRoom(code) + if r.Status != RoomPlaying { + t.Errorf("started room should be Playing, got %d", r.Status) + } + err := l.JoinRoom(code, "Bob") + if err == nil { + t.Error("should not be able to join a Playing room") + } +} + func TestJoinRoomFull(t *testing.T) { lobby := NewLobby() code := lobby.CreateRoom("Test Room") diff --git a/ui/model.go b/ui/model.go index 53eb255..7ef6175 100644 --- a/ui/model.go +++ b/ui/model.go @@ -262,6 +262,7 @@ func (m Model) updateClassSelect(msg tea.Msg) (tea.Model, tea.Cmd) { player.Fingerprint = m.fingerprint m.session.AddPlayer(player) m.session.StartGame() + m.lobby.StartRoom(m.roomCode) m.gameState = m.session.GetState() m.screen = screenGame }