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

Fixed issue with partition to/from json, #98

Merged
merged 4 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
8 changes: 6 additions & 2 deletions game/common/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
from game.common.action import Action
from game.common.game_object import GameObject
from game.common.enums import *
from game.common.moving.shooter import Shooter


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

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

def to_json(self):
data = super().to_json()

data['functional'] = self.functional
data['error'] = self.error
data['team_name'] = self.team_name
data['shooter'] = self.shooter.to_json()
data['action'] = self.action.to_json(
) if self.action is not None else None

Expand All @@ -33,6 +35,8 @@ def from_json(self, data):
self.functional = data['functional']
self.error = data['error']
self.team_name = data['team_name']
shtr = Shooter()
self.shooter = shtr.from_json(data['shooter'])
act = Action()
self.action = act.from_json(
data['action']) if data['action'] is not None else None
Expand Down
22 changes: 11 additions & 11 deletions game/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,17 @@ def boot(self):
continue

# Otherwise, instantiate the player
player = Player()
self.clients.append(player)
if len(self.clients) == 0:
erickbickler marked this conversation as resolved.
Show resolved Hide resolved
# Add players one and two
ar = GameStats.player_stats["hitbox"][0]
hit = Hitbox(ar[0], ar[1], (ar[2], ar[3]))
player = Player(shooter=Shooter(hitbox=hit))
self.clients.append(player)
else:
ar = GameStats.player_stats["hitbox"][1]
hit = Hitbox(ar[0], ar[1], (ar[2], ar[3]))
player = Player(shooter=Shooter(hitbox=hit))
self.clients.append(player)

# Verify client isn't using invalid imports or opening anything
imports, opening = verify_code(filename + '.py')
Expand Down Expand Up @@ -167,15 +176,6 @@ def load(self):
gameBoard = GameBoard()
game_map = gameBoard.from_json(world['game_map'])

# Add players one and two
ar = GameStats.player_stats["hitbox"][0]
hit = Hitbox(ar[0], ar[1], (ar[2], ar[3]))
game_map.player_list.append(Shooter(hitbox=hit))

ar = GameStats.player_stats["hitbox"][1]
hit = Hitbox(ar[0], ar[1], (ar[2], ar[3]))
game_map.player_list.append(Shooter(hitbox=hit))

# add game map object to dictionary
world.pop("game_map", None)
self.world["game_map"] = game_map
Expand Down
4 changes: 2 additions & 2 deletions game/utils/generate_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def generate():
wall_copy = copy.deepcopy(wall)
x_offset = plot.position[0] + wall_copy.hitbox.position[0]
y_offset = plot.position[1] + wall_copy.hitbox.position[1]
wall_copy.position = (x_offset, y_offset)
game_map.wall_list.append(wall_copy)
wall_copy.hitbox.position = (x_offset, y_offset)
game_map.partition.add_object(wall_copy)

# Verify logs location exists
if not os.path.exists(GAME_MAP_DIR):
Expand Down
4 changes: 2 additions & 2 deletions game/utils/partition_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def remove_object(self, obj: MapObject) -> None:
def to_json(self):
data = {'matrix': [
[
[obj.to_json() for obj in self.__matrix[row][column]]
[obj.to_json() if "to_json" in dir(obj) else obj for obj in self.__matrix[row][column]]
for column in range(len(self.__matrix[row]))
]
for row in range(len(self.__matrix))
Expand All @@ -104,7 +104,7 @@ def to_json(self):
def from_json(self, data):
self.__matrix = [
[
[obj.from_json() for obj in column]
[obj.from_json() if "from_json" in dir(obj) else obj for obj in column]
erickbickler marked this conversation as resolved.
Show resolved Hide resolved
for column in row
]
for row in data['matrix']
Expand Down