游戏介绍
本游戏是最初版本。
主要是由for循环及if-else选择语句构成。
游戏玩法
第一个输入是游戏版本(1.单人 2.多人 3.退出)
第二个及下面的输入是输入猜的数,如机会用尽却没有猜对系统会公布正确答案。
这里我就不多说了直接上源代码:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <stdio.h>
using namespace std;
int main(void)
{
int a,b,c,d,e,f,g;
cout<<" 【猜猜我是谁】目录系统"<<endl;
cout<<" 1:单人模式"<<endl;
cout<<" 2:多人模式"<<endl;
cout<<" 3:退出游戏"<<endl;
cout<<endl;
time_t t = time(0);
char tmp[64];
cout<<" 打开时间:";
strftime( tmp, sizeof(tmp), " %Y/%m/%d %X ",localtime(&t) );
puts( tmp );
cout<<endl;
cout<<"请输入";
cin>>a;
cout<<endl;
srand (time(NULL));
d=10+rand()%(99-10+1);
if(a==3)
{
cout<<"已退出游戏"<<endl;
return 0;
}
if(a==1)
{
cout<<"你有6次机会快来猜吧"<<endl;
for(f=1; f<=6;)
{
cout<<"请输入第"<<f<<"个数" ;
cin>>e;
if(e==d)
{
cout<<endl;
cout<<"恭喜你猜对了!"<<endl;
return 0;
}
else if(e<d)
{
cout<<"小了"<<endl;
f=f+1;
}
else
{
cout<<"大了"<<endl;
f=f+1;
}
}
cout<<"机会用尽,正确答案为:"<<d;
return 0;
}
if(a==2)
{
cout<<"请输入玩家数量";
cin>>g;
cout<<endl;
for(f=1; f<=g; f++)
{
cout<<"请"<<f<<"号玩家猜数"<<endl;
cout<<"请输入";
cin>>e;
if(e==d)
{
cout<<endl;
cout<<"恭喜玩家"<<f<<"猜对了!"<<endl;
return 0;
}
else if(e<d)
{
cout<<"小了"<<endl;
cout<<endl;
}
else
{
cout<<"大了"<<endl;
cout<<endl;
}
}
cout<<endl;
cout<<"正确答案是"<<d;
}
return 0;
}
/*
===================================================
曹炜哲同学制作
(roboone.scratch3.fun)
---------------------------------------------------
鸣谢:
@adengou
已及roboone编程教师-黄老师
===================================================
*/