-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave.js
133 lines (105 loc) · 4.18 KB
/
save.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Base64 Encoder
function base64Encode(str) {
return btoa(str);
}
// Base64 Decoder
function base64Decode(encodedStr) {
return atob(encodedStr);
}
// Auto Save Progress
setInterval(saveProgress, 30000);
// Show Message
function showMessage(message, color = 'black') {
const messageEl = document.createElement('div');
messageEl.style.position = 'absolute';
messageEl.style.top = '0';
messageEl.style.left = '0';
messageEl.style.color = color;
messageEl.textContent = message;
document.body.appendChild(messageEl);
setTimeout(() => {
document.body.removeChild(messageEl);
}, 3000);
}
// Modify Save Progress to show auto save message
function saveProgress() {
const progress = {
money: count,
upgradeLevel: upgradeLevel,
upgradeCost: upgradeCost
};
const serializedProgress = JSON.stringify(progress);
const encodedProgress = base64Encode(serializedProgress);
localStorage.setItem('progress', encodedProgress);
showMessage("Progress auto saved successfully!", 'green');
}
// Reset Progress
function resetProgress() {
// Reset game variables
count = 0;
upgradeLevel = 0;
upgradeCost = 10;
// Update UI
counterEl.textContent = count;
upgradeBtn.textContent = `Buy Upgrader (Cost: ${upgradeCost})`;
// Save the reset progress
saveProgress();
showMessage("Progress reset and saved successfully!", 'red');
}
// Load Progress
function loadProgress() {
const encodedProgress = localStorage.getItem('progress');
if (encodedProgress) {
const decodedProgress = base64Decode(encodedProgress);
const progress = JSON.parse(decodedProgress);
count = progress.money;
upgradeLevel = progress.upgradeLevel;
upgradeCost = progress.upgradeCost;
counterEl.textContent = count;
upgradeBtn.textContent = `Buy Upgrader (Cost: ${upgradeCost})`;
showMessage("Progress loaded successfully!");
} else {
showMessage("No saved progress found!");
}
}
// Save Progress
function saveProgress() {
const progress = {
money: count,
upgradeLevel: upgradeLevel,
upgradeCost: upgradeCost
};
const serializedProgress = JSON.stringify(progress);
const encodedProgress = base64Encode(serializedProgress);
localStorage.setItem('progress', encodedProgress);
showMessage("Progress saved successfully!");
// Reset Progress
function resetProgress() {
// Reset game variables
count = 0;
upgradeLevel = 0;
upgradeCost = 10;
// Update UI
counterEl.textContent = count;
upgradeBtn.textContent = `Buy Upgrader (Cost: ${upgradeCost})`;
// Save the reset progress
saveProgress();
showMessage("Progress reset and saved successfully!", 'red');
}
// Load Progress
function loadProgress() {
const encodedProgress = localStorage.getItem('progress');
if (encodedProgress) {
const decodedProgress = base64Decode(encodedProgress);
const progress = JSON.parse(decodedProgress);
count = progress.money;
upgradeLevel = progress.upgradeLevel;
upgradeCost = progress.upgradeCost;
counterEl.textContent = count;
upgradeBtn.textContent = `Buy Upgrader (Cost: ${upgradeCost})`;
showMessage("Progress loaded successfully!");
} else {
showMessage("No saved progress found!");
}
}
}