免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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,迷宮,. %顯示圖形窗口的標(biāo)題 Numbertitle,off,. %標(biāo)題欄中是否顯示Figure No. n,其中n為圖形窗口的編號(hào) Menubar,none,. %轉(zhuǎn)換圖形窗口菜單條的“關(guān)” 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);%計(jì)時(shí)timing = 1;start_time = clock; %按下鍵盤時(shí)觸發(fā) 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%產(chǎn)生邊界道路信息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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 廚房衛(wèi)生工具管理規(guī)定(3篇)
- 《工程合同管理》課程教學(xué)大綱
- 船舶側(cè)向推進(jìn)器課程設(shè)計(jì)
- 物聯(lián)網(wǎng)煙霧報(bào)警課程設(shè)計(jì)
- 生物數(shù)學(xué)的基礎(chǔ)課程設(shè)計(jì)
- 自動(dòng)服務(wù)課程設(shè)計(jì)
- 2024幼兒園安全生產(chǎn)月活動(dòng)工作總結(jié)范文(31篇)
- 藝術(shù)家作品課程設(shè)計(jì)
- 航空公司服務(wù)員工作總結(jié)
- 教育行業(yè)營(yíng)銷策略分享
- 污水處理廠有毒有害氣體檢測(cè)記錄表
- 馬克思主義與社會(huì)科學(xué)方法論課后思考題答案全
- 針灸推拿習(xí)題庫(kù)+參考答案
- 手術(shù)區(qū)皮膚消毒及鋪單法課件
- 血液科侵襲性真菌的治療
- 淺析巖溶地區(qū)工程地質(zhì)勘察手段及應(yīng)用
- 2023-2024學(xué)年六年級(jí)上期末數(shù)學(xué)考試試卷附答案解析
- 羅伊模式個(gè)案護(hù)理
- 公益性崗位開發(fā)申請(qǐng)審批表
- 中國(guó)馬克思主義與當(dāng)代知到章節(jié)答案智慧樹2023年西安交通大學(xué)
- 組織協(xié)同運(yùn)用平衡計(jì)分卡創(chuàng)造企業(yè)合力
評(píng)論
0/150
提交評(píng)論