Your question is extremely but i’m bored
This is a good guide to make a simple idle game Guide, you can take the knowledge you learn from the guide to make your own small game.
- How to update the JS to html
You are going to use document.getElementById("thekey").innerHTML = thekey;
in the function
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;
}
- How to save data
To save your data ex. money, xp and levels, you are going to use 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);
}
- How to you make a leveling system with max level
To make a simple leveling system with max level, you are going to use if..else and 1 function.
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);
}
- How to generate random numbers
To generate random numbers in startClick, you are going to use Math.random
like var random = Math.floor(Math.random() * (Max - min + min)) + 1;
add it to your function and use the var random
like money = parseInt(money) + random;
it will generate a random number everytime.
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);
}
1
solved How to make this? [closed]