From 24f940f175911b66f316c0cbe50c1a8dba96b1aa Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sun, 18 May 2025 09:34:43 +0300 Subject: [PATCH] Enha: mime move check; start game backlog msg --- handlers/elements.go | 2 +- handlers/game.go | 27 +++++++++++++++++++++++++++ todos.md | 3 +-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/handlers/elements.go b/handlers/elements.go index 7c032cb..39eaabd 100644 --- a/handlers/elements.go +++ b/handlers/elements.go @@ -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 } diff --git a/handlers/game.go b/handlers/game.go index 3c85e4e..720d83a 100644 --- a/handlers/game.go +++ b/handlers/game.go @@ -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), diff --git a/todos.md b/todos.md index 8a0eae0..1ce9847 100644 --- a/todos.md +++ b/todos.md @@ -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