版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、/* A simple game*/*CopyRight: Guanlin*/ #include #include #include #include #include #include struct object_fixchar name20;char id5;char desc500;char action30;char im5;struct object_movechar name20;char id5;char desc500;int loc;int pwr;int strg;char im5;struct roverchar name20;char id5;char desc500;
2、int pwr;int strg;int location2;char im5;struct map /* this is the map structure*/char data20;char add_data20;int amount;int x; /* this were the successor keeps its x & y values*/ int y;struct location /*this structure is for the successor lister*/ float height;char obj;void stats_update( int selecte
3、d, struct rover *p_rover)switch (selected)case 1:if (p_rover-pwr pwr) -= 7;printf( You have destroyed the object!nn );break ;case 2:if (p_rover-pwr strg 90)printf( nnYou do not have enough storage space for this object!nn);else(p_rover-pwr) -= 3;(p_rover-strg) += 10;printf( You have collected a samp
4、le of the object!nn );break ;case 3:p_rover-pwr -= 10;/*Distance around object- value gained from mapper module. 1square = -1 power*/printf( You have avoided the object!nn );break ;case 4:p_rover-pwr -= 2;printf( You have driven through the obstacle!nn);break ;case 5:if (p_rover-pwr = 100)printf( nn
5、You do not need to charge up!nn);elsep_rover-pwr = 100;printf( You have charged up your rover!nn );break ;default :printf( nn*ERROR*nInvalid Selectionnn );break ;void action( char object, struct rover *p_rover)int selection;switch (object)case 1:printf( nYou have encountered: A Sandy Rocknn);printf(
6、 This object can be:n1.tDestroyedn2.tCollectednPlease choose action 1 or 2:t );scanf( %d , &selection); stats_update(selection, p_rover);break ;case 2:printf( nYou have encountered: A Solid Rocknn );printf( This object can be:n1.tAvoidedn2.tCollectednPlease choose action 1 or 2:t);scanf( %d , &selec
7、tion);if (selection = 1) selection = 3; stats_update(selection, p_rover);break ;case 3:printf( nYou have encountered: A Mountainnn );printf( This object can be:n1.tAvoidednPlease enter 1:t );scanf( %d , &selection); selection = 3;stats_update(selection, p_rover);break ;case 4:printf( nYou have encou
8、ntered: Dustnn );printf( This object can be:n1.tDriven throughn2.tCollectednPlease choose action 1 or 2:t );scanf( %d , &selection);if (selection = 1) selection = 4;stats_update(selection, p_rover);break ;case 5:printf( nYou have encountered: A Sheer Valleynn );printf( This object can be:n1.tAvoided
9、nPlease enter 1:t );scanf( %d , &selection); selection = 3;stats_update(selection, p_rover);break ;case 6:printf( nYou have encountered: A Gentle Valleynn );printf( This object can be:n1.tDriven throughn2.tAvoidednPlease choose action 1 or 2:t );scanf( %d , &selection);if (selection = 1) selection =
10、 4;if (selection = 2)selection = 3;stats_update(selection, p_rover);break ;case 7:printf( nYou have encountered: A Martian Treenn );printf( This object can be:n1.tDestroyedn2.tCollectedn3.tAvoidednPlease choose action 1, 2 or 3:t);scanf( %d , &selection); stats_update(selection, p_rover);break ;case
11、 8:printf( nYou have encountered: Shallow Waternn );printf( This object can be:n1.tDriven throughn2.tCollectedn3.tAvoidednPlease choose action 1, 2 or 3:t );scanf( %d , &selection);if (selection = 1)selection = 4;stats_update(selection, p_rover);break ;case 9:printf( nYou have encountered: Deep Wate
12、rnn );printf( This object can be:n1.tAvoidedn2.tCollectednPlease choose action 1 or 2:t);scanf( %d , &selection);if (selection = 1)selection = 3;stats_update(selection, p_rover);break ;case 10:printf( nYou have encountered: An Aggressive Aliennn);printf( This object can be:n1.tDestroyednPlease enter
13、 1:t ); scanf( %d , &selection);selection = 1;stats_update(selection, p_rover);break ;case 11:printf( nYou have encountered: A Non-Aggressive Aliennn );printf( This object can be:n1.tAvoidednPlease enter 1:t ); scanf( %d , &selection);selection = 3;stats_update(selection, p_rover);break ;case 12:pri
14、ntf( nYou have encountered: Another Rovernn );printf( This object can be:n1.tAvoidednPlease enter 1:t ); scanf( %d , &selection);selection = 3;stats_update(selection, p_rover);break ;case 13:printf( nYou have encountered: A Power Stationnn);printf( You can:n1.tCharge upn2.tAvoidnPlease choose action
15、 1 or 2:t);scanf( %d , &selection);if (selection = 1) selection = 5;if (selection = 2) selection = 3;stats_update(selection, p_rover);break ; default : structure to see if moveable objects are needed*/ voidshow_map( structmap *number, structstructobject_fix *rsld,structobject_fix *mnt,structobject_f
16、ix *vshr,structobject_fix *vgnt,structobject_fix *wshl,structobject_fix *wdp,printf( nn*ERROR*nn ); break ;map *number_2,struct object_fix *rsny,struct object_fix *dst,struct object_fix *mtre,struct object_move *aagr,*pstn, structstruct object_move *anon, struct object_move *rvr, struct object_move
17、rover *p_rover) /*the show map function calling number and number_2 from the mapstruct map f_map88;/*8 by 8 map*/ int i,j, rx, ry, object; /*this is your x and y value in your map (f_map)*/ system( cls ); /* this is your x and y value in your map (f_map)*/ /srand(time(NULL); /*calling the time from
18、include to gather random variables*/for (i=0;i8;i+)/*for loop to copy all your fixed object lists into f_map so they can bedisplayed*/for (j=0;jamount0)/*this is looking at the add function to see weather or not thereare aliens in f_map*/for (i=0;iamount;i+)/*allocating the number of aliens in f_map
19、*/strcpy(f_maprand()%8rand()%8.data, anon-im); /*randomizing their position*/ if (number_2-amount0)/*repeat of above just for rovers instead*/for (i=0;iamount;i+) strcpy(f_maprand()%8rand()%8.data, rvr-im);rx= p_rover-location0;ry= p_rover-location1;strcpy(f_map10.data, wdp-im); strcpy(f_map40.data,
20、 mnt-im); strcpy(f_map50.data, mnt-im); strcpy(f_map31.data, dst-im); strcpy(f_map41.data, dst-im); strcpy(f_map32.data, dst-im); strcpy(f_map42.data, dst-im);strcpy(f_map03.data, mnt-im); strcpy(f_map13.data, mnt-im);strcpy(f_map33.data, vshr-im); strcpy(f_map43.data, dst-im);strcpy(f_map53.data, v
21、gnt-im); strcpy(f_map34.data, vshr-im);strcpy(f_map44.data, dst-im); strcpy(f_map54.data, vgnt-im);strcpy(f_map25.data, wshl-im); strcpy(f_map35.data, wshl-im);strcpy(f_map45.data, wshl-im); strcpy(f_map16.data, pstn-im);strcpy(f_map26.data, wdp-im); strcpy(f_map36.data, wdp-im);strcpy(f_map46.data,
22、 wshl-im); strcpy(f_map76.data, mnt-im);strcpy(f_map07.data, mnt-im); strcpy(f_map17.data, wdp-im);strcpy(f_map27.data, wshl-im); strcpy(f_map37.data, wshl-im);strcpy(f_map67.data, mnt-im); strcpy(f_maprxry.data, p_rover-im);if (rx = 1 & ry = 0) | (rx = 2 & ry = 6) |(rx = 3 & ry = 6) |(rx = 1 & ry =
23、 7)object = 9;action(object, p_rover);else if (rx = 4 & ry = 0) | (rx = 5 & ry = 0) | (rx = 0 & ry = 3) | (rx = 1 & ry = 3) | (rx = 7 & ry = 6) | (rx = 0 & ry = 7) | (rx = 6 & ry = 7)object = 3;action(object, p_rover);else if (rx = 3 & ry= 1) | (rx = 4 & ry = 1) | (rx = 3 & ry= 2) | (rx = 4 & ry = 2
24、) | (rx = 4 & ry = 3) | (rx = 4 & ry = 4)object = 4;action(object, p_rover);else if (rx = 3 & ry = 3) | (rx = 3 & ry = 4)object = 5;action(object, p_rover);else if (rx = 5 & ry = 3) | (rx = 5 & ry = 4)object = 6;action(object, p_rover);else if (rx = 2 & ry = 5) | (rx = 3 & ry = 5 ) | (rx = 4 & ry =
25、5) | (rx= 4 & ry = 6) |(rx = 2 & ry = 7) | (rx = 3 & ry = 7)object = 8;action(object, p_rover);else if (rx = 1 & ry = 6)object = 13;action(object, p_rover);i=0; /*re-allocate i to 0 so map is printed from start*/for (i=0;i8;i+) /*8 by 8 map*/ printf( +n );for (j=0;jamount=t;/*saving the number in st
26、ructure map-amount*/printf( how many rovers would you like?n );scanf( %d ,&f); /*user input of amount of rovers*/ number_2-amount=f;/*saving the number in structure map-amount*/show_map(number, number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl,wdp, aagr, anon, rvr, pstn, p_rover); aliens and nu
27、mber of rovers*/ void successor()/*go to show map function with the number of/*this functions askes the user for the location and then were they wantto go from there, printing out that location*/ struct map location;int menu; int ncol,nrow; ncol=8; nrow=8; printf( This is the successor functionn pri
28、ntf( Enter the nx=ty=n ); scanf( %d%d ,&location.x,&location.y); printf( Enter operator choicen ); printf( 1=leftn );printf( 2=rightn ); printf( 3=upwardsn );printf( 4=downn ); printf( 5=quitn ); scanf( %d ,&menu);switch rover*/ case 1:location.x=location.x-1;printf( The position is %d,%dn break ;ca
29、se 2:location.x=location.x+1; printf( The position is %d,%dn break ;case 3:location.y=location.y-1; printf( The position is %d,%dn break ;case 4:location.y=location.y+1; printf( The position is %d,%dn break ;/*we can change the n value depends how large the map you need.*/);/*saving location in map
30、location x and y*/(menu) /*menu switch to show the position above, underneith, and next to the,location.x,location.y);,location.x,location.y);,location.x,location.y);,location.x,location.y);case 5:); /* Quits the program and prints out theprintf( *back to program*n message */break ;default :); /* A
31、default option if the userprintf( *Please enter an integer from 1-5*n enters an incorrect value */break ;printf( n );void help( struct map *number,struct map *number_2,struct object_fix *rsny,struct object_fix *rsld, struct object_fix *vshr, struct object_fix *wshl,struct object_fix *mnt, struct obj
32、ect_fix *vgnt, struct object_fix *wdp, struct object_fix *dst, struct object_fix *mtre, struct object_move *aagr,struct object_move *anon,struct object_move *rvr,struct object_move *pstn, structrover *p_rover)/*help function*/int i;char mov_obj;printf( +This is the help function+n);printf( | 1-succe
33、ssor |n);printf( | 2-add movable obj |n);printf( | 3-remove moveabla obj |nn);printf( t* * *n);printf( t Index: nn);printf( t Sandy Rock: *n);printf( t Solid Rock: on);printf( t Water:262262262262 n);printf( t Shallow water: 260260260260n);printf( t Mountain: n);printf( t Dust: n );printf( t* sher v
34、alley: VVVV *n);printf( t shallow valey: vvvvn);printf( t power station: 025n);printf( t alien: *_*n);printf( t other rovers: #n);printf( t* * *n ); scanf( %d ,&i);switch (i) /*switch menu to go to the successor function, or the add/remove function*/ case 1: successor();break ;case 2:add_obj(number,
35、 number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover);break ; case 3: add_obj(number, number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover); break ;);default :voiddirection( int input,structmap *number,structmap *number_2
36、,structobject_fix*rsny,structobject_fix *rsld,structobject_fix *mnt,structobject_fix *dst,structobject_fix *vshr,structobject_fix *vgnt,structobject_fix *mtre,structobject_fix *wshl,structobject_fix *wdp,structobject_move *aagr,structobject_move *anon,struct object_move*rvr,struct object_move*pstn,s
37、tructprintf( choose a number from the listn rover *p_rover)switch (input)case 119: /*w = up*/ if (p_rover-location0 0) p_rover-location0-;p_rover-pwr-; else p_rover-location0=7; break ;case 115: /*s = down*/ if (p_rover-location0 location0+; p_rover-pwr-; else p_rover-location0=0; break ;case 97: /*
38、a = left*/ if (p_rover-location1 0)p_rover-location1-; p_rover-pwr-; else p_rover-location1=7; break ;case 100: /*d = right*/if (p_rover-location1 location1+; p_rover-pwr-; else p_rover-location1=0; break ;default :);printf( Invalid operator!nnbreakint control( int input)input = _getch(); return inp
39、ut;void main( void )int menu;int quit = 0;int input = 0;struct object_fix rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp;struct object_move aagr, anon, rvr, pstn;struct rover p_rover;number.amount = 0; number_2.amount = 0;struct map number, number_2;/* setting the initial amount of aliens as 0*/s
40、trcpy(, strcpy(rsny.id, strcpy(rsny.desc, strcpy(rsny.im, strcpy(, strcpy(rsld.id, strcpy(rsld.desc,Sandy Rock );RSNY );A rock made of softer material that can be destroyed or collected * );Solid Rock ); RSLD );A rock made of hard material that cannot be destroyed, but can be ););c
41、ollected or avoided strcpy(rsld.im, strcpy(, strcpy(mnt.id, strcpy(mnt.desc, strcpy(mnt.im, strcpy(, strcpy(dst.id, strcpy(dst.desc, down the vehicle, can be driven through but has extra power consumptionO );Mountain ); MNT );A large obstacle made of different materials that can only
42、 be avoided );Dust ); DST );Small particles of sand, rock, etc. that may reduce visibility or slow););strcpy(dst.im, );strcpy(, Sheer Valley ); strcpy(vshr.id, VSHR );strcpy(vshr.desc,A depression in the land with sheer sides, it cannot be driven throughand must be avoided );strcpy(vshr.im,
43、 strcpy(, strcpy(vgnt.id, strcpy(vgnt.desc,VVVV );Gentle Valley );VGNT );A depression in the land with gentle sides, it can be driven throughwith extra power consumption or can be avoided);strcpy(vgnt.im, vvvv );strcpy(,Martian Tree);strcpy(mtre.id, MTRE );strcpy(mtre.desc,A woody
44、plant native to Mars, it may have the same characteristics asan Earth tree );strcpy(mtre.im, 330 ); strcpy(, Shallow Water );strcpy(wshl.id, WSHL );strcpy(wshl.desc,A shallow body of water that can be driven through, can be in the formof a small puddle or a large lake);strcpy(wshl.im, 26026
45、0260260 );strcpy(, Deeper Water ); strcpy(wdp.id, WDP );strcpy(wdp.desc,A deeper body of water that cannot be driven through, commonly inthe form of a large lake or river);strcpy(wdp.im, 262262262262 );strcpy(, Aggressive Alien );strcpy(aagr.id, AAGR );strcpy(aagr.desc,An alien crea
46、ture that will move upon its own accord, may become aggressive on contact );strcpy(aagr.im, *_* );strcpy(, Non-Aggressive Alien ); strcpy(anon.id, ANON );strcpy(anon.desc,An alien creature that will move upon its own accord, will not become aggressive on contact );strcpy(anon.im, *_* );strc
47、py(, Rover ); strcpy(rvr.id, RVR );strcpy(rvr.desc,A Mars Rover vehicle to transport around the map, it can destroy,);collect or avoid objects. It has a power and object storagestrcpy(rvr.im, strcpy(, strcpy(pstn.id, strcpy(pstn.desc, strcpy(pstn.im,# );Power Station ); PSTN ););A movable power station that will restore power to the Mars Rovers 025 );strcpy(p_, User Mars Rover ); strcpy(p_rover.id, URVR );strcpy(p_rover.desc,A Mars vehicle that is controlled by the user. Explores the map collecting, destroying and avoiding objects ); strcpy(p_rover.im,
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 狼獲獎(jiǎng)?wù)n件教學(xué)課件
- 統(tǒng)計(jì)分析軟件模擬試題三及答案
- 飛向太空的航程說(shuō)課稿
- 隊(duì)列口令說(shuō)課稿
- 適合小班課件教學(xué)課件
- 怎樣評(píng)價(jià)課件教學(xué)課件
- 南京工業(yè)大學(xué)浦江學(xué)院《公益營(yíng)銷(xiāo)》2021-2022學(xué)年第一學(xué)期期末試卷
- 南京工業(yè)大學(xué)浦江學(xué)院《籌資原理和技巧》2022-2023學(xué)年第一學(xué)期期末試卷
- 秸稈打捆協(xié)議書(shū)(2篇)
- 南京工業(yè)大學(xué)《應(yīng)用統(tǒng)計(jì)學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 豎井井架安裝安全技術(shù)措施
- 無(wú)縫線路鋪設(shè)與養(yǎng)護(hù)維修方法
- 高分子物理教案(Word)
- 豆綠色時(shí)尚風(fēng)送貨單excel模板
- 新蘇教版五年級(jí)上冊(cè)科學(xué)全冊(cè)教學(xué)課件(2022年春整理)
- 小學(xué)體育水平一《走與游戲》教學(xué)設(shè)計(jì)
- 秋日私語(yǔ)(完整精確版)克萊德曼(原版)鋼琴雙手簡(jiǎn)譜 鋼琴譜
- 鹽酸安全知識(shí)培訓(xùn)
- 萬(wàn)盛關(guān)于成立醫(yī)療設(shè)備公司組建方案(參考模板)
- 科技特派員工作調(diào)研報(bào)告
- 中波廣播發(fā)送系統(tǒng)概述
評(píng)論
0/150
提交評(píng)論