纯C语言写的一个小型游戏源代码_第1页
纯C语言写的一个小型游戏源代码_第2页
纯C语言写的一个小型游戏源代码_第3页
纯C语言写的一个小型游戏源代码_第4页
纯C语言写的一个小型游戏源代码_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、/* A simple game*/*CopyRight: Gua nlin */#i nclude<stdio.h>#i nclude<stdlib.h>#i nclude<stri ng.h>#i nclude<time.h>#i ncludevconi o.h>#in clude<process.h>struct object_fixchar name20;char id5;char desc500;char action30;char im5;struct object_movechar name20;char id5;

2、char 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 locati

3、on /*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 eno ugh power to perform this acti on!nn");else(p_rover->pwr) -= 7;printf( "

4、You have destroyed the object!nn");break ;case 2:if (p_rover->pwr < 3)printf( "nnYou do not have eno ugh power to perform this acti on!nn");else if (p_rover->strg > 90)printf( "nnYou do not have eno ugh storage space for this object!nn");else(p_rover->pwr) -=

5、3;(p_rover->strg) += 10;printf( "You have collected a sample of the object!nn");break ;case 3:p_rover->pwr -= 10;/*Dista nee arou nd object- value gained from mapper module. 1square = -1 power*/printf( "You have avoided the object!nn");break ;case 4:p_rover->pwr -= 2;pri

6、n tf( "You have drive n through the obstacle!nn");break ;case 5:if (p_rover->pwr = 100)printf( "nnYou do not n eed to charge up!nn");elsep_rover->pwr = 100;printf( "You have charged up your rover!nn");break ;default :printf( "nn*ERROR* nln valid Selectio nnn&

7、quot;);break ;void action( char object, struct rover *p_rover)int selection;switch (object)case 1:printf( "nYou have en cou ntered: A Sandy Rock nn");printf( "This object can be:n1.tDestroyedn2.tCollectednPlease choose acti on 1 or 2:t");scanf( "%d" , &selection);st

8、ats_update(selecti on, p_rover);break ;case 2:printf( "nYou have en cou ntered: A Solid Rock nn");printf( "This object can be: n1.tAvoidedn2.tCollectednPlease choose acti on 1 or 2:t");scanf( "%d" , &selection);if (selectio n = 1)selecti on = 3;stats_update(selecti

9、on, p_rover);break ;case 3:printf( "nYou have en cou ntered: A Mountainnn");printf( "This object can be: n1.tAvoidednPlease en ter 1:t");scanf( "%d" , &selection);selecti on = 3;stats_update(selecti on, p_rover);break ;case 4:prin tf( "nYou have en cou ntered:

10、Dustnn");printf( "This object can be: n1.tDrive n throughn2.tCollectednPlease choose acti on 1 or2:t");scanf( "%d" , &selection);if (selectio n = 1)selecti on = 4;stats_update(selecti on, p_rover);break ;case 5:printf( "nYou have en cou ntered: A Sheer Valley nn&quo

11、t;);printf( "This object can be: n1.tAvoidednPlease en ter 1:t");scanf( "%d" , &selection);selecti on = 3;stats_update(selecti on, p_rover);break ;case 6:printf( "nYou have en cou ntered: A Gen tle Valley nn");printf( "This object can be: n1.tDrive n throughn2.

12、tAvoidednPlease choose acti on 1 or2:t");scanf( "%d" , &selection);if (selectio n = 1)selecti on = 4;if (selecti on = 2)selecti on = 3;stats_update(selecti on, p_rover);break ;case 7:printf( "nYou have en cou ntered: A 'Martia n' Treenn");printf( "This objec

13、t can be:n1.tDestroyedn2.tCollectedn3.tAvoidednPlease chooseaction 1,2 or 3:t");scanf( "%d" , &selection);stats_update(selecti on, p_rover);break ;case 8:printf( "nYou have en cou ntered: Shallow Waternn");printf( "This object can be: n1.tDrive n throughn2.tCollecte

14、dn3.tAvoidednPlease chooseaction 1,2 or 3:t");scanf( "%d" , &selection);if (selectio n = 1)selecti on = 4;stats_update(selecti on, p_rover);break ;case 9:prin tf( "nYou have en cou ntered: Deep Waternn");printf( "This object can be: n1.tAvoidedn2.tCollectednPlease c

15、hoose acti on 1 or 2:t");scanf( "%d" , &selection);if (selectio n = 1)selecti on = 3;stats_update(selecti on, p_rover);break ;case 10:printf( "nYou have en cou ntered: An Aggressive Alie nnn");printf( "This object can be: n1.tDestroyednPlease en ter 1:t");scanf

16、( "%d" , &selection);selecti on = 1;stats_update(selecti on, p_rover);break ;case 11:printf( "nYou have en cou ntered: A Non-Aggressive Alie nnn");printf( "This object can be: n1.tAvoidednPlease en ter 1:t");scanf( "%d" , &selection);selecti on = 3;sta

17、ts_update(selecti on, p_rover);break ;case 12:printf( "nYou have en cou ntered: Ano ther Rovernn");printf( "This object can be: n1.tAvoidednPlease en ter 1:t");scanf( "%d" , &selection);selecti on = 3;stats_update(selecti on, p_rover);break ;case 13:printf( "nY

18、ou have en cou ntered: A Power Stati onnn");printf( "You can: n1.tCharge upn2.tAvoidnPlease choose action 1 or 2:t");seanf( "%d" , &selection);if (selectio n = 1)selecti on = 5;if (selecti on = 2)selecti on = 3;stats_update(selecti on, p_rover);break ;default :printf( &q

19、uot;nn*ERROR* nn");breakvoidshow_map( structmap *n umber,structstructobject_fix *rsld,structobject_fix *mn t,structobject_fix *vshr,structobject_fix *vg nt,structobject_fix *wshl,structobject_fix *wdp,map *n umber_2,struct object_fix *rs ny,struct object_fix *dst,struct object_fix *mtre,struct

20、object_move *aagr,roverstruct object_move *anon,struct object_move *rvr, struct object_move *pst n,struct*p_rover) /*the show map fun cti on call ing n umber and n umber_2 from the map structure to see if moveable objects are n eeded*/struct map f_map88;/*8 by 8 map*/int i,j, rx, ry, object;/*this i

21、s your x and y value in your map (f_map)*/ system( "cls" ); /* this is your x and y value in your map (f_map)*/sra nd(time(NULL); /*calli ng the time from in clude to gather ran dom variables*/ for (i=0;i<8;i+) /*for loop to copy all your fixed object lists into f_map so they can be dis

22、played*/for (j=0;j<8;j+)strcpy(f_mapij.data,"");if (n umber->amou nt>0)/*this is look ing at the add fun cti on to see weather or not thereare alie ns in f_map*/for (i=0;i<number->amount;i+)/*allocating the number of aliens in f_map*/strcpy(f_mapra nd()%8ra nd()%8.data, anon

23、-> im);/*ran domizi ng their positi on*/if (n umber_2->amou nt>0)/*repeat of above just for rovers in stead*/for (i=0;i<number_2->amount;i+)strcpy(f_mapra nd()%8ra nd()%8.data, rvr->im);rx= p_rover->locati on 0;ry= p_rover->locatio n1;strcpy(f_map10.data, wdp->im); strcpy(

24、f_map40.data, mn t->im); strcpy(f_map50.data, mn t->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, mn t->im);strcpy(f_map13.data, mn t->im);strcpy(f_map33.data, vshr->im);st

25、rcpy(f_map43.data, dst->im);strcpy(f_map53.data, vgn t->im);strcpy(f_map34.data, vshr->im);strcpy(f_map44.data, dst->im);strcpy(f_map54.data, vgn t->im);strcpy(f_map25.data, wshl->im);strcpy(f_map35.data, wshl->im);strcpy(f_map45.data, wshl->im); strcpy(f_map16.data, pst n-&g

26、t;im);strcpy(f_map26.data, wdp->im);strcpy(f_map36.data, wdp->im);strcpy(f_map46.data, wshl->im);strcpy(f_map76.data, mn t->im);strcpy(f_map07.data, mn t->im);strcpy(f_map17.data, wdp->im);strcpy(f_map27.data, wshl->im);strcpy(f_map37.data, wshl->im);strcpy(f_map67.data, mn t

27、->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;acti on(o bject, p_rover);else if (rx = 4 && ry = 0) | (rx = 5 && ry = 0) | (rx = 0 && ry = 3) | (rx =

28、1 && ry = 3) | (rx = 7 && ry = 6) | (rx = 0 && ry = 7) | (rx = 6 && ry = 7) object = 3;acti on(o bject, 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 =

29、 4 && ry = 4)object = 4;acti on(o bject, p_rover);else if (rx = 3 && ry = 3) | (rx = 3 && ry = 4)object = 5;acti on(o bject, p_rover);else if (rx = 5 && ry = 3) | (rx = 5 && ry = 4)object = 6;acti on(o bject, p_rover);else if (rx = 2 && ry = 5) | (rx =

30、 3 && ry = 5 ) | (rx = 4 && ry = 5) | (rx = 4&& ry = 6) |(rx = 2 && ry = 7) | (rx = 3 && ry = 7)object = 8;acti on(o bject, p_rover);else if (rx = 1 && ry = 6)object = 13;acti on(o bject, p_rover);i=0; /*re-allocate i to 0 so map is pri nted from start

31、*/for (i=0;i<8;i+)/*8 by 8 map*/printf( "+n");for (j=0;j<8;j+)/*8 by 8 map*/if (strle n( f_mapij.data)!=O)/*if fun cti on to print nothing but 4 spaces if there in nothingallocated in ij*/printf( "|%4s" ,f_mapij.data);elseprintf( "I" ); /*end of coloumn visible ma

32、p*/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 *number,struct map *n umber_2,struct object_fix *rsny,struct object_fix *rsld,struct object

33、_fix *vshr,struct object_fix *wshl,struct object_fix *mnt,struct object_fix *vg nt,struct object_fix *wdp,struct object_fix *dst, struct object_fix *mtre, struct object_move *aagr,struct object_move *anon,struct object_move *rvr,struct object_move *pst n,structrover*p_rover) /* add movable object fu

34、n cti on, *n umber=alie ns, * number_2=rovers*/int object, t, f;char alien;char rover;printf( "This is the add movable object fun cti onn");prin tf( "how many alie ns would you like?n");sca nf( "%d" ,& t); /*user in put of amou nt of alie ns*/n umber->amou nt=t;/

35、*sav ing the n umber in structure map-amou nt*/printf( "how many rovers would you like?n");sca nf( "%d" ,&f); /*user in put of amou nt of rovers*/n umber_2->amou nt=f;/*sav ing the n umber in structure map-amou nt*/ show_map (n umber, n umber_2, rsny, rsld, mnt, dst, vshr,

36、 vgnt, mtre, wshl,wdp, aagr, anon, rvr, pst n, p_rover);/*go to show map fun cti on with the n umber of alie nsand n umber of rovers*/void successor() /*this functions askes the user for the location and then were they want togo from there, pr in ti ng out that locati on*/struct map locati on;int me

37、nu;int ncol,nrow;/*we can change the n value depends how large the map you need.*/n col=8;n row=8;printf( "This is the successor fun cti onn");prin tf( "En ter the n x=ty=n");scanf( "%d%d",&location.x,&location.y);/*saving location in map location x and y*/print

38、f( "En ter operator choicen");printf( "1=leftn" );printf( "2=rightn");prin tf( "3=upwardsn");printf( "4=dow nn");printf( "5=quitn" );scanf( "%d",&menu);switch (menu)/*menu switch to show the position above, underneith, and nex

39、t to therover*/case 1:locati on. x=locati on. x-1;printf( "The positi on is %d,%dn",locati on. x,locati on. y);break ;,locati on. x,locati on. y);,locati on. x,locati on. y);,locati on. x,locati on. y);case 2:location.x=location.x+1; printf( "The position is %d,%dn" break ;case 3

40、:location.y=location.y-1; printf( "The position is %d,%dn" break ;case 4:location.y=location.y+1; printf( "The position is %d,%dn" break ;case 5:printf( "*back to program*'n") /* Quits the program and prints out the message*/break ;default :prmtf( "*Please ente

41、r an integer from 1-5*n"); /* A default option if the useren ters an in correct value */break ;printf( "n");voidhelp( struct map *number,struct map *n umber_2,struct object_fix *rsny,structobject_fix *rsld,structobject_fix *mn t,structobject_fix *dst,structobject_fix *vshr,structobjec

42、t_fix *vg nt,structobject_fix *mtre,structobject_fix *wshl,structobject_fix *wdp,structobject_move *aagr,structobject_move *anon,struct object_move*rvr,struct object_move *pst n,struct rover*p_rover)/*help fun cti on*/int i;char mov_obj;prin tf( "+This is the help fun cti on+n");printf( &q

43、uot;| 1-successor | n");printf( "| 2-add movable obj |n");printf( "| 3-remove moveabla obj |nn");printf( "t* * *n");printf( "t In dex: nn");printf( "t Sandy Rock: *n");printf( "t Solid Rock: on" );printf( "t Water:262262262262 n&q

44、uot;);printf( "t Shallow water: 260260260260n");printf( "t Mou ntain:小小门");printf( "t Dust: .n" );printf( "t* sher valley: VVVV *n");printf( "t shallow valey: vvvvn");printf( "t power statio n: 025n");printf( "t alie n: *_*n");pri

45、n tf( "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 (n umber, n umber_2, rs ny, rsld, mnt, dst, vshr,vgnt, mtre, wshl, wdp, aa

46、gr, anon, rvr, pst n, p_rover);break ;case 3:add_obj (n umber, n umber_2, rs ny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp, aagr, anon, rvr, pst n, p_rover); break ;default :printf( "choose a n umber from the listn");struct object_move *rvr,rovervoiddirecti on(int in put,structmap *n umb

47、er,*rsny,structobject_fix *rsld,structobject_fix *mnt,structobject_fix *vshr,structobject_fix *vg nt,structobject_fix *wshl,structobject_fix *wdp,struct object_move *anon,*p_rover)switch (input)case 119:/*w = up*/if (p_rover->locati on0 > 0)p_rover->locatio n0-; p_rover->pwr-; else p_rov

48、er->location0=7; break ;case 115:/*s = dow n*/if (p_rover->locati on0 < 7)p_rover->locati on 0+; p_rover->pwr-; else p_rover->location0=0; break ;case 97:/*a = left*/if (p_rover->locati on 1 > 0)p_rover->locatio n1-; p_rover->pwr-; else p_rover->location 1=7; break ;

49、case 100:/*d = right*/if (p_rover->locati on 1 < 7) p_rover->locatio n1+; p_rover->pwr-; else p_rover->location 1=0; break ;struct map *n umber_2, struct object_fixstruct object_fix *dst,struct object_fix *mtre,struct object_move *aagr,struct object_move *pst n,structdefault :);printf

50、( "In valid operator!nn" break ;int con trol( int in put) in put = _getch(); return in put;void main( void )int menu;int quit = 0;int in put = 0;struct object_fix rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp;struct object_move aagr, anon, rvr, pst n;struct rover p_rover;struct map n u

51、mber, n umber_2;n umber.amou nt = 0;/* sett ing the in itial amou nt of alie ns as 0*/n umber_2.amou nt = 0;strcpy(rs ny.n ame, strcpy(rs ny.id, strcpy(rs ny .desc, strcpy(rs ny.im, strcpy(rsld. name, strcpy(rsld.id, strcpy(rsld.desc,collected or avoided" strcpy(rsld.im, strcpy( mn t. name, str

52、cpy( mn t.id, strcpy( mn t.desc, strcpy( mn t.im, strcpy(dst. name, strcpy(dst.id, strcpy(dst.desc,"Sa ndy Rock");"RSNY");"A rock made of softer material that can be destroyed or collected""*" );"Solid Rock");"RSLD");"A rock made of ha

53、rd material that cannot be destroyed, but can be););"O");"Mou ntai n");"MNT");"A large obstacle made of differe nt materials that can only be avoided""AAAA");"Dust");"DST");"Small particles of san d, rock, etc. that may reduc

54、e visibility or slow dow n););the vehicle, can be drive n through but has extra power con sumpti on" strcpy(dst.im, strcpy(vshr. name, strcpy(vshr.id, strcpy(vshr.desc, must be avoided" strcpy(vshr.im, strcpy(vg nt. name, strcpy(vg nt.id, strcpy(vg nt.desc," " ); / J"Sheer V

55、alley" );"VSHR");"A depressi on in the land with sheer sides, it cannot be drive n through and );"VVVV");"Ge ntle Valley");"VGNT");"A depressi on in the land with gen tle sides, it can be drive n through with);extra power con sumpti on or can be

56、 avoided"strcpy(vg nt.im,"vvvv");strcpy(mtre. name, "'Martia n' Tree" );strcpy(mtre.id,"MTRE");strcpy(mtre.desc, 'Earth' tree"); strcpy(mtre.im, strcpy(wshl. name, strcpy(wshl.id, strcpy(wshl.desc,"A woody pla nt n ative to Mars, it may ha

57、ve the same characteristics as ana small puddle or a large lake" strcpy(wshl.im, strcpy(wdp .n ame, strcpy(wdp.id, strcpy(wdp.desc,"330");"Shallow Water" );"WSHL");"A shallow body of water that can be drive n through, can be in the form of );form of a large la

58、ke or river" strcpy(wdp.im, strcpy(aagr. name, strcpy(aagr.id, strcpy(aagr.desc,"260260260260" );"Deeper Water" );"WDP");"A deeper body of water that cannot be drive n through, com monly in the);aggressive on con tact" strcpy(aagr.im, strcpy(a non.n ame,

59、strcpy(a non .id, strcpy(a non. desc,"262262262262" );"Aggressive Alie n" );"AAGR");"An alie n creature that will move upon its own accord, may become);');"Non-Aggressive Alie n""ANON");"An alie n creature that will move upon its own accord, will n ot become););"Rover");"RVR");"A Mars Rover vehicle to tran sport arou nd the map, it can destroy, collect or);II* *11);aggressive on con tact"

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论