Commit 3c669984 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

basic stats implementation

parent d3110477
...@@ -132,4 +132,16 @@ table.snake-list { ...@@ -132,4 +132,16 @@ table.snake-list {
#snake_edit_form { #snake_edit_form {
clear: both; clear: both;
}
#bot_stats {
z-index:100;
background-color:rgba(0,0,0,0.5);
font-size:8pt;
position:absolute;
right:0; bottom:0;
}
#bot_stats tbody {
cursor:pointer;
} }
\ No newline at end of file
...@@ -68,6 +68,7 @@ Game.prototype.HandleMessage = function(event) ...@@ -68,6 +68,7 @@ Game.prototype.HandleMessage = function(event)
{ {
this.HandleMessage(this.preGameInfoMessages.pop()); this.HandleMessage(this.preGameInfoMessages.pop());
} }
return;
} else if (!this.gameInfoReceived) } else if (!this.gameInfoReceived)
{ {
this.preGameInfoMessages.push(event); this.preGameInfoMessages.push(event);
...@@ -76,9 +77,6 @@ Game.prototype.HandleMessage = function(event) ...@@ -76,9 +77,6 @@ Game.prototype.HandleMessage = function(event)
switch (data.t) switch (data.t)
{ {
case "GameInfo":
return this.vis.HandleGameInfoMessage(data.world_size_x, data.world_size_y, data.food_decay_per_frame);
case "WorldUpdate": case "WorldUpdate":
return this.vis.HandleWorldUpdateMessage(data); return this.vis.HandleWorldUpdateMessage(data);
...@@ -99,6 +97,13 @@ Game.prototype.HandleMessage = function(event) ...@@ -99,6 +97,13 @@ Game.prototype.HandleMessage = function(event)
} }
return this.vis.HandleTickMessage(null); // FIXME this is a workaround because we somehow do not receive TickMessage return this.vis.HandleTickMessage(null); // FIXME this is a workaround because we somehow do not receive TickMessage
case "BotStats":
this.HandleBotStatsMessage(data.data);
return;
case "BotMoveHead":
return;
case "FoodSpawn": case "FoodSpawn":
for (let item of data.items) for (let item of data.items)
{ {
...@@ -131,4 +136,20 @@ Game.prototype.HandleMessage = function(event) ...@@ -131,4 +136,20 @@ Game.prototype.HandleMessage = function(event)
return; return;
} }
}; };
\ No newline at end of file
Game.prototype.HandleBotStatsMessage = function(data)
{
let el = $('#bot_stats tbody');
let vis = this.vis;
el.empty();
for (let id in data)
{
let snake = this.vis.GetSnake(id);
if (!snake) { continue; }
let d = data[id];
let row = $("<tr><td>"+snake.GetName()+"</td><td>"+d.n.toFixed(1)+"</td><td>"+d.c.toFixed(1)+"</td><td>"+d.h.toFixed(1)+"</td></tr>");
row.click(function() { vis.FollowName(snake.GetName())});
el.append(row);
}
};
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
{% block content %} {% block content %}
<div id="stage" class="fullwindow" style="background-color:#00000080"></div> <div id="stage" class="fullwindow" style="background-color:#00000080"></div>
<table id="bot_stats">
<thead>
<tr>
<td>Snake</td>
<td>natural</td>
<td>carrison</td>
<td>hunted</td>
</tr>
</thead>
<tbody></tbody>
</table>
{% endblock %} {% endblock %}
{% block js %} {% block js %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment