Enha: mime move check; start game backlog msg

This commit is contained in:
Grail Finder
2025-05-18 09:34:43 +03:00
parent 734088d96d
commit 24f940f175
3 changed files with 29 additions and 3 deletions

View File

@ -41,7 +41,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
return
}
if fi.State.Role != "guesser" {
err = errors.New("need to guesser to open the card")
err = errors.New("need to be guesser to open the card")
abortWithError(w, err.Error())
return
}

View File

@ -180,6 +180,15 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
loadCards(fi.Room)
fi.Room.UpdateCounter()
fi.Room.TeamWon = ""
action := models.Action{
Actor: fi.State.Username,
ActorColor: string(fi.State.Team),
WordColor: string(fi.State.Team),
Action: "game started",
// Word: clue,
// Number: num,
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
if err := saveFullInfo(fi); err != nil {
abortWithError(w, err.Error())
return
@ -196,6 +205,7 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
}
// to update only the room that should be updated
notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "")
// notify(models.NotifyBacklogPrefix+fi.Room.ID, "game started")
tmpl.ExecuteTemplate(w, "room", fi)
}
@ -240,6 +250,23 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
// validations ===
if fi.State.Team != models.UserTeam(fi.Room.TeamTurn) {
err = errors.New("not your team's move")
abortWithError(w, err.Error())
return
}
if fi.State.Role != "mime" {
err = errors.New("need to be mime to open the card")
abortWithError(w, err.Error())
return
}
if fi.Room.MimeDone {
// team already have a clue
abortWithError(w, "your team already has a clue")
return
}
// ===
action := models.Action{
Actor: fi.State.Username,
ActorColor: string(fi.State.Team),

View File

@ -19,6 +19,5 @@
### issues
- after the game started (isrunning) players should be able join guessers, but not switch team, or join as a mime;
- do not let wrong team press buttons;
- mime can give clues out of turn;
- guesser can guess the word before the clue;
- cleanup backlog after new game is started;
- guesser: word is not found