基于控制台使用简单c++语言实现的打地鼠小游戏

基于控制台使用简单c++语言实现的打地鼠小游戏

#include <iostream>
using namespace std;
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include<conio.h>

int shuijishu()
{
	int i = 0;
	srand(time(NULL));
	i = rand() % 10;
	return i;
}
int caidan()
{
    loop:
	char c;
	cout << "欢迎来到打地鼠游戏世界" << endl;
	cout << "开始游戏【Y/N】" << endl;
	cin >> c;
	if (c == 'Y')
	{
		cout << "游戏开始";
	}
	else { goto loop; }
	return 0;
}
int youxi1()
{		
	
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|老鼠|    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;
	
}
int youxi2()
{

	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |老鼠|    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int youxi3()
{

	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |老鼠|" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int youxi4()
{

	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|老鼠|    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int youxi5()
{

	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |老鼠|    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int youxi6()
{

	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |老鼠|" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int youxi7()
{

	cout << "+----+----+----+" << endl;
	cout << "|老鼠|    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int youxi8()
{

	cout << "+----+----+----+" << endl;
	cout << "|    |老鼠|    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int youxi9()
{

	cout << "+----+----+----+" << endl;
	cout << "|    |    |老鼠|" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "|    |    |    |" << endl;
	cout << "+----+----+----+" << endl;
	cout << "小键盘1-9对应九宫格" << endl;
	return 0;

}
int main()
{
	int m=0,n=0,k=0;
	caidan();
	while (1)
	{
	    loop:
		system("cls");
		m = shuijishu();
		if (m == 1) {youxi1();}
		else if(m==2) { youxi2(); }
		else if(m==3) { youxi3(); }
		else if (m == 4) { youxi4(); }
		else if (m == 5) { youxi5(); }
		else if (m == 6) { youxi6(); }
		else if (m == 7) { youxi7(); }
		else if (m == 8) { youxi8(); }
		else if (m == 9) { youxi9(); }
		for (int q = 0; q < 100000; q++)
		{
			if (q == 99999) { break; }
			if (_kbhit())
			{
				cin >> n;
				if (m == n) { k++; 
				system("cls");
				goto loop;}
				else { break; }
			}
		}
		break;
	}
	cout << " 你输了,你个loser" << endl;
	cout <<"你的得分是" << k<<endl;
	system("pause");
	return 0;
}
  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值