Rename status field

This commit is contained in:
Trevor Slocum 2020-08-16 16:31:09 -07:00
parent 2a1cdd9b6f
commit d745adedd6
2 changed files with 19 additions and 19 deletions

View File

@ -29,7 +29,7 @@ type Client struct {
game *Game
gameplayer int
gameready bool
gamewaiting string
gamestatus string
gamego bool
readbuffer chan string
writebuffer chan string
@ -199,16 +199,16 @@ func (c *Client) handleWrite() {
}
}
func (c *Client) setWaiting(waiting string) {
func (c *Client) setStatus(status string) {
c.Lock()
defer c.Unlock()
c.gamewaiting = waiting
c.gamestatus = status
}
func (c *Client) getWaiting() string {
func (c *Client) getStatus() string {
c.RLock()
defer c.RUnlock()
return c.gamewaiting
return c.gamestatus
}

28
game.go
View File

@ -209,12 +209,12 @@ func (g *Game) exportJSON(player int) (string, error) {
if player > 0 {
gamestate["player"] = strconv.Itoa(player)
jsonvalue, err := json.Marshal(g.getClient(player).getWaiting())
jsonvalue, err := json.Marshal(g.getClient(player).getStatus())
if err != nil {
return "", err
}
gamestate["waiting"] = string(jsonvalue)
gamestate["status"] = string(jsonvalue)
}
throwPileSum := cribbage.Sum(g.ThrowPile.Cards())
@ -334,7 +334,7 @@ func (g *Game) scoreHands() (int, int, int) {
}
g.getClient(msgplayer).gameready = false
g.getClient(msgplayer).setWaiting("You scored " + yourscore + " - Your opponent scored " + theirscore)
g.getClient(msgplayer).setStatus("You scored " + yourscore + " - Your opponent scored " + theirscore)
log.Println(msgplayer, "You scored "+yourscore+" - Your opponent scored "+theirscore)
}
@ -416,7 +416,7 @@ func (g *Game) Throw(player int, cardidentifier string) bool {
if opponentHand.Len() > 0 && !g.getClient(g.getOpponent(player)).gamego {
log.Println("Setting Go - Player", g.getOpponent(player))
g.getClient(g.getOpponent(player)).gamego = true
g.getClient(g.getOpponent(player)).setWaiting("Go")
g.getClient(g.getOpponent(player)).setStatus("Go")
g.getClient(g.getOpponent(player)).gameready = false
g.NextTurn()
@ -457,15 +457,15 @@ func (g *Game) ResetGo() {
func (g *Game) ResetReady() {
if g.Phase > 0 {
g.Player1.gameready = true
g.Player1.setWaiting("")
g.Player1.setStatus("")
g.Player2.gameready = true
g.Player2.setWaiting("")
g.Player2.setStatus("")
}
}
func (g *Game) Ready(player int) {
g.getClient(player).gameready = true
g.getClient(player).setWaiting("Waiting on opponent...")
g.getClient(player).setStatus("Waiting on opponent...")
}
func (g *Game) AllReady() bool {
@ -756,7 +756,7 @@ func (g *Game) pegTurn(player int) {
g.PegPhase = PegPhaseSolo
g.getClient(g.getOpponent(player)).gameready = false
g.getClient(g.getOpponent(player)).setWaiting("Go - Pegging finished")
g.getClient(g.getOpponent(player)).setStatus("Go - Pegging finished")
}
g.NextTurn()
@ -772,14 +772,14 @@ func (g *Game) pegTurn(player int) {
}
g.getClient(g.Turn).gameready = false
g.getClient(g.Turn).setWaiting("You pegged " + strconv.Itoa(finalpeg) + " point")
g.getClient(g.Turn).setStatus("You pegged " + strconv.Itoa(finalpeg) + " point")
if finalpeg != 1 {
g.getClient(g.Turn).gamewaiting += "s"
g.getClient(g.Turn).gamestatus += "s"
}
g.getClient(g.getOpponent(g.Turn)).gameready = false
g.getClient(g.getOpponent(g.Turn)).setWaiting("Your opponent pegged " + strconv.Itoa(finalpeg) + " point")
g.getClient(g.getOpponent(g.Turn)).setStatus("Your opponent pegged " + strconv.Itoa(finalpeg) + " point")
if finalpeg != 1 {
g.getClient(g.getOpponent(g.Turn)).gamewaiting += "s"
g.getClient(g.getOpponent(g.Turn)).gamestatus += "s"
}
g.NextTurn()
} else if g.PegPhase == PegPhaseFinal {
@ -839,8 +839,8 @@ func (g *Game) processGameCommand(command GameCommand) {
g.Ready(command.Player)
if g.AllReady() {
g.Player1.setWaiting("")
g.Player2.setWaiting("")
g.Player1.setStatus("")
g.Player2.setStatus("")
g.logDebug("ALL READY")
if g.Phase == PhasePeg {