Add lobby and pack concept.
This commit is contained in:
@@ -18,7 +18,7 @@ func deckIDs(p *Player, filter func(Card) bool) []string {
|
||||
|
||||
func current(g *Game) *Player { return g.Players[g.Turn] }
|
||||
|
||||
func TestLobbyStartsWhenFull(t *testing.T) {
|
||||
func TestLobbyManualStart(t *testing.T) {
|
||||
g := New()
|
||||
if g.Phase != PhaseLobby {
|
||||
t.Fatalf("new game should be in lobby, got %s", g.Phase)
|
||||
@@ -26,18 +26,26 @@ func TestLobbyStartsWhenFull(t *testing.T) {
|
||||
if _, err := g.AddPlayer("Alice"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if g.Phase != PhaseLobby {
|
||||
t.Fatal("game should wait for second player")
|
||||
// One player isn't enough to start.
|
||||
if err := g.StartGame(); err == nil {
|
||||
t.Fatal("start should be rejected with fewer than MinPlayers")
|
||||
}
|
||||
if _, err := g.AddPlayer("Bob"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if g.Phase != PhaseShop || g.Round != 1 {
|
||||
t.Fatalf("game should start round 1 shop, got phase=%s round=%d", g.Phase, g.Round)
|
||||
}
|
||||
if _, err := g.AddPlayer("Carol"); err == nil {
|
||||
t.Fatal("third player should be rejected while MaxPlayers=2")
|
||||
}
|
||||
// The lobby stays open until the host explicitly starts.
|
||||
if g.Phase != PhaseLobby {
|
||||
t.Fatalf("game should wait in the lobby for the host to start, got %s", g.Phase)
|
||||
}
|
||||
if err := g.StartGame(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if g.Phase != PhaseShop || g.Round != 1 {
|
||||
t.Fatalf("game should start round 1 shop, got phase=%s round=%d", g.Phase, g.Round)
|
||||
}
|
||||
for _, p := range g.Players {
|
||||
if p.Coins != CoinsPerRound {
|
||||
t.Fatalf("player should start with %d coins", CoinsPerRound)
|
||||
|
||||
Reference in New Issue
Block a user