我需要帮助我的点击游戏的保存功能。到目前为止,我的游戏非常小,但我认为在进一步发展之前,我已经更好地完成了自动扫描。
这是我到目前为止所做的:
var cookies = 0;
var cursors = 0;
var workers = 0;
function cookieClick(number){
cookies = cookies + number;
document.getElementById("cookies").innerHTML = cookies;
};
function buyCursor(){
var cursorCost = Math.floor(10 * Math.pow(1.1,cursors)); //works out the cost of this cursor
if(cookies >= cursorCost){ //checks that the player can afford the cursor
cursors = cursors + 1; //increases number of cursors
cookies = cookies - cursorCost; //removes the cookies spent
document.getElementById('cursors').innerHTML = cursors; //updates the number of cursors for the user
document.getElementById('cookies').innerHTML = cookies; //updates the number of cookies for the user
};
var nextcursorCost = Math.floor(10 * Math.pow(1.1,cursors)); //works out the cost of the next cursor
document.getElementById('cursorCost').innerHTML = nextcursorCost; //updates the cursor cost for the user
};
function buyWorker(){
var workerCost = Math.floor(200 * Math.pow(1.1,workers));
if(cookies >= workerCost){
workers = workers + 1;
cookies = cookies - workerCost;
document.getElementById('workers').innerHTML = workers;
};
var nextworkerCost = Math.floor(200 * Math.pow(1.1,workers));
document.getElementById('workerCost').innerHTML = nextworkerCost;
}
window.setInterval(function(){
cookieClick(cursors);
}, 1000);
window.setInterval(function(){
cookieClick(workers);
}, 250);
//SAVE AND LOAD THE GAME
function saveGame(){
printMessageLine("Saved.");
localStorage['shittyInc_save'] = btoa(JSON.stringify(game));
}
function loadGame() {
var save_data = localStorage['shittyInc_save']
printMessageLine("Loaded.");
console.log(save_data);
if (!save_data) return;
console.log(save_data);
game = JSON.parse(atob(localStorage['shittyInc_save']))
}

注意:我当前的保存功能不起作用。
我不打算拥有并导入保存功能。自动保存是我正在寻求帮助的所有内容,如果您愿意,我很乐意将您的推特或其他内容纳入学分。