I'm working on an experimental javascript-based game. Player has to travel to exit on a 2-dimensional tiled map.
Feel free to check this fiddle and play
I'm just randomly placing obstacles, but sometimes obstacles block the way between player and exit, and level becomes impossible to beat.
The code below which showing how obstacles being placed in the map is not a part of actual code, I've just simplified and translated this part to English to improve intelligibility:
var arrayCoordinates;
var targetSquare;
var obstacleAmount = 30;
for (var i = 1; i <= obstacleAmount; i++) {
arrayCoordinates= randomCoordinates();
targetSquare = document.getElementById(arrayCoordinates[0] + '-' + arrayCoordinates[1]);
targetSquare.className = 'obstacle';
}
I'm just searching for a path-finding algorithm or an idea for me to write one.