From 845c6b1cf165c93032d4947b79584cff6fb05560 Mon Sep 17 00:00:00 2001 From: Simon Pirkelmann Date: Thu, 24 Sep 2020 08:04:06 +0200 Subject: [PATCH] enabled displaying robot position in the web app and setting the position at the start of the game --- app.py | 18 +++++++++++++++--- roborally.py | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 00a0d43..2fbcc90 100644 --- a/app.py +++ b/app.py @@ -88,7 +88,6 @@ class Player: def __init__(self): if Player.player_counter < Player.MAX_PLAYERS: self.id = Player.player_counter - self.marker_id = 11 Player.player_counter += 1 self.max_cards = 9 @@ -99,11 +98,14 @@ class Player: self.action_count = 5 self.action_chosen = False - self.robot = game.board.create_robot(1,1,'>', self.id, self.marker_id) + self.robot = None else: print("max players reached!") + def initialize_robot(self, x, y, orientation, marker_id): + self.robot = game.board.create_robot(x, y, orientation, self.id, marker_id) + def draw_new_cards(self): self.player_hand += deck.draw_cards(self.max_cards - len(self.player_hand)) @@ -115,6 +117,11 @@ def send_cmds(): player_id = session['player_id'] p = players[player_id] + if p.robot is None: + x = int(request.form.get('x')) + y = int(request.form.get('y')) + p.initialize_robot(x, y, '>', 11) + if game.register_actions(p.id, p.player_hand[0:p.action_count]): p.player_hand = p.player_hand[p.action_count:] # discard used cards p.draw_new_cards() @@ -154,7 +161,12 @@ def hello_world(): if request.method == 'GET': - return render_template('drag_example.html', cmds=player_hand, player_id=player_id) + robot = players[player_id].robot + if robot is not None: + robot_pos = (robot.x, robot.y) + else: + robot_pos = None + return render_template('drag_example.html', cmds=player_hand, player_id=player_id, robot_pos=robot_pos) elif request.method == 'POST': #print(request.form) diff --git a/roborally.py b/roborally.py index 5e2f567..c0b36ed 100644 --- a/roborally.py +++ b/roborally.py @@ -311,7 +311,9 @@ class Board: #self.create_robot(1,1,'>', 7, 11) def create_robot(self, x, y, orientation, player_id, marker_id): - self.robots[player_id] = Robot(x, y, orientation, marker_id, self.board) + new_robot = Robot(x, y, orientation, marker_id, self.board) + self.robots[player_id] = new_robot + return new_robot def handle_push(self, direction, pushed_robot, forward=True, pushing_robot=None):