Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
79 lines (69 loc) · 3.07 KB
/
Copy pathindex.html
File metadata and controls
79 lines (69 loc) · 3.07 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game Selector</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<h1>Select Game</h1>
<button id="newGameButton" class="new-game-button" onclick="redirectToNewGame()">New Game</button>
<div id="gameButtons" class="button-list">
<!-- Buttons from local storage will be added here -->
</div>
</div>
<script>
// Function to populate the buttons based on local storage
function loadButtonsFromLocalStorage() {
const gameButtonsContainer = document.getElementById('gameButtons');
gameButtonsContainer.innerHTML = ''; // Clear existing buttons
// Get all keys from local storage
const keys = Object.keys(localStorage);
// Create a button for each key
keys.forEach(key => {
const buttonContainer = document.createElement('div');
buttonContainer.className = 'button-container';
// Main game button
const button = document.createElement('button');
button.className = 'game-button';
button.textContent = key; // Use the key as the button label
button.onclick = () => {
window.location.href = `game.html?item=${key}`;
};
// Settings button
const settingsButton = document.createElement('button');
settingsButton.className = 'settings-button';
settingsButton.onclick = () => {
window.location.href = `settings.html?item=${key}`;
};
// Add settings icon inside the button
const settingsIcon = document.createElement('img');
settingsIcon.src = 'images/settings.png';
settingsIcon.alt = 'Settings';
settingsButton.appendChild(settingsIcon);
// Delete button
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-button';
deleteButton.textContent = 'X';
deleteButton.onclick = () => {
localStorage.removeItem(key); // Remove item from local storage
loadButtonsFromLocalStorage(); // Reload the buttons
};
// Append buttons to the container
buttonContainer.appendChild(button);
buttonContainer.appendChild(settingsButton);
buttonContainer.appendChild(deleteButton);
gameButtonsContainer.appendChild(buttonContainer);
});
}
// Redirect to area.html when "New Game" button is clicked
function redirectToNewGame() {
window.location.href = 'area.html';
}
// Load the buttons on page load
window.onload = loadButtonsFromLocalStorage;
</script>
</body>
</html>