-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a80a286
commit ffea0a0
Showing
9 changed files
with
220 additions
and
0 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,48 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Simon</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
<link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet"> | ||
|
||
|
||
</head> | ||
|
||
<body> | ||
<h1 id="level-title"><button type="button" class="btn btn-light top">Let's Go</button></h1> | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
|
||
<div type="button" id="green" class="btnc green"> | ||
|
||
</div> | ||
|
||
<div type="button" id="red" class="btnc red"> | ||
|
||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
|
||
<div type="button" id="yellow" class="btnc yellow"> | ||
|
||
</div> | ||
<div type="button" id="blue" class="btnc blue"> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
|
||
<!-- jQuerry CDN --> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | ||
<script src="index.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,108 @@ | ||
|
||
var buttonColors=['red','blue','green','yellow']; | ||
var gamePattern=[]; | ||
var userClickedPattern=[]; | ||
|
||
var level=0; | ||
var started=false; | ||
|
||
|
||
$(".btn").click(function(event) { | ||
if(!started) | ||
{ | ||
$("#level-title").text("level "+level); | ||
nextSequence(); | ||
started=true; | ||
} | ||
}); | ||
|
||
|
||
|
||
$(".btnc").click(function(){ | ||
|
||
var userChosenColor=this.id; | ||
userClickedPattern.push(userChosenColor); | ||
|
||
playSound(userChosenColor); | ||
animatePress(userChosenColor) | ||
checkAnswer(userClickedPattern.length-1); | ||
}); | ||
|
||
|
||
function checkAnswer(currentLevel) | ||
{ | ||
if( gamePattern[currentLevel] === userClickedPattern[currentLevel]) | ||
{ | ||
console.log("success"); | ||
|
||
if( gamePattern.length === userClickedPattern.length) | ||
{ | ||
setTimeout(function(){ | ||
nextSequence(); | ||
},1000); | ||
} | ||
} | ||
|
||
else | ||
{ | ||
|
||
console.log("wrong"); | ||
|
||
playSound("wrong"); | ||
|
||
|
||
$("body").addClass("game-over"); | ||
|
||
setTimeout(function () { | ||
$("body").removeClass("game-over"); | ||
}, 200); | ||
|
||
$("#level-title").text("Game Over,refresh to restart"); | ||
|
||
startOver(); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
function nextSequence() | ||
{ | ||
|
||
level++; | ||
|
||
userClickedPattern = []; | ||
|
||
$("#level-title").text(level); | ||
|
||
var randomNumber=Math.floor(Math.random()*4); | ||
var randomChosenColor=buttonColors[randomNumber]; | ||
gamePattern.push(randomChosenColor); | ||
|
||
$("#"+randomChosenColor).fadeIn(100).fadeOut(100).fadeIn(100); | ||
|
||
playSound(randomChosenColor); | ||
} | ||
|
||
|
||
function playSound(name) | ||
{ | ||
var audio=new Audio("sounds/"+name+".mp3"); | ||
audio.play(); | ||
} | ||
|
||
function animatePress(currentColor) | ||
{ | ||
$("."+currentColor).addClass("pressed"); | ||
|
||
setTimeout(function(){ $("."+currentColor).removeClass("pressed"); },100); | ||
} | ||
|
||
|
||
function startOver() | ||
{ | ||
level = 0; | ||
gamePattern = []; | ||
started = false; | ||
} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,64 @@ | ||
body { | ||
text-align: center; | ||
/* background-color: #011F3F; */ | ||
background-image: url(spacebackground.webp); | ||
} | ||
|
||
#level-title { | ||
font-family: 'Press Start 2P', cursive; | ||
font-size: 3rem; | ||
color: #FEF2BF; | ||
} | ||
|
||
|
||
|
||
.container { | ||
display: block; | ||
width: 50%; | ||
margin: auto; | ||
|
||
} | ||
|
||
.btnc { | ||
margin: 25px; | ||
display: inline-block; | ||
height: 200px; | ||
width: 200px; | ||
border: 10px solid black; | ||
border-radius: 20%; | ||
} | ||
|
||
.btn | ||
{ | ||
font-family: 'Press Start 2P', cursive; | ||
height: 80px; | ||
width: 200px; | ||
border: 10px solid black; | ||
border-radius: 20%; | ||
} | ||
|
||
.game-over { | ||
background-color: red; | ||
opacity: 0.8; | ||
} | ||
|
||
.red { | ||
background-color: red; | ||
} | ||
|
||
.green { | ||
background-color: green; | ||
} | ||
|
||
.blue { | ||
background-color: blue; | ||
} | ||
|
||
.yellow { | ||
background-color: yellow; | ||
} | ||
|
||
.pressed { | ||
box-shadow: 0 0 20px white; | ||
background-color: grey; | ||
} |