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> | ||||
|       {{end}} | ||||
|     </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> | ||||
|     {{end}} | ||||
|     <p> | ||||
|       {{if eq .State.Team ""}} | ||||
|       join the team! | ||||
|   | ||||
| @@ -51,8 +51,6 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	log.Debug("got state", "state", fi) | ||||
| 	// TODO: update room score | ||||
| 	color, exists := roundWords[word] | ||||
| 	log.Debug("got show-color request", "word", word, "color", color) | ||||
| 	if !exists { | ||||
| @@ -75,14 +73,29 @@ 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() | ||||
| 	switch color { | ||||
| 	case "black": | ||||
| 		// game over | ||||
| 		fi.Room.IsRunning = false | ||||
| 		fi.Room.IsOver = true | ||||
| 	case "white", fi.Room.GetOppositeTeamColor(): | ||||
| 		fi.Room.TeamWon = oppositeColor | ||||
| 	case "white", oppositeColor: | ||||
| 		// 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 { | ||||
| 		abortWithError(w, err.Error()) | ||||
|   | ||||
| @@ -192,11 +192,12 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) { | ||||
| 	fi.Room.IsOver = false | ||||
| 	fi.Room.TeamTurn = "blue" | ||||
| 	fi.Room.LoadTestCards() | ||||
| 	fi.Room.UpdateCounter() | ||||
| 	fi.Room.TeamWon = "" | ||||
| 	if err := saveFullInfo(fi); err != nil { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	fi.Room.UpdateCounter() | ||||
| 	// reveal all cards | ||||
| 	if fi.State.Role == "mime" { | ||||
| 		fi.Room.RevealAllCards() | ||||
|   | ||||
| @@ -71,6 +71,7 @@ type Room struct { | ||||
| 	RoundTime int32  `json:"round_time"` | ||||
| 	// ProgressPct uint32 `json:"progress_pct"` | ||||
| 	IsOver  bool | ||||
| 	TeamWon string // blue | red | ||||
| } | ||||
|  | ||||
| func (r *Room) GetOppositeTeamColor() string { | ||||
|   | ||||
							
								
								
									
										8
									
								
								todos.md
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								todos.md
									
									
									
									
									
								
							| @@ -1,10 +1,7 @@ | ||||
| ### 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: two reasons (black word; all words); | ||||
| - ability to leave room; | ||||
|  | ||||
| #### sse points | ||||
| - clue sse update; | ||||
| @@ -19,3 +16,6 @@ | ||||
| ### 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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder