Fix doubling cube posession

This commit is contained in:
Trevor Slocum 2023-10-20 14:24:18 -07:00
parent 8da2829b6a
commit 70d2ccb39b
2 changed files with 27 additions and 17 deletions

View file

@ -638,6 +638,11 @@ COMMANDS:
continue
}
if clientGame.DoublePlayer != 0 && clientGame.DoublePlayer != cmd.client.playerNumber {
cmd.client.sendNotice("You do not currently hold the doubling cube.")
continue
}
clientGame.DoubleOffered = true
cmd.client.sendNotice(fmt.Sprintf("Double offered to opponent (%d points).", clientGame.Points*2))
@ -667,16 +672,15 @@ COMMANDS:
cmd.client.sendNotice("Declined double offer")
clientGame.opponent(cmd.client).sendNotice(fmt.Sprintf("%s declined double offer.", cmd.client.name))
log.Println("RESIGN VALUE: ", clientGame.DoubleValue) // TODO
if cmd.client.playerNumber == 1 {
clientGame.Player2.Points += clientGame.DoubleValue
clientGame.Player2.Points = clientGame.Player2.Points + clientGame.DoubleValue
if clientGame.Player2.Points >= clientGame.Points {
clientGame.Winner = 2
} else {
clientGame.Reset()
}
} else {
clientGame.Player1.Points += clientGame.DoubleValue
clientGame.Player1.Points = clientGame.Player2.Points + clientGame.DoubleValue
if clientGame.Player1.Points >= clientGame.Points {
clientGame.Winner = 1
} else {
@ -873,10 +877,15 @@ COMMANDS:
}
clientGame.DoubleOffered = false
clientGame.DoubleValue *= 2
clientGame.DoublePlayer = opponent.playerNumber
clientGame.DoubleValue = clientGame.DoubleValue * 2
clientGame.DoublePlayer = cmd.client.playerNumber
cmd.client.sendNotice("Accepted double.")
opponent.sendNotice(fmt.Sprintf("%s accepted double.", cmd.client.name))
clientGame.eachClient(func(client *serverClient) {
clientGame.sendBoard(client)
})
continue
}

25
game.go
View file

@ -43,18 +43,19 @@ func NewGame() *Game {
func (g *Game) Copy() *Game {
newGame := &Game{
Board: make([]int, len(g.Board)),
Player1: g.Player1,
Player2: g.Player2,
Turn: g.Turn,
Winner: g.Winner,
Roll1: g.Roll1,
Roll2: g.Roll2,
Moves: make([][]int, len(g.Moves)),
Points: g.Points,
DoubleValue: g.DoubleValue,
DoublePlayer: g.DoublePlayer,
boardStates: make([][]int, len(g.boardStates)),
Board: make([]int, len(g.Board)),
Player1: g.Player1,
Player2: g.Player2,
Turn: g.Turn,
Winner: g.Winner,
Roll1: g.Roll1,
Roll2: g.Roll2,
Moves: make([][]int, len(g.Moves)),
Points: g.Points,
DoubleValue: g.DoubleValue,
DoublePlayer: g.DoublePlayer,
DoubleOffered: g.DoubleOffered,
boardStates: make([][]int, len(g.boardStates)),
}
copy(newGame.Board, g.Board)
copy(newGame.Moves, g.Moves)