enabled displaying robot position in the web app and setting the

position at the start of the game
master
Simon Pirkelmann 2020-09-24 23:58:17 +02:00
parent 845c6b1cf1
commit 4baeace2ee
1 changed files with 24 additions and 2 deletions

View File

@ -26,6 +26,24 @@
</div> </div>
{% if robot_pos is none %}
<div class="row">
<label for="inputRobotX">X:</label>
<input type="number" id="inputRobotX" name="robot_x" min="1" max="12" value="5">
<label for="inputRobotY">Y:</label>
<input type="number" id="inputRobotY" name="robot_y" min="1" max="6" value="3">
</div>
{% else %}
<div class="row">
<label for="inputRobotX">X:</label>
<input type="number" id="inputRobotX" name="robot_x" min="1" max="12" value="{{ robot_pos[0] }}" readonly>
<label for="inputRobotY">Y:</label>
<input type="number" id="inputRobotY" name="robot_y" min="1" max="6" value="{{ robot_pos[1] }}" readonly>
</div>
{% endif %}
</div><!-- container --> </div><!-- container -->
<input id="btnSubmit" type="submit" value="Befehle abschicken" /> <input id="btnSubmit" type="submit" value="Befehle abschicken" />
@ -43,7 +61,12 @@
var box = $(".box"); var box = $(".box");
var mainCanvas = $(".main-canvas"); var mainCanvas = $(".main-canvas");
$("#btnSubmit").click(function () { $("#btnSubmit").click(function () {
var robot_x = $("#inputRobotX");
var robot_y = $("#inputRobotY");
//alert("button"); //alert("button");
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
var c = document.getElementsByClassName("box card" + String(i)); var c = document.getElementsByClassName("box card" + String(i));
@ -51,10 +74,9 @@
$(c).hide(); $(c).hide();
} }
} }
$(please_wait).show(); $(please_wait).show();
$.post("/send_cmds", "", function (data) { $.post("/send_cmds", { "x" : robot_x.val(), "y": robot_y.val()}, function (data) {
console.log(data); console.log(data);
if (data === 'OK') { if (data === 'OK') {
location.reload(); // reload page to get new cards for next round location.reload(); // reload page to get new cards for next round