#include<stdio.h>
#include<string.h>
#include<windows.h>
void show(char* a,char* b,char* c,float a_s,float b_s,float c_s)
{
printf("%s: %.2f\n%s: %.2f\n%s: %.2f\n", a,a_s,b,b_s,c,c_s);
}
void main_system(char* a,char* b,char* c,float* a_s,float* b_s,float* c_s,int basis)
{
printf("输入分(1分,2分,3分):");
int time;
scanf("%d", &time);
fflush(stdin);
printf("输入地主(1,2,3):");
int number;
scanf("%d", &number);
fflush(stdin);
float* host;
float* farmer_1;
float* farmer_2;
if(number == 1){
host = a_s;
farmer_1 = b_s;
farmer_2 = c_s;
}
else if(number == 2){
host = b_s;
farmer_1 = a_s;
farmer_2 = c_s;
}
else{
host = c_s;
farmer_1 = a_s;
farmer_2 = b_s;
}
int bomb,n;
bomb = 1;
printf("输入炸弹数:");
scanf("%d", &n);
fflush(stdin);
for(int k = 0; k < n; k++){
bomb *= 2;
}
int spring;
printf("是否春天(是为2,否为1):");
scanf("%d", &spring);
fflush(stdin);
//计算分数
float score;
score = basis*time*bomb*spring;
char win;
printf("地主胜况(赢了输入 y,输了输入 n):");
win = getchar();
if(win == 'y'){
*host += score*2;
*farmer_1 -= score;
*farmer_2 -= score;
}
else{
*host -= score*2;
*farmer_1 += score;
*farmer_2 += score;
}
fflush(stdin);
show(a,b,c, *a_s, *b_s, *c_s);
}
int main()
{
printf("输入系统延迟关闭时间(单位:秒):");
int time;
scanf("%d", &time);
fflush(stdin);
printf("输入基数(单位:元):");
float basis;
scanf("%f", &basis);
char a[30];
char b[30];
char c[30];
fflush(stdin);
printf("请输入玩家名称:\n");
printf("1号玩家:");
gets(a);
fflush(stdin);
printf("2号玩家:");
gets(b);
fflush(stdin);
printf("3号玩家:");
gets(c);
fflush(stdin);
float a_s,b_s,c_s;
a_s = 0;
b_s = 0;
c_s = 0;
printf("输入轮数:");
int i = 1, n;
scanf("%d", &n);
fflush(stdin);
if( n == 0 ){
printf("Error_2!");
return 0;
}
printf("录入成功, 开始输入 s, 退出输入 e\n");
char temp;
temp = getchar();
if(temp == 's' && n != 0){
printf("\n");
printf("第%d轮:\n", i);
main_system(a,b,c,&a_s,&b_s,&c_s,basis);
i += 1;
while(i <= n){
printf("\n");
printf("继续下一轮(输入 c) 或 退出(输入 e):\n");
char var;
var = getchar();
fflush(stdin);
if(var == 'c'){
printf("\n");
printf("第%d轮:\n", i);
main_system(a,b,c,&a_s,&b_s,&c_s,basis);
i += 1;
}
else if(var == 'e'){
printf("成功退出!程序将在%d秒钟后关闭。", time);
Sleep(time*1000);
return 0;
}
else{
printf("Error!");
}
}
printf("\n游戏结束,显示最终得分情况:\n");
show(a,b,c, a_s,b_s,c_s);
printf("\n游戏结束,程序将在%d秒钟后关闭。", time);
Sleep(time*1000);
}
else if(temp == 'e'){
printf("成功退出!程序将在%d秒钟后关闭。", time);
Sleep(time*1000);
return 0;
}
else{
printf("Error!System will be closed in %d seconds!", time);
Sleep(time*1000);
}
return 0;
}