Skip to content

Instantly share code, notes, and snippets.

@maximeshr
Created December 4, 2017 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximeshr/fbf365d22978ea51e4d525fd0a26a818 to your computer and use it in GitHub Desktop.
Save maximeshr/fbf365d22978ea51e4d525fd0a26a818 to your computer and use it in GitHub Desktop.
function isWallNotOnPath(
activePlayer,
destinationLine,
destinationColumn,
walls
) {
// je vérifie que mon déplacement ne tombe pas sur un mur
const isOnAWall = walls.find(function(wall) {
if (wall.l === destinationLine && wall.c === destinationColumn) {
return true;
}
return false;
});
if (isOnAWall) {
return false;
}
const deltaL = Math.abs(activePlayer.line - destinationLine);
const deltaC = Math.abs(activePlayer.column - destinationColumn);
const L = -(activePlayer.line - destinationLine);
const C = -(activePlayer.column - destinationColumn);
const targetPositions = [];
console.log({
deltaL: deltaL,
deltaC: deltaC,
L: L,
C: C
});
if (L > 0) {
console.log("j'effectue un mouvement vers le bas");
for (let l = 0; l <= L; l++) {
targetPositions.push({
l: activePlayer.line + l,
c: activePlayer.column
});
}
}
if (L < 0) {
console.log("j'effectue un mouvement vers le haut");
for (let l = 0; l >= L; l--) {
targetPositions.push({
l: activePlayer.line + l,
c: activePlayer.column
});
}
}
if (C > 0) {
console.log("j'effectue un mouvement vers la droite");
for (let c = 0; c <= C; c++) {
targetPositions.push({
l: activePlayer.line,
c: activePlayer.column + c
});
}
}
if (C < 0) {
console.log("j'effectue un mouvement vers la gauche");
for (let c = 0; c >= C; c--) {
targetPositions.push({
l: activePlayer.line,
c: activePlayer.column + c
});
}
}
console.log(targetPositions);
const wallOnTarget = function(walls) {
let finded = false;
walls.find(function(wall) {
targetPositions.find(function(position) {
if (position.l == wall.l && position.c == wall.c) {
finded = true;
return true;
}
return false;
});
});
return finded;
};
if (wallOnTarget(walls)) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment