Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@ body{
cursor: auto;
}

.button-wrapper {
text-align: center;
padding-top: 20px;
}

.moves {
display: inline-block;
color: white;
font-size: 20px;
}

#moves {
display: inline-block;
color: white;
margin-left: 5px;
font-size: 20px;
}

#reset {
background-color: blue;
color: white;
display: inline-block;
height: 40px;
line-height: 40px;
text-decoration: bold;
width: 80px;
text-align: center;
border-radius: 5%;
font-size: 20px;
margin-left: 20px;
}

@keyframes finish{
0% {transform : scale(1) }
100% {transform: scale(0.3)}
Expand Down
15 changes: 10 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<body>
<div class = "wrapper">

<div class = "button-wrapper">
<div class="moves">Moves:</div>
<div id="moves">0</div>
<div id="reset">Reset</div>
</div>

<ul class = "panels">

<li id = "dropbox" name = "dropbox">
Expand Down Expand Up @@ -60,7 +66,7 @@
<li id = "youtube" name = "youtube">
<div class = "front" style = "background:#43a047"><i class="fa fa-circle fa-3x" aria-hidden="true" style = "color:#43a047"></i></div>
<div class = "back" style = "background: #888888"><i class="fa fa-youtube fa-3x" aria-hidden="true"></i></div>
</li>
</li>
<li id = "android" name = "android2">
<div class = "front" style = "background:#1e88e5"><i class="fa fa-circle fa-3x" aria-hidden="true" style = "color:#1e88e5"></i></div>
<div class = "back" style = "background: #888888"><i class="fa fa-android fa-3x" aria-hidden="true"></i></div>
Expand Down Expand Up @@ -99,7 +105,7 @@
<div class = "back" style = "background: #888888"><i class="fa fa-github fa-3x" aria-hidden="true"></i></div>
</li>


<!-- Third row -->

<li id = "paypal" name = "paypal2">
Expand Down Expand Up @@ -141,8 +147,8 @@
<li id = "quora" name = "quora2">
<div class = "front" style = "background:#43a047"><i class="fa fa-circle fa-3x" aria-hidden="true" style = "color:#43a047"></i></div>
<div class = "back" style = "background: #888888"><i class="fa fa-quora fa-3x" aria-hidden="true"></i></div>
</li>
</li>

<!-- Fourth Row -->
<li id = "free-code-camp" name = "free-code-camp2">
<div class = "front" style = "background:#880e4f"><i class="fa fa-circle fa-3x" aria-hidden="true" style = "color:#880e4f"></i></div>
Expand Down Expand Up @@ -188,7 +194,6 @@

</ul>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g=" crossorigin="anonymous"></script>
<script src="js/index.js"></script>

Expand Down
33 changes: 18 additions & 15 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,41 @@ var first = null, second = null;
var tiles = 0;
var time = new Date().getTime();
var blockInput = false;

var moves = 0;
$(document).ready(function(){

var ul = document.querySelector('ul');
for (var i = ul.children.length; i >= 0; i--) {
ul.appendChild(ul.children[Math.random() * i | 0]);
}

randomizeStartOffset();
transitionToStartPosition();


$("#reset").click(function(){
$('#moves').html(function(i, val) { return val = 0 });
location.reload()
})

$(".front").click(function(){
if(blockInput){
return;
}

if(first == null){
first = $(this).parent();
first = $(this).parent();
first.addClass("activated");
return;
}

if(first != second){
second = $(this).parent();
second = $(this).parent();
second.addClass("activated");
}

if(first != null && second != null){
if(first.attr("id") == second.attr("id")){
blockInput = true;
blockInput = true;
first.removeClass("activated").addClass("match");
second.removeClass("activated").addClass("match");
setTimeout(function() { removeCorrectTiles(); }, 700);
Expand All @@ -56,7 +61,6 @@ removeCorrectTiles = function(){
first.removeClass("match").addClass("done");
second.removeClass("match").addClass("done");
unblock();

tiles += 2;
checkWin();
}
Expand All @@ -67,6 +71,7 @@ unblock = function(){
firstID = -1;
secondID = -1;
blockInput = false;
$('#moves').html(function(i, val) { return val*1+1 });
}

checkWin = function(){
Expand All @@ -78,7 +83,7 @@ checkWin = function(){

randomizeStartOffset = function(){
$(".front").each(function( index ) {$( this ).css({
top: (Math.random() * 2 - 1) * 550,
top: (Math.random() * 2 - 1) * 550,
left: (Math.random() * 2 - 1) * 550}) });
}

Expand All @@ -88,13 +93,11 @@ transitionToStartPosition = function(){
$(".front").each(function( index ) {
var position = $( this ).position();
$( this ).css({
top: position.top * .85,
top: position.top * .85,
left: position.left * .85});
});
setTimeout(function() { transitionToStartPosition(); }, 16);
}else{
$(".front").each(function( index ) {$( this ).css({top: 0, left: 0}) });
}
}