enabled displaying robot position in the web app and setting the

position at the start of the game
This commit is contained in:
Simon Pirkelmann 2020-09-24 08:04:06 +02:00
parent 5359dfc4ac
commit 845c6b1cf1
2 changed files with 18 additions and 4 deletions

18
app.py
View File

@ -88,7 +88,6 @@ class Player:
def __init__(self): def __init__(self):
if Player.player_counter < Player.MAX_PLAYERS: if Player.player_counter < Player.MAX_PLAYERS:
self.id = Player.player_counter self.id = Player.player_counter
self.marker_id = 11
Player.player_counter += 1 Player.player_counter += 1
self.max_cards = 9 self.max_cards = 9
@ -99,11 +98,14 @@ class Player:
self.action_count = 5 self.action_count = 5
self.action_chosen = False self.action_chosen = False
self.robot = game.board.create_robot(1,1,'>', self.id, self.marker_id) self.robot = None
else: else:
print("max players reached!") 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): def draw_new_cards(self):
self.player_hand += deck.draw_cards(self.max_cards - len(self.player_hand)) 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'] player_id = session['player_id']
p = players[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]): 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.player_hand = p.player_hand[p.action_count:] # discard used cards
p.draw_new_cards() p.draw_new_cards()
@ -154,7 +161,12 @@ def hello_world():
if request.method == 'GET': 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': elif request.method == 'POST':
#print(request.form) #print(request.form)

View File

@ -311,7 +311,9 @@ class Board:
#self.create_robot(1,1,'>', 7, 11) #self.create_robot(1,1,'>', 7, 11)
def create_robot(self, x, y, orientation, player_id, marker_id): 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): def handle_push(self, direction, pushed_robot, forward=True, pushing_robot=None):