game: add: goal statistic
This commit is contained in:
@ -97,6 +97,13 @@ class Game(AbstractRoom):
|
||||
for member in members:
|
||||
member.send(detail, data)
|
||||
|
||||
def goal(self, goal_taker: Player):
|
||||
|
||||
timestamp = goal_taker.add_goal()
|
||||
|
||||
self.broadcast("goal", {"player_id": goal_taker.user_id,
|
||||
"timestamp": timestamp})
|
||||
|
||||
def get_player_by_user_id(self, user_id: int) -> Player:
|
||||
for player in self.players:
|
||||
if (player.user_id == user_id):
|
||||
@ -144,11 +151,10 @@ class Game(AbstractRoom):
|
||||
connected_players: list[Player] = self.get_players_connected()
|
||||
|
||||
if (self.model.started):
|
||||
print(len(connected_players))
|
||||
if (len(connected_players) == 1):
|
||||
last_player: Player = connected_players[0]
|
||||
print("finish")
|
||||
self.finish(last_player)
|
||||
#self.finish(last_player)
|
||||
return
|
||||
|
||||
self._update_player(player)
|
||||
|
@ -25,7 +25,7 @@ class Player(Spectator):
|
||||
|
||||
self.position: Position = Position(0.5, 0)
|
||||
|
||||
self.nb_goal: int = 0
|
||||
self.score: list[int] = []
|
||||
|
||||
self.rail: Segment = rail
|
||||
|
||||
@ -112,13 +112,23 @@ class Player(Spectator):
|
||||
print("bozoman")
|
||||
self.game.leave(self)
|
||||
|
||||
def add_goal(self):
|
||||
|
||||
timestamp = self.game.model.add_goal(self.user_id)
|
||||
|
||||
self.score.append(timestamp)
|
||||
|
||||
print(self.score)
|
||||
|
||||
return timestamp
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
|
||||
data = {
|
||||
"username": self.username,
|
||||
"user_id": self.user_id,
|
||||
"position": self.position.to_dict(),
|
||||
"nb_goal": self.nb_goal,
|
||||
"score": [*self.score],
|
||||
|
||||
"rail": self.rail.to_dict(),
|
||||
|
||||
|
Reference in New Issue
Block a user