1、纯C语言写的一个小型游戏源代码纯C语言写的一个小型游戏-源代码/* A simple game*/*CopyRight: Guanlin*/#include#include#include#include#include#includestruct object_fixchar name20;char id5;char desc500;char action30;char im5;struct object_movechar name20;char id5;char desc500;int loc;int pwr;int strg;char im5;struct roverchar name2
2、0;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*/float height;char obj;int sel
3、ection;switch(object)case 1:printf(nYou have encountered: A Sandy Rocknn);printf(This object can be:n1.tDestroyedn2.tCollectednPlease choose action 1 or 2:t);scanf(%d, &selection);stats_update(selection, p_rover);break;case 2:printf(nYou have encountered: A Solid Rocknn);printf(This object can be:n1
4、.tAvoidedn2.tCollectednPlease choose action 1 or 2:t);scanf(%d, &selection);if (selection = 1)selection = 3;stats_update(selection, p_rover);break;case 3:printf(nYou have encountered: A Mountainnn);printf(This object can be:n1.tAvoidednPlease enter 1:t);scanf(%d, &selection);selection = 3;stats_upda
5、te(selection, p_rover);break;case 4:printf(nYou have encountered: Dustnn);printf(This object can be:n1.tDriven throughn2.tCollectednPlease choose action 1 or 2:t);scanf(%d, &selection);if (selection = 1)selection = 4;stats_update(selection, p_rover);break;case 5:printf(nYou have encountered: A Sheer
6、 Valleynn);printf(This object can be:n1.tAvoidednPlease enter 1:t);scanf(%d, &selection);selection = 3;stats_update(selection, p_rover);break;case 6:printf(nYou have encountered: A Gentle Valleynn);printf(This object can be:n1.tDriven throughn2.tAvoidednPlease choose action 1 or 2:t);scanf(%d, &sele
7、ction);if (selection = 1)selection = 4;if (selection = 2)selection = 3;stats_update(selection, p_rover);break;case 7:printf(nYou have encountered: A Martian Treenn);printf(This object can be:n1.tDestroyedn2.tCollectedn3.tAvoidednPlease choose action 1, 2 or 3:t);scanf(%d, &selection);stats_update(se
8、lection, p_rover);break;case 8:printf(nYou have encountered: Shallow Waternn);printf(This object can be:n1.tDriven throughn2.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(nYou have en
9、countered: Deep Waternn);printf(This object can be:n1.tAvoidedn2.tCollectednPlease choose action 1 or 2:t);scanf(%d, &selection);if (selection = 1)selection = 3;stats_update(selection, p_rover);break;case 10:printf(nYou have encountered: An Aggressive Aliennn);printf(This object can be:n1.tDestroyed
10、nPlease enter 1:t);scanf(%d, &selection);selection = 1;stats_update(selection, p_rover);break;case 11:printf(nYou have encountered: A Non-Aggressive Aliennn);printf(This object can be:n1.tAvoidednPlease enter 1:t);scanf(%d, &selection);selection = 3;stats_update(selection, p_rover);break;case 12:pri
11、ntf(nYou have encountered: Another Rovernn);printf(This object can be:n1.tAvoidednPlease enter 1:t);scanf(%d, &selection);selection = 3;stats_update(selection, p_rover);break;case 13:printf(nYou have encountered: A Power Stationnn);printf(You can:n1.tCharge upn2.tAvoidnPlease choose action 1 or 2:t)
12、;scanf(%d, &selection);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 *mnt, struct obj
13、ect_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 function calling numb
14、er 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)*/system(cls); /* this is your x and y value in your map (f_map)*/srand(time(NULL); /*calling the time from include
15、 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 or not there are aliens in f_map*/for(i=0;iamount;i+) /*allocating the number of aliens in f_map*/str
16、cpy(f_maprand()%8rand()%8.data, anon-im); /*randomizing their position*/if(number_2-amount0) /*repeat of above just for rovers instead*/for(i=0;iamount;i+)strcpy(f_maprand()%8rand()%8.data, rvr-im);rx= p_rover-location0;ry= p_rover-location1;strcpy(f_map10.data, wdp-im);strcpy(f_map40.data, mnt-im);
17、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_map13.data, mnt-im);strcpy(f_map33.data, vshr-im);strcpy(f_map43.data, dst-im);strcpy(f_map53.data, vgnt-im);strcpy(f
18、_map34.data, vshr-im);strcpy(f_map44.data, dst-im);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_map16.data, pstn-im);strcpy(f_map26.data, wdp-im);strcpy(f_map36.data, wdp-im);strcpy(f_map46.data, wshl-im);strcpy(f_ma
19、p76.data, mnt-im);strcpy(f_map07.data, mnt-im);strcpy(f_map17.data, wdp-im);strcpy(f_map27.data, wshl-im);strcpy(f_map37.data, wshl-im);strcpy(f_map67.data, mnt-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;action(objec
20、t, p_rover);else 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
21、= 4 & ry = 4)object = 4;action(object, 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
22、 & ry = 7) | (rx = 3 & ry = 7)object = 8;action(object, p_rover);else if(rx = 1 & ry = 6)object = 13;action(object, p_rover);i=0; /*re-allocate i to 0 so map is printed from start*/for(i=0;i8;i+) /*8 by 8 map*/ printf(+-+-+-+-+-+-+-+-+n);for(j=0;jamount=t; /*saving the number in structure map-amount
23、*/printf(how many rovers would you like?n);scanf(%d,&f); /*user input of amount of rovers*/number_2-amount=f; /*saving the number in structure map-amount*/show_map(number, number_2, rsny, rsld, mnt, dst, vshr, vgnt, mtre, wshl, wdp, aagr, anon, rvr, pstn, p_rover); /*go to show map function with the
24、 number of aliens and number of rovers*/ void successor() /*this functions askes the user for the location and then were 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;
25、printf(This is the successor functionn);printf(Enter the nx=ty=n);scanf(%d%d,&location.x,&location.y); /*saving location in map location x and y*/printf(Enter operator choicen);printf(1=leftn);printf(2=rightn);printf(3=upwardsn);printf(4=downn);printf(5=quitn);scanf(%d,&menu);switch(menu) /*menu switch to show the position above,