CSIT 441

Maze generator

The method that I used to generate the maze comes from a Java game design book. And this week, I am still working on how to make a random maze. I build a new method generate. I use a Boolean to mark the sell or square and use random generator to generate a direction. Then I will not visit the squares I marked. Then I still use random generator to generate a number which decide the direction. But here are a lot of situations, I already finished the cases when the  square is at top left, top right, bottom left and bottom right, which have only two direction. In addition, here are two other cases. One for the square at the first lines but the corner, which have four situations at four sides. For this case, I need to generator three different directions. And the last case is the square in the middle, which are all the squares except the outermost layer, so I have (height-2)*(width-2) squares. For this case, I have to generate 4 different directions obviously. Actually, what I did is use the position of squares to do the classification and use the random number generator use generator the number accordingly and then use a Boolean method to judge the existence of the wall, then take the walls. Then I made another method called traverse to find the path from origin to termination. I used the valid method to judge if the aim square is valid which means I didn't get out of the area and I didn't go back to the square I've been to.

Comments

Popular posts from this blog

Conclusion

My model

Random Maze Generator