fix: set room status to Playing when game starts
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user