Commit d3e28a65 authored by Hubert Denkmair's avatar Hubert Denkmair

add kill log to tv log

parent 43db42e9
......@@ -9,6 +9,7 @@ function Game(assets, snakeMoveStrategy, container)
this.snakeMoveStrategy = snakeMoveStrategy;
this.vis = new GameVisualization(assets, snakeMoveStrategy, container);
this.logHandlers = [];
this.gameEventHandlers = [];
this.gameInfoReceived = false;
this.preGameInfoMessages = [];
......@@ -21,9 +22,17 @@ function Game(assets, snakeMoveStrategy, container)
}
Game.prototype.AddLogHandler = function(callback, thisArg)
Game.prototype.AddGameEventHandler = function(callback, thisArg)
{
this.logHandlers.push([callback, thisArg]);
this.gameEventHandlers.push([callback, thisArg]);
};
Game.prototype.SendGameEvent = function(className, message)
{
for (let i of this.gameEventHandlers)
{
i[0].call(i[1], className, message);
}
};
Game.prototype.Run = function()
......@@ -100,6 +109,13 @@ Game.prototype.HandleMessage = function(event)
return this.vis.HandleBotSpawnMessage(data.bot);
case "BotKill":
let killer = this.vis.snakes[data.killer_id];
let victim = this.vis.snakes[data.victim_id];
if (killer && victim)
{
let msg = killer.GetName() + " killed " + victim.GetName();
this.SendGameEvent("kill", msg);
}
return this.vis.HandleBotKilledMessage(data.killer_id, data.victim_id);
case "BotMove":
......
......@@ -17,6 +17,17 @@
border-radius: 0.5em 0.5em 0 0;
padding: 0.1em 0.5em;
}
#gameEvents {
position: absolute;
bottom: 0;
right: 0;
background-color: rgba(0,0,0,0.5);
font-size: 18px;
text-align:right;
padding:10px;
}
body { background:black; }
</style>
{% endblock %}
......@@ -28,6 +39,7 @@
<div id="stage"></div>
<img id="tvlogo" src="{% static "visualization/assets/bytewerk_tv_150w_2.png" %}">
<div id="url"><span>https://schlangen.bytewerk.org/</span></div>
<div id="gameEvents"></div>
{% endblock %}
{% block footer %}
......@@ -47,6 +59,16 @@
game.vis.Resize();
};
game.AddGameEventHandler(function(className, msg) {
console.log(msg);
let logDiv = $("#gameEvents");
while ($("#gameEvents").children().length >= 10)
{
$("#gameEvents").children().first().remove();
}
$("<div></div>").addClass(className).text(msg).appendTo(logDiv);
}, this);
let currentView = 0;
window.setInterval(function() {
currentView = (currentView + 1) % 10;
......
Markdown is supported
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