diff --git a/xtrn/synchronetris/tetris.js b/xtrn/synchronetris/tetris.js index 97c3c55e320b30491a38671233e9ce7875b6ba43..78e693cc02513fb6c8dc0679e6b1c849e63b8f54 100644 --- a/xtrn/synchronetris/tetris.js +++ b/xtrn/synchronetris/tetris.js @@ -3,6 +3,8 @@ For Synchronet v3.15+ Matt Johnson(2009) */ +//$Id$ +const VERSION="$Revision$".split(' ')[1]; load("chateng.js"); load("graphic.js"); @@ -308,8 +310,7 @@ function lobby() break; case 0: if(!t.timer.countdown) t.loadGame(); - var current=time(); - var difference=current-t.timer.lastupdate; + var difference=time()-t.timer.lastupdate; if(!difference>=1) break; if(!t.timer.countDown(difference)) { startGame(t); @@ -353,7 +354,7 @@ function lobby() game.status=0; var file=new File(game.dataFile); file.open('r+',true); - file.iniSetValue(null,"created",system.timer); + file.iniSetValue(null,"created","" + time()); file.iniSetValue(null,"status",0); file.close(); } @@ -438,7 +439,7 @@ function lobby() function playGame(game) { var menu; - var lastupdate=system.timer; + var lastupdate=time(); /* lines per level */ var lines=10; @@ -471,13 +472,6 @@ function playGame(game) } 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() { redraw(); @@ -573,9 +567,11 @@ function playGame(game) } killPlayer(currentPlayerID); send("DEAD"); - if(game.status == 2 && game.winner == currentPlayerID) { - if(file_exists(game.dataFile.name)) - file_remove(game.dataFile.name); + if((game.status == 2 && game.winner == currentPlayerID) || countMembers(game.players)==1) { + if(file_exists(game.dataFile)) + file_remove(game.dataFile); + if(file_exists(game.dataFile + ".bck")) + file_remove(game.dataFile + ".bck"); } return true; } @@ -587,10 +583,10 @@ function playGame(game) if(!currentPlayer || !currentPlayer.active) return; var update=false; - var difference=system.timer-lastupdate; + var difference=time()-lastupdate; if(difference<pause) return; - lastupdate=system.timer; + lastupdate=time(); getLines(); @@ -645,6 +641,7 @@ function playGame(game) game.players[packet.player].drawNext(); break; case "HOLD": + game.players[packet.player].unDrawPiece(); game.players[packet.player].holdPiece=packet.piece; game.players[packet.player].drawHold(); break; @@ -700,6 +697,8 @@ function playGame(game) break; case "UPDATE": break; + case "PLAYER": + break; case "GRID": data.grid=currentPlayer.grid; break; @@ -843,14 +842,14 @@ function playGame(game) currentPlayer.drawPiece(); currentPlayer.drawNext(); currentPlayer.drawHold(); + send("HOLD"); send("PIECE"); send("NEXT"); - send("HOLD"); } else { currentPlayer.holdPiece=currentPlayer.currentPiece.id; + send("HOLD"); getNewPiece(); currentPlayer.drawHold(); - send("HOLD"); } } function getNewPiece() @@ -1017,7 +1016,6 @@ function playGame(game) } initGame(); - //initChat(); main(); } diff --git a/xtrn/synchronetris/tetrisobj.js b/xtrn/synchronetris/tetrisobj.js index 7cabb0fda40504f0e1cd17e20210ed6194c3e095..cd3c5639a5f383e2800df50f4e21a136411610f3 100644 --- a/xtrn/synchronetris/tetrisobj.js +++ b/xtrn/synchronetris/tetrisobj.js @@ -3,7 +3,7 @@ function Tetris(dataFile) this.timer=new Timer("\1y\1h"); this.players=[]; this.status=-1; - this.lastupdate=0; + this.lastupdate=-1; this.garbage=true; this.update=true; this.winner=false; @@ -41,19 +41,20 @@ function Tetris(dataFile) var created=file.iniGetValue(null,"created"); if(created > 0) { - var current=system.timer; + var current=time(); var difference=current-created; this.timer.init(20-difference); } this.gameNumber=Number(file.iniGetValue(null,"gameNumber")); this.status=file.iniGetValue(null,"status"); - this.players=file.iniGetObject("players"); - for(var p in this.players) { - this.players[p]=new Player(players.getAlias(p),this.players[p]); + var plist=file.iniGetObject("players"); + for(var p in plist) { + if(!this.players[p]) this.players[p]=new Player(players.getAlias(p),plist[p]); + else this.players[p].active=plist[p]; } this.update=true; - + log("loaded game: " + this.gameNumber); file.close(); } this.redraw=function() diff --git a/xtrn/synchronetris/timer.js b/xtrn/synchronetris/timer.js index c94705c2d0eebc1983f73294411b01607517ac8d..5285afc2dcd8087ca0d9b56655ab298dd2419865 100644 --- a/xtrn/synchronetris/timer.js +++ b/xtrn/synchronetris/timer.js @@ -10,7 +10,7 @@ function Timer(color) this.init=function(length) { this.countdown=length; - this.lastupdate=time(); + this.lastupdate="" + time(); } this.redraw=function() { @@ -35,11 +35,13 @@ function Timer(color) console.putmsg(this.color + time); console.attributes=ANSI_NORMAL; } - this.countDown=function(difference) + this.countDown=function() { + var difference=time()-this.lastupdate; this.countdown-=difference; + if(this.countdown<=0) return false; - this.lastupdate=time(); + this.lastupdate="" + time(); return true; } }