Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekvardhan2810 committed Jul 26, 2024
1 parent bff6386 commit a1a4d83
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
Binary file added Wigglenog Game Extension/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Wigglenog Game Extension/index.html
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>
10 changes: 10 additions & 0 deletions Wigglenog Game Extension/manifest.json
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
}
}
65 changes: 65 additions & 0 deletions Wigglenog Game Extension/script.js
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));
40 changes: 40 additions & 0 deletions Wigglenog Game Extension/styles.css
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;
}

0 comments on commit a1a4d83

Please sign in to comment.