《纯c语言写的一个小型游戏-源代码》由会员分享,可在线阅读,更多相关《纯c语言写的一个小型游戏-源代码(14页珍藏版)》请在金锄头文库上搜索。
1、/* 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 name20;char id5;char desc500; int pw
2、r;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;void stats_update(int selected, struct
3、 rover *p_rover)switch (selected)case 1:if(p_rover-pwr pwr) -= 7;printf(You have destroyed the object!nn);break;case 2:if(p_rover-pwr strg 90)printf(nnYou do not have enough storage space for this object!nn);else(p_rover-pwr) -= 3;(p_rover-strg) += 10;printf(You have collected a sample of the object
4、!nn);break;case 3:p_rover-pwr -= 10; /*Distance around object- value gained from mapper module. 1 square = -1 power*/printf(You have avoided the object!nn);break;case 4:p_rover-pwr -= 2; printf(You have driven through the obstacle!nn);break;case 5:if(p_rover-pwr = 100)printf(nnYou do not need to cha
5、rge up!nn);elsep_rover-pwr = 100;printf(You have charged up your rover!nn);break;default:printf(nn*ERROR*nInvalid Selectionnn);break;void action(char object, struct rover *p_rover)int selection;switch(object)case 1:printf(nYou have encountered: A Sandy Rocknn);printf(This object can be:n1.tDestroyed
6、n2.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.tAvoidedn2.tCollectednPlease choose action 1 or 2:t);scanf(%d, &selection);if (selection = 1)selection = 3;stats
7、_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_update(selection, p_rover);break;case 4:printf(nYou have encountered: Dustnn);printf(This object can be:n1.tDriven th
8、roughn2.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 Valleynn);printf(This object can be:n1.tAvoidednPlease enter 1:t);scanf(%d, &selection);selection = 3;stats_upda
9、te(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, &selection);if (selection = 1)selection = 4;if (selection = 2)selection = 3;stats_update(selection, p_rover);break;cas
10、e 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(selection, p_rover);break;case 8:printf(nYou have encountered: Shallow Waternn);printf(This object can be:n1.tDrive
11、n 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 encountered: Deep Waternn);printf(This object can be:n1.tAvoidedn2.tCollectednPlease choose action 1 or 2:t);scanf(
12、%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.tDestroyednPlease enter 1:t);scanf(%d, &selection);selection = 1;stats_update(selection, p_rover);break;case 11:printf(nYou
13、 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:printf(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.tAvoidnPlea