设置 Cookie 以存储游戏数据



我正在为我的同学开发一个点击游戏,但我无法了解如何工作/使用 cookie 将数据保存在计算机上,我希望能够通过 cookie/例如他们自己的计算机存储人们进度的内容。我用来帮助编码的程序是glitch.com我还希望帮助启用一项功能来在线显示其他人的进度,并帮助配置非作弊系统

<html>
<head>   
<script type = "text/javascript">
<!--
function WriteCookie() {
if( document.myform.customer.value == "0" ) {
alert("Enter Password value!");
return;
}
cookievalue = escape(document.myform.customer.value) + ";";
document.cookie = "name=" + cookievalue;
document.write ("Setting Cookies : " + "name=" + cookievalue );
}
//-->
</script>      
</head>
<body>      
<form name = "myform" action = "">
Enter name: <input type = "text" name = "customer"/>
<input type = "button" value = "Set Cookie" onclick = "WriteCookie();"/>
</form>   
</body>
</html>
<html>
<body>
<script> src="Save_File.js" </script>
<img
width="60"
height="50"
src="https://media.giphy.com/media/U7qVJMN039tGU/giphy.gif"
style="
position: absolute;
top: 98px;
left: 413px;
"
/>
<img
width="50"
height="50"     
src="https://media.giphy.com/media/D8nU1wFQ62aZ2/giphy.gif"
style="
position: absolute;
top: 116px;
left: 187px;
"
/>
<p id="cool"></p>
<p id="press"></p>
<p id="ss"></p>
<button type="button" id="cool" onclick="Click()">OwO</button>
<button
type="button"
id="DPS"
onclick="DPS()"
style="
position: absolute;
top: 20;
left: 240px;
"
>
Buy Auto click cost:
</button>
<p
id="DPSprice"
style="
position: absolute;
top: 105px;
left: 350px;
"
></p>
<button
type="button"
id="ClickDM"
onclick="ClickDM()"
style="
position: absolute;
top: 20;
left: 478px;
"
>
Buy OwO Click cost:
</button>
<p
id="addCost"
style="
position: absolute;
top: 105px;
left: 620px;
"
></p>
<script>
function Click() {
press += addPress;
document.getElementById("cool").innerHTML = "You've OwO'd that button:";
document.getElementById("press").innerHTML = press;
document.getElementById("ss").innerHTML = "time(s)";
document.getElementById("DPSprice").innerHTML = DPSprice;
document.getElementById("addCost").innerHTML = addCost;
}
function DPS() {
if (press > DPSprice) {
press -= DPSprice;
DPSprice *= 3;
document.getElementById("press").innerHTML = press;
document.getElementById("DPSprice").innerHTML = DPSprice;
window.setInterval(function() {
DPSadd();
Refresh();
}, 2000);
}
}
function DPSadd() {
press += 1;
}
function ClickDM() {
if (press > addCost) {
press -= addCost;
addCost *= 2;
addPress += 1;
document.getElementById("press").innerHTML = press;
document.getElementById("addCost").innerHTML = addCost;
}
}
function Refresh() {
document.getElementById("cool").innerHTML =
"The bot has pressed that button:";
document.getElementById("press").innerHTML = press;
document.getElementById("ss").innerHTML = "time(s)";
document.getElementById("DPSprice").innerHTML = DPSprice;
document.getElementById("addCost").innerHTML = addCost;
}
var press = 0;
var DPSprice = 3;
var addPress = 1;
var addCost = 50;
</script>
<script src="/check.js" defer></script>
</body>
</html>```

您可以将此用于您的 cookie。

有关如何在 https://www.w3schools.com/js/js_cookies.asp 上写入、读取、更改和删除一个或多个 Cookie 的更多信息

function WriteCookie() {
// the next 4 lines: why should someone enter "0" ?
if( document.myform.customer.value == "0" ) {
alert("Enter Password value!");
return;
}
cookievalue = escape(document.myform.customer.value);
document.cookie = "name="+cookievalue+"; expires=Fri, 25 Dec 2037 23:59:59 GMT; path=/";
console.log("name="+cookievalue+"; expires=Fri, 25 Dec 2037 23:59:59 GMT; path=/");
}

最新更新