refactoring
This commit is contained in:
parent
c18c1351da
commit
74b14ef337
@ -117,6 +117,7 @@ export default {
|
||||
&-count {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
user-select: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (gm *Game) ContinueGame() {
|
||||
@ -14,47 +13,11 @@ func (gm *Game) ContinueGame() {
|
||||
|
||||
switch phase {
|
||||
case PHASE_SELECT_QUOTE:
|
||||
gm.proceedToReveal()
|
||||
gm.revealShowCount()
|
||||
case PHASE_REVEAL_SHOW_COUNT:
|
||||
gm.revealSource()
|
||||
default:
|
||||
fmt.Printf("invalid state, can't continue game in %s state, %s phase\n", state, phase)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (gm *Game) proceedToReveal() {
|
||||
if !gm.allPlayersHaveSelectedAQuote() {
|
||||
fmt.Println("not all players have selected a quote yet")
|
||||
return
|
||||
}
|
||||
|
||||
if err := gm.changeGamePhase(STATE_PLAY, PHASE_SELECT_QUOTE, PHASE_REVEAL_START); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
gm.notifyClients()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
if err := gm.changeGamePhase(STATE_PLAY, PHASE_REVEAL_START, PHASE_REVEAL_SHOW_COUNT); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
gm.notifyClients()
|
||||
}
|
||||
|
||||
func (gm *Game) allPlayersHaveSelectedAQuote() bool {
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
for id, playerInfo := range gm.players {
|
||||
if !playerInfo.isPlaying || playerInfo.isIdle {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(gm.round.selections[id]) == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
@ -54,13 +54,8 @@ func (gm *Game) getRevelation() *syncdata.Revelation {
|
||||
return nil
|
||||
}
|
||||
|
||||
votes := make(map[string][]string, 0)
|
||||
for key, val := range gm.round.selections {
|
||||
votes[val] = append(votes[val], key)
|
||||
}
|
||||
|
||||
revelation := syncdata.Revelation{
|
||||
Votes: votes,
|
||||
Votes: gm.round.revelation.votes,
|
||||
}
|
||||
|
||||
return &revelation
|
||||
|
50
server/src/game/revealShowCount.go
Normal file
50
server/src/game/revealShowCount.go
Normal file
@ -0,0 +1,50 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (gm *Game) revealShowCount() {
|
||||
if !gm.allPlayersHaveSelectedAQuote() {
|
||||
fmt.Println("not all players have selected a quote yet")
|
||||
return
|
||||
}
|
||||
|
||||
if err := gm.changeGamePhase(STATE_PLAY, PHASE_SELECT_QUOTE, PHASE_REVEAL_START); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
gm.round.revelation = Revelation{
|
||||
votes: make(map[string][]string, 0),
|
||||
}
|
||||
gm.notifyClients()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
if err := gm.changeGamePhase(STATE_PLAY, PHASE_REVEAL_START, PHASE_REVEAL_SHOW_COUNT); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
for key, val := range gm.round.selections {
|
||||
gm.round.revelation.votes[val] = append(gm.round.revelation.votes[val], key)
|
||||
}
|
||||
gm.notifyClients()
|
||||
}
|
||||
|
||||
func (gm *Game) allPlayersHaveSelectedAQuote() bool {
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
for id, playerInfo := range gm.players {
|
||||
if !playerInfo.isPlaying || playerInfo.isIdle {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(gm.round.selections[id]) == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
13
server/src/game/revealSource.go
Normal file
13
server/src/game/revealSource.go
Normal file
@ -0,0 +1,13 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (gm *Game) revealSource() {
|
||||
if err := gm.changeGamePhase(STATE_PLAY, PHASE_REVEAL_SHOW_COUNT, PHASE_REVEAL_SOURCE); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
gm.notifyClients()
|
||||
}
|
@ -18,6 +18,7 @@ const (
|
||||
PHASE_SELECT_QUOTE = "select-quote"
|
||||
PHASE_REVEAL_START = "reveal-start"
|
||||
PHASE_REVEAL_SHOW_COUNT = "reveal-show-count"
|
||||
PHASE_REVEAL_SOURCE = "reveal-source"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -37,10 +38,15 @@ type Source struct {
|
||||
name string
|
||||
}
|
||||
|
||||
type Revelation struct {
|
||||
votes map[string][]string
|
||||
}
|
||||
|
||||
type Round struct {
|
||||
quoteId string
|
||||
selections map[string]string
|
||||
sources []Source
|
||||
revelation Revelation
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
|
Loading…
Reference in New Issue
Block a user