你提的問題是非常,但我很無聊
這是製作簡單空閒遊戲的好指南Guide,你可以從指南中學到的知識來製作自己的小遊戲。
- 如何更新JS到html
Demo
您要使用document.getElementById("thekey").innerHTML = thekey;
在功能
var money = 0;
var xp = 0;
var level = 0;
function startClick(number){
money = parseInt(money) + 50; //Want it to be random number to get
xp = xp + 100;//Same here
//This will update money,xp to your html
document.getElementById("money").innerHTML = money;
document.getElementById("xp").innerHTML = xp;
}
- 如何保存數據
Demo
Good guide about localStorage
要保存數據前。錢,XP和水平,你將使用localStorage。
var money = 0;
var xp = 0;
var level = 0;
//This loads the data
if(localStorage.money) money = localStorage.getItem('money');
//This updates the data when you load the html
document.getElementById("money").innerHTML = money;
if(localStorage.xp) xp = localStorage.getItem('xp');
document.getElementById("xp").innerHTML = xp;
function startClick(number){
money = parseInt(money) + 50; //Want it to be random number to get
xp = parseInt(xp) + 100;//Same here
//This will update money,xp to your html
document.getElementById("money").innerHTML = money;
//This sets the data, so "getItem" can load it
localStorage.setItem('money', money);
document.getElementById("xp").innerHTML = xp;
localStorage.setItem('xp', xp);
}
- 怎麼給你做一個調整系統,具有最高級別
Demo
爲了使一個簡單的調平系統,最大水平,你打算使用if..else和1函數。
var money = 0;
var xp = 0;
var level = 0;
//This loads the data
if(localStorage.money) money = localStorage.getItem('money');
//This updates the data when you load the html
document.getElementById("money").innerHTML = money;
if(localStorage.xp) xp = localStorage.getItem('xp');
document.getElementById("xp").innerHTML = xp;
if(localStorage.level) level = localStorage.getItem('level');
document.getElementById("level").innerHTML = level;
//This will set the max level, you can change the max by change 30 to what you want.
if(level > 30){
level = 30;
document.getElementById("level").innerHTML = level;
}
//This is your leveling system, its combine to the button with startClick.
function levelClick(number){
if(xp >= 500){
level = parseInt(level) + 1;
document.getElementById("level").innerHTML = level;
xp = parseInt(xp) - 500;
document.getElementById("xp").innerHTML = xp;
localStorage.setItem('level', level);
}
}
function startClick(number){
money = parseInt(money) + 50; //Want it to be random number to get
xp = parseInt(xp) + 100;//Same here
//This will update money,xp to your html
document.getElementById("money").innerHTML = money;
//This sets the data, so "getItem" can load it
localStorage.setItem('money', money);
document.getElementById("xp").innerHTML = xp;
localStorage.setItem('xp', xp);
}
- 如何生成隨機數
要產生startClick隨機數,你要使用Math.random
像var random = Math.floor(Math.random() * (Max - min + min)) + 1;
將它添加到您的功能並使用var random
像money = parseInt(money) + random;
它會生成一個ra ndom號每次。
var money = 0;
var xp = 0;
var level = 0;
//This loads the data
if(localStorage.money) money = localStorage.getItem('money');
//This updates the data when you load the html
document.getElementById("money").innerHTML = money;
if(localStorage.xp) xp = localStorage.getItem('xp');
document.getElementById("xp").innerHTML = xp;
if(localStorage.level) level = localStorage.getItem('level');
document.getElementById("level").innerHTML = level;
//This will set the max level, you can change the max by change 30 to what you want.
if(level > 30){
level = 30;
document.getElementById("level").innerHTML = level;
}
//This is your leveling system, its combine to the button with startClick.
function levelClick(number){
if(xp >= 500){
level = parseInt(level) + 1;
document.getElementById("level").innerHTML = level;
xp = parseInt(xp) - 500;
document.getElementById("xp").innerHTML = xp;
localStorage.setItem('level', level);
}
}
function startClick(number){
//This generate a random number, every time you click the button
var moneyrandom = Math.floor(Math.random() * (300 - 100 + 100)) + 1;
var xprandom = Math.floor(Math.random() * (500 - 100 + 100)) + 1;
money = parseInt(money) + moneyrandom;
xp = parseInt(xp) + xprandom;
//This will update money,xp to your html
document.getElementById("money").innerHTML = money;
//This sets the data, so "getItem" can load it
localStorage.setItem('money', money);
document.getElementById("xp").innerHTML = xp;
localStorage.setItem('xp', xp);
}
你的問題是非常廣泛的,不適合StackOverflow。您需要閱讀[幫助中心](https://stackoverflow.com/help/how-to-ask)。 –
你有什麼嘗試?對遊戲進行編程可能是學習JS的好方法,但您需要了解基礎知識。你幾乎沒有發佈任何代碼,並希望其他人爲你編寫其餘的代碼?我很抱歉,但這不是Stack Overflow的工作原理。 – Mike