1 / 8

Lab16

Lab16. 程序设计 B 班 2007-12-27. Maze 迷宫问题. 设计一个 applet, 在 8*8 个 cell 的 board 上寻找一条由左上角 (0,0) 到右下角 (7,7) 的 path ( 不要求最短 ). board 上的 cell 可以放置障碍 mark, mark 可以由用户点击鼠标添加或移除. 一条合法的 path 是由一组连续相邻 ( 不包括对角 ) 的 cell 组成的 , 须绕过所有的 mark, 并且要求用序号把 path 经过的 cell 给标出来.

jade-french
Télécharger la présentation

Lab16

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab16 程序设计B班 2007-12-27

  2. Maze 迷宫问题 • 设计一个applet, 在8*8个cell的board上寻找一条由左上角(0,0)到右下角(7,7)的path (不要求最短)

  3. board上的cell可以放置障碍mark, mark可以由用户点击鼠标添加或移除

  4. 一条合法的path是由一组连续相邻(不包括对角)的cell组成的, 须绕过所有的mark, 并且要求用序号把path经过的cell给标出来.

  5. 如果maze无解, 给出” No path exists” 的提示

  6. 点击按钮ClearAll, 可以清楚Path和所有mark • 进阶功能(不要求,有兴趣可以课后做): • 如何使path不包含square形式的cell(不存在4个相邻的cell) • 如何找到Maze中的最短路径 • New Mark随机生成mark(s), mark的数量由board右方的选择按钮指定。如下图

  7. 提示: • 可能用到的类: • Maze • board为8*8的cell对象二维数组 • 寻找path 对访问过的cell设置标记, 可以考虑递归实现 • Cell • 作mark 实现MouseListener; Graphics对象的drawLine方法 • 画path 可以为cell分配一个path中的序列号 • Mark, Path…

  8. 提示: • Cell 可以用面板实现, 使用2个布尔变量和一个路径ID(可选,在Maze中设置亦可): • marked 标志是否被mark • Visited 是否被访问过(寻找path时防止重复) • 画mark 获取cell大小: panel 的getsize().width, getsize().height, 用drawline画2个交叉斜线 • Maze • 递归调用Findpath(row, col) • 设置当前row,col所指cell为访问过 • Findpath(row-1, col) • Findpath(row+1, col) • Findpath(row, col-1) • Findpath(row, col+1)

More Related