




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
[cpp]viewplaincopy#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>//行和列#defineROW10#defineCOL11/*runthisprogramusingtheconsolepauseroraddyourowngetch,system("pause")orinputloop*//*****///地圖charmap[ROW][COL]={”##########",//0”### ##",//1”### ##",//2"##AX###",//3TOC\o"1-5"\h\z”##### ",//4”##### #",//5"## #",//6"# ####",//7"### ",//8”##########"http://9//A:人,X:箱子);//打印地圖VOidshowMap();//接收小人的方向charenterDirection();//小人向上移動的方法voidmoveToUp();//小人向下移動的方法voidmoveToDown();//小人向右移動的方法voidmoveToRight();//小人向左移動的方法voidmoveToLeft();
43.//當前小人的坐標44.intcurrentPersonRow=3;45.intcurrentPersonCol=2;46.//當前箱子的坐標47.intcurrentBoxRow=3;1.intcurrentBoxCol=3;5.86.intmain(intargc,char*argv[]){//system("clear");printf("點擊回車鍵開始游戲A_A\n\n");//1代表運行0停止intflag=1;while(fiag==1){//顯示地圖showMap();//接收小人的方向chardir=enterDirection();switch(dir){//小人向上移動case'w':case'w':moveToUp();break;//小人向下移動case's':case's':moveToDown();break;//小人向右移動case'd':case'd':moveToRight();break;//小人向左移動case'a':case'a':moveToLeft();break;〃停止運行case'q':case'Q':87.printf("你的智商真低!T_T\n");88.flag=0;89.break;90.}91.showMap();92.if(currentBoxRow==8&tBoxCol==9){93.printf你的智商真高94.flag=0;95.})}/*101,方法的實現102.*/103.104.//打印地圖VOidshowMap(){107.inti;108.for(i=0;i<row;i++){109.printf("%s\n",map[i]);110.}111.printf("\n\n\n\n\n");112.printf("W:上,S:下,A:左,D:右。Q:退出");113.printf("\n\n\n\n\n");114.}115.//接收小人的方向116.charenterDirection(){117.//清除SCANF中的緩沖區118.rewind(stdin);119.chardir;120.dir=getch();121.//scanf("%c",&dir);122.returndir;123.}124.//小人向上移動的方法125.voidmoveToUp(){126.//小人的下一個坐標127.intnextPersonCol=currentPersonCol;128.intnextPersonRow=currentPersonRow-1;129.//箱子的下一個坐標130.intnextBoxRow=currentBoxRow-1;
131.intnextBoxCol=currentBoxCol;132.133.//如果小人的下一個坐標是路134.if(map[nextPersonRow][nextPersonCol]==''){135.map[nextPersonRow][nextPersonCol]='A';136.map[currentPersonRow][currentPersonCol]='';137.currentPersonRow=nextPersonRow;138.currentPersonCol=nextPersonCol;139.}140.//如果小人的下一個坐標是墻141.if(map[nextPersonRow][nextPersonCol]=='#'){142.//什么也不做143.}144.//如果小人的下一個坐標是箱子145.if(map[nextPersonRow][nextPersonCol]=='X'){146.if(map[nextBoxRow][nextBoxCol]'){147.148.map[nextPersonRow][nextPersonCol]='A';149.map[currentPersonRow][currentPersonCol]='';150.151.map[nextBoxRow][nextBoxCol]='X';152.map[currentBoxRow][currentBoxCol]='A';153.154.155.currentPersonRow=nextPersonRow;156.currentPersonCol=nextPersonCol;157.currentBoxRow=nextBoxRow;158.currentBoxCol=nextBoxCol;159.}160.}161.}162.//小人向下移動的方法163.voidmoveToDown(){164.//小人的下一個坐標165.intnextPersonCol=currentPersonCol;166.intnextPersonRow=currentPersonRow+1;167.//箱子的下一個坐標168.intnextBoxRow=currentBoxRow+1;169.intnextBoxCol=currentBoxCol;170.171.//如果小人的下一個坐標是路172.if(map[nextPersonRow][nextPersonCol]==''){173.map[nextPersonRow][nextPersonCol]='A';174.map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;currentPersonCol=nextPersonCol;}//如果小人的下一個坐標是墻if(map[nextPersonRow][nextPersonCol]=='#'){〃什么也不做}//如果小人的下一個坐標是箱子if(map[nextPersonRow][nextPersonCol]=='X'){if(map[nextBoxRow][nextBoxCol]'){map[nextPersonRow][nextPersonCol] = 'A';map[currentPersonRow][currentPersonCol]=map[nextBoxRow][nextBoxCol]='X';map[currentBoxRow][currentBoxCol] = 'A';currentPersonRow=nextPersonRow;currentPersonCol=nextPersonCol;currentBoxRow=nextBoxRow;currentBoxCol=nextBoxCol;}}}//小人向右移動的方法VOldmoveToRight(){〃小人的下一個坐標intnextPersonCol=currentPersonCol+1;intnextPersonRow=currentPersonRow;〃箱子的下一個坐標intnextBoxRow=currentBoxRow;intnextBoxCol=currentBoxCol+1;//如果小人的下一個坐標是路if(map[nextPersonRow][nextPersonCol]==' '){map[nextPersonRow][nextPersonCol]='A';map[currentPersonRow][currentPersonCol]=''currentPersonRow=nextPersonRow;currentPersonCol=nextPersonCol;}//如果小人的下一個坐標是墻if(map[nextPersonRow][nextPersonCol]=='#'){//什么也不做}
//如果小人的下一個坐標是箱子if(map[nextPersonRow][nextPersonCol]=='X'){if(map[nextBoxRow][nextBoxCol]==''){map[nextPersonRow][nextPersonCol] = 'A';map[currentPersonRow][currentPersonCol]=map[nextBoxRow][nextBoxCol]='X';map[currentBoxRow][currentBoxCol] = 'A';currentPersonRow=nextPersonRow;currentPersonCol=nextPersonCol;currentBoxRow=nextBoxRow;currentBoxCol=nextBoxCol;}}}//小人向左移動的方法voidmoveToLeft(){//小人的下一個坐標intnextPersonCol=currentPersonCol-1;intnextPersonRow =currentPersonRow;//箱子的下一個坐標intnextBoxRow= currentBoxRow;intnextBoxCol= currentBoxCol- 1;//如果小人的下一個坐標是路if(map[nextPersonRow][nextPersonCol]==' '){map[nextPersonRow][nextPersonCol]='A';map[currentPersonRow][currentPersonCol]=''currentPersonRow=nextPersonRow;currentPersonCol=nextPersonCol;TOC\o"1-5"\h\z}//如果小人的下一個坐標是墻if(map[nextPersonRow][nextPersonCol]=='#'){//什么也不做}//如果小人的下一個坐標是箱子if(map[nextPersonRow][nextPersonCol]=='X'){if(map[nextBoxRow][nextBoxCol]==' '){map[nextPersonRow][nextPersonCol] ='A';map[cur
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025標準專業工程承包合同范本
- 《職場精英職業形象》課件
- 2025品牌加盟合同書
- 2025知識產權合同專利權許可協議格式
- 《探尋海底世界教學》課件
- 《常用教學策略》課件
- 2025年度供貨合同模板
- 《探索品格之美》課件
- 《社區環保教育課件解讀》
- 2025模板工程分包施工合同
- 中職世界歷史試題及答案
- 糖尿病護理查房提出問題
- T-ZMDS 10019-2024 經顱電刺激儀基本技術規范
- 人教版六年級下冊科學全冊教案
- 2024福建中閩能源股份有限公司招聘12人筆試參考題庫附帶答案詳解
- 2025年江西省旅游集團股份有限公司招聘筆試參考題庫含答案解析
- 《外科補液原則》課件
- 《墨家思想》課件
- 浙江省2025年1月首考高考英語試卷試題真題(含答案)
- 川教版(2024)小學信息技術三年級上冊《跨學科主題活動-在線健康小達人》教學實錄
- 機械專業英語
評論
0/150
提交評論