Skip to content
Snippets Groups Projects
Commit a994f368 authored by mcmlxxix's avatar mcmlxxix
Browse files

reformatted player info line, correctly filter games by status, remove game...

reformatted player info line, correctly filter games by status, remove game file when a player exits, more cursor cleanup
parent 2c869c8b
No related branches found
No related tags found
No related merge requests found
...@@ -353,7 +353,7 @@ function lobby() ...@@ -353,7 +353,7 @@ function lobby()
for(var m in battles) { for(var m in battles) {
var battle=battles[m]; var battle=battles[m];
if(battle.in_progress) if(battle.status == 1)
in_progress.push(battle); in_progress.push(battle);
else else
waiting.push(battle); waiting.push(battle);
...@@ -442,7 +442,7 @@ function playGame(battle) ...@@ -442,7 +442,7 @@ function playGame(battle)
break; break;
case "Q": case "Q":
case "\x1b": case "\x1b":
delete battle.players[currentPlayerID]; deleteBattle();
return false; return false;
case "R": case "R":
redraw(); redraw();
...@@ -467,23 +467,22 @@ function playGame(battle) ...@@ -467,23 +467,22 @@ function playGame(battle)
var shot=shots[s]; var shot=shots[s];
unDrawShot(shot); unDrawShot(shot);
moveShot(shot);
if(shot.range == 0) { if(shot.range == 0) {
shots.splice(s,1); shots.splice(s,1);
s--; s--;
console.home();
continue; continue;
} }
moveShot(shot);
if(checkHit(shot)) { if(checkHit(shot,currentPlayer)) {
shots.splice(s,1); shots.splice(s,1);
s--; s--;
hitPlayer(shot.range); hitPlayer(shot.range);
continue; } else {
}
drawShot(shot); drawShot(shot);
} }
}
lastUpdate=system.timer; lastUpdate=system.timer;
} }
...@@ -516,6 +515,7 @@ function playGame(battle) ...@@ -516,6 +515,7 @@ function playGame(battle)
break; break;
case "SHOT": case "SHOT":
var shot=new Shot(packet.heading,packet.coords,packet.range,packet.player,packet.color); var shot=new Shot(packet.heading,packet.coords,packet.range,packet.player,packet.color);
var p=packet.player;
drawShot(shot); drawShot(shot);
shots.push(shot); shots.push(shot);
break; break;
...@@ -555,6 +555,7 @@ function playGame(battle) ...@@ -555,6 +555,7 @@ function playGame(battle)
} }
function deleteBattle() function deleteBattle()
{ {
delete battle.players[currentPlayerID];
if(file_exists(battle.dataFile)) { if(file_exists(battle.dataFile)) {
file_remove(battle.dataFile); file_remove(battle.dataFile);
} }
...@@ -710,32 +711,32 @@ function playGame(battle) ...@@ -710,32 +711,32 @@ function playGame(battle)
{ {
switch(heading) { switch(heading) {
case 0: case 0:
y-=3; y-=2;
break; break;
case 45: case 45:
y-=3; y-=2;
x+=3; x+=2;
break; break;
case 90: case 90:
x+=3; x+=2;
break; break;
case 135: case 135:
x+=3; x+=2;
y+=3; y+=2;
break; break;
case 180: case 180:
y+=3; y+=2;
break; break;
case 225: case 225:
x-=3; x-=2;
y+=3; y+=2;
break; break;
case 270: case 270:
x-=3; x-=2;
break; break;
case 315: case 315:
y-=3; y-=2;
x-=3; x-=2;
break; break;
} }
return new Coords(x,y); return new Coords(x,y);
...@@ -1008,9 +1009,9 @@ function playGame(battle) ...@@ -1008,9 +1009,9 @@ function playGame(battle)
} }
return false; return false;
} }
function checkHit(shot) function checkHit(shot,player)
{ {
var position=currentPlayer.coords; var position=player.coords;
var spots=[]; var spots=[];
spots.push(new Coords(position.x-2,position.y-2)); spots.push(new Coords(position.x-2,position.y-2));
spots.push(new Coords(position.x-2,position.y-1)); spots.push(new Coords(position.x-2,position.y-1));
...@@ -1033,8 +1034,10 @@ function playGame(battle) ...@@ -1033,8 +1034,10 @@ function playGame(battle)
{ {
console.home(); console.home();
for(var p in battle.players) { for(var p in battle.players) {
var ply=battle.players[p]; var player=battle.players[p];
console.putmsg(" " + ply.color + ply.name + "\1k\1h:" + (ply.health<=25?"\1r":ply.color) + ply.health); var name=player.color + players.getAlias(player.name);
var hline=(player.health<=25?"\1r":player.color) + player.health;
console.putmsg(" " + name + "\1k\1h [\1n" + player.color + "hp\1h:\1n" + hline + "\1k\1h]");
} }
console.cleartoeol(); console.cleartoeol();
} }
...@@ -1048,6 +1051,10 @@ function playGame(battle) ...@@ -1048,6 +1051,10 @@ function playGame(battle)
{ {
console.gotoxy(shot.coords.x,shot.coords.y); console.gotoxy(shot.coords.x,shot.coords.y);
console.putmsg(" "); console.putmsg(" ");
if(checkHit(shot,battle.players[shot.player])) {
drawTank(battle.players[shot.player]);
drawTurret(battle.players[shot.player]);
}
} }
function unDrawTank(tank) function unDrawTank(tank)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment