-
Notifications
You must be signed in to change notification settings - Fork 838
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
9f30724
commit f3eee93
Showing
6 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
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,56 @@ | ||
# Cooking Challenge Game | ||
|
||
Welcome to the Cooking Challenge Game! This is a simple web-based game where players must match a given order by selecting the correct ingredients within a limited time. | ||
|
||
## Table of Contents | ||
|
||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Game Mechanics](#game-mechanics) | ||
- [Technologies Used](#technologies-used) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
To get a copy of this project up and running on your local machine, follow these steps: | ||
|
||
1. Clone the repository: | ||
```bash | ||
git clone https://github.com/yourusername/cooking-challenge-game.git | ||
``` | ||
2. Navigate to the project directory: | ||
```bash | ||
cd cooking-challenge-game | ||
``` | ||
|
||
## Usage | ||
|
||
To start the game, simply open the `index.html` file in your preferred web browser. | ||
|
||
## Game Mechanics | ||
|
||
1. **Objective:** | ||
- Match the order by selecting the correct ingredients within the given time limit. | ||
|
||
2. **Controls:** | ||
- Click on the ingredient icons to select them. | ||
- Click the "Serve" button to check if the selected ingredients match the order. | ||
|
||
3. **Scoring:** | ||
- Each correct order gives you 10 points. | ||
- The game lasts for 60 seconds. Your score is displayed at the end of the game. | ||
|
||
## Technologies Used | ||
|
||
- **HTML:** Structure of the game. | ||
- **CSS:** Styling and layout. | ||
- **JavaScript:** Game logic and interactivity. | ||
|
||
## File Structure | ||
|
||
```plaintext | ||
. | ||
├── index.html | ||
├── styles.css | ||
└── script.js |
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,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Cooking Challenge Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div id="gameContainer"> | ||
<div id="kitchen"> | ||
<div class="ingredient" id="tomato">🍅</div> | ||
<div class="ingredient" id="lettuce">🥬</div> | ||
<div class="ingredient" id="cheese">🧀</div> | ||
<div class="ingredient" id="bread">🍞</div> | ||
</div> | ||
<div id="orderBoard"> | ||
<div id="order">Order: </div> | ||
<button id="serveButton">Serve</button> | ||
</div> | ||
<div id="scoreBoard"> | ||
<p>Score: <span id="score">0</span></p> | ||
<p>Time: <span id="time">60</span> seconds</p> | ||
</div> | ||
</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,74 @@ | ||
// script.js | ||
const ingredients = document.querySelectorAll('.ingredient'); | ||
const orderDisplay = document.getElementById('order'); | ||
const serveButton = document.getElementById('serveButton'); | ||
const scoreDisplay = document.getElementById('score'); | ||
const timeDisplay = document.getElementById('time'); | ||
|
||
let currentOrder = []; | ||
let selectedIngredients = []; | ||
let score = 0; | ||
let time = 60; | ||
|
||
const allIngredients = ['tomato', 'lettuce', 'cheese', 'bread']; | ||
|
||
function getRandomIngredient() { | ||
return allIngredients[Math.floor(Math.random() * allIngredients.length)]; | ||
} | ||
|
||
function generateOrder() { | ||
currentOrder = []; | ||
for (let i = 0; i < 3; i++) { | ||
currentOrder.push(getRandomIngredient()); | ||
} | ||
orderDisplay.innerHTML = 'Order: ' + currentOrder.join(', '); | ||
} | ||
|
||
ingredients.forEach(ingredient => { | ||
ingredient.addEventListener('click', () => { | ||
if (!selectedIngredients.includes(ingredient.id)) { | ||
selectedIngredients.push(ingredient.id); | ||
ingredient.style.backgroundColor = '#dcdcdc'; | ||
} | ||
}); | ||
}); | ||
|
||
serveButton.addEventListener('click', () => { | ||
if (arraysEqual(selectedIngredients, currentOrder)) { | ||
score += 10; | ||
scoreDisplay.innerHTML = score; | ||
resetRound(); | ||
} else { | ||
alert('Wrong ingredients!'); | ||
} | ||
}); | ||
|
||
function resetRound() { | ||
selectedIngredients = []; | ||
ingredients.forEach(ingredient => { | ||
ingredient.style.backgroundColor = '#fff'; | ||
}); | ||
generateOrder(); | ||
} | ||
|
||
function arraysEqual(a, b) { | ||
if (a.length !== b.length) return false; | ||
a.sort(); | ||
b.sort(); | ||
for (let i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
function updateTimer() { | ||
time--; | ||
timeDisplay.innerHTML = time; | ||
if (time <= 0) { | ||
clearInterval(timer); | ||
alert('Game over! Your score is ' + score); | ||
} | ||
} | ||
|
||
generateOrder(); | ||
const timer = setInterval(updateTimer, 1000); |
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,51 @@ | ||
/* styles.css */ | ||
body { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
background: #f0f0f0; | ||
margin: 0; | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
#gameContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
text-align: center; | ||
} | ||
|
||
#kitchen { | ||
display: flex; | ||
justify-content: center; | ||
gap: 10px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.ingredient { | ||
padding: 20px; | ||
background: #fff; | ||
border: 1px solid #ccc; | ||
cursor: pointer; | ||
font-size: 2rem; | ||
transition: background 0.3s; | ||
} | ||
|
||
.ingredient:hover { | ||
background: #f9f9f9; | ||
} | ||
|
||
#orderBoard { | ||
margin-bottom: 20px; | ||
} | ||
|
||
#serveButton { | ||
padding: 10px; | ||
font-size: 1rem; | ||
cursor: pointer; | ||
} | ||
|
||
#scoreBoard p { | ||
margin: 5px 0; | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.