From dc845c5454f2d6edbb16622148f55df6839e3a62 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 12 2023 18:40:47 +0000 Subject: handle skips --- diff --git a/game.py b/game.py index f564d48..f420e7e 100644 --- a/game.py +++ b/game.py @@ -46,13 +46,24 @@ class Player: friend = self.game.players[1] if self.game.players[0] == self else self.game.players[0] friendId = None if friend.joined else friend.id friendSelection = friend.selection if self.game.selected else -1 + + percent = None + turns = self.game.turn - self.game.skips + if not self.game.selected: turns -= 1 + if turns: + percent = round(self.game.score/turns*100, 2) + cards = [] for i in range(0, len(self.game.cards)): cards.append({ "index": i, "name": self.game.cards[i], "my": self.selection == i, "friends": friendSelection == i }) + return { "vocabulary": self.game.vocabulary, "turn": self.game.turn, + "skips": self.game.skips, "score": self.game.score, + "turns": turns, + "percent": percent, "word": self.game.word, "wordSource": self.game.wordSource, "cards": cards, @@ -62,8 +73,9 @@ class Player: "prefix": config.prefix, "cardsPrefix": config.cardsPrefix, "waiting": (self.joined and not self.game.started) or (self.selection >= 0 and not self.game.selected) or self.ready, - "win": self.game.selected and self.selection == friend.selection, - "lose": self.game.selected and self.selection != friend.selection, + "lose": self.game.turnResult == 1, + "win": self.game.turnResult == 2, + "skipped": self.game.turnResult == 3, "me": { "id": self.id, "name": self.name, @@ -82,8 +94,10 @@ class Game: self.players = ( Player(self, "Player1"), Player(self, "Player2") ) self.turn = 1 self.score = 0 + self.skips = 0 self.started = False self.selected = False + self.turnResult = 0 self.cards = [] self.word = "" self.wordSource = "" @@ -121,6 +135,7 @@ class Game: self.wordSource = "suggested by player2 (player1 may be lucky next time)" self.players[0].beginturn() self.players[1].beginturn() + self.turnResult = 0 self.selected = False def playerJoin(self): @@ -131,8 +146,15 @@ class Game: def playerSelect(self): if self.started and not self.selected and all(p.selection >= 0 for p in self.players): self.selected = True - if self.players[0].selection == self.players[1].selection: - self.score = self.score + 1 + self.turnResult = 1 + if any(p.selection == len(self.cards) - 1 for p in self.players): + self.skips += 1 + self.turnResult = 3 + elif self.players[0].selection == self.players[1].selection: + self.score += 1 + self.turnResult = 2 + else: + self.turnResult = 1 def playerReady(self): if self.started and self.selected and all(p.ready for p in self.players): diff --git a/tpl/css.tpl b/tpl/css.tpl index 2eb19e9..ed9313c 100644 --- a/tpl/css.tpl +++ b/tpl/css.tpl @@ -28,6 +28,13 @@ body { font-size: 12px; text-align: center; } color: gray; } +#skipped { + font-size: 24px; + font-weight: bold; + margin: 18px; + color: gray; +} + #mainform { display: block; padding-top: 100px; diff --git a/tpl/playerpage.tpl b/tpl/playerpage.tpl index d0bbcbd..0525a88 100644 --- a/tpl/playerpage.tpl +++ b/tpl/playerpage.tpl @@ -1,6 +1,6 @@ {include:header.tpl} {if:friend.id}
URL for the friend: {:host}{:prefix}/{:friend.id}
{endif} -
{:me.name}, score: {:score}, turn: {:turn}
+
{:me.name}, score: {:score}/{:turns}{if:percent}, percent: {:percent}%{endif}, turn: {:turn}, skipped: {:skips}

{:word}

{:wordSource} @@ -12,6 +12,9 @@ {if:lose}
Answers are different. You lose...
{endif} +{if:skipped} +
Word was skipped
+{endif} {if:waiting}
waiting for the friend