-
Notifications
You must be signed in to change notification settings - Fork 5
/
saveload.js
55 lines (49 loc) · 1.55 KB
/
saveload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//playerData for saves.
var money = "";
var AutoPrinters = "";
var AutoPrinterCost = 10;
function loadAllValues() {
document.getElementById('TotalMoney').innerHTML = money;
document.getElementById('TotalAutoPrinters').innerHTML = AutoPrinters;
document.getElementById('AutoPrinterCost').innerHTML = AutoPrinterCost;
}
function saveGame() {
var playerData = {
money: money,
AutoPrinters: AutoPrinters,
AutoPrinterCost: AutoPrinterCost
}
//stringifying the player data for JSON.
localStorage.setItem("playerData", JSON.stringify(playerData));
}
var autoSave = window.setInterval(function() {
var playerData = {
money: money,
AutoPrinters: AutoPrinters,
AutoPrinterCost: AutoPrinterCost
}
//stringifying the player data for JSON.
localStorage.setItem("playerData", JSON.stringify(playerData));
}, 2000);
//setting up a loading function.
function loadGame() {
var gamesave = JSON.parse(localStorage.getItem("playerData"));
money = gamesave.money;
AutoPrinters = gamesave.AutoPrinters;
AutoPrinterCost = gamesave.AutoPrinterCost;
loadAllValues();
}
window.onload = loadGame();
//function used to delete the player's save.
function saveKill() {
let saveKillPrompt = prompt(
"Are you sure? Type 'I am a Tax Evader' (case sensitive) if you are confident that you wish to delete your save."
)
if (saveKillPrompt == "I am a Tax Evader") {
money = "";
AutoPrinters = "";
AutoPrinterCost = 10;
localStorage.removeItem("playerData")
}
loadAllValues();
}