From 56bb29611bbae217f9ef6b835a177f4e5ca45cd0 Mon Sep 17 00:00:00 2001 From: Settel Date: Mon, 20 Sep 2021 16:53:49 +0200 Subject: [PATCH] randomize order of sources --- server/src/game/nextRound.go | 11 ++++++++++- server/src/game/setupRound.go | 16 +++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/server/src/game/nextRound.go b/server/src/game/nextRound.go index e2cead4..a0997c1 100644 --- a/server/src/game/nextRound.go +++ b/server/src/game/nextRound.go @@ -21,7 +21,16 @@ func (gm *Game) nextRound() { } gm.notifyClients() - time.Sleep(2 * time.Second) + time.Sleep(1500 * time.Millisecond) + + err = gm.changeGameState(STATE_READY_SET, STATE_READY_SET, "") + if err != nil { + fmt.Println(err) + return + } + gm.notifyClients() + + time.Sleep(1500 * time.Millisecond) err = gm.changeGameState(STATE_READY_SET, STATE_PLAY, PHASE_NONE) if err != nil { diff --git a/server/src/game/setupRound.go b/server/src/game/setupRound.go index eccf5a4..bb10e4e 100644 --- a/server/src/game/setupRound.go +++ b/server/src/game/setupRound.go @@ -36,18 +36,24 @@ func (gm *Game) selectQuote() { } sourceId := q.GetSourceId() - if !gm.isSourceIdInList(sources, sourceId) { - sources = append(sources, gm.getSourceById(sourceId)) - } if len(sources) == 12 { - break + if quote != nil { + break + } + } else { + if !gm.isSourceIdInList(sources, sourceId) { + sources = append(sources, gm.getSourceById(sourceId)) + } } } gm.mu.Lock() defer gm.mu.Unlock() gm.round.quoteId = quote.GetId() - gm.round.sources = sources + gm.round.sources = make([]Source, len(sources)) + for idx, idxPerm := range r.Perm(len(sources)) { + gm.round.sources[idx] = sources[idxPerm] + } } func (gm *Game) getSourceById(id string) Source {