-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bff6386
commit a1a4d83
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Wigglenog Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div id="game-container"> | ||
<h1>Wigglenog Game</h1> | ||
<div id="buttons-container"> | ||
<button class="wigglenog-button" id="button1">Button 1</button> | ||
<button class="wigglenog-button" id="button2">Button 2</button> | ||
<button class="wigglenog-button" id="button3">Button 3</button> | ||
<button class="wigglenog-button" id="button4">Button 4</button> | ||
</div> | ||
<div id="result-container"></div> | ||
<button id="start-game">Start Game</button> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"highScores": [ | ||
{"player": "Vivek", "score": 10}, | ||
{"player": "Ranga", "score": 8} | ||
], | ||
"gameConfig": { | ||
"sequenceLength": 4, | ||
"buttonCount": 4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const buttons = document.querySelectorAll('.wigglenog-button'); | ||
const resultContainer = document.getElementById('result-container'); | ||
const startGameButton = document.getElementById('start-game'); | ||
|
||
let sequence = []; | ||
let userSequence = []; | ||
|
||
function startGame() { | ||
sequence = generateSequence(4); | ||
userSequence = []; | ||
resultContainer.textContent = 'Memorize the sequence!'; | ||
displaySequence(sequence); | ||
} | ||
|
||
function generateSequence(length) { | ||
const arr = []; | ||
for (let i = 0; i < length; i++) { | ||
const randomIndex = Math.floor(Math.random() * buttons.length); | ||
arr.push(buttons[randomIndex].id); | ||
} | ||
return arr; | ||
} | ||
|
||
function displaySequence(seq) { | ||
let index = 0; | ||
const interval = setInterval(() => { | ||
if (index < seq.length) { | ||
const button = document.getElementById(seq[index]); | ||
button.classList.add('active'); | ||
setTimeout(() => button.classList.remove('active'), 500); | ||
index++; | ||
} else { | ||
clearInterval(interval); | ||
resultContainer.textContent = 'Your turn!'; | ||
} | ||
}, 1000); | ||
} | ||
|
||
buttons.forEach(button => { | ||
button.addEventListener('click', () => { | ||
userSequence.push(button.id); | ||
if (userSequence.length === sequence.length) { | ||
checkSequence(); | ||
} | ||
}); | ||
}); | ||
|
||
function checkSequence() { | ||
const isCorrect = userSequence.every((val, index) => val === sequence[index]); | ||
if (isCorrect) { | ||
resultContainer.textContent = 'You win!'; | ||
} else { | ||
resultContainer.textContent = 'Try again!'; | ||
} | ||
} | ||
|
||
startGameButton.addEventListener('click', startGame); | ||
|
||
fetch('manifest.json') | ||
.then(response => response.json()) | ||
.then(manifest => { | ||
console.log(manifest); | ||
// Use data.highScores or data.gameConfig as needed | ||
}) | ||
.catch(error => console.error('Error loading JSON:', error)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
#game-container { | ||
text-align: center; | ||
background: white; | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.wigglenog-button { | ||
margin: 10px; | ||
padding: 15px 25px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
} | ||
|
||
.wigglenog-button.active { | ||
background-color: #00ff00; | ||
} | ||
|
||
#result-container { | ||
margin-top: 20px; | ||
font-size: 18px; | ||
} | ||
|
||
#start-game { | ||
margin-top: 20px; | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
} |