Skip to content

Commit f1703a5

Browse files
authored
Merge pull request #760 from mrswastik-robot/SimonGame-mrswastik-robot
SimonGame added by mrswastik-robot
2 parents d4878b0 + 4065aab commit f1703a5

File tree

9 files changed

+220
-0
lines changed

9 files changed

+220
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SimonGame
2+
![image](https://github.com/mrswastik-robot/SimonGame/assets/107865087/7cb96e34-a0c4-4372-bb30-9143cb422235)
3+
4+
# What is a Simon Game and how it works ?
5+
6+
7+
Simon is a classic electronic memory game designed to test and improve your memory skills. It was invented by Ralph H. Baer and Howard J. Morrison and first released by Milton Bradley (now part of Hasbro) in 1978. The game consists of a console with four colored buttons (usually red, green, blue, and yellow) arranged in a circular pattern. Here's how the Simon game works:
8+
9+
(1).Sequence Generation: The game starts by lighting up one of the colored buttons in a random sequence. This is the beginning of the pattern that you need to remember.
10+
11+
(2).Playback: After the initial button is illuminated, the game will play a sequence of button presses by lighting up the buttons in the same order. The sequence will start with just one button and progressively get longer as you advance in the game.
12+
13+
(3).Player's Turn: Your goal is to mimic the sequence played by Simon. To do this, you must press the buttons in the same order that Simon did. Each button press corresponds to a sound and a flash of light. If you successfully repeat the sequence, the game will add another random button to the end of the sequence and repeat the pattern.
14+
15+
(4).Continue Playing: The game continues to increase the length of the sequence as long as you continue to correctly repeat it. It becomes more challenging as the pattern gets longer.
16+
17+
(5).Mistakes: If you make a mistake by pressing the wrong button or pressing them in the wrong order, the game will signal your error with a distinctive sound, and the game ends. Your final score is based on how many rounds you successfully completed.
18+
19+
(6).Scoring: Simon games often use a scoring system to keep track of your progress and high scores. The score typically reflects the number of rounds or steps you successfully completed in a single game.
20+
21+
(7).Difficulty Levels: Some Simon games have multiple difficulty levels, which can affect the speed of the sequence playback or the complexity of the patterns.
22+
23+
The objective of Simon is to see how far you can get by correctly repeating the increasingly longer and more complex sequences. It's a game that tests your memory, concentration, and pattern recognition skills. It can be played individually or in a competitive mode where players take turns trying to outdo each other's scores.
24+
25+
26+
27+
28+
29+

SimonGame/mrswastik-robot/game.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
var buttonColours = ["red", "blue", "green", "yellow"];
3+
4+
var gamePattern = [];
5+
var userClickedPattern = [];
6+
7+
var level = 0;
8+
var started = false;
9+
$(document).keypress(function() {
10+
if (!started) {
11+
$("#level-title").text("Level " + level);
12+
nextSequence();
13+
started = true;
14+
}
15+
});
16+
17+
18+
$(".btn").on("click", function(){ // saari document ki buttons k kisi pe bhi dabaaane pr function run ho jaa raha jisme apan har click hone waale <button> ka attribute "id" store kara rahe variable me aur usse phir bhej rahe array me
19+
var userChosenColour = $(this).attr("id"); // this se pura " <div type="button" id="green" class="btn green">" select ho jaata hain phir bas ab apan ko isme attribute "id" ka pata krna hain ki kis color ka button click kiya gaya tha
20+
userClickedPattern.push(userChosenColour);
21+
playsound(userChosenColour);
22+
animatePress(userChosenColour);
23+
checkAnswer(userClickedPattern.length - 1);
24+
25+
});
26+
27+
function checkAnswer(currentlevel)
28+
{
29+
if(gamePattern[currentlevel] == userClickedPattern[currentlevel])
30+
{
31+
console.log("Success");
32+
if (userClickedPattern.length === gamePattern.length) //checking if one complete round of game is completed or not
33+
{
34+
setTimeout(function(){
35+
nextSequence();} , 1000);
36+
}
37+
38+
}
39+
else{
40+
var audio = new Audio("sounds/wrong.mp3");
41+
audio.play();
42+
43+
$("body").addClass("game-over");
44+
setTimeout(function(){document.querySelector("body").classList.remove("game-over")}, 200);
45+
$("h1").html("<span style='color: red;'>Gameover.</span></br></br> Press any key to Restart.");
46+
47+
startOver();
48+
}
49+
}
50+
51+
52+
53+
54+
55+
function nextSequence(){
56+
57+
userClickedPattern = [];
58+
++level;
59+
$("h1").text("Level - " + level);
60+
61+
var randomNumber = Math.floor(Math.random() * 4);
62+
var randomChosenColour = buttonColours[randomNumber];
63+
gamePattern.push(randomChosenColour);
64+
65+
$("#" + randomChosenColour).fadeIn(100).fadeOut(100).fadeIn(100);
66+
67+
playsound(randomChosenColour);
68+
}
69+
70+
function playsound(name)
71+
{
72+
var audio = new Audio("sounds/" + name + ".mp3");
73+
audio.play();
74+
}
75+
76+
function animatePress(currentColour)
77+
{
78+
$("#" + currentColour).addClass("pressed");
79+
setTimeout(function(){document.querySelector("#" + currentColour).classList.remove("pressed")}, 100);
80+
}
81+
82+
function startOver(){
83+
level = 0;
84+
started = false;
85+
gamePattern = [];
86+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Simon</title>
7+
<link rel="stylesheet" href="styles.css">
8+
<link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet">
9+
</head>
10+
11+
<body>
12+
<h1 id="level-title">Press A Key to Start</h1>
13+
<div class="container">
14+
<div class="row">
15+
16+
<div type="button" id="green" class="btn green">
17+
18+
</div>
19+
20+
<div type="button" id="red" class="btn red">
21+
22+
</div>
23+
</div>
24+
25+
<div class="row">
26+
27+
<div type="button" id="yellow" class="btn yellow">
28+
29+
</div>
30+
<div type="button" id="blue" class="btn blue">
31+
32+
</div>
33+
34+
</div>
35+
36+
</div>
37+
38+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <!--aur ye entry hui jquery ki, ye cdn hain jquey ka aur ise yaad se javascript jo ki hamesha hi body k last me rahega uske upar chipka diya krna-->
39+
<script src="game.js" charset="utf-8"></script>
40+
41+
</body>
42+
43+
<footer>Designed by <span style="color: red">Swastik.</span></footer>
44+
45+
</html>
3.56 KB
Binary file not shown.
17.3 KB
Binary file not shown.
16.3 KB
Binary file not shown.
7.74 KB
Binary file not shown.
10.8 KB
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
body {
2+
text-align: center;
3+
background-color: #011F3F;
4+
}
5+
6+
#level-title {
7+
font-family: 'Press Start 2P', cursive;
8+
font-size: 3rem;
9+
margin: 5%;
10+
color: #FEF2BF;
11+
}
12+
13+
.container {
14+
display: block;
15+
width: 50%;
16+
margin: auto;
17+
18+
}
19+
20+
.btn {
21+
margin: 25px;
22+
display: inline-block;
23+
height: 200px;
24+
width: 200px;
25+
border: 10px solid black;
26+
border-radius: 20%;
27+
}
28+
29+
.game-over {
30+
background-color: red;
31+
opacity: 0.8;
32+
}
33+
34+
.red {
35+
background-color: red;
36+
}
37+
38+
.green {
39+
background-color: green;
40+
}
41+
42+
.blue {
43+
background-color: blue;
44+
}
45+
46+
.yellow {
47+
background-color: yellow;
48+
}
49+
50+
.pressed {
51+
box-shadow: 0 0 20px white;
52+
background-color: grey;
53+
}
54+
55+
footer{
56+
font-family: 'Press Start 2P', cursive;
57+
font-size: 1rem;
58+
color: #FEF2BF;
59+
margin-top: 1.50%;
60+
}

0 commit comments

Comments
 (0)