李子的猜数游戏!(已更新!)

猜数游戏

最近闲来无事,便随便做了个猜数游戏,话不多说,上代码!
(已更新!!!时间为2020-1-8)
(已更新!!!时间为2020-1-17本次更新γ版)
(在这我就不写γ版的代码了,乱,去另一条博客看)
(γ版地址:https://blog.csdn.net/qing_dao_boy/article/details/104020816)
(2020/5/18更新,地址为https://blog.csdn.net/qing_dao_boy/article/details/106198877)
(已更新!epsilon版,这位作者(就是我)并不想公开代码~ )
首先进行库处理
Ctrl+click< iostream >
打开如下代码

// Standard iostream objects -*- C++ -*-

// Copyright (C) 1997-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file include/iostream
 *  This is a Standard C++ Library header.
 */

//
// ISO C++ 14882: 27.3  Standard iostream objects
//

#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1

#pragma GCC system_header

#include <bits/c++config.h>
#include <ostream>
#include <istream>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  /**
   *  @name Standard Stream Objects
   *
   *  The &lt;iostream&gt; header declares the eight <em>standard stream
   *  objects</em>.  For other declarations, see
   *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch24.html
   *  and the @link iosfwd I/O forward declarations @endlink
   *
   *  They are required by default to cooperate with the global C
   *  library's @c FILE streams, and to be available during program
   *  startup and termination. For more information, see the HOWTO
   *  linked to above.
  */
  //@{
  extern istream cin;		/// Linked to standard input
  extern ostream cout;		/// Linked to standard output
  extern ostream cerr;		/// Linked to standard error (unbuffered)
  extern ostream clog;		/// Linked to standard error (buffered)

#ifdef _GLIBCXX_USE_WCHAR_T
  extern wistream wcin;		/// Linked to standard input
  extern wostream wcout;	/// Linked to standard output
  extern wostream wcerr;	/// Linked to standard error (unbuffered)
  extern wostream wclog;	/// Linked to standard error (buffered)
#endif
  //@}

  // For construction of filebuffers for cout, cin, cerr, clog et. al.
  static ios_base::Init __ioinit;

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

#endif /* _GLIBCXX_IOSTREAM */

改为:

// Standard iostream objects -*- C++ -*-

// Copyright (C) 1997-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file include/iostream
 *  This is a Standard C++ Library header.
 */

//
// ISO C++ 14882: 27.3  Standard iostream objects
//

#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1

#pragma GCC system_header

#include <bits/c++config.h>
#include <ostream>
#include <conio.h>
#include <cstdio>
#include <cstring>
#include <windows.h>
#include <cstdlib>
#include <time.h>
#include <istream>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  /**
   *  @name Standard Stream Objects
   *
   *  The &lt;iostream&gt; header declares the eight <em>standard stream
   *  objects</em>.  For other declarations, see
   *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch24.html
   *  and the @link iosfwd I/O forward declarations @endlink
   *
   *  They are required by default to cooperate with the global C
   *  library's @c FILE streams, and to be available during program
   *  startup and termination. For more information, see the HOWTO
   *  linked to above.
  */
  //@{
  extern istream cin;		/// Linked to standard input
  extern ostream cout;		/// Linked to standard output
  extern ostream cerr;		/// Linked to standard error (unbuffered)
  extern ostream clog;		/// Linked to standard error (buffered)

#ifdef _GLIBCXX_USE_WCHAR_T
  extern wistream wcin;		/// Linked to standard input
  extern wostream wcout;	/// Linked to standard output
  extern wostream wcerr;	/// Linked to standard error (unbuffered)
  extern wostream wclog;	/// Linked to standard error (buffered)
#endif
  //@}

  // For construction of filebuffers for cout, cin, cerr, clog et. al.
  static ios_base::Init __ioinit;

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

#endif /* _GLIBCXX_IOSTREAM */

保存,接下来就可以用以下的代码了。(这是1.0α版本,如果要β版,请往下翻或去我的另一条博客,这里贴上网址https://blog.csdn.net/qing_dao_boy/article/details/103897462)

#include<iostream>
using namespace std;
//
void pause()
{
	cout<<"请按任意键退出本程序......"; 
	getch();
	exit (0);
}
int main()
{
	cout<<"欢迎来到由李子开发的猜数游戏1.0α(alpha)版本!!!!!"<<" /"<<"(*^▽^*)/"<<endl;
	cout<<"你要不要玩呢???(Y/N)"<<endl;
	char choose;
	
	while(1)
	{
		cin>>choose;
		if(choose=='Y'||choose=='y')
		{
			break; 
		}
		else if(choose=='N'||choose=='n')
		{
			cout<<"好吧,ヾ(ToT)Bye~Bye~";
			exit (0); 
		}
		else
		  {
		  cout<<"无效选择!请重选!";
		  continue;
		   }
	}


	cout<<"好的!接下来,请选择级别"<<endl<<"1、简单(10次机会,0~50内的数字)"<<endl<<"2、中等(8次机会,0~100内的数字)"<<endl<<"3、高级(7次机会,0~200内的数字)"<<endl<<"4、困难(只有3次机会,0~500内的数字)"<<endl;
	int choose1=0;
	int truenum=0;
	int num=0;
	cin>>choose1; 
	if(choose1==1)
	{
		cout<<"------游戏开始------"<<endl; 
		srand((unsigned)time(NULL));
		truenum=rand() % 50;
		cout<<"开始吧!"<<endl;
		int opportunities_easy=10; 
		while(opportunities_easy!=0)
		{
			cout<<"你还有"<<opportunities_easy<<"次机会"<<endl; 
			cin>>num;
			if(truenum==num)
			{
				cout<<"你太牛了!对了!";
				pause();
				return 0;
			}
			else
			{
				/*cout<<"错了!";
				opportunities_easy--;*/
				if(num<truenum)
				{
					cout<<"小了!"<<endl; 
					opportunities_easy--;
				}
				else
				{
					cout<<"大了!"<<endl;
					opportunities_easy--;
				}
			}
		}
		cout<<"没机会了!!自动退出!"<<endl;
		pause();
		return 0;
		} 
		else if(choose1==2)
		{
			cout<<"------游戏开始------"<<endl; 
			srand((unsigned)time(NULL));
			truenum=rand() % 100;
			cout<<"开始吧!"<<endl;
			int opportunities_secondary=8;
			while(opportunities_secondary!=0)
			{
				cout<<"你还有"<<opportunities_secondary<<"次机会"<<endl; 
				cin>>num;
				if(truenum==num)
				{
					cout<<"你太牛了!对了!"<<endl;
					return 0;
					pause();
				}
				else
				{
					/*cout<<"错了!"<<endl;
					opportunities_secondary--;*/
					if(num<truenum)
					{
						cout<<"小了!"<<endl; 
						opportunities_secondary--;
					}
					else
					{
						cout<<"大了!"<<endl;
						opportunities_secondary--;
					}
				}
			}
			cout<<"没机会了!!自动退出!"<<endl;
			pause();
			return 0;
		}
	else if(choose1==3)
	{
		
		cout<<"------游戏开始------"<<endl; 
		srand((unsigned)time(NULL));
		truenum=rand() % 100;
		cout<<"开始吧!"<<endl;
		int opportunities_senior=7;
		while(opportunities_senior!=0)
		{
			cout<<"你还有"<<opportunities_senior<<"次机会"<<endl; 
			cin>>num;
			if(truenum==num)
			{
				cout<<"你太牛了!对了!"<<endl;
				pause();
				return 0;
			}
			else
			{
				/*cout<<"错了!"<<endl;
				opportunities_senior--;*/
				if(num<truenum)
				{
					cout<<"小了!"<<endl; 
					opportunities_senior--;
				}
				else
				{
					cout<<"大了!"<<endl;
					opportunities_senior--;
				}
			}
		}
		cout<<"没机会了!!自动退出!"<<endl;
		pause();
		return 0;
	}
	else
	{
		cout<<"------游戏开始------"<<endl; 
		srand((unsigned)time(NULL));
		truenum=rand() % 100;
		cout<<"开始吧!"<<endl;
		int opportunities_difficulty=3;
		while(opportunities_difficulty!=0)
		{
			cout<<"你还有"<<opportunities_difficulty<<"次机会"<<endl; 
			cin>>num;
			if(truenum==num)
			{
				cout<<"挖槽,困难竟然对了,啊啊啊啊啊啊啊!你太牛了!"<<endl;
				pause();
				pause();
				return 0;
			}
			else
			{
				/*cout<<"错了!"<<endl;
				opportunities_difficulty--;*/
				if(num<truenum)
				{
					cout<<"小了!"<<endl; 
					opportunities_difficulty--;
				}
				else
				{
					cout<<"大了!"<<endl;
					opportunities_difficulty--;
				}
			}
		}
		cout<<"没机会了!!自动退出!"<<endl;
		pause();
		return 0;
	}

	return 0;
}
/*THIS IS NOT COMPLINING OF GCC,PLEASE OPEN GCC COPLINING.
这是没有 使用GCC编译器编译过的,请打开GCC编译. 
LZGZS 
李子工作室
ben-lz
本-李子 
----THANK YOU----
----谢谢---- 
*/

(这是1.0β版本)

#include<iostream>
using namespace std;
void pause()
{
	cout<<"请按任意键退出本程序......"; 
	getch();
	exit (0);
}
int main()
{
	cout<<"欢迎来到由李子开发的猜数游戏1.0β(beta)版本!!!!!"<<" /"<<"(*^▽^*)/"<<endl<<"本次更新了教程!"<<" /"<<"(*^▽^*)/"<<endl;
	cout<<"你要不要玩呢???(Y/N)"<<endl;
	char choose;
	
	while(1)
	{
		cin>>choose;
		if(choose=='Y'||choose=='y')
		{
			break; 
		}
		else if(choose=='N'||choose=='n')
		{
			cout<<"好吧,ヾ(ToT)Bye~Bye~";
			exit (0); 
		}
		else
		  {
		  cout<<"无效选择!请重选!";
		  continue;
		   }
	}


	cout<<"好的!接下来,请选择级别"<<endl<<"1、萌新(教学)"<<endl<<"2、简单(10次机会,0~50内的数字)"<<endl<<"3、中等(8次机会,0~100内的数字)"<<endl<<"4、高级(7次机会,0~200内的数字)"<<endl<<"5、困难(只有3次机会,0~500内的数字)"<<endl;
	int choose1=0;
	int truenum=0;
	int num=0;
	cin>>choose1; 
	if(choose1==1)
	{
		cout<<"你进入了教学!"<<endl<<"这是一个猜数游戏,除去教学共4个级别,按0开始教学"<<endl;
		int u=0;
		cin>>u;
		 cout<<"------游戏开始------"<<endl; 
		srand((unsigned)time(NULL));
		truenum=rand() % 50;
		cout<<"现在已经生成了一个0~50的随机数,你需要将这个随机数输入,如果错误将提示,简单共10次机会。"<<endl; 
		cout<<"开始吧!"<<endl;
		int opportunities_easy=10; 
		while(opportunities_easy!=0)
		{
			cout<<"你还有"<<opportunities_easy<<"次机会"<<endl<<"你一定要注意机会,机会用光将自动退出!"; 
			cin>>num;
			if(truenum==num)
			{
				cout<<"你太牛了!对了!"<<"重新打开这个程序,体验一下吧!";
				pause();
				return 0;
			}
			else
			{
				/*cout<<"错了!";
				opportunities_easy--;*/
				if(num<truenum)
				{
					cout<<"小了!"<<endl<<"你猜的数比答案小,请猜一个大点的qwq"; 
					opportunities_easy--;
					cout<<"你的机会已经-1了!请注意机会!"<<endl; 
				}
				else
				{
					cout<<"大了!"<<"你猜的数比答案大,请猜一个小点的qwq"<<endl;
					opportunities_easy--;
					cout<<"你的机会已经-1了!请注意机会!"<<endl;
				}
			}
		}
		cout<<"没机会了!!自动退出!"<<endl<<"好吧,你太*了,再来一次教学吧!";
		pause();
		return 0;
		
	}
	else if(choose1==2)
	{
		cout<<"------游戏开始------"<<endl; 
		srand((unsigned)time(NULL));
		truenum=rand() % 50;
		cout<<"开始吧!"<<endl;
		int opportunities_easy=10; 
		while(opportunities_easy!=0)
		{
			cout<<"你还有"<<opportunities_easy<<"次机会"<<endl; 
			cin>>num;
			if(truenum==num)
			{
				cout<<"你太牛了!对了!";
				pause();
				return 0;
			}
			else
			{
				/*cout<<"错了!";
				opportunities_easy--;*/
				if(num<truenum)
				{
					cout<<"小了!"<<endl; 
					opportunities_easy--;
				}
				else
				{
					cout<<"大了!"<<endl;
					opportunities_easy--;
				}
			}
		}
		cout<<"没机会了!!自动退出!"<<endl;
		pause();
		return 0;
		} 
		else if(choose1==3)
		{
			cout<<"------游戏开始------"<<endl; 
			srand((unsigned)time(NULL));
			truenum=rand() % 100;
			cout<<"开始吧!"<<endl;
			int opportunities_secondary=8;
			while(opportunities_secondary!=0)
			{
				cout<<"你还有"<<opportunities_secondary<<"次机会"<<endl; 
				cin>>num;
				if(truenum==num)
				{
					cout<<"你太牛了!对了!"<<endl;
					return 0;
					pause();
				}
				else
				{
					/*cout<<"错了!"<<endl;
					opportunities_secondary--;*/
					if(num<truenum)
					{
						cout<<"小了!"<<endl; 
						opportunities_secondary--;
					}
					else
					{
						cout<<"大了!"<<endl;
						opportunities_secondary--;
					}
				}
			}
			cout<<"没机会了!!自动退出!"<<endl;
			pause();
			return 0;
		}
	else if(choose1==4)
	{
		
		cout<<"------游戏开始------"<<endl; 
		srand((unsigned)time(NULL));
		truenum=rand() % 100;
		cout<<"开始吧!"<<endl;
		int opportunities_senior=7;
		while(opportunities_senior!=0)
		{
			cout<<"你还有"<<opportunities_senior<<"次机会"<<endl; 
			cin>>num;
			if(truenum==num)
			{
				cout<<"你太牛了!对了!"<<endl;
				pause();
				return 0;
			}
			else
			{
				/*cout<<"错了!"<<endl;
				opportunities_senior--;*/
				if(num<truenum)
				{
					cout<<"小了!"<<endl; 
					opportunities_senior--;
				}
				else
				{
					cout<<"大了!"<<endl;
					opportunities_senior--;
				}
			}
		}
		cout<<"没机会了!!自动退出!"<<endl;
		pause();
		return 0;
	}
	else
	{
		cout<<"------游戏开始------"<<endl; 
		srand((unsigned)time(NULL));
		truenum=rand() % 100;
		cout<<"开始吧!"<<endl;
		int opportunities_difficulty=3;
		while(opportunities_difficulty!=0)
		{
			cout<<"你还有"<<opportunities_difficulty<<"次机会"<<endl; 
			cin>>num;
			if(truenum==num)
			{
				cout<<"挖槽,困难竟然对了,啊啊啊啊啊啊啊!你太牛了!"<<endl;
				pause();
				pause();
				return 0;
			}
			else
			{
				/*cout<<"错了!"<<endl;
				opportunities_difficulty--;*/
				if(num<truenum)
				{
					cout<<"小了!"<<endl; 
					opportunities_difficulty--;
				}
				else
				{
					cout<<"大了!"<<endl;
					opportunities_difficulty--;
				}
			}
		}
		cout<<"没机会了!!自动退出!"<<endl;
		pause();
		return 0;
	}

	return 0;
}
/*THIS IS NOT COMPLINING OF GCC,PLEASE OPEN GCC COPLINING.
这是没有 使用GCC编译器编译过的,请打开GCC编译. 
LZGZS 
李子工作室
ben-lz
本-李子 
----THANK YOU----
----谢谢---- 
*/

PS:这个可以使用Dev-cpp编译,我用的是Dev-cpp5.9.2版,如用VS或VC[++],可以把using namespace std;删掉,可编译,可运行,如有不足,请多多指教!

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值