Feat: add game over
This commit is contained in:
@ -9,7 +9,11 @@
|
|||||||
<button hx-get="/start-game" hx-target="#room" class="bg-amber-100 text-black px-4 py-2 rounded">Start Game</button>
|
<button hx-get="/start-game" hx-target="#room" class="bg-amber-100 text-black px-4 py-2 rounded">Start Game</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
</p>
|
</p>
|
||||||
|
{{if .Room.IsOver}}
|
||||||
|
<p>GAME OVER; team <span class="text-{{.Room.TeamWon}}-500">{{.Room.TeamWon}}</span> won! 🧚</p>
|
||||||
|
{{else}}
|
||||||
<p>Turn of the <span class="text-{{.Room.TeamTurn}}-500">{{.Room.TeamTurn}}</span> team</p>
|
<p>Turn of the <span class="text-{{.Room.TeamTurn}}-500">{{.Room.TeamTurn}}</span> team</p>
|
||||||
|
{{end}}
|
||||||
<p>
|
<p>
|
||||||
{{if eq .State.Team ""}}
|
{{if eq .State.Team ""}}
|
||||||
join the team!
|
join the team!
|
||||||
|
@ -51,8 +51,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
|
|||||||
abortWithError(w, err.Error())
|
abortWithError(w, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug("got state", "state", fi)
|
|
||||||
// TODO: update room score
|
|
||||||
color, exists := roundWords[word]
|
color, exists := roundWords[word]
|
||||||
log.Debug("got show-color request", "word", word, "color", color)
|
log.Debug("got show-color request", "word", word, "color", color)
|
||||||
if !exists {
|
if !exists {
|
||||||
@ -75,14 +73,29 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
|
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
|
||||||
// if opened card is of color of opp team, change turn
|
// if opened card is of color of opp team, change turn
|
||||||
|
oppositeColor := fi.Room.GetOppositeTeamColor()
|
||||||
switch color {
|
switch color {
|
||||||
case "black":
|
case "black":
|
||||||
// game over
|
// game over
|
||||||
fi.Room.IsRunning = false
|
fi.Room.IsRunning = false
|
||||||
fi.Room.IsOver = true
|
fi.Room.IsOver = true
|
||||||
case "white", fi.Room.GetOppositeTeamColor():
|
fi.Room.TeamWon = oppositeColor
|
||||||
|
case "white", oppositeColor:
|
||||||
// end turn
|
// end turn
|
||||||
fi.Room.TeamTurn = fi.Room.GetOppositeTeamColor()
|
fi.Room.TeamTurn = oppositeColor
|
||||||
|
}
|
||||||
|
// 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"
|
||||||
|
}
|
||||||
|
if fi.Room.RedCounter == 0 {
|
||||||
|
// red won
|
||||||
|
fi.Room.IsRunning = false
|
||||||
|
fi.Room.IsOver = true
|
||||||
|
fi.Room.TeamWon = "red"
|
||||||
}
|
}
|
||||||
if err := saveFullInfo(fi); err != nil {
|
if err := saveFullInfo(fi); err != nil {
|
||||||
abortWithError(w, err.Error())
|
abortWithError(w, err.Error())
|
||||||
|
@ -192,11 +192,12 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
|
|||||||
fi.Room.IsOver = false
|
fi.Room.IsOver = false
|
||||||
fi.Room.TeamTurn = "blue"
|
fi.Room.TeamTurn = "blue"
|
||||||
fi.Room.LoadTestCards()
|
fi.Room.LoadTestCards()
|
||||||
|
fi.Room.UpdateCounter()
|
||||||
|
fi.Room.TeamWon = ""
|
||||||
if err := saveFullInfo(fi); err != nil {
|
if err := saveFullInfo(fi); err != nil {
|
||||||
abortWithError(w, err.Error())
|
abortWithError(w, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fi.Room.UpdateCounter()
|
|
||||||
// reveal all cards
|
// reveal all cards
|
||||||
if fi.State.Role == "mime" {
|
if fi.State.Role == "mime" {
|
||||||
fi.Room.RevealAllCards()
|
fi.Room.RevealAllCards()
|
||||||
|
@ -71,6 +71,7 @@ type Room struct {
|
|||||||
RoundTime int32 `json:"round_time"`
|
RoundTime int32 `json:"round_time"`
|
||||||
// ProgressPct uint32 `json:"progress_pct"`
|
// ProgressPct uint32 `json:"progress_pct"`
|
||||||
IsOver bool
|
IsOver bool
|
||||||
|
TeamWon string // blue | red
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) GetOppositeTeamColor() string {
|
func (r *Room) GetOppositeTeamColor() string {
|
||||||
|
8
todos.md
8
todos.md
@ -1,10 +1,7 @@
|
|||||||
### feats
|
### feats
|
||||||
- game state (running/not);
|
|
||||||
- start game: btn, endpoint;
|
|
||||||
- mime: clue + number;
|
|
||||||
- game log: what clues were given, who opened what cards;
|
|
||||||
- end game: who won.
|
- end game: who won.
|
||||||
- end game: two reasons (black word; all words);
|
- end game: two reasons (black word; all words);
|
||||||
|
- ability to leave room;
|
||||||
|
|
||||||
#### sse points
|
#### sse points
|
||||||
- clue sse update;
|
- clue sse update;
|
||||||
@ -19,3 +16,6 @@
|
|||||||
### issues
|
### issues
|
||||||
- after the game started (isrunning) players should be able join guessers, but not switch team, or join as a mime;
|
- 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;
|
- 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;
|
||||||
|
Reference in New Issue
Block a user