-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4468 from Saipradyumnagoud/main
Added Memory Matching Game
- Loading branch information
Showing
6 changed files
with
170 additions
and
7 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,39 @@ | ||
# **Memory Matching Game** | ||
|
||
--- | ||
|
||
<br> | ||
|
||
## **Description 📃** | ||
<!-- add your game description here --> | ||
- The Memory Matching Game is a fun and interactive game where players flip over pairs of cards to find matches. The goal is to match all pairs of cards in the shortest time and with the fewest attempts possible. This game helps improve memory and concentration skills. | ||
|
||
## **Functionalities 🎮** | ||
<!-- add functionalities over here --> | ||
- Randomly shuffled cards at the start of each game. | ||
- Cards flip back over if they don't match. | ||
- Score tracking: gain points for each match. | ||
- Game ends when all pairs are matched. | ||
- Alerts the player when the game is completed with their final score. | ||
|
||
<br> | ||
|
||
## **How to play? 🕹️** | ||
<!-- add the steps how to play games --> | ||
- Start the game by clicking on any card. | ||
- Cards will flip to reveal the symbol on the other side. | ||
- Try to find matching pairs by remembering the position of previously flipped cards. | ||
- Click on two cards to flip them. If they match, they will stay flipped. If they don't, they will flip back over. | ||
- Continue flipping cards until all pairs are matched. | ||
- Your score is displayed at the top, increasing with each successful match. | ||
|
||
<br> | ||
|
||
## **Screenshots 📸** | ||
|
||
<br> | ||
<!-- add your screenshots like this --> | ||
![Memory_Matching_Game](https://github.com/Saipradyumnagoud/GameZone/assets/143107589/193e98bf-82e1-49f7-9cc4-41fcdfcdb618) | ||
|
||
<br> | ||
|
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Memory Matching Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="game-container"> | ||
<h1>Memory Matching Game</h1> | ||
<p id="score">Score: 0</p> | ||
<div class="game-board" id="game-board"></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,69 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const cardArray = [ | ||
{ name: 'A', id: 1 }, { name: 'A', id: 2 }, | ||
{ name: 'B', id: 3 }, { name: 'B', id: 4 }, | ||
{ name: 'C', id: 5 }, { name: 'C', id: 6 }, | ||
{ name: 'D', id: 7 }, { name: 'D', id: 8 }, | ||
{ name: 'E', id: 9 }, { name: 'E', id: 10 }, | ||
{ name: 'F', id: 11 }, { name: 'F', id: 12 }, | ||
{ name: 'G', id: 13 }, { name: 'G', id: 14 }, | ||
{ name: 'H', id: 15 }, { name: 'H', id: 16 } | ||
]; | ||
|
||
cardArray.sort(() => 0.5 - Math.random()); | ||
|
||
const gameBoard = document.getElementById('game-board'); | ||
const scoreDisplay = document.getElementById('score'); | ||
let cardsChosen = []; | ||
let cardsChosenId = []; | ||
let cardsWon = []; | ||
let score = 0; | ||
|
||
function createBoard() { | ||
cardArray.forEach((card, index) => { | ||
const cardElement = document.createElement('div'); | ||
cardElement.setAttribute('data-id', index); | ||
cardElement.classList.add('card'); | ||
cardElement.addEventListener('click', flipCard); | ||
gameBoard.appendChild(cardElement); | ||
}); | ||
} | ||
|
||
function checkForMatch() { | ||
const cards = document.querySelectorAll('.card'); | ||
const [optionOneId, optionTwoId] = cardsChosenId; | ||
|
||
if (cardsChosen[0] === cardsChosen[1]) { | ||
cards[optionOneId].classList.add('flipped'); | ||
cards[optionTwoId].classList.add('flipped'); | ||
cardsWon.push(cardsChosen); | ||
score += 10; | ||
scoreDisplay.textContent = `Score: ${score}`; | ||
} else { | ||
cards[optionOneId].innerHTML = ''; | ||
cards[optionTwoId].innerHTML = ''; | ||
} | ||
|
||
cardsChosen = []; | ||
cardsChosenId = []; | ||
|
||
if (cardsWon.length === cardArray.length / 2) { | ||
setTimeout(() => alert(`Congratulations! You found all the matches! Your final score is ${score}.`), 100); | ||
} | ||
} | ||
|
||
function flipCard() { | ||
const cardId = this.getAttribute('data-id'); | ||
if (!cardsChosenId.includes(cardId) && cardsChosen.length < 2) { | ||
cardsChosen.push(cardArray[cardId].name); | ||
cardsChosenId.push(cardId); | ||
this.innerHTML = cardArray[cardId].name; | ||
this.classList.add('flipped'); | ||
if (cardsChosen.length === 2) { | ||
setTimeout(checkForMatch, 500); | ||
} | ||
} | ||
} | ||
|
||
createBoard(); | ||
}); |
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,44 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
text-align: center; | ||
background-color: #f0f0f0; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.game-container { | ||
margin: 0 auto; | ||
width: 600px; | ||
} | ||
|
||
.game-board { | ||
display: grid; | ||
grid-template-columns: repeat(4, 1fr); | ||
gap: 10px; | ||
margin-top: 20px; | ||
} | ||
|
||
.card { | ||
width: 100px; | ||
height: 100px; | ||
background-color: #333; | ||
cursor: pointer; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 2em; | ||
color: white; | ||
border-radius: 8px; | ||
transition: transform 0.2s; | ||
} | ||
|
||
.card.flipped { | ||
background-color: #fff; | ||
color: #333; | ||
transform: rotateY(180deg); | ||
} | ||
|
||
#score { | ||
font-size: 1.5em; | ||
margin-top: 20px; | ||
} |
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.