Created
April 17, 2014 03:05
-
-
Save jli-hashrocket/10950115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function(){ | |
| var MemoryGame = function(){ | |
| this.init(); | |
| }; | |
| MemoryGame.prototype = jQuery.extend(MemoryGame.prototype, { | |
| init: function(){ | |
| var deck = [1,5,3,5,7,8]; | |
| this.createDeck(deck); | |
| this.handleClick(); | |
| }, | |
| createDeck: function(deck){ | |
| deck.forEach(function(num){ | |
| $('#gameContainer').append(function(){ | |
| var card = $('<div class="card"/>'); | |
| return card.html(num); | |
| }); | |
| }); | |
| }, | |
| reset: function(clicked){ | |
| $('.card').css("color","#fff"); | |
| clicked = []; | |
| }, | |
| handleClick: function(){ | |
| var clicked = []; | |
| $('.card').click(function(event){ | |
| event.preventDefault(); | |
| $(this).css('color', '#000'); | |
| clicked.push($(this).html()); | |
| if(clicked.length == 2){ | |
| if(clicked[0] == clicked[1] ){ | |
| alert('This is a match!'); | |
| $('.card').css("color","#fff"); | |
| clicked = []; | |
| }else{ | |
| alert('This is not a match :('); | |
| $('.card').css("color","#fff"); | |
| clicked = []; | |
| } | |
| clicked = []; | |
| } | |
| }); | |
| } | |
| }); | |
| memoryGame = new MemoryGame(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment