免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
function mazerow = 20;col = 39;rand(state,sum(100*clock)cc,rr = meshgrid(1:col,1:row);state = reshape(1:row*col,row,col);id = reshape(1:row*col,row,col);ptr_left = zeros(size(id);ptr_up = zeros(size(id);ptr_right = zeros(size(id);ptr_down = zeros(size(id);ptr_left(:,2:size(id,2) = id(:,1:size(id,2)-1);ptr_up(2:size(id,1),:) = id(1:size(id,1)-1,:);ptr_right(:,1:size(id,2)-1) = id(:,2:size(id,2);ptr_down(1:size(id,1)-1,:) = id(2:size(id,1),:);the_maze = cat(2,reshape(id,row*col,1),reshape(rr,row*col,1),reshape(cc,row*col,1),reshape(state,row*col,1),. reshape(ptr_left,row*col,1),reshape(ptr_up,row*col,1),reshape(ptr_right,row*col,1),reshape(ptr_down,row*col,1) );the_maze = sortrows(the_maze);id = the_maze(:,1);rr = the_maze(:,2);cc = the_maze(:,3);state = the_maze(:,4);ptr_left = the_maze(:,5);ptr_up = the_maze(:,6);ptr_right = the_maze(:,7);ptr_down = the_maze(:,8);clear the_maze;state, ptr_left, ptr_up, ptr_right, ptr_down=. make_pattern(row,col,rr, cc, state, ptr_left, ptr_up, ptr_right, ptr_down);f = figure(Name,迷宫,. %显示图形窗口的标题 Numbertitle,off,. %标题栏中是否显示Figure No. n,其中n为图形窗口的编号 Menubar,none,. %转换图形窗口菜单条的“关” Color,white,. DoubleBuffer,on,. outerposition,get(0,ScreenSize),. Colormap,.1 .71 0;.3 .4 .4;0 0 0;1 1 0,. CloseRequestFcn,close_window,. KeyPressFcn,move_spot);%建菜单gameMenu = uimenu(f,Label,游戏);uimenu(gameMenu,Label,新游戏,Accelerator,N,Callback,new_game);uimenu(gameMenu,Label,退出,Accelerator,Q,Separator,on,Callback,close_window);show_maze(row, col, rr, cc, ptr_left, ptr_up, ptr_right, ptr_down,f);% 开始cursor_pos = 1,1;current_id = 1;text(cursor_pos(1),cursor_pos(2),diamondsuit,HorizontalAlignment,Center,color,r);%计时timing = 1;start_time = clock; %按下键盘时触发 function move_spot(src,evnt)%获取方向建 % 记录过程 key = double(get(gcbf,Currentcharacter); if (ischar(key)|isscalar(key) return; end if all(cursor_pos = col,row) key = double(get(gcbf,Currentcharacter); switch key case 28 % left if ptr_left(current_id) 0 % check for legal move current_id =- ptr_left(current_id); text(cursor_pos(1),cursor_pos(2),diamondsuit,HorizontalAlignment,Center,color,.8,.8,.8); cursor_pos(1) = cursor_pos(1) - 1; text(cursor_pos(1),cursor_pos(2),diamondsuit,HorizontalAlignment,Center,color,r); end case 29 % right if ptr_right(current_id) 0 % check for legal move current_id =- ptr_right(current_id); text(cursor_pos(1),cursor_pos(2),diamondsuit,HorizontalAlignment,Center,color,.8,.8,.8); cursor_pos(1) = cursor_pos(1) + 1; text(cursor_pos(1),cursor_pos(2),diamondsuit,HorizontalAlignment,Center,color,r); end case 30 % up if ptr_up(current_id) 0 % check for legal move current_id =- ptr_up(current_id); text(cursor_pos(1),cursor_pos(2),diamondsuit,HorizontalAlignment,Center,color,.8,.8,.8); cursor_pos(2) = cursor_pos(2) - 1; text(cursor_pos(1),cursor_pos(2),diamondsuit,HorizontalAlignment,Center,color,r); end case 31 % down if ptr_down(current_id) 0 % right passage blocked line(cc(ii)+.5,cc(ii)+.5,rr(ii)-.5,rr(ii)+.5); hold on end if ptr_down(ii)0 % down passage blocked line(cc(ii)-.5,cc(ii)+.5,rr(ii)+.5,rr(ii)+.5); hold on end endaxis equalaxis(.5,col+.5,.5,row+.5)axis offset(gca,YDir,reverse)end%产生边界道路信息function state, ptr_left, ptr_up, ptr_right, ptr_down=make_pattern(row,col, rr, cc, state, ptr_left, ptr_up, ptr_right, ptr_down)while max(state) 1 tid = ceil(col*row*rand(15,1); cityblock = cc(tid) + rr(tid); is_linked = (state(tid) = 1); temp = sortrows(cat(2,tid,cityblock,is_linked),3,2); tid = temp(1,1); dir = ceil(4*rand); switch dir case 1 if ptr_left(tid) 0 & state(tid) = state(ptr_left(tid) state( state = state(tid) | state = state(ptr_left(tid) ) = min(state(tid),state(ptr_left(tid); ptr_right(ptr_left(tid) =- ptr_right(ptr_left(tid); ptr_left(tid) =- ptr_left(tid); end case 2 if ptr_right(tid) 0 & state(tid) = state(ptr_right(tid) state( state = state(tid) | state = state(ptr_right(tid) ) = min(state(tid),state(ptr_right(tid); ptr_left(ptr_right(tid) =- ptr_left(ptr_right(tid); ptr_right(tid) =- ptr_right(tid); end case 3 if ptr_up(tid) 0 & state(tid) = state(ptr_up(tid) state( state = state(tid) | state = state(ptr_up(tid) ) = min(state(tid),state(ptr_up(tid); ptr_down(ptr_up(tid) =- ptr_down(ptr_up(tid); ptr_up(tid) =- ptr_up(tid); end case 4 if ptr_down(tid) 0 & state(tid) = state(pt
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 太阳对地球的影响 课件-2026-2027学年高一上学期地理新授课教学
- creo机械课程设计资源网站
- 老人70岁换新本驾照三力测试题库
- 2026年健康管理师理论试题与答案
- 2026年乡村医生考试题库及答案(常见疾病诊疗)
- 2026年海南省国家公务员申论考试真题及答案
- 2026年监理工程师《建设工程合同管理》真题练习卷
- 2026年工业碳中和合作协议范本
- 护理核心制度与患者权利
- 2025年滁州市全椒消防救援大队招聘笔试真题
- 2025年江苏泰兴市新源农产品加工投资发展有限公司招聘8人笔试历年备考题库附带答案详解
- 2025年夏季黑龙江省新产业投资集团有限公司财务共享中心公开招聘7人笔试参考题库附带答案详解
- 2025年“中华经典诵读”知识竞答备赛试题库150题(含各题型)
- SEMI F101-1105气体分配系统中压力调节器性能测定的试验方法中文版
- 2025年江苏辅警招聘考试真题含答案详解(基础题)
- DB34T-地质公园建设项目地质遗迹及生态影响评估技术规范
- 家政服务员理论考试题及答案(初级)
- 钢筋加工设备安全操作培训资料
- 人教部编版四年级下册语文《必背课文、古诗、日积月累》默写填空
- 学校食堂食材配送应急响应措施及事故应急预案
- 退役军人法治培训课件
评论
0/150
提交评论