版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
{
/*Asimplegame*//*CopyRight:Guanlin*/
#include<stdio.h>
#include<stdlib.h>#include<string.h>#include<time.h>#include<conio.h>#include<process.h>
structobject_fix
{
charname[20];
charid[5];
chardesc[500];
charaction[30];
charim[5];
};
structobject_move
{
charname[20];
charid[5];
chardesc[500];
intloc;
intpwr;
intstrg;
charim[5];
};
structrover
charname[20];
charid[5];
chardesc[500];
intpwr;
intstrg;
intlocation[2];
charim[5];
};
structmap/*thisisthemapstructure*/
{
chardata[20];
charadd_data[20];
intamount;
intx;/*thiswerethesuccessorkeepsit'sx&yvalues*/
inty;
};
structlocation/*thisstructureisforthesuccessorlister*/
{
floatheight;
charobj;
};
voidstats_update(intselected,structrover*p_rover)
{
switch(selected)
{
case1:
if(p_rover->pwr<7)
printf("\n\nYoudonothaveenoughpowertoperformthisaction!\n\n");else
(p_rover->pwr)-=7;
printf("Youhavedestroyedtheobject!\n\n");
}
break;
case2:
if(p_rover->pwr<3)
printf("\n\nYoudonothaveenoughpowertoperformthisaction!\n\n");elseif(p_rover->strg>90)
printf("\n\nYoudonothaveenoughstoragespaceforthisobject!\n\n");
else
{
(p_rover->pwr)-=3;
(p_rover->strg)+=10;
printf("Youhavecollectedasampleoftheobject!\n\n");
}
break;
case3:
p_rover->pwr-=10;/*Distancearoundobject-valuegainedfrommappermodule.1square=-1power*/
printf("Youhaveavoidedtheobject!\n\n");
break;
case4:
p_rover->pwr-=2;
printf("Youhavedriventhroughtheobstacle!\n\n");
break;
case5:
if(p_rover->pwr==100)
printf("\n\nYoudonotneedtochargeup!\n\n");
else
p_rover->pwr=100;
printf("Youhavechargedupyourrover!\n\n");
}
break;
default:
printf("\n\n*****ERROR*****\nInvalidSelection\n\n");
break;
}
}
voidaction(charobject,structrover*p_rover)
{
intselection;
switch(object)
{
case1:
printf("\nYouhaveencountered:ASandyRock\n\n");
printf("Thisobjectcanbe:\n1.\tDestroyed\n2.\tCollected\nPleasechooseaction1or2:\t");scanf("%d",&selection);
stats_update(selection,p_rover);
break;
case2:
printf("\nYouhaveencountered:ASolidRock\n\n");
printf("Thisobjectcanbe:\n1.\tAvoided\n2.\tCollected\nPleasechooseaction1or2:\t");scanf("%d",&selection);
if(selection==1)
selection=3;
stats_update(selection,p_rover);
break;
case3:
printf("\nYouhaveencountered:AMountain\n\n");
printf("Thisobjectcanbe:\n1.\tAvoided\nPleaseenter1:\t");
scanf("%d",&selection);
selection=3;
stats_update(selection,p_rover);
break;
case4:
printf("\nYouhaveencountered:Dust\n\n");
printf("Thisobjectcanbe:\n1.\tDriventhrough\n2.\tCollected\nPleasechooseaction1or2:\t");
scanf("%d",&selection);
if(selection==1)
selection=4;
stats_update(selection,p_rover);
break;
case5:
printf("\nYouhaveencountered:ASheerValley\n\n");
printf("Thisobjectcanbe:\n1.\tAvoided\nPleaseenter1:\t");
scanf("%d",&selection);
selection=3;
stats_update(selection,p_rover);
break;
case6:
printf("\nYouhaveencountered:AGentleValley\n\n");
printf("Thisobjectcanbe:\n1.\tDriventhrough\n2.\tAvoided\nPleasechooseaction1or2:\t");
scanf("%d",&selection);
if(selection==1)
selection=4;
if(selection==2)
selection=3;
stats_update(selection,p_rover);
break;
case7:
printf("\nYouhaveencountered:A'Martian'Tree\n\n");
printf("Thisobjectcanbe:\n1.\tDestroyed\n2.\tCollected\n3.\tAvoided\nPleasechooseaction1,2or3:\t");
scanf("%d",&selection);
stats_update(selection,p_rover);
break;
case8:
printf("\nYouhaveencountered:ShallowWater\n\n");
printf("Thisobjectcanbe:\n1.\tDriventhrough\n2.\tCollected\n3.\tAvoided\nPleasechooseaction1,2or3:\t");
scanf("%d",&selection);
if(selection==1)
selection=4;
stats_update(selection,p_rover);
break;
case9:
printf("\nYouhaveencountered:DeepWater\n\n");
printf("Thisobjectcanbe:\n1.\tAvoided\n2.\tCollected\nPleasechooseaction1or2:\t");
scanf("%d",&selection);
if(selection==1)
selection=3;
stats_update(selection,p_rover);
break;
case10:
printf("\nYouhaveencountered:AnAggressiveAlien\n\n");
printf("Thisobjectcanbe:\n1.\tDestroyed\nPleaseenter1:\t");
scanf("%d",&selection);
selection=1;
stats_update(selection,p_rover);
break;
case11:
printf("\nYouhaveencountered:ANon-AggressiveAlien\n\n");
printf("Thisobjectcanbe:\n1.\tAvoided\nPleaseenter1:\t");scanf("%d",&selection);
selection=3;
stats_update(selection,p_rover);
break;
case12:
printf("\nYouhaveencountered:AnotherRover\n\n");
printf("Thisobjectcanbe:\n1.\tAvoided\nPleaseenter1:\t");scanf("%d",&selection);
selection=3;
stats_update(selection,p_rover);
break;
case13:
printf("\nYouhaveencountered:APowerStation\n\n");
printf("Youcan:\n1.\tChargeup\n2.\tAvoid\nPleasechooseaction1or2:\t");scanf("%d",&selection);
if(selection==1)
selection=5;
if(selection==2)
selection=3;
stats_update(selection,p_rover);
break;
default:printf("\n\n*****ERROR*****\n\n");
break;
}
voidshow_map(structmap*number,structmap*number_2,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,structobject_move*rvr,structobject_move*pstn,structrover*p_rover)/*theshowmapfunctioncallingnumberandnumber_2fromthemapstructuretoseeifmoveableobjectsareneeded*/
{
structmapf_map[8][8];/*8by8map*/
inti,j,rx,ry,objec/*thisisyourxandyvalueinyourmap(f_map)*/system("cls);/*thisisyourxandyvalueinyourmap(f_map)*///srand(time(NULL));/*callingthetimefromincludetogatherrandomvariables*/
for(i=0;i<8;i++)/*forlooptocopyallyourfixedobjectlistsintof_mapsotheycanbedisplayed*/
{for(j=0;j<8;j++)strcpy(f_map[i][j].data,"");
}
if(number->amount>0)/*thisislookingattheaddfunctiontoseeweatherornottherearealiensinf_map*/
{for(i=0;i<number->amount;i++)/*allocatingthenumberofaliensinf_map*/strcpy(f_map[rand()%8][rand()%8].data,anon->im);/*randomizingtheirposition*/
}
i(number_2->amount>0)/*repeatofabovejustforroversinstead*/
{for(i=0;i<number_2->amount;i++)strcpy(f_map[rand()%8][rand()%8].data,rvr->im);
rx=p_rover->location[0];
ry=p_rover->location[1];
strcpy(f_map[1][0].data,wdp->im);
strcpy(f_map[4][0].data,mnt->im);
strcpy(f_map[5][0].data,mnt->im);
strcpy(f_map[3][1].data,dst->im);
strcpy(f_map[4][1].data,dst->im);
strcpy(f_map[3][2].data,dst->im);
strcpy(f_map[4][2].data,dst->im);
strcpy(f_map[0][3].data,mnt->im);
strcpy(f_map[1][3].data,mnt->im);
strcpy(f_map[3][3].data,vshr->im);
strcpy(f_map[4][3].data,dst->im);
strcpy(f_map[5][3].data,vgnt->im);
strcpy(f_map[3][4].data,vshr->im);
strcpy(f_map[4][4].data,dst->im);
strcpy(f_map[5][4].data,vgnt->im);
strcpy(f_map[2][5].data,wshl->im);
strcpy(f_map[3][5].data,wshl->im);
strcpy(f_map[4][5].data,wshl->im);
strcpy(f_map[1][6].data,pstn->im);
strcpy(f_map[2][6].data,wdp->im);
strcpy(f_map[3][6].data,wdp->im);
strcpy(f_map[4][6].data,wshl->im);
strcpy(f_map[7][6].data,mnt->im);
strcpy(f_map[0][7].data,mnt->im);
strcpy(f_map[1][7].data,wdp->im);
strcpy(f_map[2][7].data,wshl->im);
strcpy(f_map[3][7].data,wshl->im);
strcpy(f_map[6][7].data,mnt->im);
strcpy(f_map[rx][ry].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);
}
elseif((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);
}
elseif((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(object,p_rover);
}
elseif((rx==3&&ry==3)||(rx==3&&ry==4))
{
object=5;
action(object,p_rover);
}
elseif((rx==5&&ry==3)||(rx==5&&ry==4))
{
object=6;
action(object,p_rover);elseif((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);
}
elseif(rx==1&&ry==6)
{
object=13;
action(object,p_rover);
}
i=0;/*re-allocateito0somapisprintedfromstart*/
for(i=0;i<8;i++)/*8by8map*/
{
printf("+++++++++\n");
for(j=0;j<8;j++)/*8by8map*/
{
if(strlen(f_map[i][j].data)!=0)/*iffunctiontoprintnothingbut4spacesifthereinnothingallocatedin[i][j]*/
printf("|%4s",f_map[i][j].data);
else
printf("|");/*endofcoloumnvisiblemap*/
}
printf("|\n");/*endoflastcoloumnvisiblemap*/
}
printf("+++++++++\n");/*bottomofmap*/
printf("\n");
}
printf("\270");
printf("GroupB\n");
}
voidadd_obj(structmap*number,structmap*number_2,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,structobject_move*rvr,structobject_move*pstn,structrover*p_rover)/*addmovableobjectfunction,*number=aliens,*number_2=rovers*/
{
intobject,t,f;
charalien;
charrover;
printf("Thisistheaddmovableobjectfunction\n");
printf("howmanyalienswouldyoulike?\n");
scanf("%d",&t);/*userinputofamountofaliens*/
number->amount=t;/*savingthenumberinstructuremap-amount*/
printf("howmanyroverswouldyoulike?\n");
scanf("%d",&f);/*userinputofamountofrovers*/
number_2->amount=f;/*savingthenumberinstructuremap-amount*/
show_map(number,number_2,rsny,rsld,mnt,dst,vshr,vgnt,mtre,wshl,
wdp,aagr,anon,rvr,pstn,p_rover);/*gotoshowmapfunctionwiththenumberofaliensandnumberofrovers*/
voidsuccessor()/*thisfunctionsaskestheuserforthelocationandthenweretheywanttogofromthere,printingoutthatlocation*/
{
structmaplocation;
intmenu;
intncol,nrow;/*wecanchangethenvaluedependshowlargethemapyouneed.*/
ncol=8;
nrow=8;
printf("Thisisthesuccessorfunction\n");
printf("Enterthe\nx=\ty=\n");
scanf("%d%d",&location.x,&location.y);/*savinglocationinmaplocationxandy*/
printf("Enteroperatorchoice\n");
printf("1=left\n");
printf("2=right\n");
printf("3=upwards\n");
printf("4=down\n");
printf("5=quit\n");
scanf("%d",&menu);
switch(menu)/*menuswitchtoshowthepositionabove,underneith,andnexttotherover*/
{
case1:location.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年国际足球赛事场地租赁合同
- 2024年建筑施工劳务承包简约合同样本
- 2024桩基础工程专业分包合同模板
- 2024代理合同样式
- 2024技术参股合作协议书
- 2024版药品代理合同
- 二手房交易合同
- 店面承租协议书范本
- 2024项目开发全过程专项法律服务合同
- 2024常用合作合同范本
- 2023~2024学年第一学期高一期中考试数学试题含答案
- 2023年全国中学生英语能力竞赛初三年级组试题及答案
- (完整版)青年就业创业见习基地汇报材料(完整版)
- 月光(羽泉)原版五线谱钢琴谱正谱乐谱.docx
- 660MW机组空预器声波吹灰器可行性研究报告最新(精华版)
- 控制柜安装施工方案
- 动车组火灾检测(报警)系统
- 水面垃圾自动打捞船的设计 (全套图纸)
- 烟草企业安全生产标准化 规范
- 装饰施工技术标准及要求
- 2018秋七年级虎外考试卷英语试卷
评论
0/150
提交评论