Feat: add game over
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user