版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、/* A simple game*/*CopyRight: Guanlin*/#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>#include<conio.h>#include<process.h> struct object_fixchar name20;char id5;char desc500;char action30;char im5;struct object_movechar name20;char id5;c
2、har desc500;int loc;int pwr;int strg;char im5;struct roverchar name20;char id5;char desc500; 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 it's x & y values*/int y;struct locatio
3、n /*this structure is for the successor lister*/float height;char obj;void stats_update(int selected, struct rover *p_rover)switch (selected)case 1:if(p_rover->pwr < 7)printf("nnYou do not have enough power to perform this action!nn");else(p_rover->pwr) -= 7;printf("You have
4、destroyed the object!nn");break;case 2:if(p_rover->pwr < 3)printf("nnYou do not have enough power to perform this action!nn");else if(p_rover->strg > 90)printf("nnYou do not have enough storage space for this object!nn");else(p_rover->pwr) -= 3;(p_rover->st
5、rg) += 10;printf("You have collected a sample of the object!nn");break;case 3:p_rover->pwr -= 10; /*Distance around object- value gained from mapper module. 1 square = -1 power*/printf("You have avoided the object!nn");break;case 4:p_rover->pwr -= 2; printf("You have d
6、riven through the obstacle!nn");break;case 5:if(p_rover->pwr = 100)printf("nnYou 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 obje
7、ct, struct rover *p_rover)int selection;switch(object)case 1:printf("nYou have encountered: A Sandy Rocknn");printf("This object can be:n1.tDestroyedn2.tCollectednPlease choose action 1 or 2:t");scanf("%d", &selection);stats_update(selection, p_rover);break;case 2:p
8、rintf("nYou have encountered: A Solid Rocknn");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 3:printf("nYou have encountere
9、d: 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 encountered: Dustnn");printf("This object can be:n1.tDriven throughn2.tCollect
10、ednPlease 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.tAvoidednPlease enter 1:t");scanf("%d&q
11、uot;, &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)se
12、lection = 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", &sel
13、ection);stats_update(selection, p_rover);break;case 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;st
14、ats_update(selection, p_rover);break;case 9:printf("nYou have encountered: Deep Waternn");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);bre
15、ak;case 10:printf("nYou have encountered: An Aggressive Aliennn");printf("This object can be:n1.tDestroyednPlease enter 1:t");scanf("%d", &selection);selection = 1;stats_update(selection, p_rover);break;case 11:printf("nYou have encountered: A Non-Aggressive Al
16、iennn");printf("This object can be:n1.tAvoidednPlease enter 1:t");scanf("%d", &selection);selection = 3;stats_update(selection, p_rover);break;case 12:printf("nYou have encountered: Another Rovernn");printf("This object can be:n1.tAvoidednPlease enter 1:t&
17、quot;);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 1 or 2:t");scanf("%d", &selection);if (selection
18、= 1)selection = 5;if (selection = 2)selection = 3;stats_update(selection, p_rover);break;default:printf("nn*ERROR*nn");break;void show_map(struct map *number, struct map *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst, struct obje
19、ct_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre, struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr, struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /*the show map function calling number and number_2 from the
20、map structure to see if moveable objects are needed*/struct 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 include to gather ra
21、ndom variables*/for(i=0;i<8;i+) /*for loop to copy all your fixed object lists into f_map so they can be displayed*/for(j=0;j<8;j+)strcpy(f_mapij.data,"");if (number->amount>0) /*this is looking at the add function to see weather or not there are aliens in f_map*/for(i=0;i<n
22、umber->amount;i+) /*allocating the number of aliens in f_map*/strcpy(f_maprand()%8rand()%8.data, anon->im); /*randomizing their position*/if(number_2->amount>0) /*repeat of above just for rovers instead*/for(i=0;i<number_2->amount;i+)strcpy(f_maprand()%8rand()%8.data, rvr->im);r
23、x= p_rover->location0;ry= p_rover->location1;strcpy(f_map10.data, wdp->im);strcpy(f_map40.data, 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.dat
24、a, mnt->im);strcpy(f_map13.data, mnt->im);strcpy(f_map33.data, vshr->im);strcpy(f_map43.data, dst->im);strcpy(f_map53.data, vgnt->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.d
25、ata, 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, wshl->im);strcpy(f_map76.data, mnt->im);strcpy(f_map07.data, mnt->im);strcpy(f_map17.data, wdp->im);strcpy(f_map27.
26、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 = 7)object = 9;action(object, p_rover);else if(rx = 4 && r
27、y = 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
28、= 2) | (rx = 4 && ry = 2) | (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;acti
29、on(object, p_rover);else if(rx = 2 && ry = 5) | (rx = 3 && ry = 5 ) | (rx = 4 && ry = 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
30、);i=0; /*re-allocate i to 0 so map is printed from start*/for(i=0;i<8;i+) /*8 by 8 map*/ printf("+-+-+-+-+-+-+-+-+n");for(j=0;j<8;j+) /*8 by 8 map*/if(strlen(f_mapij.data)!=0) /*if function to print nothing but 4 spaces if there in nothing allocated in ij*/printf("|%4s",f_m
31、apij.data);elseprintf("| "); /*end of coloumn visible map*/ printf("|n"); /*end of last coloumn visible map*/printf("+-+-+-+-+-+-+-+-+n"); /*bottom of map*/printf("n");printf("270");printf("Group Bn"); void add_obj(struct map *nu
32、mber, struct map *number_2, struct object_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst, struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre, struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr, struct object_move *anon
33、, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /* add movable object function, *number=aliens, *number_2=rovers*/int object, t, f;char alien; char rover;printf("This is the add movable object functionn");printf("how many aliens would you like?n");scan
34、f("%d",&t); /*user input of amount of aliens*/number->amount=t; /*saving the number in structure 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 m
35、ap-amount*/show_map(number, number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover); /*go to show map function with the number of aliens and number of rovers*/ void successor() /*this functions askes the user for the location and then were they want to go f
36、rom there, printing out that location*/struct map location;int menu;int ncol,nrow; /*we can change the n value depends how large the map you need.*/ncol=8;nrow=8;printf("This is the successor functionn");printf("Enter the nx=ty=n");scanf("%d%d",&location.x,&loca
37、tion.y); /*saving location in map location x and y*/printf("Enter operator choicen");printf("1=leftn");printf("2=rightn");printf("3=upwardsn");printf("4=downn");printf("5=quitn");scanf("%d",&menu);switch(menu) /*menu switch to
38、 show the position above, underneith, and next to the rover*/case 1:location.x=location.x-1; printf("The position is %d,%dn",location.x,location.y);break; case 2:location.x=location.x+1; printf("The position is %d,%dn",location.x,location.y);break;case 3:location.y=location.
39、y-1; printf("The position is %d,%dn",location.x,location.y);break;case 4:location.y=location.y+1; printf("The position is %d,%dn",location.x,location.y);break;case 5:printf("*back to program*n"); /* Quits the program and prints out the message */break; default:printf(&q
40、uot;*Please enter an integer from 1-5*n"); /* A default option if the user 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 *mnt, struct object_fix *dst, struct o
41、bject_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre, struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr, struct object_move *anon, struct object_move *rvr, struct object_move *pstn, struct rover *p_rover) /*help function*/int i;char mov_obj;printf("+This is
42、the help function+n");printf("| 1-successor |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(&quo
43、t;t Water:262262262262 n");printf("t Shallow water: 260260260260n");printf("t Mountain: n");printf("t Dust: .n");printf("t* sher valley: VVVV *n");printf("t shallow valey: vvvvn");printf("t power station: 025n");printf("t alien: *
44、_*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, number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp,
45、 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:printf("choose a number from the listn"); void direction(int input, struct map *number, struct map *number_2, struct obje
46、ct_fix *rsny, struct object_fix *rsld, struct object_fix *mnt, struct object_fix *dst, struct object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre, struct object_fix *wshl, struct object_fix *wdp, struct object_move *aagr, struct object_move *anon, struct object_move *rvr, struct objec
47、t_move *pstn, struct 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 < 7)p_rover->location0+;p_rover->pwr-;else p_rover->location0=0;b
48、reak;case 97: /*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 < 7)p_rover->location1+;p_rover->pwr-;else p_rover->location1=0;break;default:printf("Invalid operator
49、!nn");break;int control(int input)input = _getch();return input; 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;struct map number, number_2;number.amount =
50、0; /* setting the initial amount of aliens as 0*/number_2.amount = 0; strcpy(,"Sandy Rock");strcpy(rsny.id,"RSNY");strcpy(rsny.desc,"A rock made of softer material that can be destroyed or collected");strcpy(rsny.im,"*");strcpy(,"Solid R
51、ock");strcpy(rsld.id,"RSLD");strcpy(rsld.desc,"A rock made of hard material that cannot be destroyed, but can be collected or avoided");strcpy(rsld.im,"O");strcpy(,"Mountain");strcpy(mnt.id,"MNT");strcpy(mnt.desc,"A large obstacle m
52、ade of different materials that can only be avoided");strcpy(mnt.im,"");strcpy(,"Dust");strcpy(dst.id,"DST");strcpy(dst.desc,"Small particles of sand, rock, etc. that may reduce visibility or slow down the vehicle, can be driven through but has extra p
53、ower consumption");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 through and must be avoided");strcpy(vshr.im,"VVVV");strcpy(,
54、"Gentle Valley");strcpy(vgnt.id,"VGNT");strcpy(vgnt.desc,"A depression in the land with gentle sides, it can be driven through with extra power consumption or can be avoided");strcpy(vgnt.im,"vvvv");strcpy(,"'Martian' Tree");strcpy(m
55、tre.id,"MTRE");strcpy(mtre.desc,"A woody plant native to Mars, it may have the same characteristics as an 'Earth' tree");strcpy(mtre.im,"330");strcpy(,"Shallow Water");strcpy(wshl.id,"WSHL");strcpy(wshl.desc,"A shallow body of w
56、ater that can be driven through, can be in the form of a small puddle or a large lake");strcpy(wshl.im,"260260260260");strcpy(,"Deeper Water");strcpy(wdp.id,"WDP");strcpy(wdp.desc,"A deeper body of water that cannot be driven through, commonly in the f
57、orm of a large lake or river");strcpy(wdp.im,"262262262262");strcpy(,"Aggressive Alien");strcpy(aagr.id,"AAGR");strcpy(aagr.desc,"An alien creature that will move upon its own accord, may become aggressive on contact");strcpy(aagr.im,"*_*&qu
58、ot;);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,"*_*");strcpy(,"Rover");strcpy(rvr.id,"RV
59、R");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 storage");strcpy(rvr.im,"#");strcpy(,"Power Station");strcpy(pstn.id,"PSTN");strcpy(pstn.desc,"A movab
60、le power station that will restore power to the Mars Rovers");strcpy(pstn.im,"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,"<>");p_rover.pwr = 100;p_rover.strg = 0;p_rover.location0 = 7;p_rover.location1 = 0; /*/printf("*START*nn");do /* Object will be gained from mapper */printf("+MENU+n"); printf("Please choose one of the
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司警衛(wèi)人員聘用協(xié)議書
- 二零二五年度個人與企業(yè)貸款及利息管理協(xié)議2篇
- 門禁采購合同
- 的房屋買賣合同范文
- 二零二五年度企業(yè)公務(wù)車租賃及維護管理協(xié)議3篇
- 二零二五年度金融機構(gòu)委托貸款業(yè)務(wù)合作協(xié)議6篇
- 電商采購供貨協(xié)議范本
- 物流倉儲配送合同范本
- 合同權(quán)益轉(zhuǎn)讓協(xié)議
- 紀(jì)錄片合作拍攝合同協(xié)議書范本
- 2024年九省聯(lián)考高考數(shù)學(xué)卷試題真題答案詳解(精校打?。?/a>
- 軍人結(jié)婚函調(diào)報告表
- 民用無人駕駛航空器實名制登記管理規(guī)定
- 繪本分享《狐貍打獵人》
- 北京地鐵6號線
- 航空油料計量統(tǒng)計員(初級)理論考試復(fù)習(xí)題庫大全-上(單選題匯總)
- (39)-總論第四節(jié)針灸處方
- 《民航服務(wù)溝通技巧》教案第10課兒童旅客服務(wù)溝通
- 諒解書(標(biāo)準(zhǔn)樣本)
- 西班牙語構(gòu)詞.前后綴
- 《工程測試技術(shù)》全套教學(xué)課件
評論
0/150
提交評論