javascript - 评分停止并在 javascript 上重置游戏
问题描述
所以我基本上是一名手动测试人员,现在正试图提高 javascript 的技能。我正在开发一个名为 Hand cricket 的 javascript 迷你项目。这只是我和朋友们玩的童年游戏。所以我在这里有一个函数可以检查玩家是否出局。如果玩家出局,我无法停止游戏,但用户仍然可以提供输入。请帮助我,一旦玩家退出,我应该如何停止程序。它应该会在几秒钟后停止游戏并重置玩家分数。下面是代码片段......
我已宣布玩家得分为
////// player score initialised to zero
let pScore = 0;
// checking if the player is out
//comparing hands
const compareHands = (playerChoice, computerChoice) => {
//updating text
const winner = document.querySelector(".winner");
//checking player is out
if (playerChoice === computerChoice) {
winner.textContent = "You are out!";
return;
}
else {
updateScore(playerChoice);
}
};
更新计分板:
const updateScore = (playerChoice) => {
let playerScore = document.getElementById("playerScore").innerHTML;
let scores = getScoreInDigits(playerChoice)
playerScore = parseInt(playerScore) + scores.pScore;
document.getElementById("playerScore").innerHTML = playerScore;
}
解决方案
尝试在return之前禁用按钮:
button.setAttribute("disabled", true);
推荐阅读
- haskell - 分组参数
- java - 单声道 switchIfEmpty() 总是被调用
- python - “如何在 python 3 中使用 while 循环从同一个文件中读取字符串和数字?”
- regex - 替换文件中所有出现的“:{any character}{end of line}”的sed表达式是什么?
- c++ - 检查没有初始化器的 C++ 枚举是否有多个值
- swift - RxBluetoothKit 与 RxAndroidBle
- hive - 如何在 HIVE SQL 中删除字符串中的分号
- node.js - 如何在 babel-node 中包含一些 node_modules 包
- swift - 关闭插页式广告后呈现新的 ViewController - Swift 4
- css - ReactJS 中的 jsx 不使用 Css