/
scoreboard.go
51 lines (45 loc) · 1.11 KB
/
scoreboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import "log"
// Scoreboard defines the data structure for the home team and away team
type Scoreboard struct {
Home *Team
Away *Team
HomeMaps int
AwayMaps int
HomeGames int
AwayGames int
}
// IncrementHome accounts for when the home team wins a map
func (s *Scoreboard) IncrementHome() {
s.HomeMaps++
if s.HomeMaps == 3 {
s.HomeMaps = 0
s.AwayMaps = 0
s.HomeGames++
}
log.Printf("Scoreboard Update: %s Won Map\n", s.Home.Name)
log.Printf("%s: %d Games %d Maps\n", s.Home.Name, s.HomeGames, s.HomeMaps)
}
// DecrementHome accounts for an error in scoring
func (s *Scoreboard) DecrementHome() {
if s.HomeMaps > 0 {
s.HomeMaps--
}
}
// IncrementAway accounts for when the away team wins a map
func (s *Scoreboard) IncrementAway() {
s.AwayMaps++
if s.AwayMaps == 3 {
s.HomeMaps = 0
s.AwayMaps = 0
s.AwayGames++
}
log.Printf("Scoreboard Update: %s Won Map\n", s.Away.Name)
log.Printf("%s: %d Games %d Maps\n", s.Away.Name, s.AwayGames, s.AwayMaps)
}
// DecrementAway accounts for an error in scoring
func (s *Scoreboard) DecrementAway() {
if s.AwayMaps > 0 {
s.AwayMaps--
}
}