Build a Simon Game

Developer
Size
4,017 Kb
Views
12,144

How do I make an build a simon game?

What is a build a simon game? How do you make a build a simon game? This script and codes were developed by Roksana on 22 November 2022, Tuesday.

Build a Simon Game Previews

Build a Simon Game - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Build a Simon Game</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!DOCTYPE HTML>
<html lang="en">
<head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <title>Exercise - Build a Simon Game</title> <link rel="stylesheet" href="main.css" type="text/css" /> <link href="https://fonts.googleapis.com/css?family=Oswald|Raleway" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js" defer></script> <script src="main.js" defer></script>
</head>
<body> <div class="container"> <div class="game"> <div class="tile greenTile" id="green"></div> <div class="tile redTile" id="red"></div> <div class="tile yellowTile" id="yellow"></div> <div class="tile blueTile" id="blue"></div> </div> <div class="center"> <h1>Simon</h1> <div class="buttons"> <div class="counter"></div> <div class="start"></div> <div class="strict"></div> </div> <div class="namesButtons"> <div class="nameButton">COUNTER</div> <div class="nameButton roundButton">START</div> <div class="nameButton roundButton">STRICT</div> </div> <div id="strictChanger"></div> <div class="bar"> <div class="names">OFF</div> <div class="turningBar"> <div class="buttonBar"></div> </div> <div class="names">ON</div> </div> </div> <div class="playAgain playAgain-hide"> <h2>You won!</h2> <h4>Do you want to play again?</h4> <button id="yes">YES</button> <button id="no">NO</button> </div> </div> <footer> <p>by <a href="#">Roksana</a></p> </footer>
</body> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Build a Simon Game - Script Codes CSS Codes

html { font-size: 62.5%; margin: 0; padding: 0;
}
body { margin: 0; padding: 0; font-family: 'Raleway', sans-serif; font-size: 2.3rem; background: #8C8C8C;
}
.container { width: 520px; height: 520px; padding: 0; padding-top: 50px; margin: auto; text-align: center; color: #191919;
}
.game { margin: 0; display: flex; flex-wrap: wrap; width: 100%; height: 100%; border-radius: 50%;
}
.tile { flex: 0 0 46%; background: #2EAC63; border: 10px solid #191919; transition: background .5s ease-in-out;
}
.greenTile { border-top-left-radius: 100%;
}
.lightgreen { background: #49D684; transition: background .2s ease-in-out;
}
.redTile { background: #890819; border-top-right-radius: 100%;
}
.lightred { background: #C12035; transition: background .2s ease-in-out;
}
.blueTile { background: #3E7085; border-bottom-right-radius: 100%;
}
.lightblue{ background: #6B9DB2; transition: background .2s ease-in-out;
}
.yellowTile { background: #D19A37; border-bottom-left-radius: 100%;
}
.lightyellow { background: #FFC253; transition: background .2s ease-in-out;
}
.center, .playAgain { background-color: #E8E8E8; position: relative; top: -395px; height: 250px; width: 250px; margin: auto; border-radius: 50%; border: 10px solid #191919;
}
.playAgain-hide { display: none;
}
button { width: 60px; height: 30px; font-size: 1.8rem; cursor: pointer; border-radius: 3px; border: 1px solid #191919;
}
.center-hide { display: none;
}
.center h1 { margin: 22px 0;
}
.buttons, .namesButtons { font-family: 'Oswald', sans-serif; font-size: 1.3rem; display: flex; margin: 0 25px; align-items: center; justify-content: space-around;
}
.namesButtons { margin-left: 35px;
}
.counter { height: 30px; width: 50px; background-color: #32050C; border-radius: 5px; border: 4px solid #191919; color: #DC0D29; font-family: 'Raleway', sans-serif; font-size: 2rem; padding-top: 5px;
}
.start, .strict { height: 20px; width: 20px; background-color: #FF1B1C; border-radius: 50%; border: 3px solid #191919; cursor: pointer;
}
.strict { background-color: #E4FF1A;
}
#strictChanger { position: relative; top: -77px; left: 190px; height: 11px; width: 11px; background-color: #32050C; border-radius: 50%; border: 2px solid #191919;
}
.strictOn { background-color: #DC0D29 !important;
}
.bar { display: flex; margin: 10px; align-items: center; justify-content: center;
}
.names { font-family: 'Oswald', sans-serif; font-size: 1.3rem;
}
.turningBar { width: 40px; height: 20px; margin: 0 10px; background: #191919; border: 2px solid #191919; border-radius: 2px; cursor: pointer;
}
.buttonBar { width: 18px; height: 18px; border: 1px solid #1E3888; background-color: #3993DD; border-radius: 2px;
}
.runGame { margin-left: 20px;
}
footer { position: fixed; right: 10px; bottom: 5px; text-align: center; color: #191919; font-size: 1.8rem;
}
footer p { margin: 0; padding: 0;
}
footer a { text-decoration: none; color: #191919;
}

Build a Simon Game - Script Codes JS Codes

$(document).ready(simon);
function simon() { var isStrict = false; var isOn = false; var playerTurn = false; var isWrong = false; var playerMoves = []; var list = []; var nrMoves = 0; var TIMER = 1200; $(".turningBar").click(turningOn); $(".tile").click(clickColor); function turningOn() { $(".buttonBar").toggleClass("runGame"); if (!isOn) { isOn = true; $(".strict").click(strictMode); $(".counter").html("--"); return $(".start").click(startGame); } clearAll(); } function strictMode() { $("#strictChanger").toggleClass("strictOn"); if (!isStrict) { isStrict = true; return; } isStrict = false; } function startGame() { isWrong = false; playerMoves = []; list = []; nrMoves = 0; playGame(); } function playGame() { var options = ["green", "red", "yellow", "blue"]; $(".playAgain").addClass("playAgain-hide"); $(".center").removeClass("center-hide"); $(".start").off("click"); //wyłączamy możliwość startu gry podczas działania playerTurn = false; if (!isWrong && !playerTurn) { playerMoves = []; nrMoves++; getRandomColor(options); } $(".counter").html(nrMoves); var i = 0; playerMoves = []; randomAnimation = window.setInterval(function() { var buttonId = list[i]; activeTile(buttonId); i++; if (i >= nrMoves) { window.clearInterval(randomAnimation); isWrong = false; playerTurn = true; playerMoves = []; } }, TIMER); } function getRandomColor(arr) { list.push(arr[Math.floor(Math.random() * arr.length)]); } function activeTile(color) { var NORMAL_TIMER = 300; var colorAudios = { green: new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"), red: new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"), yellow: new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"), blue: new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3") }; $("." + color + "Tile").addClass("light" + color); setTimeout(function() { $("." + color + "Tile").removeClass("light" + color); }, NORMAL_TIMER); colorAudios[color].play(); } function clickColor() { var colorId = $(this).attr("id"); var notMatch = true; if (isOn && playerTurn) { playerMoves.push(colorId); activeTile(colorId); playerMoves.forEach(function(val, index) { if (val !== list[index]) { $(".counter").html("!!"); playerTurn = false; isWrong = true; setTimeout(function() { if (isStrict) { startGame(); } else { isWrong = true; playGame(); } }, TIMER); } }); for (var i = 0; i < list.length; i++) { notMatch = (playerMoves[i] !== list[i]); } if (!notMatch) { playerTurn = false; checkWinning(); } } } function clearAll() { isOn = false; isStrict = false; isWrong = false; playerMoves = []; list = []; nrMoves = 0; $(".start").off("click"); $(".counter").html(""); $("#strictChanger").removeClass("strictOn"); $(".buttonBar").removeClass("runGame"); $(".playAgain").addClass("playAgain-hide"); $(".center").removeClass("center-hide"); } function checkWinning() { var MAX_MOVES = 20; return (nrMoves >= MAX_MOVES) ? winning() : playGame(); } function winning() { setTimeout(function() { $(".center").addClass("center-hide"); $(".playAgain").removeClass("playAgain-hide"); }, TIMER); $("button").click(function() { var yesOrNo = $(this).attr("id"); if (yesOrNo === "yes") { return startGame(); } clearAll(); }); }
}
Build a Simon Game - Script Codes
Build a Simon Game - Script Codes
Home Page Home
Developer Roksana
Username roksanaop
Uploaded November 22, 2022
Rating 3
Size 4,017 Kb
Views 12,144
Do you need developer help for Build a Simon Game?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Roksana (roksanaop) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!