扫雷游戏代码

#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

void Start();
void GetResults();

int i, j, life, maxrand,mixrand;
char c;

void Start() {
	i = 0;
	j = 0;
	life = 0;
	maxrand = 6;
	mixrand = 0;
	
	cout << "请选择难度:\n"; 
	cout << "1 : 简单 (0-120)\n";
	cout << "2 : 一般 (0-105)\n";
	cout << "3 : 普通 (0-90)\n";
	cout << "4 : 中等 (0-75)\n";
	cout << "5 : 偏难 (0-60)\n";
	cout << "6 : 困难 (0-45)\n";
	cout << "7 : 终极 (0-30)\n";
	cout << "8 : 地狱 (0-15)\n";
	cout << "输入其他内容则会退出\n";
	c = 30;

	cin >> c;                   
	cout << "\n";

	switch (c) {
		case '8':
			maxrand = 15;  
			break;
		case '7':
			maxrand = 30;
			break;
		case '6':
			maxrand = 45;
			break;
		case '5':
			maxrand = 60;
			break;
		case '4':
			maxrand = 75;
			break;
		case '3':
			maxrand = 90;
			break;
		case '2':
			maxrand = 105;
			break;
		case '1':
			maxrand = 120;
			break;
		default:
			exit(0);
		break;
	}

	life = 9+maxrand/15;         
	srand((unsigned)time(NULL)); 
	j = rand() % (maxrand-2)+1;  
	GetResults();
}

void GetResults() {
	if (life <= 0) { 
		cout << "恭喜你,你赢了!\n\n\n\n\n\n";
		Start();
	}

	cout << "请输入数字: \n";
	cin >> i;
	
	if((i>=maxrand) || (i<=mixrand)) { 
		cout << "错误: 请输入"<<mixrand<<"到 " << maxrand<<"之间的数字\n";
		GetResults();
	}

	if(i == j) {
		cout << "很遗憾,你踩雷了!\n\n\n\n\n\n"; 
		Start();
	} else if(i>j) {
		maxrand=i;
		life = life - 1;
		cout<<"请输入"<<mixrand<<"到 " << maxrand<<"之间的数字\n";
		cout << "你还要走" << life << "步\n\n";
		GetResults();
	} else if(i<j) {
		mixrand=i;
		life = life - 1;
		cout<<"请输入"<<mixrand<<"到 " << maxrand<<"之间的数字\n";
		cout << "你还要走" << life << "步\n\n";
		GetResults();
	}
}

int main() {
	cout << "** 杨式子工作室出品 **\n";
	cout << "欢迎来到[扫雷]游戏。\n";
	cout << "选择难度后,把数字告诉我,\n";
	cout << "我会告诉你有没有踩雷哦!\n\n";
	Start();
	return 0;
}

希望对大家有所帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安卓 扫雷源码 添加重新开始按钮支持 Android studio ====================================== Risky Project Location: ----------------------- The tools *should* handle project locations in any directory. However, due to bugs, placing projects in directories containing spaces in the path, or characters like ", ' and &, have had issues. We're working to eliminate these bugs, but to save yourself headaches you may want to move your project to a location where this is not a problem. D:\Program Files\android_s_workplace\terrysaolei - Ignored Files: -------------- The following files were *not* copied into the new Gradle project; you should evaluate whether these are still needed in your project and if so manually move them: * ic_launcher-web.png * proguard-project.txt Moved Files: ------------ Android Gradle projects use a different directory structure than ADT Eclipse projects. Here's how the projects were restructured: * AndroidManifest.xml => app\src\main\AndroidManifest.xml * assets\ => app\src\main\assets * res\ => app\src\main\res\ * src\ => app\src\main\java\ Next Steps: ----------- You can now build the project. The Gradle project needs network connectivity to download dependencies. Bugs: ----- If for some reason your project does not build, and you determine that it is due to a bug or limitation of the Eclipse to Gradle importer, please file a bug at http://b.android.com with category Component-Tools. (This import summary is for your information only, and can be deleted after import once you are satisfied with the results.)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值