完整word版纯C语言写的一个小型游戏 源代码.docx

上传人:b****5 文档编号:7878260 上传时间:2023-01-26 格式:DOCX 页数:14 大小:19.62KB
下载 相关 举报
完整word版纯C语言写的一个小型游戏 源代码.docx_第1页
第1页 / 共14页
完整word版纯C语言写的一个小型游戏 源代码.docx_第2页
第2页 / 共14页
完整word版纯C语言写的一个小型游戏 源代码.docx_第3页
第3页 / 共14页
完整word版纯C语言写的一个小型游戏 源代码.docx_第4页
第4页 / 共14页
完整word版纯C语言写的一个小型游戏 源代码.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

完整word版纯C语言写的一个小型游戏 源代码.docx

《完整word版纯C语言写的一个小型游戏 源代码.docx》由会员分享,可在线阅读,更多相关《完整word版纯C语言写的一个小型游戏 源代码.docx(14页珍藏版)》请在冰豆网上搜索。

完整word版纯C语言写的一个小型游戏 源代码.docx

完整word版纯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;iamount;i++)/*allocatingthenumberofaliensinf_map*/

strcpy(f_map[rand()%8][rand()%8].data,anon->im);/*randomizingtheirposition*/

}

if(number_2->amount>0)/*repeatofabovejustforroversinstead*/

{

for(i=0;iamount;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("howmanyalienswould

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1