Skip to content

Instantly share code, notes, and snippets.

@stormsweeper
Created May 18, 2017 01:16
Show Gist options
  • Select an option

  • Save stormsweeper/fa63de3f224de9ce7d67322b8044dae3 to your computer and use it in GitHub Desktop.

Select an option

Save stormsweeper/fa63de3f224de9ce7d67322b8044dae3 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=fa63de3f224de9ce7d67322b8044dae3
<!DOCTYPE html>
<html>
<head>
<title>Pop Those Bubbles</title>
</head>
<body>
<h1>How fast can you pop all the bubbles?</h1>
(play this in full screen)
<div class="bubbles">
<button>Play</button>
</div>
</body>
</html>
{"enabledLibraries":["jquery"]}
var start;
function startGame() {
start = new Date();
$('.bubbles').html('<span class="bubble full"></span>');
}
function maybeStopGame() {
if ($('.bubble').length === 0) {
var time = Math.round((new Date() - start) / 1000);
var playAgain = confirm(
'You popped all the bubbles in ' + time + 'seconds! Play again?'
);
if (playAgain) {
startGame();
} else {
$('.bubbles').html('<button>Play</button>');
}
}
}
$('.bubbles').on('click', 'button', startGame);
$('.bubbles').on(
'click',
'.bubble',
function(event){
var $bubble = $(this);
var newSize = null;
if ($bubble.hasClass('full')) {
newSize = 'half';
} else if ($bubble.hasClass('half')) {
newSize = 'quarter';
} else if ($bubble.hasClass('quarter')) {
newSize = 'eighth';
} else if ($bubble.hasClass('eighth')) {
newSize = 'sixteenth';
} else if ($bubble.hasClass('sixteenth')) {
$bubble.remove();
maybeStopGame();
return;
}
$bubble.replaceWith(
'<span class="bubble '
+ newSize
+ '"></span><span class="bubble '
+ newSize
+ '"></span>'
);
}
);
.bubbles {
width: 400px;
margin: auto;
text-align: center;
}
.bubble {
display: inline-block;
border-radius: 50%;
margin: 1%;
}
.full {
background: lightblue;
width: 200px;
height: 200px;
}
.half {
background: green;
width: 140px;
height: 140px;
}
.quarter {
background: purple;
width: 100px;
height: 100px;
}
.eighth {
background: orange;
width: 70px;
height: 70px;
}
.sixteenth {
background: pink;
width: 50px;
height: 50px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment