第一个自己写的小游戏——猜数游戏。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)
int main()
{
int t;
printf("%s\n","要玩游戏请按1,退出请按0");
scanf("%d",&t);
if(t==0)
return 0;
while(1)
{
int n1,n2,k=1,z=0;
printf("%s\n","请输入参与人数");
scanf("%d",&n2);
int y=n2*50;
srand((int)time(0));
int x=random(y);
printf("%d%s%s%s%d\n",z,"<","?","<",y);
while(1)
{
if(k>n2)
k=1;
printf("%s%d%s\n","玩家",k,"输入数字");
scanf("%d",&n1);
if(n1==x)
{
printf("%s%d%s\n","玩家",k,"失败!");
break;
}
if((n1>=y||n1<=z)&&y-z==2)
{
printf("%s%d%s\n","玩家",k,"失败!");
break;
}
if(n1>=y||n1<=z)
printf("%s%d%s\n","玩家",k,"因为输入错误范围数字,失去这轮输入权利");
else
{
if(n1>x)
y=n1;
else
z=n1;
}
printf("%d%s%s%s%d\n",z,"<","?","<",y);
k++;
}
printf("%s\n","再来一局按1,退出按0");
scanf("%d",&t);
if(t==0)
break;
}
printf("%s","再见!");
return 0;
}
本人原创小游戏,大家多支持。