Feat: mark words [for guessers]
This commit is contained in:
		| @@ -171,6 +171,7 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) { | ||||
| 		abortWithError(w, "word is not found") | ||||
| 		return | ||||
| 	} | ||||
| 	cardword := models.WordCard{} | ||||
| 	// check if card already was revealed | ||||
| 	for i, card := range fi.Room.Cards { | ||||
| 		if !strings.EqualFold(card.Word, word) { | ||||
| @@ -180,97 +181,29 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) { | ||||
| 			abortWithError(w, "cannot mark already revealed") | ||||
| 			return | ||||
| 		} | ||||
| 		fi.Room.Cards[i].Mark = append(card.Mark, models.CardMark{ | ||||
| 			Username: fi.State.Username, | ||||
| 			Active:   true, | ||||
| 		}) | ||||
| 	} | ||||
| 	cardword := models.WordCard{ | ||||
| 		Word:     word, | ||||
| 		Color:    color, | ||||
| 		Revealed: false, | ||||
| 	} | ||||
| 	fi.Room.RevealSpecificWord(word) | ||||
| 	fi.Room.UpdateCounter() | ||||
| 	action := models.Action{ | ||||
| 		Actor:      fi.State.Username, | ||||
| 		ActorColor: string(fi.State.Team), | ||||
| 		WordColor:  string(color), | ||||
| 		Action:     models.ActionTypeGuess, | ||||
| 		Word:       word, | ||||
| 	} | ||||
| 	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 > 0 { | ||||
| 		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 | ||||
| 		fi.Room.IsRunning = false | ||||
| 		fi.Room.IsOver = true | ||||
| 		fi.Room.TeamWon = oppositeColor | ||||
| 		action := models.Action{ | ||||
| 			Actor:      fi.State.Username, | ||||
| 			ActorColor: string(fi.State.Team), | ||||
| 			WordColor:  models.WordColorBlack, | ||||
| 			Action:     models.ActionTypeGameOver, | ||||
| 		} | ||||
| 		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 | ||||
| 		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:  models.WordColorBlue, | ||||
| 				Action:     models.ActionTypeGameOver, | ||||
| 		// Check if the current user already has an active mark on this card | ||||
| 		found := false | ||||
| 		var newMarks []models.CardMark | ||||
| 		for _, mark := range card.Mark { | ||||
| 			if mark.Username == fi.State.Username && mark.Active { | ||||
| 				found = true | ||||
| 			} else { | ||||
| 				newMarks = append(newMarks, mark) | ||||
| 			} | ||||
| 			fi.Room.OpenedThisTurn = 0 | ||||
| 			fi.Room.ThisTurnLimit = 0 | ||||
| 			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:  models.WordColorRed, | ||||
| 				Action:     models.ActionTypeGameOver, | ||||
| 			} | ||||
| 			fi.Room.OpenedThisTurn = 0 | ||||
| 			fi.Room.ThisTurnLimit = 0 | ||||
| 			fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) | ||||
| 		if !found { | ||||
| 			newMarks = append(newMarks, models.CardMark{ | ||||
| 				Username: fi.State.Username, | ||||
| 				Active:   true, | ||||
| 			}) | ||||
| 		} | ||||
| 		fi.Room.Cards[i].Mark = newMarks | ||||
| 		cardword = fi.Room.Cards[i] | ||||
| 	} | ||||
| 	if err := saveFullInfo(fi); err != nil { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	// get mime bot for opp team and notify it | ||||
| 	notifyBotIfNeeded(fi) | ||||
| 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | ||||
| 	if err := tmpl.ExecuteTemplate(w, "cardword", cardword); err != nil { | ||||
| 		log.Error("failed to execute cardword template", "error", err) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder