Javascript 设置cookies以存储游戏数据
我正在为我的同学制作一个点击器游戏,但我不知道如何使用cookies在计算机上保存数据,我希望能够通过cookies(例如他们自己的计算机)存储人们进步的内容。我用来帮助编写代码的程序是glitch.com 我还想帮助启用一个功能,以显示其他在线进度,并帮助配置一个非作弊系统Javascript 设置cookies以存储游戏数据,javascript,html,css,Javascript,Html,Css,我正在为我的同学制作一个点击器游戏,但我不知道如何使用cookies在计算机上保存数据,我希望能够通过cookies(例如他们自己的计算机)存储人们进步的内容。我用来帮助编写代码的程序是glitch.com 我还想帮助启用一个功能,以显示其他在线进度,并帮助配置一个非作弊系统 <html> <head> <script type = "text/javascript"> <!-- func
<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>```
输入名称:
src=“Save_File.js”
奥沃
购买自动点击成本:
购买OwO点击成本:
函数单击(){
press+=addPress;
document.getElementById(“酷”).innerHTML=“您已经打开了那个按钮:”;
document.getElementById(“press”).innerHTML=press;
document.getElementById(“ss”).innerHTML=“时间”;
document.getElementById(“DPSprice”).innerHTML=DPSprice;
document.getElementById(“addCost”).innerHTML=addCost;
}
函数DPS(){
如果(按>DPSprice){
按-=DPSprice;
DPSprice*=3;
document.getElementById(“press”).innerHTML=press;
document.getElementById(“DPSprice”).innerHTML=DPSprice;
setInterval(函数(){
DPSadd();
刷新();
}, 2000);
}
}
函数DPSadd(){
按+=1;
}
函数ClickDM(){
如果(按>添加成本){
按-=增加成本;
附加成本*=2;
addPress+=1;
document.getElementById(“press”).innerHTML=press;
document.getElementById(“addCost”).innerHTML=addCost;
}
}
函数刷新(){
document.getElementById(“酷”).innerHTML=
“机器人按下了那个按钮:”;
document.getElementById(“press”).innerHTML=press;
document.getElementById(“ss”).innerHTML=“时间”;
document.getElementById(“DPSprice”).innerHTML=DPSprice;
document.getElementById(“addCost”).innerHTML=addCost;
}
var-press=0;
var-DPSprice=3;
var-addPress=1;
var addCost=50;
```
您可以将其用于cookie
有关如何在上写入、读取、更改和删除一个或多个cookie的更多信息
你用了两次html,头和身体,这是不允许的。欢迎!您共享的代码不代表一个。我建议查看以消除任何可能的错误。然后,共享MRE,让其他人回答特定问题。它还可以帮助链接到位于的模板源代码。
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=/");
}