Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added avatar implementations into the player.py file #11

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions game/common/player.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,65 @@
import uuid

from game.common.action import Action
from game.common.game_object import GameObject
from game.common.avatar import Avatar
from game.common.enums import *


class Player(GameObject):
def __init__(self, code=None, team_name=None, action=None):
def __init__(self, code=None, team_name=None, action=None, avatar=None):
super().__init__()
self.object_type = ObjectType.player
self.object_type = ObjectType.PLAYER

self.functional = True
self.error = None
self.team_name = team_name
self.code = code
self.action = action
self.avatar = avatar

@property
def action(self) -> Action: # Will need to change Avatar class to the enum eventually
return self.__action

@action.setter
def action(self, action: Action):
if action is None or isinstance(action, Action):
self.__action = action

@property
def functional(self) -> bool:
return self.__functional

@functional.setter
def functional(self, functional: bool):
if functional is None or isinstance(functional, bool):
self.__functional = functional

@property
def team_name(self) -> str:
return self.__team_name

@team_name.setter
def team_name(self, team_name: str):
if team_name is None or isinstance(team_name, str):
self.__team_name = team_name

@property
def avatar(self) -> Avatar:
return self.__avatar

@avatar.setter
def avatar(self, avatar: Avatar):
if avatar is None or isinstance(avatar, Avatar):
self.__avatar = avatar

@property
def object_type(self) -> ObjectType:
return self.object_type

@object_type.setter
def object_type(self, object_type: ObjectType):
if object_type is None or isinstance(object_type, GameObject):
self.__object_type = object_type

def to_json(self):
data = super().to_json()
Expand All @@ -23,6 +68,7 @@ def to_json(self):
data['error'] = self.error
data['team_name'] = self.team_name
data['action'] = self.action.to_json() if self.action is not None else None
data['avatar'] = self.avatar.to_json() if self.avatar is not None else None

return data

Expand All @@ -32,12 +78,12 @@ def from_json(self, data):
self.functional = data['functional']
self.error = data['error']
self.team_name = data['team_name']
act = Action()
self.action = act.from_json(data['action']) if data['action'] is not None else None
self.action = Action().from_json(data['action']) if data['action'] is not None else None
self.avatar = Avatar().from_json(data['avatar']) if data['avatar'] is not None else None

def __str__(self):
p = f"""ID: {self.id}
Team name: {self.team_name}
Action: {self.action}
"""
return p
return p