fix: set room status to Playing when game starts

This commit is contained in:
2026-03-24 10:40:04 +09:00
parent 4db3ba1fc5
commit b6c28ddd80
3 changed files with 28 additions and 0 deletions

View File

@@ -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()

View File

@@ -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")

View File

@@ -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
}