diff --git a/Simon Game Challenge Starting Files/.DS_Store b/Simon Game Challenge Starting Files/.DS_Store new file mode 100644 index 0000000..2814ac6 Binary files /dev/null and b/Simon Game Challenge Starting Files/.DS_Store differ diff --git a/Simon Game Challenge Starting Files/index.html b/Simon Game Challenge Starting Files/index.html new file mode 100644 index 0000000..2344a8f --- /dev/null +++ b/Simon Game Challenge Starting Files/index.html @@ -0,0 +1,46 @@ + + + + + + Simon + + + + + +

Press A Key to Start

+
+
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + + + + + diff --git a/Simon Game Challenge Starting Files/script.js b/Simon Game Challenge Starting Files/script.js new file mode 100644 index 0000000..a9134a2 --- /dev/null +++ b/Simon Game Challenge Starting Files/script.js @@ -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; +} diff --git a/Simon Game Challenge Starting Files/sounds/blue.mp3 b/Simon Game Challenge Starting Files/sounds/blue.mp3 new file mode 100644 index 0000000..ae68cba Binary files /dev/null and b/Simon Game Challenge Starting Files/sounds/blue.mp3 differ diff --git a/Simon Game Challenge Starting Files/sounds/green.mp3 b/Simon Game Challenge Starting Files/sounds/green.mp3 new file mode 100644 index 0000000..896b9f9 Binary files /dev/null and b/Simon Game Challenge Starting Files/sounds/green.mp3 differ diff --git a/Simon Game Challenge Starting Files/sounds/red.mp3 b/Simon Game Challenge Starting Files/sounds/red.mp3 new file mode 100644 index 0000000..e7738ae Binary files /dev/null and b/Simon Game Challenge Starting Files/sounds/red.mp3 differ diff --git a/Simon Game Challenge Starting Files/sounds/wrong.mp3 b/Simon Game Challenge Starting Files/sounds/wrong.mp3 new file mode 100644 index 0000000..5ece8fd Binary files /dev/null and b/Simon Game Challenge Starting Files/sounds/wrong.mp3 differ diff --git a/Simon Game Challenge Starting Files/sounds/yellow.mp3 b/Simon Game Challenge Starting Files/sounds/yellow.mp3 new file mode 100644 index 0000000..b360c08 Binary files /dev/null and b/Simon Game Challenge Starting Files/sounds/yellow.mp3 differ diff --git a/Simon Game Challenge Starting Files/styles.css b/Simon Game Challenge Starting Files/styles.css new file mode 100644 index 0000000..6edc539 --- /dev/null +++ b/Simon Game Challenge Starting Files/styles.css @@ -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; +} diff --git a/__MACOSX/._Simon Game Challenge Starting Files b/__MACOSX/._Simon Game Challenge Starting Files new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/._Simon Game Challenge Starting Files differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/._.DS_Store b/__MACOSX/Simon Game Challenge Starting Files/._.DS_Store new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/._.DS_Store differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/._index.html b/__MACOSX/Simon Game Challenge Starting Files/._index.html new file mode 100644 index 0000000..d6e0906 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/._index.html differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/._sounds b/__MACOSX/Simon Game Challenge Starting Files/._sounds new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/._sounds differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/._styles.css b/__MACOSX/Simon Game Challenge Starting Files/._styles.css new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/._styles.css differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/sounds/._blue.mp3 b/__MACOSX/Simon Game Challenge Starting Files/sounds/._blue.mp3 new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/sounds/._blue.mp3 differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/sounds/._green.mp3 b/__MACOSX/Simon Game Challenge Starting Files/sounds/._green.mp3 new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/sounds/._green.mp3 differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/sounds/._red.mp3 b/__MACOSX/Simon Game Challenge Starting Files/sounds/._red.mp3 new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/sounds/._red.mp3 differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/sounds/._wrong.mp3 b/__MACOSX/Simon Game Challenge Starting Files/sounds/._wrong.mp3 new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/sounds/._wrong.mp3 differ diff --git a/__MACOSX/Simon Game Challenge Starting Files/sounds/._yellow.mp3 b/__MACOSX/Simon Game Challenge Starting Files/sounds/._yellow.mp3 new file mode 100644 index 0000000..94b8038 Binary files /dev/null and b/__MACOSX/Simon Game Challenge Starting Files/sounds/._yellow.mp3 differ