Add match start and end times to board state

This commit is contained in:
Trevor Slocum 2023-11-02 14:48:36 -07:00
parent 171948e21c
commit 522663becc
3 changed files with 17 additions and 0 deletions

View file

@ -43,17 +43,25 @@ func (g *serverGame) roll(player int) bool {
}
if g.Turn == 0 {
var secondRoll bool
if player == 1 {
if g.Roll1 != 0 {
return false
} else {
secondRoll = true
}
g.Roll1 = g.r.Intn(6) + 1
} else {
if g.Roll2 != 0 {
return false
} else {
secondRoll = true
}
g.Roll2 = g.r.Intn(6) + 1
}
if secondRoll && g.Started.IsZero() {
g.Started = time.Now()
}
// Only allow the same players to rejoin the game.
if g.allowed1 == nil {

View file

@ -708,6 +708,7 @@ COMMANDS:
clientGame.Player2.Points = clientGame.Player2.Points + clientGame.DoubleValue
if clientGame.Player2.Points >= clientGame.Points {
clientGame.Winner = 2
clientGame.Ended = time.Now()
} else {
clientGame.Reset()
}
@ -715,6 +716,7 @@ COMMANDS:
clientGame.Player1.Points = clientGame.Player2.Points + clientGame.DoubleValue
if clientGame.Player1.Points >= clientGame.Points {
clientGame.Winner = 1
clientGame.Ended = time.Now()
} else {
clientGame.Reset()
}
@ -880,12 +882,16 @@ COMMANDS:
clientGame.Player1.Points = clientGame.Player1.Points + winPoints*clientGame.DoubleValue
if clientGame.Player1.Points < clientGame.Points {
clientGame.Reset()
} else {
clientGame.Ended = time.Now()
}
} else {
winEvent.Player = clientGame.Player2.Name
clientGame.Player2.Points = clientGame.Player2.Points + winPoints*clientGame.DoubleValue
if clientGame.Player2.Points < clientGame.Points {
clientGame.Reset()
} else {
clientGame.Ended = time.Now()
}
}
}

View file

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strconv"
"time"
)
var boardTopBlack = []byte("+13-14-15-16-17-18-+---+19-20-21-22-23-24-+")
@ -18,6 +19,8 @@ type Game struct {
Player1 Player
Player2 Player
Turn int
Started time.Time
Ended time.Time
Winner int
Roll1 int
Roll2 int