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

Press A Key to Start

13 |
14 |
15 | 16 |
17 | 18 |
19 | 20 |
21 | 22 |
23 |
24 | 25 |
26 | 27 |
28 | 29 |
30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /sounds/blue.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/SimonGame/b93b22132150e59ed700f9c6a79bf7436ba79635/sounds/blue.mp3 -------------------------------------------------------------------------------- /sounds/green.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/SimonGame/b93b22132150e59ed700f9c6a79bf7436ba79635/sounds/green.mp3 -------------------------------------------------------------------------------- /sounds/red.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/SimonGame/b93b22132150e59ed700f9c6a79bf7436ba79635/sounds/red.mp3 -------------------------------------------------------------------------------- /sounds/wrong.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/SimonGame/b93b22132150e59ed700f9c6a79bf7436ba79635/sounds/wrong.mp3 -------------------------------------------------------------------------------- /sounds/yellow.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/SimonGame/b93b22132150e59ed700f9c6a79bf7436ba79635/sounds/yellow.mp3 -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 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 | --------------------------------------------------------------------------------