Skip to content

Commit

Permalink
fix firstgoal and undo sound
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Müller 🚀 <code@brauser.io>
  • Loading branch information
Flipez committed Jan 20, 2020
1 parent a79865c commit 9cf1814
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ var (
teamAWinCount = 0
teamBWinCount = 0

winHistory = []Round{}
goalHistory = []Goal{}
winHistory = []Round{}
goalHistory = []Goal{}
lastGoalHistory = []Goal{}

availableSoundModes = []string{"default", "meme", "quake", "techno"}
Expand Down Expand Up @@ -75,17 +75,27 @@ func leadingTeam() string {
}

func increaseScore(team string) {
if (!gameIsRunning) { return }
if !gameIsRunning {
return
}
goalHistory = append(goalHistory, Goal{Team: team, Time: time.Since(roundStartTime).Seconds()})
playSound("goal")
if len(goalHistory) == 1 {
playSound("firstgoal")
} else {
playSound("goal")
}

updateScore()
}

func undoScore() {
if (!gameIsRunning) { return }
if !gameIsRunning {
return
}

playSound("denied")

if (len(goalHistory) == 0 && len(winHistory) >= 1) {
if len(goalHistory) == 0 && len(winHistory) >= 1 {
goalHistory = lastGoalHistory
winHistory = winHistory[:len(winHistory)-1]
}
Expand All @@ -98,14 +108,16 @@ func undoScore() {
}

func resetScore() {
if (!gameIsRunning) { return }
if !gameIsRunning {
return
}
goalHistory = []Goal{}
roundStartTime = time.Now()
updateScore()
}

func updateScore() {
debug()
debug()

scoreRed = 0
scoreWhite = 0
Expand Down Expand Up @@ -157,7 +169,7 @@ func teamsAreSwapped() bool {
func nextRound() {
publish("round/end", "end", false)
publish("round/current", strconv.Itoa(currentRound()), true)

rounds, _ := json.Marshal(winHistory)
fmt.Printf(string(rounds))
lastGoalHistory = goalHistory
Expand All @@ -184,10 +196,10 @@ func roundEnd() {
for _, round := range winHistory {
switch round.Winner {
case "a":
teamAWinCount++
teamAWinCount++

case "b":
teamBWinCount++
teamBWinCount++
}
}

Expand Down Expand Up @@ -227,13 +239,11 @@ func clearAll() {
gameIsRunning = false

publish("round/current", strconv.Itoa(currentRound()), true)

debug()
}



func debug() {
publish("debug/teamAWinCount", strconv.Itoa(teamAWinCount), false)
publish("debug/teamBWinCount", strconv.Itoa(teamBWinCount), false)
}
}

0 comments on commit 9cf1814

Please sign in to comment.