纯C语言写地一个小型游戏 源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/* A simple game*/
/*CopyRight: Guanlin*/
#include
#include
#include
#include
#include
#include
struct object_fix
{
char name[20];
char id[5];
char desc[500];
char action[30];
char im[5];
};
struct object_move
{
char name[20];
char id[5];
char desc[500];
int loc;
int pwr;
int strg;
char im[5];
};
struct rover
{
char name[20];
char id[5];
char desc[500];
int pwr;
int strg;
int location[2];
char im[5];
};
struct map /* this is the map structure*/
{
char data[20];
char add_data[20];
int amount;
int x; /* this were the successor keeps it's x & y values*/
int y;
};
struct location /*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("\n\nYou do not have enough power to perform this action!\n\n");
else
{
(p_rover->pwr) -= 7;
printf("You have destroyed the object!\n\n");
}
break;
case 2:
if(p_rover->pwr < 3)
printf("\n\nYou do not have enough power to perform this action!\n\n");
else if(p_rover->strg > 90)
printf("\n\nYou do not have enough storage space for this object!\n\n");
else
{
(p_rover->pwr) -= 3;
(p_rover->strg) += 10;
printf("You have collected a sample of the object!\n\n");
}
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!\n\n");
break;
case 4:
p_rover->pwr -= 2;
printf("You have driven through the obstacle!\n\n");
break;
case 5:
if(p_rover->pwr == 100)
printf("\n\nYou do not need to charge up!\n\n");
else
{
p_rover->pwr = 100;
printf("You have charged up your rover!\n\n");
}
break;
default:
printf("\n\n*****ERROR*****\nInvalid Selection\n\n");
break;
}
}
void action(char object, struct rover *p_rover)
{
int selection;
switch(object)
{
case 1:
printf("\nYou have encountered: A Sandy Rock\n\n");
printf("This object can be:\n1.\tDestroyed\n2.\tCollected\nPlease choose action 1 or
2:\t");
scanf("%d", &selection);
stats_update(selection, p_rover);
break;
case 2:
printf("\nYou have encountered: A Solid Rock\n\n");
printf("This object can be:\n1.\tAvoided\n2.\tCollected\nPlease 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 Mountain\n\n");
printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");
scanf("%d", &selection);
selection = 3;
stats_update(selection, p_rover);
break;
case 4:
printf("\nYou have encountered: Dust\n\n");
printf("This object can be:\n1.\tDriven through\n2.\tCollected\nPlease 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 Valley\n\n");
printf("This object can be:\n1.\tAvoided\nPlease enter 1:\t");
scanf("%d", &selection);