matlab编写的迷宫小游戏.doc

matlab编写的迷宫小游戏.doc

ID:51938758

大小:29.50 KB

页数:5页

时间:2020-03-19

matlab编写的迷宫小游戏.doc_第1页
matlab编写的迷宫小游戏.doc_第2页
matlab编写的迷宫小游戏.doc_第3页
matlab编写的迷宫小游戏.doc_第4页
matlab编写的迷宫小游戏.doc_第5页
资源描述:

《matlab编写的迷宫小游戏.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、functionmazerow=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

2、_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),re

3、shape(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);clearthe_maze;[state,ptr_left,ptr_up,ptr_right,ptr_do

4、wn]=...make_pattern(row,col,rr,cc,state,ptr_left,ptr_up,ptr_right,ptr_down);f=figure('Name','迷宫',...%显示图形窗口的标题'Numbertitle','off',...%标题栏中是否显示’FigureNo.n’,其中n为图形窗口的编号'Menubar','none',...%转换图形窗口菜单条的“关”'Color','white',...'DoubleBuffer','on',...'outerposition',get(0,'ScreenSize'),...'Colormap',[.1.710

5、;.3.4.4;000;110],...'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,c

6、c,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;%按下键盘时触发functionmove_spot(src,evnt)%获取方向建%记录过程key=double(get(gcbf,'Currentcharacter'));if~(ischar(key)

7、

8、i

9、sscalar(key))return;endif~all(cursor_pos==[col,row])key=double(get(gcbf,'Currentcharacter'));switchkeycase28%leftifptr_left(current_id)<0%checkforlegalmovecurrent_id=-ptr_left(current_id);text(cursor_pos(1)

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。