Skip to content

Commit

Permalink
Update test1.html
Browse files Browse the repository at this point in the history
added saving!!!
  • Loading branch information
Avid-Xenoblade-Player authored Jun 21, 2024
1 parent 1723e94 commit 5736a7e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test1.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@
}
</script>
<script>
function saveGame() {
const gameData = {
timesPressed: timesPressed,
pressesPer: pressesPer,
pressesSquared: pressesSquared,
purchaseCostOne: purchaseCostOne,
purchaseCostTwo: purchaseCostTwo,
totalTimesPressed: totalTimesPressed,
};
localStorage.setItem('clickerGameData', JSON.stringify(gameData));
document.getElementById("saveLoadStatus").innerHTML = "Saved successfully.";
}
function loadGame() {
const savedData = localStorage.getItem('clickerGameData');
if (savedData) {
const gameData = JSON.parse(savedData);
timesPressed = gameData.timesPressed;
pressesPer = gameData.pressesPer;
pressesSquared = gameData.pressesSquared;
purchaseCostOne = gameData.purchaseCostOne;
purchaseCostTwo = gameData.purchaseCostTwo;
totalTimesPressed = gameData.totalTimesPressed;
document.getElementById("saveLoadStatus").innerHTML = "Game loaded successfully.";
}
}


var timesPressed = 0;
var totalTimesPressed = 0;
var pressesPer = 0;
Expand Down Expand Up @@ -172,5 +199,12 @@ <h1>
<p id="buttonFour"></p>
<p id="purchaseInfo"></p>
<p id="buttonFive"></p>
<button onclick="loadGame()">
Click to load your game.
</button>
<button onclick="saveGame()">
Click to save your game.
</button>
<p id="saveLoadStatus"></p>
</body>
</html>

0 comments on commit 5736a7e

Please sign in to comment.