diff --git a/app.py b/app.py index ea5437a..41574ef 100644 --- a/app.py +++ b/app.py @@ -28,6 +28,7 @@ class Game: print("connected!") except socket.error: print("could not connect to robot control socket!") + self.comm_socket = None def ready(self): # have all players chosen an action? @@ -54,7 +55,7 @@ class Game: # process the chosen commands and generate a list of robot commands to send to the controller program cmd_list = self.board.apply_actions(chosen_cards) - if True: + if self.comm_socket is not None: # send movements to the controller program for c in cmd_list: if not 'nop' in c: @@ -111,27 +112,28 @@ class Player: def initialize_robot(self, x, y, orientation, marker_id): self.robot = game.board.create_robot(x, y, orientation, self.id, marker_id) - # TODO: general form - # (1,1) <-> (-6, 3) - # (1,2) <-> (-6, 2) -> y_ctrl = y_game - 4 - # (2,1) <-> (-5, 3) -> x_ctrl = x_game - 7 - x_trans = x - 7 - y_trans = 4 - y - angle_trans = {'>': 0.0, 'v': -np.pi/2, '<': -np.pi, '^': np.pi/2} - cmd = "set position, {}, ({}, {}, {})\n".format(marker_id, x_trans, y_trans, angle_trans[orientation]) - game.comm_socket.sendall(cmd.encode()) - data = game.comm_socket.recv(32) - print("data from set position: ", data) + if game.comm_socket is not None: + # TODO: general form + # (1,1) <-> (-6, 3) + # (1,2) <-> (-6, 2) -> y_ctrl = y_game - 4 + # (2,1) <-> (-5, 3) -> x_ctrl = x_game - 7 + x_trans = x - 7 + y_trans = 4 - y + angle_trans = {'>': 0.0, 'v': -np.pi/2, '<': -np.pi, '^': np.pi/2} + cmd = "set position, {}, ({}, {}, {})\n".format(marker_id, x_trans, y_trans, angle_trans[orientation]) + game.comm_socket.sendall(cmd.encode()) + data = game.comm_socket.recv(32) + print("data from set position: ", data) - cmd2 = "turn left, {}\n".format(marker_id) - game.comm_socket.sendall(cmd2.encode()) - data = game.comm_socket.recv(32) - print("data from turn left: ", data) + cmd2 = "turn left, {}\n".format(marker_id) + game.comm_socket.sendall(cmd2.encode()) + data = game.comm_socket.recv(32) + print("data from turn left: ", data) - cmd3 = "turn right, {}\n".format(marker_id) - game.comm_socket.sendall(cmd3.encode()) - data = game.comm_socket.recv(32) - print("data from turn right: ", data) + cmd3 = "turn right, {}\n".format(marker_id) + game.comm_socket.sendall(cmd3.encode()) + data = game.comm_socket.recv(32) + print("data from turn right: ", data) def draw_new_cards(self): self.player_hand += deck.draw_cards(self.max_cards - len(self.player_hand)) @@ -151,8 +153,9 @@ def send_cmds(): marker_id = int(request.form.get('marker_id')) p.initialize_robot(x, y, orient, marker_id) - 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 + number_of_cards = p.action_count - p.robot.damage + if game.register_actions(p.id, p.player_hand[0:number_of_cards]): + p.player_hand = p.player_hand[number_of_cards:] # discard used cards p.draw_new_cards() if game.ready(): @@ -192,7 +195,7 @@ def hello_world(): if request.method == 'GET': robot = players[player_id].robot if robot is not None: - robot_info = (robot.x, robot.y, robot.orientation, robot.marker_id) + robot_info = (robot.x, robot.y, robot.orientation, robot.marker_id, robot.damage, robot.collected_flags) else: robot_info = None return render_template('drag_example.html', cmds=player_hand, player_id=player_id, robot_info=robot_info) diff --git a/board.txt b/board.txt index f093c5d..740298e 100644 --- a/board.txt +++ b/board.txt @@ -1,5 +1,5 @@ ############### -# #p<<<<< # +#p #p<<<<< # # a # b # # v # v>> # # + - +r- + p-# diff --git a/roborally.py b/roborally.py index e34eed0..d21ede2 100644 --- a/roborally.py +++ b/roborally.py @@ -201,7 +201,7 @@ class Robot: return True def take_damage(self, count): - self.damage = min(self.damage + count, 10) + self.damage = min(self.damage + count, 4) def heal_damage(self, count): self.damage = max(self.damage - count, 0) diff --git a/static/style.css b/static/style.css index b7f4153..1fc4b30 100644 --- a/static/style.css +++ b/static/style.css @@ -6,6 +6,14 @@ position: relative; } +.register { + outline: 3px dashed #dddddd;; + width: 120px; + height: 240px; + margin: 0px auto 0; + position: relative; +} + .box{ width: 62px; height: 100px; @@ -79,6 +87,9 @@ transform: rotate(270deg); } +.top-buffer { margin-top:20px; } + + .card0 { left: 0; top: 0; background-color: #E74C3C; } .card1 { left: 100px; top: 0; background-color: #8E44AD; } .card2 { left: 200px; top: 0; background-color: #5DADE2; } diff --git a/templates/drag_example.html b/templates/drag_example.html index c86fd0a..32097b8 100644 --- a/templates/drag_example.html +++ b/templates/drag_example.html @@ -1,57 +1,72 @@ - + + Drag + + -

Hallo Spieler {{ player_id + 1 }}

+

Hallo Spieler {{ player_id + 1 }}

-
+
+
+ {% for i in range(0,9) %} +
{{ cmds[i].action }} +

{{ cmds[i].priority }}

+
+ {% endfor %} - {% for i in range(0,9) %} -
{{ cmds[i].action }} -

{{ cmds[i].priority }}

- {% endfor %} -
- -
+
{% if robot_info is none %} - - +
+ +
- - -
- + + +
+
+
0 -
- - +
+ {% for f in ['a', 'b', 'c', 'd'] %} + +
+ {% endfor %} +
{% else %} - - -
- - +
+ +
+ + +
+
+
{% if robot_info[2] == '>' %} 0 {% elif robot_info[2] == 'v' %} @@ -62,15 +77,31 @@ 0 {% endif %}
- - +
+ +
+
+ + +
+ {% for f in ['a', 'b', 'c', 'd'] %} + {% if f in robot_info[5] %} + + {% else %} + + {% endif %} +
+ {% endfor %} +
{% endif %} -
+
+
+ +
-