0

I'm developing the memory game in javascript (based on this tutorial: http://www.developphp.com/view.php?tid=1393 ), and now i need to calculate a fair score, based on these conditions: - The game consists of 4x4 cards (that means there are 16 cards) therefore, it takes at the very least 8 attempts (every 2 cards flipped counts as an attempt) - The game has a count down timer of 45 seconds

So, in short, the best final score will have: - 8 attempts, ~10 seconds ellapsed time, 0 cards left to find. For every further attempt, elapsed time or/and cards left, the score will be decreased

How can i accomplish something like this?

Below, is the code i have written so far:

nrTries =8;
time = 35;
tilesLeft = 0;

function calcScore(){
  var triesBonus = (nrTries * 700) / 8;
  var timeBonus = ((45 - time) == 0) ? 10 : (45 - time);
  //timeBonus = (timeBonus*500) / 10;
  console.log((triesBonus+'|'+timeBonus));
    //score += score - ((tilesLeft / 2)*6);
    //return score;
}

//console.log(calcScore());
calcScore();

Thanks in advance!

I-NOZex
  • 25
  • 3
  • 20

1 Answers1

1

Let's say a perfect game consists of 8 tries in 10 seconds and no tiles left and that a perfect score is valued at 1000 points. Then you could do it like this:

function calcScore(){
    var tilesbonus = (16 - tilesleft) * 20; // 20 points for each successful tile=320 pts
    var timebonus = (45 - time) * 8;  // 8 points for each second = 280 pts
    var triesbonus = (48 - nrTries) * 10;  // (deduct) 10 points for each try = 400 pts
    if (tilesbonus <0) { tilesbonus = 0; }
    if (timebonus <0) { timebonus = 0; }
    if (triesbonus <0) { triesbonus = 0; }
    return tilesbonus + timebonus + triesbonus;
}

The numbers are just a suggestion, you could mess around with them to change the scoring on a specific factor.

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • This was exactly the base code that I needed to generate the score. I'll just make some improvements, "play" with the values. Very grateful. – I-NOZex Jan 22 '15 at 13:00