纯C语言写的一个小型游戏 源代码.docx
- 文档编号:30586872
- 上传时间:2023-08-18
- 格式:DOCX
- 页数:26
- 大小:19.65KB
纯C语言写的一个小型游戏 源代码.docx
《纯C语言写的一个小型游戏 源代码.docx》由会员分享,可在线阅读,更多相关《纯C语言写的一个小型游戏 源代码.docx(26页珍藏版)》请在冰豆网上搜索。
纯C语言写的一个小型游戏源代码
/*Asimplegame*/
/*CopyRight:
Guanlin*/
#include
#include
#include
#include
#include
#include
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,object;/*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
strcpy(f_map[rand()%8][rand()%8].data,anon->im);/*randomizingtheirposition*/
}
if(number_2->amount>0)/*repeatofabovejustforroversinstead*/
{
for(i=0;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");
sc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 纯C语言写的一个小型游戏 源代码 语言 一个 小型 游戏