




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、HUA system office room HUA 16H-TTMS2A-HUAS8Q8-HUAH1688/* A simple game*/*CopyRight: Guan1in*/#include#include#include#include#include#include struct object-fix char name20;char id5;char desc500;char action30;char im5;struct object_move(char name20;char id5;char desc 500;int loc;int pwr;int strg;char
2、 im5;struct rover(char 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 its x & y values*/int y;struct location *this structure is for the successor lister*/ f
3、loat height;char obj;;void stats_update(int selected, 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 (/znnYou do not have enough storage space for this object! nn);else(p_rover-pwr) -= 3;(p_r
4、over-strg) += 10;printf (You have collected a sample of the object! nnz,);)break;case 3:p_rover-pwr -= 10; /*Distance around object- value gained from mapper module.1 square = T power*/printf(You have avoided the object!nn);break;case 4: p_rover-pwr -= 2;printf (You have driven through the obstacle!
5、 nnz/);break;case 5:if(p_rover-pwr = 100)printf CnnYou do not need to charge up!nn);else(p_rover-pwr = 100;printf (You have charged up your rover! nnzz);break;default:printf(nn*ERR0R*nlnvalid Selectionnn);break;printf (This object can be:nl. tAvoidedn2.tCollectednPlease choose actionvoid action (cha
6、r object, struct rover *p_rover)(int selection;switch(object)case 1:printf (/znYou have encountered: A Sandy Rocknn);printf (This object can be:nl. tDestroyedn2.tCollectednPlease chooseaction 1 or 2:t);scanf (飞d,ftselection);stats_update(selection, p_rover);break;case 2: printf (/znYou have encounte
7、red: A Solid RocknrT);1 or 2:t);scanf (飞d,ftselection);if (selection = 1)selection = 3;stats_update(selection, p_rover);break;case 3:printf (z/nYou have encountered: A MountainnrT);printf (This object can be:nl. tAvoidednPlease enter scanf (飞d,&selection);selection = 3;stats_update(selection, p_rove
8、r);break;case 4: printf (/znYou have encountered: DustnrT);printf (This object can be:nl. tDriven throughn2.tCollectednPlease chooseaction 1 or 2:t);scanf (飞d,ftselection);if (selection = 1)selection = 4;stats_update(selection, p_rover);break;case 5:printf (z/nYou have encountered: A Sheer Valleynn/
9、Z);printf (This object can be:nl. tAvoidednPlease enterscanf (飞d,&selection);selection = 3;stats_update(selection, p_rover);break;case 6: printf (/znYou have encountered: A Gentle Valleynn/Z);printf (This object can be:nl. tDriven throughn2. tAvoidednPlease chooseaction 1 or 2:t);scanf (飞d,ftselecti
10、on);if (selection = 1)selection = 4;if (selection = 2)selection = 3;stats_update(selection, p_rover);break;case 7:printfCnYou have encountered: A ,Martian Treenn);printf (This object can be:nl. tDestroyedn2. tCollectedn3. tAvoidednPlease choose action 1, 2 orscanf (飞d,&selection);stats_update(select
11、ion, p_rover);break;case 8:printf CnYou have encountered: Shallow Waternn,z);printf(This object can be:nl. tDriventhroughn2. 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 CnYou have
12、encountered: Deep Waternn);printf(This object can be:nl.tAvoidedn2.tCollectednPlease choose action 1 or 2:t);scanf (飞d,ftselection);if (selection = 1)selection = 3;stats_update(selection, p_rover);break;case 10: printf CnYou have encountered: An Aggressive Aliennn); printf (This object can be:nl. tD
13、estroyednPlease enter scanf(与d, ftselection);selection = 1;stats_update(selection, p_rover);break;case 11: printf (/znYou have encountered: A Non-Aggressive Aliennn); printf (This object can be:nl. tAvoidednPlease enter scanf (飞d,ftselection);selection = 3;stats_update(selection, p_rover);break;case
14、 12: printf CnYou have encountered: Another Rovernn);printf (This object can be:nl. tAvoidednPlease enterscanf (飞d,ftselection);selection = 3;stats_update(selection, p_rover);break;case 13: printf CnYou have encountered: A Power StationnrT);printf (You can:nl. tCharge upn2. tAvoidnPlease choose acti
15、on 1 or 2:t);scanf (飞d,ftselection);if (selection = 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
16、 *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 object_move *pstn, struct rover *p_rover) /*the show map functio
17、n calling number and number_2 from the 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)*/ systemCcls/z) ; /冰 this is your x and y value in your map (f_map)*/srand(time(5JJLL) ; /*calling
18、 the time from 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 be displayed*/for(j=0;jamount0) /”this is looking at the add function to see weather ornot there are aliens in f_map*/ for(i=0;iamount;i+) /*allocating the number
19、of aliens in f_map*/ 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;i amount;i+) strcpy (f_map rand () %8 rand()%8. data, rvr-im);rx= p_rover-location0;ry= p_rover-locationl;strcpy(f_mapl0. data,
20、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. data, mnt-im);strcpy(f_mapl3. data, mnt-im);strcpy(f_map43. data,strcpy(f_map53. data,vgnt-im);s
21、trcpy(f_map34. data,vshr-im);strcpy(f_map44. data,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_mapl6. data,pstn-im);strcpy(f_map26. data,wdp-im);strcpy(f_map36. data,wdp-im);strcpy(f_map46. data,wshl-im);strcpy(f_map
22、76. data,strcpy(f_mapO7. data,strcpy(f_mapl7. data, wdp-im);strcpy(f_map27. data, wshl-im);wshl-im);strcpy(f_map37. data, strcpy(f_map67. data, strcpy(f_maprxry. data, p_rover-im);if (rx = 1 & ry = 0) (rx = 2 & ry = 6) (rx = 3 & ry = 6) I I (rx二二 1 & ry = 7)(object = 9;action (object, p_rover);)else
23、 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) (rx = 4 & ry = 3) (rx = 4 & ry = 4)(object = 4;action (obj
24、ect, 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= 5)(rx =二 4 & ry = 6)(rx=二 2 & ry =二 7) (rx=二 3 & ry 二二 7) object = 8;ac
25、tion (object, p_rover);else if (rx = 1 & ry = 6)object = 13;action (object, p_rover);)from start*/i=0; /*re-allocate i to 0 so map is printed for(i=0;i8;i+) /*8 by 8 map*/printf(z,+十n);for(j=0;jamount=t; /*saving the number in structure map-amount*/ printf Chow many rovers would you like scanf Cz%dz
26、/, &f) ; /*user input of amount of rovers*/ number_2-amount=f; /*saving the number in structure map-amount*/show_map(number,wdp, aagr, anon,number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl,rvr, pstn, p_rover); /*go to show map function with thenumber of aliensand number of rovers*/void success
27、or ()/*this functions askes the user for the location and thenwere they want to go from 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 functionXn);printf(Ent
28、er the nx=ty=n);scanf Cz%d%d?7, &location. x, ftlocation. y) ; /*saving location in map location x and y*/printf (Enter operator choicen);printf(1二leftn);printf (,2=rightn,/);printf C3=upwardsn/Z);printf C4=downn/Z);printf (5=quitll);scanf (飞d,&menu);switch(menu) /*menu switch to show the position a
29、bove, underneith, and next to the rover*/(case 1:location. x=location. x-l;printf(The position is %d, %dn, location, x, location.y);break;9case 2:location.x=location. x+1;printf (The position is %d,%dn,location, x,location, y);break;case 3:location. y=location. y-1;printf(The position is %d, %dn, lo
30、cation, 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 C*back to program*n); /* Quits the program and prints out themessage 冰/break;default:printfC*Please enter an integer from 1-5*n); /* A default option if the user
31、enters an incorrect value */break;)printf (n);9 *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 object_fix *vshr, struct object_fix *vgnt, struct object_fix *mtre, struct object-fix Wshl, st
32、ruct object_fix ):%dp, 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 (/Z+This is the help function+n);printf C 1-successor n);printf C 2-add movable obj rT);printf C 3-remove mo
33、veabla obj nn);printf Ct* * *nz/);printf (z,t Index: nn);printf (z,t Sandy Rock: *n);printf Ct Solid Rock: on); printf (/zt Water :262262262262 n);printfCt Shallow water: 260260260260n); printf Ct Mountain:八 n);printf (t Dust: . . . n);printf(Xt* sher valley: VVVV *n);printf (z/t shallow valey: vvvv
34、n);printf (/t power station: 025n);printf (/zt alien: *_*rT);printf Ct other rovers : #n);printf Ct* * *nz/);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,
35、 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:printf (choose a number from the listn);void direction(int input, struct map *number, struct map *number_2, struct
36、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 ):%dp, struct object_move *aagr,struct object_move *anon, struct object_move *rvr, struct ob
37、ject_move *pstn,struct rover *p_rover)(switch(input)(case 119:= up*/if(p_rover-location0 0)p_rover-locat ion0一;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: /*a = left*/ if(p_rover-locationl 0)
38、p_rover-location1一;p_rover-pwr-;else p_rover-locationl=7;break;case 100: /*d = right*/ if(p_rover-location1 location1+;p_rover-pwr-;else p_rover-locationL1J =0;break;default:operator! nn/z);input)printf (Invalid break;)int control(int(input = _getch() return input;9void main(void)int menu;int quit =
39、 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 = 0; /* setting the initial amount of aliens as 0*/number_2. amount = 0;strcpy(rsny. name, “Sandy Rock);strcpy
40、 (rsny. id, RSY);strcpy(rsny. desc, A rock made of softer material that can be destroyed or collected);strcpy (rsny. im, *);strcpy(rsld. name, “Solid Rock);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
41、. im, 0);strcpy(mnt. name, “Mountain);strcpy(mnt. id, MNT);strcpy(mnt. desc, A large obstacle made of different materials that can only be avoided);strcpy(mnt. im, );strcpy(dst. name, “Dust);strcpy(dst. id,DST);strcpy(dst. desc, Small particles of sand, rock, etc. that may reduce visibility or slow
42、down the vehicle, can be driven through but has extra power consumption7);strcpy (dst. im, );strcpy(vshr. name, “Sheer Valley);strcpy (vshr. id, VSHR);strcpy(vshr. desc, A depression in the land with sheer sides, it cannot bedriven through and must be avoided);strcpy(vshr. im, VVVV);strcpy(vgnt. nam
43、e, Gentle Valley );strcpy(vgnt. id, VGT);strcpy(vgnt. desc, Z/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 (mtre. name, Martian Tree);strcpy (mtre. id, MTRE);strcpy(mtre. desc, A woody plant native
44、to Mars, it may have the same characteristics as an Earth tree);strcpy(mtre. im, 330);strcpy(wshl. name, Shallow Water);strcpy(wshl. id, WSHL);strcpy(wshl. desc, A shallow body of water that can be driven through, can be in the form of a small puddle or a large lake);strcpy(wshl. im, 260260260260);s
45、trcpy(wdp. name, Deeper Water);strcpy (wdp. id, WDP);strcpy(wdp. desc, A deeper body of water that cannot be driven through, commonly in the form of a large lake or river);strcpy(wdp. im, ”262262262262”);strcpy(aagr. name, Aggressive Alien);strcpy(aagr. id, AAGR);strcpy(aagr. desc, An alien creature
46、 that will move upon its own accord, may become aggressive on contact);strcpy(aagr. im, ;strcpy(anon, name, Xon-Aggressive Alien);strcpy (anon, id, AN0);strcpy(anon, desc,An alien creature that will move upon its own accord, will not become aggressive on contact);strcpy(anon, im, *_*); strcpy(rvr. n
47、ame, “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 storage);strcpy(rvr. im, #);strcpy(pstn, name, Power Station);strcpy(pstn, id, PST);strcpy(pstn, desc, A movable power station th
48、at will restore power to the MarsRovers/z);strcpy (pstn, im, 025);strcpy (p_rover. name, User Mars Rover);strcpy(prover. id, URVR);strcpy (p_rover. desc,,ZA Mars vehicle that is controlled by the user. Explores the map collecting, destroying and avoiding objects);strcpy (p_rover. im, O);p_rover. pwr = 100;p_rover. strg = 0;p_rover. location0 = 7;p_rover. location1 = 0;(、,、/ f、
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工程项目居间服务合同
- 股份制文书关于企业股权结构调整方案
- 新农业科技成果转化实施方案
- 影视制作行业数字化制作与发行平台开发方案
- 珠宝首饰行业数字化管理与展示技术方案
- 土地复垦工程项目合同
- 金华浙江金华义乌市公证处招聘工作人员笔试历年参考题库附带答案详解
- 金华2025年浙江金华武义县教育系统招聘教师37人笔试历年参考题库附带答案详解
- 眉山2025年四川眉山职业技术学院编制内招聘辅导员5人笔试历年参考题库附带答案详解
- 淮北安徽淮北濉溪县城市管理局招聘城市管理协管员30人笔试历年参考题库附带答案详解
- 《术前讨论制度》课件
- 梅毒病人产后护理查房
- 小班-语言社会-幸福的“叮咚”-课件(基础版)公开课教案教学设计课件案例试卷
- 专业培训金蝶k3wise供应链系统培训
- 办公耗材采购 投标方案(技术方案)
- 《干部履历表》填写样式
- 汽车电气设备检测与维修中职全套教学课件
- 卡支付敏感信息管理实施细则
- Hadoop技术之大数据概念介绍课件
- 江苏省四星级高中评估标准及评价细则
- 超级面试官:快速提升识人技能的面试实战手册
评论
0/150
提交评论