【问题标题】:Calculate "Memory Game's" score, based on the number of attempts, time spent and cards left根据尝试次数、所用时间和剩余卡片计算“记忆游戏”分数
【发布时间】:2015-01-22 10:44:24
【问题描述】:

我正在用 javascript 开发记忆游戏(基于本教程:http://www.developphp.com/view.php?tid=1393),现在我需要根据这些条件计算一个公平的分数: - 游戏由 4x4 牌组成(这意味着有 16 张牌)因此​​,至少需要 8 次尝试(每翻转 2 次牌算作一次尝试) - 游戏有 45 秒倒计时

因此,简而言之,最好的最终成绩将是: - 8 次尝试,经过约 10 秒的时间,还有 0 张卡要找到。 每进一步尝试,经过的时间或/和剩余的牌,分数将减少

我怎样才能完成这样的事情?

下面是我目前写的代码:

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();

提前致谢!

【问题讨论】:

    标签: javascript jquery html algorithm calculus


    【解决方案1】:

    假设一场完美的游戏由 10 秒内的 8 次尝试组成,并且没有剩余的牌,并且满分的价值为 1000 分。然后你可以这样做:

    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;
    }
    

    这些数字只是一个建议,您可以乱用它们来改变特定因素的得分。

    【讨论】:

    • 这正是我生成分数所需的基本代码。我只会做一些改进,“玩”这些价值观。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多