blob: d3e81449139d1c5cd57fcf4675c60d7790a0acb1 (
plain) (
blame)
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
|
import { createGameState, saveGameState, loadGameState, resetGameState } from './state.js';
import { renderScene } from './renderer.js';
let gameState = loadGameState(); // Load state on initialization
const updateAndRender = (newState) => {
Object.assign(gameState, newState);
saveGameState(gameState); // Save automatically after each update
renderScene(gameState, updateAndRender);
};
document.addEventListener('DOMContentLoaded', () => {
const app = document.getElementById('app');
app.innerHTML = '';
const controls = document.createElement('div');
controls.id = 'controls';
const saveButton = document.createElement('button');
saveButton.textContent = 'Save Progress';
saveButton.onclick = () => saveGameState(gameState);
const loadButton = document.createElement('button');
loadButton.textContent = 'Load Progress';
loadButton.onclick = () => {
const loadedState = loadGameState();
updateAndRender(loadedState);
};
const resetButton = document.createElement('button');
resetButton.textContent = 'Reset Game';
resetButton.onclick = () => {
if (confirm('Are you sure you want to reset the game? This will erase all progress.')) {
gameState = resetGameState(); // Clear state and reset game
updateAndRender(gameState);
}
};
controls.appendChild(saveButton);
controls.appendChild(loadButton);
controls.appendChild(resetButton);
app.appendChild(controls);
updateAndRender(gameState);
});
|