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

add score tracking, remove debug logging

derp the derps (stable)
parent 985d372d
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ function playGame(profile,game) {
/* variables and shit */
var menu, status, direction, queue, last_update,
gameFrame, localPlayer, pause, players, ready;
gameFrame, localPlayer, pause, players, readyMsg;
/* main shit */
function open() {
......@@ -22,6 +22,15 @@ function playGame(profile,game) {
drawScore(localPlayer);
}
function close() {
if(localPlayer) {
if(countMembers(players) > 1) {
if(game.winner == localPlayer.name)
scoreWin();
else
scoreLoss();
}
saveScore();
}
client.unsubscribe(game_id,"metadata." + game.gameNumber);
}
function cycle() {
......@@ -35,7 +44,7 @@ function playGame(profile,game) {
return;
last_update=Date.now();
if(!localPlayer || !localPlayer.active)
if(!localPlayer || !localPlayer.active || !everyoneReady())
return;
//TODO: this might not be necessary anymore
......@@ -150,8 +159,15 @@ function playGame(profile,game) {
/* init shit */
function everyoneReady() {
for each(var p in players) {
if(!p.ready)
if(!p.ready) {
if(!readyMsg)
readyMsg = showMessage("Waiting for players");
return false;
}
}
if(readyMsg) {
readyMsg.close();
delete readyMsg;
}
return true;
}
......@@ -222,7 +238,7 @@ function playGame(profile,game) {
data.grid=localPlayer.grid;
break;
default:
log("Unknown tetris data not sent");
log(LOG_WARNING,"Unknown tetris data not sent: " + cmd);
break;
}
data.gameNumber=game.gameNumber;
......@@ -282,8 +298,8 @@ function playGame(profile,game) {
drawBoard(p);
break;
default:
log("Unknown tetris data type received");
log("packet: " + data.toSource());
log(LOG_WARNING,"Unknown tetris data type received");
log(LOG_WARNING,"packet: " + data.toSource());
break;
}
}
......@@ -972,18 +988,21 @@ function playGame(profile,game) {
endGame();
}
}
function scoreWin(score) {
function scoreWin() {
profile.wins++;
if(score > profile.score)
profile.score = score;
client.write(game_id,"profiles." + localPlayer.name,profile,2);
}
function scoreLoss(score) {
function scoreLoss() {
profile.losses++;
if(score > profile.score)
profile.score = score;
}
function saveScore() {
if(localPlayer.score > profile.score)
profile.score = localPlayer.score;
if(localPlayer.lines > profile.lines)
profile.lines = localPlayer.lines;
if(localPlayer.level > profile.level)
profile.level = localPlayer.level;
client.write(game_id,"profiles." + localPlayer.name,profile,2);
}
}
function endGame() {
game.status=status.FINISHED;
client.write(game_id,"games." + game.gameNumber + ".status",game.status,2);
......
......@@ -271,16 +271,16 @@ var lobby=(function() {
/* show rankings */
function showScores() {
var scoreFrame = new Frame(16,6,50,14,BG_BLUE + YELLOW,frame);
var scoreFrame = new Frame(16,6,57,14,BG_BLUE + YELLOW,frame);
var count = 0;
var scores_per_page = 10;
var list = sortScoresByWins();
var list = sortScores("score");
scoreFrame.open();
for each(var player in list) {
if(player.wins == 0)
continue;
//if(player.wins == 0)
// continue;
if(count > 0 && count%scores_per_page == 0) {
scoreFrame.gotoxy(1,24);
//scoreFrame.gotoxy(1,24);
scoreFrame.center("\1r\1h<SPACE to continue>");
scoreFrame.draw();
while(console.getkey(K_NOCRLF|K_NOECHO) !== " ");
......@@ -289,10 +289,10 @@ var lobby=(function() {
if(count++%scores_per_page == 0) {
scoreFrame.crlf();
scoreFrame.putmsg("\1w\1h" +
format(" %3s %-25s %4s %13s","###","NAME","WINS","HIGH SCORE") + "\r\n");
format(" %3s %-25s %4s %6s %6s %6s","###","NAME","WINS","LEVEL","SCORE","LINES") + "\r\n");
}
scoreFrame.putmsg("\1w\1y" +
formatScore(count,player.name,player.wins,player.score) + "\r\n");
formatScore(count,player.name,player.wins,player.level,player.score,player.lines) + "\r\n");
}
scoreFrame.end();
scoreFrame.center("\1r\1h<SPACE to continue>");
......@@ -300,15 +300,15 @@ var lobby=(function() {
while(console.getkey(K_NOCRLF|K_NOECHO) !== " ");
scoreFrame.delete();
}
/* sort scores */
function sortScoresByWins() {
return sortListByProperty(data.profiles,"wins");
/* format score display */
function formatScore(num,name,wins,level,score,lines) {
return format(" \1c%3d \1y%-25s %4d %6d %6d %6d",num,name,wins,level,score,lines);
}
/* sort scores */
function sortScoresByTime() {
return sortListByProperty(data.profiles,"best_time").reverse();
function sortScores(property) {
return sortListByProperty(data.profiles,property);
}
/* show game help */
......
......@@ -24,17 +24,6 @@ function GameData()
this.who=function() {
this.online=client.who(game_id,"games");
}
this.storeGameStatus=function(gameNumber,status) {
this.games[gameNumber].status = status;
client.write(game_id,"games." + gameNumber + ".status", status, 2);
}
this.storeGameWinner=function(gameNumber,winner) {
this.games[gameNumber].winner = winner;
this.profiles[winner].wins++;
client.write(game_id,"games." + gameNumber + ".winner", winner,2);
client.write(game_id,"games." + gameNumber + ".raceTime", raceTime,2);
client.write(game_id,"profiles." + winner + ".wins", this.profiles[winner].wins,2);
}
this.addPlayer=function(gameNumber,profile) {
var player = new Player(profile.name,profile.avatar,profile.color);
this.games[gameNumber].players[player.name] = player;
......@@ -54,6 +43,8 @@ function Profile(name)
{
this.name=name;
this.score=0;
this.lines=0;
this.level=0;
this.wins=0;
this.losses=0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment