Memory Game
About this app
A memory game based on Simon Game by Hasbro
Memory Game Memory Game Start
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Memory Game</title>
<meta name="description" content="A memory game based on Simon Game by Hasbro">
<meta name="keywords" content="memory game, simon game, color pattern, sequence">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto" rel="stylesheet">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
const colors = ["red", "blue", "green", "yellow"];
let sequence = [];
let playerSequence = [];
let level = 1;
let isGameStarted = false;
let isPlayerTurn = false;
const startGame = () => {
if (!isGameStarted) {
sequence = [];
playerSequence = [];
level = 1;
isGameStarted = true;
isPlayerTurn = false;
showLevel();
generateSequence();
playSequence();
}
};
const generateSequence = () => {
for (let i = 0; i < level; i++) {
const randomColor = colors[Math.floor(Math.random() * colors.length)];
sequence.push(randomColor);
}
};
const playSequence = () => {
let i = 0;
const interval = setInterval(() => {
if (i < sequence.length) {
flashButton(sequence[i]);
i++;
} else {
clearInterval(interval);
isPlayerTurn = true;
}
}, 1000);
};
const flashButton = (color) => {
$(`#${color}`).addClass("active");
setTimeout(() => {
$(`#${color}`).removeClass("active");
}, 500);
};
const showLevel = () => {
$("#level").text(`Level: ${level}`);
};
const checkSequence = () => {
for (let i = 0; i < playerSequence.length; i++) {
if (playerSequence[i] !== sequence[i]) {
return false;
}
}
return true;
};
const nextLevel = () => {
level++;
playerSequence = [];
isPlayerTurn = false;
showLevel();
generateSequence();
setTimeout(() => {
playSequence();
}, 1000);
};
const endGame = () => {
alert(`Game Over! You reached level ${level}`);
isGameStarted = false;
};
$(".button").click(function() {
if (isPlayerTurn) {
const color = $(this).attr("id");
flashButton(color);
playerSequence.push(color);
if (!checkSequence()) {
endGame();
} else if (playerSequence.length === sequence.length) {
nextLevel();
}
}
});
$("#start-button").click(startGame);
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
body {
background-color: #f8f9fa;
font-family: 'Roboto', sans-serif;
}
#main-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
h1 {
margin-bottom: 20px;
color: #343a40;
text-align: center;
}
#game-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 300px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
padding: 20px;
background-image: linear-gradient(to right, #FF512F, #DD2476);
} {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 300px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
padding: 20px;
}
#level {
margin-bottom: 20px;
color: #343a40;
font-weight: bold;
}
#button-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
.button {
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 100px;
border-radius: 50%;
cursor: pointer;
transition: background-color 0.3s;
}
.button i {
font-size: 30px;
color: #fff;
}
.button.active {
background-color: #343a40;
background-image: linear-gradient(to right, #FF512F, #DD2476);
} {
background-color: #343a40;
}
#start-button {
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 40px;
border-radius: 20px;
background-color: #343a40;
color: #fff;
cursor: pointer;
transition: background-color 0.3s;
}
#start-button:hover {
background-color: #6c757d;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Memory Game</h1>
<div id="game-container">
<div id="level"></div>
<div id="button-container">
<div id="red" class="button">
<i class="fa fa-circle"></i>
</div>
<div id="blue" class="button">
<i class="fa fa-circle"></i>
</div>
<div id="green" class="button">
<i class="fa fa-circle"></i>
</div>
<div id="yellow" class="button">
<i class="fa fa-circle"></i>
</div>
</div>
<div id="start-button">
Start
</div>
</div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!