#include<stdio.h>
#include <stdlib.h>
#include <time.h>
int whof()//随机找人开始
{
int whf, i;
srand((unsigned)time(NULL));
whf = rand() % 2 + 0;
if (whf == 0)
{
i = 0;
}
else
{
i = 1;
}
return i;
}
void rule(int l, int g)//游戏函数
{
int e, d=0;
int a = 0, b = 0, c=0;
if (whof() == 0 || g != 1)
{
printf("\n到你出了!\n你要输入几个数字:\n");
scanf_s("%d", &c);
printf("请输入数字:\n");
if (c == 2)
{
scanf_s("%d%d", &a, &b);
}
if (c == 1)
{
scanf_s("%d", &b);
}
}
e = (l - c) % 3;
l -= c;
g++;
if (e == 1)
{
d = 1;
}
if (e == 2)
{
d = 2;
}
if (e != 1 && e != 2)
{
int whf;
srand((unsigned)time(NULL));
whf = rand() % 2 + 0;
if (whf == 0)
{
d = 1;
}
else
{
d = 2;
}
}
if (d == 1)
{
printf("\n机器人:%d(后手第一次请回车)\n", b + 1);
//printf("%d\n",l);
}
if (d == 2)
{
printf("\n机器人:%d %d(后手第一次请回车)\n", b + 1, b + 2);
//printf("%d\n",l);
}
l -= d;
if ((b + 2) <= 30 && getchar())
{
rule(l, g);
}
else
{
if (b + 1 == 30 || b + 2 == 30)
{
printf("电脑获胜!\n");
}
else
{
printf("玩家获胜!\n");
}
}
}
int main()
{
int l = 30, g = 1;
rule(l, g);
return 0;
}
08-24
08-24