feat: game session, turn system, lobby, and room events

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 23:55:08 +09:00
parent 8849bf5220
commit 13d468943a
6 changed files with 705 additions and 0 deletions

40
game/lobby_test.go Normal file
View File

@@ -0,0 +1,40 @@
package game
import "testing"
func TestCreateRoom(t *testing.T) {
lobby := NewLobby()
code := lobby.CreateRoom("Test Room")
if len(code) != 4 {
t.Errorf("Room code length: got %d, want 4", len(code))
}
rooms := lobby.ListRooms()
if len(rooms) != 1 {
t.Errorf("Room count: got %d, want 1", len(rooms))
}
}
func TestJoinRoom(t *testing.T) {
lobby := NewLobby()
code := lobby.CreateRoom("Test Room")
err := lobby.JoinRoom(code, "player1")
if err != nil {
t.Errorf("Join failed: %v", err)
}
room := lobby.GetRoom(code)
if len(room.Players) != 1 {
t.Errorf("Player count: got %d, want 1", len(room.Players))
}
}
func TestJoinRoomFull(t *testing.T) {
lobby := NewLobby()
code := lobby.CreateRoom("Test Room")
for i := 0; i < 4; i++ {
lobby.JoinRoom(code, "player")
}
err := lobby.JoinRoom(code, "player5")
if err == nil {
t.Error("Should reject 5th player")
}
}