Skip to content

Commit

Permalink
Cooking Challenge game is added
Browse files Browse the repository at this point in the history
  • Loading branch information
pallasivasai committed Jun 27, 2024
1 parent 9f30724 commit f3eee93
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Games/Cooking_Challenge_Game/README.md
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
28 changes: 28 additions & 0 deletions Games/Cooking_Challenge_Game/index.html
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>
74 changes: 74 additions & 0 deletions Games/Cooking_Challenge_Game/script.js
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);
51 changes: 51 additions & 0 deletions Games/Cooking_Challenge_Game/styles.css
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;
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ This repository also provides one such platforms where contributers come over an


| [Catch_The_Circle](https://github.com/kunjgit/GameZone/tree/main/Games/Catch_The_Circle) |
| [Cooking Challenge](https://github.com/kunjgit/GameZone/tree/main/Games/Cooking Challenge) |



</center>
Expand Down
Binary file added assets/images/Cooking_Challenge_Game.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f3eee93

Please sign in to comment.