Skip to content

Commit

Permalink
Final Game
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjunIyyappanav committed Aug 23, 2024
0 parents commit 24befd5
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 0 deletions.
Binary file added Simon Game Challenge Starting Files/.DS_Store
Binary file not shown.
46 changes: 46 additions & 0 deletions Simon Game Challenge Starting Files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!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">Press A Key to Start</h1>
<div class="container">
<div class="row">

<div type="button" id="green" class="btn green 1">

</div>
<audio id = "greensound" src="./sounds/green.mp3" preload="auto"></audio>

<div type="button" id="red" class="btn red 2">

</div>
<audio id = "redsound" src="./sounds/red.mp3" preload="auto"></audio>
</div>

<div class="row">

<div type="button" id="yellow" class="btn yellow 3">

</div>
<audio id = "yellowsound" src="./sounds/yellow.mp3" preload="auto"></audio>
<div type="button" id="blue" class="btn blue 4">

</div>
<audio id = "bluesound" src="./sounds/blue.mp3" preload="auto"></audio>

</div>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="script.js"></script>
</body>

</html>
79 changes: 79 additions & 0 deletions Simon Game Challenge Starting Files/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

var buttonColours = ["red", "blue", "green", "yellow"];

var gamePattern = [];
var userClickedPattern = [];

var started = false;
var level = 0;

$(document).keypress(function() {
if (!started) {
$("#level-title").text("Level " + level);
nextSequence();
started = true;
}
});

$(".btn").click(function() {

var userChosenColour = $(this).attr("id");
userClickedPattern.push(userChosenColour);

playSound(userChosenColour);
animatePress(userChosenColour);

checkAnswer(userClickedPattern.length-1);
});

function checkAnswer(currentLevel) {

if (gamePattern[currentLevel] === userClickedPattern[currentLevel]) {
if (userClickedPattern.length === gamePattern.length){
setTimeout(function () {
nextSequence();
}, 1000);
}
} else {
playSound("wrong");
$("body").addClass("game-over");
$("#level-title").text("Game Over, Press Any Key to Restart");

setTimeout(function () {
$("body").removeClass("game-over");
}, 200);

startOver();
}
}


function nextSequence() {
userClickedPattern = [];
level++;
$("#level-title").text("Level " + level);
var randomNumber = Math.floor(Math.random() * 4);
var randomChosenColour = buttonColours[randomNumber];
gamePattern.push(randomChosenColour);

$("#" + randomChosenColour).fadeIn(100).fadeOut(100).fadeIn(100);
playSound(randomChosenColour);
}

function animatePress(currentColor) {
$("#" + currentColor).addClass("pressed");
setTimeout(function () {
$("#" + currentColor).removeClass("pressed");
}, 100);
}

function playSound(name) {
var audio = new Audio("sounds/" + name + ".mp3");
audio.play();
}

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.
53 changes: 53 additions & 0 deletions Simon Game Challenge Starting Files/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
body {
text-align: center;
background-color: #011F3F;
}

#level-title {
font-family: 'Press Start 2P', cursive;
font-size: 3rem;
margin: 5%;
color: #FEF2BF;
}

.container {
display: block;
width: 50%;
margin: auto;

}

.btn {
margin: 25px;
display: inline-block;
height: 200px;
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;
}
Binary file added __MACOSX/._Simon Game Challenge Starting Files
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 24befd5

Please sign in to comment.