Fix: number of guesses
This commit is contained in:
@ -83,16 +83,34 @@ func (b *Bot) checkGuess(word string, room *models.Room) error {
|
||||
room.ActionHistory = append(room.ActionHistory, action)
|
||||
// if opened card is of color of opp team, change turn
|
||||
oppositeColor := room.GetOppositeTeamColor()
|
||||
if room.OpenedThisTurn >= room.ThisTurnLimit {
|
||||
// end turn
|
||||
room.TeamTurn = oppositeColor
|
||||
room.MimeDone = false
|
||||
room.OpenedThisTurn = 0
|
||||
room.ThisTurnLimit = 0
|
||||
}
|
||||
switch string(color) {
|
||||
case "black":
|
||||
// game over
|
||||
room.IsRunning = false
|
||||
room.IsOver = true
|
||||
room.TeamWon = oppositeColor
|
||||
room.OpenedThisTurn = 0
|
||||
room.ThisTurnLimit = 0
|
||||
action := models.Action{
|
||||
Actor: b.BotName,
|
||||
ActorColor: string(b.Team),
|
||||
WordColor: models.WordColorBlack,
|
||||
Action: models.ActionTypeGameOver,
|
||||
}
|
||||
room.ActionHistory = append(room.ActionHistory, action)
|
||||
case "white", string(oppositeColor):
|
||||
// end turn
|
||||
room.TeamTurn = oppositeColor
|
||||
room.MimeDone = false
|
||||
room.OpenedThisTurn = 0
|
||||
room.ThisTurnLimit = 0
|
||||
}
|
||||
// check if no cards left => game over
|
||||
if room.BlueCounter == 0 {
|
||||
@ -100,12 +118,30 @@ func (b *Bot) checkGuess(word string, room *models.Room) error {
|
||||
room.IsRunning = false
|
||||
room.IsOver = true
|
||||
room.TeamWon = "blue"
|
||||
room.OpenedThisTurn = 0
|
||||
room.ThisTurnLimit = 0
|
||||
action := models.Action{
|
||||
Actor: b.BotName,
|
||||
ActorColor: string(b.Team),
|
||||
WordColor: models.WordColorBlack,
|
||||
Action: models.ActionTypeGameOver,
|
||||
}
|
||||
room.ActionHistory = append(room.ActionHistory, action)
|
||||
}
|
||||
if room.RedCounter == 0 {
|
||||
// red won
|
||||
room.IsRunning = false
|
||||
room.IsOver = true
|
||||
room.TeamWon = "red"
|
||||
room.OpenedThisTurn = 0
|
||||
room.ThisTurnLimit = 0
|
||||
action := models.Action{
|
||||
Actor: b.BotName,
|
||||
ActorColor: string(b.Team),
|
||||
WordColor: models.WordColorBlack,
|
||||
Action: models.ActionTypeGameOver,
|
||||
}
|
||||
room.ActionHistory = append(room.ActionHistory, action)
|
||||
}
|
||||
if err := saveRoom(room); err != nil {
|
||||
b.log.Error("failed to save room", "room", room)
|
||||
|
Reference in New Issue
Block a user