Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.