cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              		<title>Simon Game!</title>
		<link href='https://fonts.googleapis.com/css?family=Dosis:600' rel='stylesheet' type='text/css'>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="simon.css">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
		<script type="text/javascript" src="simon.js"></script>
	</head>
	<body>
		<h1 class="label label-info">Simon Game</h1>

		<div id="simon-game-container">
			<div id="red" class="slice"></div>
			<div id="blue" class="slice"></div>
			<div id="yellow" class="slice"></div>
			<div id="green" class="slice"></div>
		</div>

		<div class="label label-default" id="level-container">Level: <span id="level"></span></div>

		<div id="bttn">
      <button class="btn btn-primary" id="start-reset">Start</button>
    </div>
            
          
!
            
              body {
	font-family: 'Dosis', sans-serif;
	text-align: center;
  background-color:gray;
}
h1 {
	font-size: 50px;
	letter-spacing: 0.2em;
}
#simon-game-container {
	width: 200px;
	height: 200px;
	border-radius: 50%;
	border: 6px black solid;
	margin: 0 auto;
	/*overflow: hidden;*/
}
.slice {
	width: 94px;
	height: 94px;
	border: 1px solid black;
	float: left;
	cursor: pointer;
}
#red {
	background-color: #ec0974;
	border-top-left-radius: 100%;
}
#green {
	background-color: #40b000;
	border-bottom-right-radius: 100%;
}
#yellow {
	background-color: #fff220;
	border-bottom-left-radius: 100%;
}
#blue {
	background-color: #0f00f0;
	border-top-right-radius: 100%;
}
#level-container {
	display: inline-block;
	margin: 10px;
	font-size: 20px;
}
#bttn {
  text-align: center;
  margin: 0 auto;
}
button {
	font-size: 20px;
	margin-top: 10px;
}


            
          
!
            
              $(document).ready(function() {
	var attempt = [], simon = [], level = 1, lives = 3, index = 0, flag = true, color = "", playerTurn = false, soundIndex;
	var slices = ["red", "blue", "yellow", "green"];
	var redSound = new Audio("http://www.chiptape.com/chiptape/sounds/short/wipeHi.wav");
	var blueSound = new Audio("http://www.chiptape.com/chiptape/sounds/short/boingShort.wav");
	var yellowSound = new Audio("http://www.chiptape.com/chiptape/sounds/short/dinkMenu.wav");
	var greenSound = new Audio("http://www.chiptape.com/chiptape/sounds/short/horn.wav");
	var sounds = [redSound, blueSound, yellowSound, greenSound];
	


	$("#level").html(level);																		// set level count to 1
	$("#lives").html(lives);																		//set lives count to 3
		
	$(".slice").on("click", function() {
		if (playerTurn) {																					// only add to attempt array if it's player's turn
			color = $(this).attr("id")
			attempt.push(color);																		// push guess into attempt array

			$(this).fadeOut(150).fadeIn(150);
			soundIndex = slices.indexOf(color);
			sounds[soundIndex].play();

			if (attempt[index] !== simon[index]) {									// if guess is incorrect	
				alert("Incorrect, try again.");
				patternBlink(simon);
				index = 0;
				attempt = [];
				//flag = true;
			}
			else {
				if (index === simon.length-1) {									// if entire guess is correct
					playerTurn = false;																		// turn control to code for new pattern, user can't click
					attempt = [];																					// reset attempt array
					level++;																							// level up
					$("#level").html(level);
					index = 0;																						// reset index
					color = slices[Math.floor(Math.random() * (3 + 1))];	// add upon pattern
					simon.push(color);
					patternBlink(simon);
				}
				else if (index !== simon.length-1) {						// if current guess is correct, but not the end of pattern
					index++;																							// increase index
					return;
				}
			}
		}
	});

	$("#start-reset").on("click", function() {									// when start button is clicked
		if ($(this).html() === "Start") {
			simon = [];																							// ensure simon array is empty
			$(this).html("Reset");																	// change text in start button to reset

			color = slices[Math.floor(Math.random() * (3 + 1))];		// add first color
			simon.push(color);

			patternBlink(simon);																		// call patterBlink() to make first pattern blink
		}
		else {																										// reset game
			reset();
		}
	});																													// end of start button click

	function patternBlink(simon) {
		setTimeout(function() {																		// delay next pattern blink from last button guess
			for(var i = 0; i < simon.length; i++) {									// make each blink sequentially
				(function(i) { 
					setTimeout(function() {
						soundIndex = slices.indexOf(simon[i]);
						sounds[soundIndex].play();
						$("#"+simon[i]).fadeOut(150).fadeIn(150);					// make selected slice blink
					}, i * 800);
				})(i);																								// make it user's turn to play														
			}		
		}, 1000);
		playerTurn = true;
	}

	function reset() {
		$("#start-reset").html("Start");
		level = 1;
		$("#level").html(level);
		//lives = 3;
		attempt = [];
		simon = [];
		index = 0;
	}
});																														// end of document.ready

            
          
!
999px
Loading ..................

Console