[button url=”http://www.gamelogic.co.za/examples/30-games-in-30-days/game02/index.html” size=”large”]CLICK HERE TO PLAY GAME 2[/button]
[divider]
[slogan]This is what Grids did for us today. What can Grids do for you?[/slogan]
Game 2 is a maze traversal puzzle game; as in all maze games, you have to find your way to the goal. There are cells where you can decide which direction to take, but most cells take you in a pre-chosen direction when you land on them. (There is one glitch with the game: occasionally you get trapped in a section of the maze with no escape. This is fairly rare though).
This game uses several algorithms.
First, we generate a maze on the hex grid using Prim’s algorithm, similar to the maze generated with this example. From the maze, we select a start and goal nodes. Then, we use A* Star to find the path between the goal and start node. (We would normally not be interested in the shortest path, but there is only one path, so any path will do.) Now we assign directions to all nodes on the path to ensure the player can reach the goal node.
Next, we select random directions for all cells, except cells that are blue in the coloring below. The blue cells are made into decision nodes. We turn all decision nodes around the goal node into direction nodes pointing towards the goal.
Finally, we do a pass on the grid to ensure there are no loops that can trap the player. For each node, we simply follow the arrows until we reach either a point outside the grid, a decision node, or a node already visited during this path-following iteration. In the latter case, we have a loop; we eliminate it by making the last node a decision node.
[divider]
Click here to check out all 30 games
[divider]