#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
void menu()
{
printf("**************Gamic Card**************\n");
printf("***********press 1 to start***********\n");
printf("***********press 2 to exit************\n");
printf("请输入:>\n");
}
struct P1
{
int mp1;
short hp1;
};
struct P2
{
int mp2;
short hp2;
};
void condition(short hp, int mp)
{
if (hp == 2)
{
printf("^-^ ");
printf("能量:%d\n", mp);
}
else if (hp == 1)
{
printf("T-T ");
printf("能量:%d\n", mp);
}
else
printf("*-*\n");
}
int main()
{
menu();
struct P1 p1 = { 0,2 };
struct P2 p2 = { 0,2 };
int a=0;
scanf("%d", &a);
int b = 0;
int c = 0;
if (a != 1 && a != 2)
{
printf("输入错误,请重新选择");
scanf("%d", &a);
};
if (a == 1)
{
while (p1.hp1 > 0 && p2.hp2 > 0)
{
condition(p1.hp1,p1.mp1);
condition(p2.hp2,p2.mp2);
printf("1.攻 2.防 3.气功 4.充能\n");
printf("p1选择\n");
scanf("%d", &b);
while (p1.mp1 < 1 && b == 1 || p1.mp1 < 2 && b == 3)
{
printf("能量不足,请重新选择\n");
scanf("%d", &b);
}
printf("p2选择\n");
scanf("%d", &c);
while (p2.mp2 < 1 && c == 1 || p2.mp2 < 2 && c == 3)
{
printf("能量不足,请重新选择\n");
scanf("%d", &c);
}
if (b == 1)
{
p1.mp1--;
if (c == 1)
{
p2.mp2--;
};
if (c == 3)
{
p1.hp1--;
p2.mp2 -= 2;
};
if (c == 4)
{
p2.mp2++;
p2.hp2--;
};
};
if (b == 2)
{
if (c == 1)
{
p2.mp2--;
};
if (c == 3)
{
p2.mp2 -= 2;
};
if (c == 4)
{
p2.mp2++;
};
};
if (b == 3)
{
p1.mp1 -= 2;
if (c == 1)
{
p2.mp2--;
p2.hp2--;
};
if (c == 3)
{
p2.mp2 -= 2;
};
if (c == 4)
{
p2.mp2++;
p2.hp2 -= 2;
};
}
if (b == 4)
{
p1.mp1++;
if (c == 1)
{
p2.mp2--;
p1.hp1--;
};
if (c == 3)
{
p2.mp2 -= 2;
p1.hp1 -= 2;
};
if (c == 4)
{
p2.mp2++;
};
};
system("cls");
menu();
};
system("cls");
menu();
condition(p1.hp1,p1.mp1);
condition(p2.hp2,p2.mp2);
};
printf("游戏结束");
return 0;
}
新手请多指教
标签:p2,p1,--,简单,小游戏,mp2,printf,mp1,充气 From: https://blog.51cto.com/u_16039642/7762933