display more info and add damage effects
This commit is contained in:
parent
5ffec68506
commit
dab4c69d50
49
app.py
49
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)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
###############
|
||||
# #p<<<<< #
|
||||
#p #p<<<<< #
|
||||
# a # b #
|
||||
# v # v>> #
|
||||
# + - +r- + p-#
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -1,57 +1,72 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Drag</title>
|
||||
|
||||
<script src="static/jquery-3.5.1.js"></script>
|
||||
<script src="static/jquery-ui.min.js"></script>
|
||||
<script src="static/bootstrap.min.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="static/bootstrap.css">
|
||||
<link rel="stylesheet" href="static/style.css">
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hallo Spieler {{ player_id + 1 }}</h1>
|
||||
<!-- container -->
|
||||
<div class="container">
|
||||
<h1>Hallo Spieler {{ player_id + 1 }}</h1>
|
||||
|
||||
<div class="main-canvas">
|
||||
<div class="row top-buffer">
|
||||
<div class="main-canvas">
|
||||
{% for i in range(0,9) %}
|
||||
<div class="box card{{ i }}" name="{{ cmds[i].number }}" >{{ cmds[i].action }}
|
||||
<p style="font-size: 10px">{{ cmds[i].priority }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% for i in range(0,9) %}
|
||||
<div class="box card{{ i }}" name="{{ cmds[i].number }}" >{{ cmds[i].action }}
|
||||
<p style="font-size: 10px">{{ cmds[i].priority }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row top-buffer">
|
||||
{% if robot_info is none %}
|
||||
<label for="inputRobotX">X:</label>
|
||||
<input type="number" id="inputRobotX" name="robot_x" min="1" max="13" value="1">
|
||||
<div class="col-sm">
|
||||
<label for="inputRobotX">X Position:</label>
|
||||
<input class="form-control" type="number" id="inputRobotX" name="robot_x" min="1" max="13" value="1">
|
||||
<br>
|
||||
<label for="inputRobotY">Y:</label>
|
||||
<input type="number" id="inputRobotY" name="robot_y" min="1" max="7" value="1">
|
||||
<br>
|
||||
<label for="orientation">Orientation:</label>
|
||||
<label for="inputRobotY">Y Position:</label>
|
||||
<input class="form-control" type="number" id="inputRobotY" name="robot_y" min="1" max="7" value="1">
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<label for="orientation">Blickrichtung:</label><br>
|
||||
<img id="orientation" class="robotOrientation" src="/static/orientation.png" alt="0">
|
||||
<input hidden id="inputRobotOrientation" value=">" readonly>
|
||||
<br>
|
||||
<label for="inputRobotID">Robot ID:</label>
|
||||
<select name="robotID" id="inputRobotID">
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<label for="inputRobotID">Roboter ID:</label>
|
||||
<select name="robotID" class="form-control" id="inputRobotID">
|
||||
<option value="11">11</option>
|
||||
<option value="12">12</option>
|
||||
<option value="13">13</option>
|
||||
<option value="14">14</option>
|
||||
</select>
|
||||
<label for="outputRobotFlags">Flaggen:</label><br>
|
||||
{% for f in ['a', 'b', 'c', 'd'] %}
|
||||
<input type="checkbox" class="form-check-input" id="flag_{{ f }}" onclick="return false;">
|
||||
<label class="form-check-label" for="flag_{{ f }}">{{ f }}</label><br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<label for="outputRobotX">X:</label>
|
||||
<input type="number" id="outputRobotX" name="robot_x" min="1" max="12" value="{{ robot_info[0] }}" readonly>
|
||||
<br>
|
||||
<label for="outputRobotY">Y:</label>
|
||||
<input type="number" id="outputRobotY" name="robot_y" min="1" max="6" value="{{ robot_info[1] }}" readonly>
|
||||
<div class="col-sm">
|
||||
<label for="outputRobotX">X Position:</label>
|
||||
<input class="form-control" type="number" id="outputRobotX" name="robot_x" min="1" max="12" value="{{ robot_info[0] }}" readonly>
|
||||
<br>
|
||||
<label for="outputRobotY">Y Position:</label>
|
||||
<input class="form-control" type="number" id="outputRobotY" name="robot_y" min="1" max="6" value="{{ robot_info[1] }}" readonly>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<label for="outputOrientation">Blickrichtung:</label><br>
|
||||
{% if robot_info[2] == '>' %}
|
||||
<img id="outputOrientation" class="robotOrientation" src="/static/orientation.png" alt="0">
|
||||
{% elif robot_info[2] == 'v' %}
|
||||
|
@ -62,15 +77,31 @@
|
|||
<img id="outputOrientation" class="robotOrientation270" src="/static/orientation.png" alt="0">
|
||||
{% endif %}
|
||||
<br>
|
||||
<label for="outputRobotID">Robot ID:</label>
|
||||
<input name="robotID" id="outputRobotID" value="{{ robot_info[3] }}" readonly>
|
||||
<label for="outputRobotDmg">Schaden:</label><br>
|
||||
<input class="form-control" name="robotDmg" id="outputRobotDmg" value="{{ robot_info[4] }}" readonly>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<label for="outputRobotID">Roboter ID:</label>
|
||||
<input class="form-control" name="robotID" id="outputRobotID" value="{{ robot_info[3] }}" readonly>
|
||||
<label for="outputRobotFlags">Flaggen:</label><br>
|
||||
{% for f in ['a', 'b', 'c', 'd'] %}
|
||||
{% if f in robot_info[5] %}
|
||||
<input type="checkbox" class="form-check-input" id="flag_{{ f }}" checked onclick="return false;">
|
||||
{% else %}
|
||||
<input type="checkbox" class="form-check-input" id="flag_{{ f }}" onclick="return false;">
|
||||
{% endif %}
|
||||
<label class="form-check-label" for="flag_{{ f }}">{{ f }}</label><br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row top-buffer">
|
||||
<input class="btn btn-primary" id="btnSubmit" type="submit" value="Befehle abschicken" />
|
||||
</div>
|
||||
|
||||
</div><!-- container -->
|
||||
|
||||
<input id="btnSubmit" type="submit" value="Befehle abschicken" />
|
||||
|
||||
|
||||
<div class="container notification" hidden>
|
||||
|
@ -119,6 +150,7 @@
|
|||
var robot_orient = $("#inputRobotOrientation");
|
||||
var robot_id = $("#inputRobotID");
|
||||
//alert("button");
|
||||
|
||||
for (i = 0; i < 9; i++) {
|
||||
var c = document.getElementsByClassName("box card" + String(i));
|
||||
if (c[0].offsetTop === 0) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user