Skip to content

Commit 7d89505

Browse files
authored
Merge pull request #198 from siddhi-244/Siddhi/simon-game
simon game
2 parents 9fd5cee + 6c2cc67 commit 7d89505

File tree

10 files changed

+191
-3
lines changed

10 files changed

+191
-3
lines changed

Index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,5 @@
6666
| [Blog Application](https://github.com/khushi-purwar/Web-dev-mini-projects/tree/main/Blog%20Application) | Blog Application is an application where user can add a new blog, edit it, delete it as well as view other blogs and make changes in them. |
6767
| [Typing Speed Test Website](https://github.com/khushi-purwar/Web-dev-mini-projects/tree/main/Typing%20Speed%20Test%20Website) | This website is used to check the typing speed of the user. It will the give the information of how many seconds require for typing the particular sentence. |
6868
| [Breaking Bad Characters](https://github.com/khushi-purwar/Web-dev-mini-projects/tree/main/breaking-bad-characters) | A single page web application that uses the breaking bad API to display and filter characters from the show |
69+
| [Simon Game](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/Simon_Game) |A basic memory game in which there are 4 boxes of different colors and one box is blinked. The user has to click the boxes blinked and also has to click the previous blinked boxes as well.|
6970
| [Javascript Color Change App](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/JAVASCRIPT%20BUTTON%20APP) | It is a basic web app where the user can select a color from the options that are given on the web app and as he clicks on that option, all the buttons background color changes to that color. |
70-
71-
72-

Simon_Game/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### Simon Game
2+
A RGB color guessing game.It has 2 levels easy and hard. In easy level you have 3 boxes and you have to guess from those 3 boxes but in hard level you have 6 boxes.
3+
4+
### Use of the Project:
5+
It is a great game to play. It is basically a memory game and will benefit your memory alot.
6+
7+
### Tech Stack
8+
* HTML5
9+
* CSS3
10+
* JAVASCRIPT
11+
12+
13+
#### Steps to Use:
14+
15+
---
16+
17+
- Download or clone the repository
18+
19+
```
20+
git clone https://github.com/Ayushparikh-code/Web-dev-mini-projects.git
21+
```
22+
23+
- Go to the directory
24+
- Run the index.html file
25+
- Start playing!
26+
27+
---
28+
29+
## Screenshots
30+
![Simon_game](https://user-images.githubusercontent.com/69195262/125393546-c5b57c80-e3c5-11eb-878f-7e57e9c8aa7d.png)

Simon_Game/game.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
var buttonColours = ["red", "blue", "green", "yellow"];
3+
4+
var gamePattern = [];
5+
var userClickedPattern = [];
6+
7+
var started = false;
8+
var level = 0;
9+
10+
$(document).keypress(function() {
11+
if (!started) {
12+
$("#level-title").text("Level " + level);
13+
nextSequence();
14+
started = true;
15+
}
16+
});
17+
18+
$(".btn").click(function() {
19+
20+
var userChosenColour = $(this).attr("id");
21+
userClickedPattern.push(userChosenColour);
22+
23+
playSound(userChosenColour);
24+
animatePress(userChosenColour);
25+
26+
checkAnswer(userClickedPattern.length-1);
27+
});
28+
29+
function checkAnswer(currentLevel) {
30+
31+
if (gamePattern[currentLevel] === userClickedPattern[currentLevel]) {
32+
if (userClickedPattern.length === gamePattern.length){
33+
setTimeout(function () {
34+
nextSequence();
35+
}, 1000);
36+
}
37+
} else {
38+
playSound("wrong");
39+
$("body").addClass("game-over");
40+
$("#level-title").text("Game Over, Press Any Key to Restart");
41+
42+
setTimeout(function () {
43+
$("body").removeClass("game-over");
44+
}, 200);
45+
46+
startOver();
47+
}
48+
}
49+
50+
51+
function nextSequence() {
52+
userClickedPattern = [];
53+
level++;
54+
$("#level-title").text("Level " + level);
55+
var randomNumber = Math.floor(Math.random() * 4);
56+
var randomChosenColour = buttonColours[randomNumber];
57+
gamePattern.push(randomChosenColour);
58+
59+
$("#" + randomChosenColour).fadeIn(100).fadeOut(100).fadeIn(100);
60+
playSound(randomChosenColour);
61+
}
62+
63+
function animatePress(currentColor) {
64+
$("#" + currentColor).addClass("pressed");
65+
setTimeout(function () {
66+
$("#" + currentColor).removeClass("pressed");
67+
}, 100);
68+
}
69+
70+
function playSound(name) {
71+
var audio = new Audio("sounds/" + name + ".mp3");
72+
audio.play();
73+
}
74+
75+
function startOver() {
76+
level = 0;
77+
gamePattern = [];
78+
started = false;
79+
}
80+
81+

Simon_Game/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Simon</title>
6+
<link rel="stylesheet" href="styles.css">
7+
<link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet">
8+
</head>
9+
<body>
10+
<h1 id="level-title">Press A Key to Start</h1>
11+
<div class="container">
12+
<div lass="row">
13+
<div type="button" id="green" class="btn green"></div>
14+
<div type="button" id="red" class="btn red"></div>
15+
</div>
16+
<div class="row">
17+
<div type="button" id="yellow" class="btn yellow"></div>
18+
<div type="button" id="blue" class="btn blue"></div>
19+
</div>
20+
</div>
21+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
22+
<script src="game.js" charset="utf-8"></script>
23+
</body>
24+
</html>
25+
26+

Simon_Game/sounds/blue.mp3

3.56 KB
Binary file not shown.

Simon_Game/sounds/green.mp3

17.3 KB
Binary file not shown.

Simon_Game/sounds/red.mp3

16.3 KB
Binary file not shown.

Simon_Game/sounds/wrong.mp3

7.74 KB
Binary file not shown.

Simon_Game/sounds/yellow.mp3

10.8 KB
Binary file not shown.

Simon_Game/style.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)