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

Use time_t for game timer, add revision info

parent c35cc6ee
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
For Synchronet v3.15+ For Synchronet v3.15+
Matt Johnson(2009) Matt Johnson(2009)
*/ */
//$Id$
const VERSION="$Revision$".split(' ')[1];
load("chateng.js"); load("chateng.js");
load("graphic.js"); load("graphic.js");
...@@ -308,8 +310,7 @@ function lobby() ...@@ -308,8 +310,7 @@ function lobby()
break; break;
case 0: case 0:
if(!t.timer.countdown) t.loadGame(); if(!t.timer.countdown) t.loadGame();
var current=time(); var difference=time()-t.timer.lastupdate;
var difference=current-t.timer.lastupdate;
if(!difference>=1) break; if(!difference>=1) break;
if(!t.timer.countDown(difference)) { if(!t.timer.countDown(difference)) {
startGame(t); startGame(t);
...@@ -353,7 +354,7 @@ function lobby() ...@@ -353,7 +354,7 @@ function lobby()
game.status=0; game.status=0;
var file=new File(game.dataFile); var file=new File(game.dataFile);
file.open('r+',true); file.open('r+',true);
file.iniSetValue(null,"created",system.timer); file.iniSetValue(null,"created","" + time());
file.iniSetValue(null,"status",0); file.iniSetValue(null,"status",0);
file.close(); file.close();
} }
...@@ -438,7 +439,7 @@ function lobby() ...@@ -438,7 +439,7 @@ function lobby()
function playGame(game) function playGame(game)
{ {
var menu; var menu;
var lastupdate=system.timer; var lastupdate=time();
/* lines per level */ /* lines per level */
var lines=10; var lines=10;
...@@ -471,13 +472,6 @@ function playGame(game) ...@@ -471,13 +472,6 @@ function playGame(game)
} }
currentPlayer=game.players[currentPlayerID]; currentPlayer=game.players[currentPlayerID];
} }
function initChat()
{
chat.init(38,15,42,8);
chat.input_line.init(42,24,38,"","\1n");
chat.partChan("tetris lobby",user.alias);
chat.joinChan("tetris game " + game.gameNumber,user.alias,user.name);
}
function main() function main()
{ {
redraw(); redraw();
...@@ -573,9 +567,11 @@ function playGame(game) ...@@ -573,9 +567,11 @@ function playGame(game)
} }
killPlayer(currentPlayerID); killPlayer(currentPlayerID);
send("DEAD"); send("DEAD");
if(game.status == 2 && game.winner == currentPlayerID) { if((game.status == 2 && game.winner == currentPlayerID) || countMembers(game.players)==1) {
if(file_exists(game.dataFile.name)) if(file_exists(game.dataFile))
file_remove(game.dataFile.name); file_remove(game.dataFile);
if(file_exists(game.dataFile + ".bck"))
file_remove(game.dataFile + ".bck");
} }
return true; return true;
} }
...@@ -587,10 +583,10 @@ function playGame(game) ...@@ -587,10 +583,10 @@ function playGame(game)
if(!currentPlayer || !currentPlayer.active) return; if(!currentPlayer || !currentPlayer.active) return;
var update=false; var update=false;
var difference=system.timer-lastupdate; var difference=time()-lastupdate;
if(difference<pause) return; if(difference<pause) return;
lastupdate=system.timer; lastupdate=time();
getLines(); getLines();
...@@ -645,6 +641,7 @@ function playGame(game) ...@@ -645,6 +641,7 @@ function playGame(game)
game.players[packet.player].drawNext(); game.players[packet.player].drawNext();
break; break;
case "HOLD": case "HOLD":
game.players[packet.player].unDrawPiece();
game.players[packet.player].holdPiece=packet.piece; game.players[packet.player].holdPiece=packet.piece;
game.players[packet.player].drawHold(); game.players[packet.player].drawHold();
break; break;
...@@ -700,6 +697,8 @@ function playGame(game) ...@@ -700,6 +697,8 @@ function playGame(game)
break; break;
case "UPDATE": case "UPDATE":
break; break;
case "PLAYER":
break;
case "GRID": case "GRID":
data.grid=currentPlayer.grid; data.grid=currentPlayer.grid;
break; break;
...@@ -843,14 +842,14 @@ function playGame(game) ...@@ -843,14 +842,14 @@ function playGame(game)
currentPlayer.drawPiece(); currentPlayer.drawPiece();
currentPlayer.drawNext(); currentPlayer.drawNext();
currentPlayer.drawHold(); currentPlayer.drawHold();
send("HOLD");
send("PIECE"); send("PIECE");
send("NEXT"); send("NEXT");
send("HOLD");
} else { } else {
currentPlayer.holdPiece=currentPlayer.currentPiece.id; currentPlayer.holdPiece=currentPlayer.currentPiece.id;
send("HOLD");
getNewPiece(); getNewPiece();
currentPlayer.drawHold(); currentPlayer.drawHold();
send("HOLD");
} }
} }
function getNewPiece() function getNewPiece()
...@@ -1017,7 +1016,6 @@ function playGame(game) ...@@ -1017,7 +1016,6 @@ function playGame(game)
} }
initGame(); initGame();
//initChat();
main(); main();
} }
......
...@@ -3,7 +3,7 @@ function Tetris(dataFile) ...@@ -3,7 +3,7 @@ function Tetris(dataFile)
this.timer=new Timer("\1y\1h"); this.timer=new Timer("\1y\1h");
this.players=[]; this.players=[];
this.status=-1; this.status=-1;
this.lastupdate=0; this.lastupdate=-1;
this.garbage=true; this.garbage=true;
this.update=true; this.update=true;
this.winner=false; this.winner=false;
...@@ -41,19 +41,20 @@ function Tetris(dataFile) ...@@ -41,19 +41,20 @@ function Tetris(dataFile)
var created=file.iniGetValue(null,"created"); var created=file.iniGetValue(null,"created");
if(created > 0) { if(created > 0) {
var current=system.timer; var current=time();
var difference=current-created; var difference=current-created;
this.timer.init(20-difference); this.timer.init(20-difference);
} }
this.gameNumber=Number(file.iniGetValue(null,"gameNumber")); this.gameNumber=Number(file.iniGetValue(null,"gameNumber"));
this.status=file.iniGetValue(null,"status"); this.status=file.iniGetValue(null,"status");
this.players=file.iniGetObject("players"); var plist=file.iniGetObject("players");
for(var p in this.players) { for(var p in plist) {
this.players[p]=new Player(players.getAlias(p),this.players[p]); if(!this.players[p]) this.players[p]=new Player(players.getAlias(p),plist[p]);
else this.players[p].active=plist[p];
} }
this.update=true; this.update=true;
log("loaded game: " + this.gameNumber);
file.close(); file.close();
} }
this.redraw=function() this.redraw=function()
......
...@@ -10,7 +10,7 @@ function Timer(color) ...@@ -10,7 +10,7 @@ function Timer(color)
this.init=function(length) this.init=function(length)
{ {
this.countdown=length; this.countdown=length;
this.lastupdate=time(); this.lastupdate="" + time();
} }
this.redraw=function() this.redraw=function()
{ {
...@@ -35,11 +35,13 @@ function Timer(color) ...@@ -35,11 +35,13 @@ function Timer(color)
console.putmsg(this.color + time); console.putmsg(this.color + time);
console.attributes=ANSI_NORMAL; console.attributes=ANSI_NORMAL;
} }
this.countDown=function(difference) this.countDown=function()
{ {
var difference=time()-this.lastupdate;
this.countdown-=difference; this.countdown-=difference;
if(this.countdown<=0) return false; if(this.countdown<=0) return false;
this.lastupdate=time(); this.lastupdate="" + time();
return true; return true;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment