From 3b7452eb85e4c372d5091b4600ca272ab524055f Mon Sep 17 00:00:00 2001 From: Fouque Dimitri <33320665+Nyroux@users.noreply.github.com> Date: Sat, 9 Dec 2017 04:14:40 +0100 Subject: [PATCH] fPQsjgiohsghioshigsgse --- assets/js/script.js | 46 +++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/assets/js/script.js b/assets/js/script.js index f29ba49..4f0ab4f 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -5,6 +5,8 @@ var maxY = document.querySelectorAll('.line').length; var x = 1; var y = 5; +var cibleValue = 0; +var score = 0; var controls = { up: 'z', @@ -27,13 +29,10 @@ var bulletX = 0; var bulletY = 0; var bulletDir = direction; -var cibleValue = 0; - function setPosition (posX, posY, dir) { gridX = x; gridY = y; - var grid = document.querySelector('.line-'+posY+' .col-'+posX); if(grid.classList.contains('cible')){ @@ -123,6 +122,22 @@ setInterval(function(){ var newY = bulletY; var newX = bulletX; + var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX); + + if(bulletDestination.classList.contains('cible')){ + bulletDestination.classList.remove('cible'); + cibleValue = cibleValue - 1; + score = score + 100 ; + console.log(score); + bulletDestination.classList.add('cible-touchee'); + bulletX = 0; + bulletY = 0; + setTimeout(function(){ + bulletDestination.classList.remove('cible-touchee'); + }, 1000); + return; + } + switch(bulletDir){ case rotation.up: newY--; @@ -155,8 +170,10 @@ setInterval(function(){ var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX); if(bulletDestination.classList.contains('cible')){ - cibleValue -= 1; bulletDestination.classList.remove('cible'); + cibleValue = cibleValue - 1; + score = score + 100 ; + console.log(score); bulletDestination.classList.add('cible-touchee'); bulletX = 0; bulletY = 0; @@ -175,17 +192,15 @@ setInterval(function(){ grid.style.backgroundPosition = bulletDir; }, 32.12); -setInterval(function(){ - x2 = Math.floor(Math.random() * 10) + 1; +var ntm = setInterval(function(){ + x2 = Math.floor(Math.random() * 11); if (x2 == x){ x2 = x+1; } - y2 = Math.floor(Math.random() * 20) + 1; + y2 = Math.floor(Math.random() * 21); if (y2 == y){ y2 = y+1; } - var ciblex = x2, - cibley = y2 if(ciblex < maxX && cibley < maxY){ console.log(ciblex+' pour '+maxX); @@ -193,13 +208,16 @@ setInterval(function(){ emplacement.classList.add('cible'); } + var ciblex = x2, + cibley = y2, + emplacement = document.querySelector(".line-"+ciblex+" .col-"+cibley); + emplacement.classList.add('cible'); cibleValue = cibleValue + 1; - - if (cibleValue>=3){ - console.log("TAS PERDU"); - // TODO + if (cibleValue>=3){ + alert("TAS PERDU"); + clearInterval(ntm); } -}, 3000); +}, 1000); document.addEventListener('keydown', move, false); setPosition(x, y, direction); \ No newline at end of file