Feat: guess limit

This commit is contained in:
Grail Finder
2025-06-14 11:37:42 +03:00
parent bddaa912de
commit fa25679624
8 changed files with 97 additions and 64 deletions

View File

@ -84,6 +84,14 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
// if opened card is of color of opp team, change turn
oppositeColor := fi.Room.GetOppositeTeamColor()
fi.Room.OpenedThisTurn++
if fi.Room.ThisTurnLimit >= fi.Room.OpenedThisTurn {
// end turn
fi.Room.TeamTurn = oppositeColor
fi.Room.MimeDone = false
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
}
switch string(color) {
case "black":
// game over
@ -96,38 +104,46 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
WordColor: "black",
Action: "game over",
}
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
case "white", string(oppositeColor):
// end turn
fi.Room.TeamTurn = oppositeColor
fi.Room.MimeDone = false
}
// check if no cards left => game over
if fi.Room.BlueCounter == 0 {
// blue won
fi.Room.IsRunning = false
fi.Room.IsOver = true
fi.Room.TeamWon = "blue"
action := models.Action{
Actor: fi.State.Username,
ActorColor: string(fi.State.Team),
WordColor: "blue",
Action: "game over",
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
// check if no cards left => game over
if fi.Room.BlueCounter == 0 {
// blue won
fi.Room.IsRunning = false
fi.Room.IsOver = true
fi.Room.TeamWon = "blue"
action := models.Action{
Actor: fi.State.Username,
ActorColor: string(fi.State.Team),
WordColor: "blue",
Action: "game over",
}
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
}
if fi.Room.RedCounter == 0 {
// red won
fi.Room.IsRunning = false
fi.Room.IsOver = true
fi.Room.TeamWon = "red"
action := models.Action{
Actor: fi.State.Username,
ActorColor: string(fi.State.Team),
WordColor: "red",
Action: "game over",
if fi.Room.RedCounter == 0 {
// red won
fi.Room.IsRunning = false
fi.Room.IsOver = true
fi.Room.TeamWon = "red"
action := models.Action{
Actor: fi.State.Username,
ActorColor: string(fi.State.Team),
WordColor: "red",
Action: "game over",
}
fi.Room.OpenedThisTurn = 0
fi.Room.ThisTurnLimit = 0
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
}
if err := saveFullInfo(fi); err != nil {
abortWithError(w, err.Error())