%PDF- %PDF-
Direktori : /proc/self/root/home/infra/jogos/memoria/ |
Current File : //proc/self/root/home/infra/jogos/memoria/game.js |
(function($){ "use strict" var JogoDaMemoria = { content:$('#game'), options:[ 'zequinha', 'caio', 'likinha', 'belinha', 'aninha', 'flora', 'binho', 'turminha' ], init:function(){ this._build(); this.watcher(); this.Pontuacao.zerar(); }, random:function(){ var opt = this.options.concat(this.options); var randed = [] while(opt.length > 0){ var posicao = Math.floor(Math.random() * opt.length); randed.push(opt[posicao]); opt.splice(posicao, 1); } return randed; }, _build:function(){ var content = this.content; $(content).empty(); $.each(this.random(), function(i,e){ $(content).append( $('<li>') .attr('class', 'memoria') .attr('data-senha',e) .attr('data-clicked', false) .attr('data-finded', false) .append( $('<img/>').attr('src','resources/turminha0.jpg') ) ); }); }, Pontuacao:{ points : 0, incrementScore : 5, decrementScore : 1, updateScore:function(){ var scoreDiv = document.getElementById("score"); scoreDiv.innerHTML = "Pontuação: " + this.points; }, increment:function(){ this.points+= this.incrementScore; this.updateScore(); }, decrement:function(){ this.points-= this.decrementScore; this.updateScore(); }, zerar: function(){ this.points = 0; this.updateScore(); } }, escolher:function(){ var selected = $('[data-clicked=true][data-finded=false]'); if(selected.length <= 2 ){ $.each(selected,function(i,e){ $(e).find('img').attr('src','resources/'+ $(e).data('senha') + '.jpg'); }); if(selected.length == 2){ if($(selected[0]).data('senha') == $(selected[1]).data('senha')) this.acertou(selected); else this.errou(selected); this.Pontuacao.decrement(); } }else this.errou(selected); if($('[data-finded=true]').length == this.options.length * 2 ) this.encerrou(); }, encerrou:function(){ setTimeout(function(){ var modal = document.getElementById('myModal'); var span = document.getElementsByClassName("close")[0]; span.onclick = function() { modal.style.display = "none"; JogoDaMemoria.init(); } modal.style.display = "block"; window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; JogoDaMemoria.init(); } } },250) }, acertou:function(selected){ $(selected).attr('data-finded',true); this.Pontuacao.increment(); }, errou:function(selected){ setTimeout(function(){ $(selected).attr('data-clicked', false); $(selected).find('img').attr('src','resources/turminha0.jpg'); },1500) }, watcher:function(){ $('#game li').on('click',function(){ $(this).attr('data-clicked', true); JogoDaMemoria.escolher(); }); } } window.JogoDaMemoria = JogoDaMemoria; JogoDaMemoria.init(); })(jQuery);