Commit 615cdb11 authored by Eben Blaisdell's avatar Eben Blaisdell

addToRankings fix

parent ddc688d9
......@@ -281,6 +281,15 @@ function ipAddresses(){
return addresses;
}
function findWithAttr(array, attr, value) {
for(var i = 0; i < array.length; i += 1) {
if(array[i][attr] === value) {
return i;
}
}
return -1;
}
var Game = function (players) {
this.width = getRandomInt(40,60);
this.height = getRandomInt(20,30);
......@@ -373,9 +382,9 @@ Game.prototype.end = function(winnerIndex){
loser = this.players[1-winnerIndex];
winnerInfo = getUserInfo(winner);
loserInfo = getUserInfo(loser);
winnerIndex = rankings.indexOf([winner,winnerInfo.score]);
winnerIndex = findWithAttr(rankings,0,winner);
rankings.splice(winnerIndex,1);
loserIndex = rankings.indexOf([loser,loserInfo.score]);
loserIndex = findWithAttr(rankings,0,loser);
rankings.splice(loserIndex,1);
winnerInfo.wins++;
loserInfo.loses++;
......
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