在Eclipse平台上,选择Java语言完成迷宫游戏的设计与开发。采用随机布点算法生成不规则迷宫地图,采用图的深度优先遍历算法随机生成规则地图。在相同的窗口,运用地图格的大小不同来生成较低、中等、较高三种不同难度的规则或不规则地图。把走迷宫的对象设置成角色方块,使用键盘的方向键控制当前移动点进行游戏。按照遍历规则地图的起点不同,把游戏分简单,中等,高难三种难易程度。运用回溯法从入口一步步进行探索,最后找到迷宫出口,并在界面上显示出该路径。编写画布类函数Canvas()实现游戏设置。游戏的成功开发表明,算法研究至关重要,应用这些算法开发游戏是有效的。
The paper designed and developed a Maze game under the Eclipse platform by using Java development tool. The random distributed point algorithm is used to generate an irregular map, and the algorithm of depth-first traveling is used to generate a regular map. Setting different size of the map’s grid in the map on the same game window forms three kinds of degree of difficulty which are low, medium, and high. Set the game walker as a role object, use the keyboard’s arrow keys to control the current point move, and we can play the game. From different point to travel form three level games on regular map which are simple, medium, and difficulty. Take backtracking method to search the path from entrance to the exit step by step, find it at last, and show the path on the interface. Program the function Canvas() to set the game configurations. The result of successful development of the Maze game shows that algorithms are important and using them to develop the game is effective.