用c语言写简单的回合制游戏
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
void writeFile(char* fileStr);
int founction (int t);
void boss (int *p);
int back;
//void treasure(int b,int treasure);
//int zhp=0;
int main (){
system("time /t") ;
system("color 3F");
int a[3],pick,hp0=6,f0=2,d0=0,instruct,count=0;
printf ("请选择你想要的精灵\n");
printf ("1-火神,2-喵喵,3-水灵\n");
printf ("请输出它的序号\n");
scanf ("%d",&pick);
switch (pick){
case 1 :a[0]=8;a[1]=3;a[2]=0;break;
case 2 :a[0]=12;a[1]=2;a[2]=0;break;
case 3 :a[0]=8;a[1]=2;a[2]=1;break;
}
printf ("你已经选择好了你的精灵!\n");
printf ("糟糕!你遇到了危机!一只巡逻的小怪发现了你!快指挥你的精灵击败它!\n");
while (hp0>0&&a[0]>0){
printf("轮到你的精灵出击!\n");
printf("请选择是让你的精灵攻击(1)还是防守(2)\n"); //攻击输入1,防守输入2;
scanf ("%d",&instruct);
if (instruct==1){
hp0=hp0-(a[1]-d0);
printf ("你的精灵发起了进攻,小怪hp变为%d.\n",hp0);
if (hp0<=0) break;
}
else {
count=founction ( count );
if (count%3==0){
a[1]=a[1]+4;
printf ("太好了!你的精灵hp增加至%d!\n",a[0]);}
else {
printf ("真可惜!你的精灵hp增加失败!\n");}
}
printf("轮到小怪出击!\n");
a[0]=a[0]-(f0-a[2]);
printf("小怪对你的精灵发起了攻击!你的精灵hp变为%d.\n",a[0]);
}
if (hp0<=0){
printf("你的精灵取得了胜利!\n");
//treasure(1,zhp);
system("CLS");
boss (a);
}
else
{
printf("you lose! 你的精灵被打败了!\n");
back=0;
}
system("PAUSE");
writeFile("D:\\战斗记录.txt");
system("PAUSE");
return 0;
return 0;
}
int founction (int t){
srand (time(NULL));
t=rand()%11;
return t;
}
void boss (int *p){
int hp1=20,f1=3,d1=2,count,instruct;
printf ("\n\n它来了!你遇到了最终危机!领主发现了你!\n");
printf ("在与领主战斗的时候,幸运女神会帮护你,你可能得到随机buff\n");
while (p[0]>0&&hp1>0){
count=founction ( 1 );
if (count%3==0){
if (count%2==0) {
p[0]=p[0]+5;
printf ("受到了女神的眷顾!你的精灵hp增加至%d!\n",p[0]);}
else{
p[1]=p[1]+1;
printf ("受到了女神的眷顾!你的精灵攻击力增加至%d!\n",p[1]);}
}
printf("轮到你的精灵出击!\n");
printf("请选择是让你的精灵攻击(1)还是防守(2)\n"); //攻击输入1,防守输入2;
scanf ("%d",&instruct);
if (instruct==1){
hp1=hp1-(p[1]-d1);
printf ("你的精灵发起了进攻,领主hp变为%d.\n",hp1);
if (hp1<=0) break;
}
else {
count=founction ( count );
if (count%3==0){
p[0]=p[0]+4;
printf ("太好了,施法成功!你的精灵hp增加至%d!\n",p[0]);}
else {
p[0]=p[0]+2;
printf ("真可惜,施法失败!你的精灵hp仅增加至%d!\n",p[0]);}
}
printf("轮到领主出击!\n");
p[0]=p[0]-(f1-p[2]);
printf("领主对你的精灵发起了攻击!你的精灵hp变为%d.\n",p[0]);
}
if (hp1<=0)
{
printf("congratulations!你的精灵取得了胜利!你已成功通关!\n");
back=1;
}
else
{
printf("you lose! 你的精灵被打败了!\n");
back=0;
}
system("PAUSE");
}
void writeFile(char* fileStr)
{
FILE *fp;
fp = fopen(fileStr,"a+");
if(fp == NULL)
{
printf ("something was wrong !");
return ;
}
if(back==1)
{
fputs ("victory!",fp);
fputs ("\n",fp);
fclose(fp);
printf ("*********战绩写入成功***********");
}
else
{
fputs ("defeat!",fp);
fputs ("\n",fp);
fclose(fp);
printf ("*********战绩写入成功***********");
}
}
/*void treasure(int b,int zhp){
printf ("恭喜你刷出了宝藏打开看看吧!\n");
b=founction ( 1 );
switch(b){
case '1':printf("恭喜你获得了一瓶补血药.\n");zhp++;break;
case '0':printf("恭喜你获得了两瓶补血药.\n");zhp=zhp+2;break;}
}*/