-
Notifications
You must be signed in to change notification settings - Fork 8
/
undoactions.go
142 lines (124 loc) · 4.64 KB
/
undoactions.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package game
import (
"github.com/dascr/dascr-board/throw"
"github.com/dascr/dascr-board/undo"
"github.com/dascr/dascr-board/utils"
)
// UndoCreateThrowRound is the undo action for CREATETHROWROUND
func UndoCreateThrowRound(action undo.Action) {
for i, rnd := range action.Player.ThrowRounds {
if rnd.Round == action.RoundNumber {
copy(action.Player.ThrowRounds[i:], action.Player.ThrowRounds[i+1:])
action.Player.ThrowRounds[len(action.Player.ThrowRounds)-1] = throw.Round{}
action.Player.ThrowRounds = action.Player.ThrowRounds[:len(action.Player.ThrowRounds)-1]
}
}
}
// UndoCreateThrow is the undo action for CREATETHROW
func UndoCreateThrow(action undo.Action) {
if len(action.Player.ThrowRounds) > 0 {
throwRound := &action.Player.ThrowRounds[action.RoundNumber-1]
if len(throwRound.Throws) > 0 {
throwRound.Throws = throwRound.Throws[:len(throwRound.Throws)-1]
}
action.Player.TotalThrowCount--
}
}
// UndoScore is the undo action for UPDATESCORE
func UndoScore(action undo.Action) {
action.Player.Score.Score = action.PreviousScore
action.Player.Average = action.PreviousAverage
action.Player.ThrowSum = action.PreviousThrowSum
action.Player.LastThrows = action.PreviousLastThree
}
// UndoScoreAndPark is the undo action for UPDATESCOREANDPARK
func UndoScoreAndPark(action undo.Action) {
action.Player.Score.Score = action.PreviousScore
action.Player.Score.ParkScore = action.PreviousParkScore
action.Player.Average = action.PreviousAverage
action.Player.ThrowSum = action.PreviousThrowSum
action.Player.LastThrows = action.PreviousLastThree
}
// UndoBustAndWin is the undo action for X01BUST and DOWIN
func UndoBustAndWin(action undo.Action, base *BaseGame) {
base.GameState = action.PreviousGameState
base.Message = action.PreviousMessage
action.Player.Score.Score = action.PreviousScore
action.Player.Score.ParkScore = action.PreviousParkScore
action.Player.ThrowRounds[len(action.Player.ThrowRounds)-1].Done = false
}
// UndoDoPodium is the undo action for DOPODIUM
func UndoDoPodium(action undo.Action, base *BaseGame) {
base.GameState = action.PreviousGameState
base.Message = action.PreviousMessage
if base.Podium.GetPodiumLength() > 0 {
base.Podium.RemoveLastPlacement()
}
}
// UndoClosePlayerThrowRound is the undo action for CLOSEPLAYERTHROWROUND
func UndoClosePlayerThrowRound(action undo.Action, base *BaseGame) {
base.GameState = action.PreviousGameState
base.Message = action.PreviousMessage
for _, rnd := range action.Player.ThrowRounds {
if rnd.Round == action.RoundNumber {
rnd.Done = false
}
}
}
// UndoIncreaseThrowRound is the undo action for INCREASETHROWROUND
func UndoIncreaseThrowRound(action undo.Action, base *BaseGame) {
base.ThrowRound--
}
// UndoNextPlayer is the undo action for NEXTPLAYER
func UndoNextPlayer(action undo.Action, base *BaseGame) {
base.ActivePlayer = action.PreviousPlayerIndex
}
// UndoCloseControllerNumber is the undo action for CLOSECONTROLLERNUMBER
func UndoCloseControllerNumber(action undo.Action, base *BaseGame) {
base.CricketController.NumberClosed[action.NumberIndex] = false
}
// UndoClosePlayerNumber is the undo action for CLOSEPLAYERNUMBER
func UndoClosePlayerNumber(action undo.Action) {
action.Player.Score.Closed[action.NumberIndex] = false
}
// UndoRevealNumber is the undo action for REVEALNUMBER
func UndoRevealNumber(action undo.Action, base *BaseGame) {
// Hide it again
base.CricketController.NumberRevealed[action.NumberIndex] = false
// Choose new random number which is not one of the 7 existing
for {
var newNumber = utils.GetSingleRandomCricketNumber()
var contained = false
for _, n := range base.CricketController.Numbers {
if newNumber == n {
contained = true
}
}
if !contained {
// substitute the revealed number with the new one
base.CricketController.Numbers[action.NumberIndex] = newNumber
break
}
}
}
// UndoIncreaseHitCount is the undo action for INCREASEHITCOUNT
func UndoIncreaseHitCount(action undo.Action) {
action.Player.Score.Numbers[action.NumberIndex] -= action.Modifier
}
// UndoGainPoints is the undo action for GAINPOINTS
func UndoGainPoints(action undo.Action) {
action.Player.Score.Score -= action.Points
}
// UndoWin is the undo action for DOWIN
func UndoWin(action undo.Action, base *BaseGame) {
base.GameState = action.PreviousGameState
base.Message = action.PreviousMessage
}
// UndoATCIncreaseNumber is the undo action for ATCINCREASENUMBER
func UndoATCIncreaseNumber(action undo.Action) {
action.Player.Score.CurrentNumber = action.PreviousNumberToHit
}
// UndoUpdateSplitScore is the undo action for UPDATESPLITSCORE
func UndoUpdateSplitScore(action undo.Action) {
action.Player.Score.Score = action.PreviousScore
}