使本地存储计数缓慢上升

Make Local storage count slowly go up

我正在尝试制作一款与流行的在线游戏 Cookie Clicker 类似或老实说只是抄袭的游戏。我的游戏实际上是 Cursor Clicker,我是编码新手,只是为学校制作一些东西,因为我们的 chromebook 上几乎所有东西都被屏蔽了。我真的需要帮助进行升级,它消除了 10 个游标,并且游标计数每(秒数)增加一次。提前致谢!

//Tells user/player that page is still in beta.
alert("Cursor Clicker is still in beta so if there are any bugs,glitches, or suggestions please let me know.\n Here: https://PHP-Contact-Form.michaelmatherne.repl.co")

//Sets the cursor image so when clicked, Cursors are added.
function clickCounter() {
  if (typeof(Storage) !== "undefined") {
    if (localStorage.clickcount) {
      localStorage.clickcount = Number(localStorage.clickcount)+1;
    } else {
      localStorage.clickcount = 1;
    }
    document.getElementById("result").innerHTML = "Cursors: " + localStorage.clickcount;
  } else {
    document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
  }
}

//Disables CTRL+U
document.onkeydown = function(e) {
        if (e.ctrlKey && 
            (e.keyCode === 67 || 
             e.keyCode === 86 || 
             e.keyCode === 85 || 
             e.keyCode === 117)) {
            alert('Sorry but i have disabled CTRL+U. \nLook at the link displayed below for help getting started. \n\nhttps://www.w3schools.com/html/tryit.asp?filename=tryhtml5_webstorage_session');
            return false;
        } else {
            return true;
        }
};

//Disables right click content-menu
document.addEventListener("contextmenu", function(e){
    e.preventDefault();
}, false);

//Clear all Cookies
function clear() {
  localStorage.clear();
}

//Alert for Cursor Reset
function reset(){
  alert("Cursors have been reset!")
}

//trash
/*function RightClick() {
  if(RightClick(Sell))  
}
function Sell() {
  var x = -1;
  x.tostring();
  (-1).tostring();
  (100-1).tostring();
} 
*/
html {
    background-color: #181818;
}

body {
  color: lightgray;
  text-align: center;
  font-family: monospace;
  font-size: 30px;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Cookie Clicker Remake But With Cursors :)">
    <meta name="keywords" content="game, fun, clicker">

    
    <title>Cursor Clicker</title>
    
    <!-- favicon -->
    <link rel="shortcut icon" href="https://cdn.glitch.com/e991135e-1ef8-4944-b9c8-e4bf9682315f%2Fb2f27baa-8b5f-4aca-9c22-73cfe6ae0ae7.image.png?v=1612226466065">
    
    <!-- import the webpage's stylesheet -->
    <link rel="stylesheet" href="/style.css">
    
    <!-- import the webpage's javascript file -->
    <script src="/script.js" defer></script>
  </head>
<body>
<h4>
  Click the Cursor to earn Cursors...Buy upgrades with Cursors to earn more Cursors
  </h4>
  <img src="https://cdn.glitch.com/e991135e-1ef8-4944-b9c8-e4bf9682315f%2Fec4700a9-10fc-474a-a6c3-9fdfc278dbfe.image.png?v=1612201917876" onclick="clickCounter()">
<div id="result"></div>
  <br>
  <button onclick="localStorage.clear(), reset()">
    Reset All Cookies
  </button>
</body>
</html>

这个基本示例应该说明如何操作。你想用setInterval()每秒连续加分

var button = document.getElementsByTagName("button")[0];
var counter = document.getElementById("cursors");
function update(){
  counter.innerHTML=parseInt(counter.innerHTML)+1;
}
function achievement(points, reduction, interval){
  counter.innerHTML=parseInt(counter.innerHTML)-reduction;
  setInterval(function(){counter.innerHTML=parseInt(counter.innerHTML)+points;}, interval);
}
<button onclick="update()">Click</button><br>
<button onclick="achievement(10, 10, 1000)">Achievement #1 (10 ps)</button><br>
Cursors: <p id="cursors">0</p>

注意:我没有在示例中使用 LocalStorage,因为 Stack Snippets 不支持它。