game: add: class: point and segment, add: type docstring
This commit is contained in:
@ -6,6 +6,8 @@ from channels.generic.websocket import WebsocketConsumer
|
||||
|
||||
from .Position import Position
|
||||
from .Spectator import Spectator
|
||||
from .Point import Point
|
||||
from .Segment import Segment
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
@ -15,7 +17,7 @@ if TYPE_CHECKING:
|
||||
|
||||
class Player(Spectator):
|
||||
|
||||
def __init__(self, game: Game, user_id: int, socket: WebsocketConsumer, rail_start_x: float, rail_start_y: float, rail_stop_x: float, rail_stop_y: float) -> None:
|
||||
def __init__(self, game: Game, user_id: int, socket: WebsocketConsumer, rail: Segment) -> None:
|
||||
|
||||
super().__init__(user_id, socket, game)
|
||||
|
||||
@ -23,10 +25,7 @@ class Player(Spectator):
|
||||
|
||||
self.nb_goal: int = 0
|
||||
|
||||
self.rail_start_x: float = rail_start_x
|
||||
self.rail_start_y: float = rail_start_y
|
||||
self.rail_stop_x: float = rail_stop_x
|
||||
self.rail_stop_y: float = rail_stop_y
|
||||
self.rail: Segment = rail
|
||||
|
||||
def receive(self, data: dict):
|
||||
|
||||
@ -106,19 +105,17 @@ class Player(Spectator):
|
||||
|
||||
def disconnect(self, code: int = 1000):
|
||||
self.socket = None
|
||||
print("bozoman")
|
||||
self.game.leave(self)
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self) -> dict:
|
||||
|
||||
data = {
|
||||
"user_id": self.user_id,
|
||||
"position": self.position.to_dict(),
|
||||
"nb_goal": self.nb_goal,
|
||||
|
||||
"rail_start_x": self.rail_start_x,
|
||||
"rail_start_y": self.rail_start_y,
|
||||
"rail_stop_x": self.rail_stop_x,
|
||||
"rail_stop_y": self.rail_stop_y,
|
||||
"rail": self.rail.to_dict(),
|
||||
|
||||
"is_connected": self.is_connected(),
|
||||
}
|
||||
|
Reference in New Issue
Block a user