fPQsjgiohsghioshigsgse

master
Fouque Dimitri 2017-12-09 04:14:40 +01:00 committed by GitHub
parent 3d1f5facc6
commit 3b7452eb85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 14 deletions

View File

@ -5,6 +5,8 @@ var maxY = document.querySelectorAll('.line').length;
var x = 1; var x = 1;
var y = 5; var y = 5;
var cibleValue = 0;
var score = 0;
var controls = { var controls = {
up: 'z', up: 'z',
@ -27,13 +29,10 @@ var bulletX = 0;
var bulletY = 0; var bulletY = 0;
var bulletDir = direction; var bulletDir = direction;
var cibleValue = 0;
function setPosition (posX, posY, dir) { function setPosition (posX, posY, dir) {
gridX = x; gridX = x;
gridY = y; gridY = y;
var grid = document.querySelector('.line-'+posY+' .col-'+posX); var grid = document.querySelector('.line-'+posY+' .col-'+posX);
if(grid.classList.contains('cible')){ if(grid.classList.contains('cible')){
@ -123,6 +122,22 @@ setInterval(function(){
var newY = bulletY; var newY = bulletY;
var newX = bulletX; 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){ switch(bulletDir){
case rotation.up: case rotation.up:
newY--; newY--;
@ -155,8 +170,10 @@ setInterval(function(){
var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX); var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX);
if(bulletDestination.classList.contains('cible')){ if(bulletDestination.classList.contains('cible')){
cibleValue -= 1;
bulletDestination.classList.remove('cible'); bulletDestination.classList.remove('cible');
cibleValue = cibleValue - 1;
score = score + 100 ;
console.log(score);
bulletDestination.classList.add('cible-touchee'); bulletDestination.classList.add('cible-touchee');
bulletX = 0; bulletX = 0;
bulletY = 0; bulletY = 0;
@ -175,17 +192,15 @@ setInterval(function(){
grid.style.backgroundPosition = bulletDir; grid.style.backgroundPosition = bulletDir;
}, 32.12); }, 32.12);
setInterval(function(){ var ntm = setInterval(function(){
x2 = Math.floor(Math.random() * 10) + 1; x2 = Math.floor(Math.random() * 11);
if (x2 == x){ if (x2 == x){
x2 = x+1; x2 = x+1;
} }
y2 = Math.floor(Math.random() * 20) + 1; y2 = Math.floor(Math.random() * 21);
if (y2 == y){ if (y2 == y){
y2 = y+1; y2 = y+1;
} }
var ciblex = x2,
cibley = y2
if(ciblex < maxX && cibley < maxY){ if(ciblex < maxX && cibley < maxY){
console.log(ciblex+' pour '+maxX); console.log(ciblex+' pour '+maxX);
@ -193,13 +208,16 @@ setInterval(function(){
emplacement.classList.add('cible'); emplacement.classList.add('cible');
} }
var ciblex = x2,
cibley = y2,
emplacement = document.querySelector(".line-"+ciblex+" .col-"+cibley);
emplacement.classList.add('cible');
cibleValue = cibleValue + 1; cibleValue = cibleValue + 1;
if (cibleValue>=3){ if (cibleValue>=3){
console.log("TAS PERDU"); alert("TAS PERDU");
// TODO clearInterval(ntm);
} }
}, 3000); }, 1000);
document.addEventListener('keydown', move, false); document.addEventListener('keydown', move, false);
setPosition(x, y, direction); setPosition(x, y, direction);