GRID Game Example
let maze = "#.#.#.#.#P.#.#.#.#.#";let currentPosition = maze.indexOf("P");
let leftPosition = currentPosition - 1;
let rightPosition = currentPosition + 1;
let leftTile = maze.charAt(leftPosition);
let rightTile = maze.charAt(rightPosition);
if (leftTile === "#") {
console.log("Can't move left, there's a wall!");
} else {
console.log("Player can move left");
}
if (rightTile === "#") {
console.log("Can't move right, there's a wall!");
} else {
console.log("Player can move right");
}Last updated