C++太难?这款游戏告诉你,C++可以很简单!

别想歪了,是我们自己做游戏哦~
先不告诉你游戏是什么,我们先来做做看

// 引入头文件,构建基本框架
#include <iostream>
#include <stdlib.h> 
#include <time.h> 
using namespace std;
//选择游戏难度
int choose_level(){
	int level;
	cout << "Please choose the Game-Level:" << endl;
	cout << "1.Easy (life:4, max number:20)" << endl;
	cout << "2.Normal (life:5, max number:50)" << endl;
	cout << "3.Medium (life:6, max number:100)" << endl;
	cout << "4.Hard (life:7, max number:200)" << endl;
	cout << "5.Expert (life:8, max number:500)" << endl;
	cout << "6.Devil (life: 20, max number:1000000)" << endl;
	cout << "7.Customize by yourself (life: UNKNOWN, max number: UNKNOWN)" << endl;
	cout << ">>> ";
	cin >> level;
	return level;
}
// 游戏主体
int game(int l, int mn){
	srand((int)time(NULL));
	int num = rand() % mn;
//	cout << num << endl;
	int tmp;
	cout << "I'm ready~ Guess now!" << endl << endl;;
	for (int i = 0; i < l; i++){
		cout << "input number here >>> ";
		cin >> tmp;
		if (tmp > num){
			cout << "Too Big!" << endl;
		}
		else if (tmp < num){
			cout << "Too Small!" << endl;
		}
		else{
			cout << "Exactly! You got it!" << endl;
			return 0;
		}
		cout << endl;
	}
	cout << "You do not have any life! " << endl;
	cout << "The right number was: " << num << endl; 
	return 1;
}
//main主函数
int main(){
	int life, maxnum;
	switch(choose_level()){
		case 1:
			life = 4;
			maxnum = 20;
			break;
		case 2:
			life = 5;
			maxnum = 50;
			break;
		case 3:
			life = 6;
			maxnum = 100;
			break;
		case 4:
			life = 7;
			maxnum = 200;
			break;
		case 5:
			life = 8;
			maxnum = 500;
			break;
		case 6:
			life = 20;
			maxnum = 1000000;
			break;
		case 7:
			cout << "Customize life value:";
			cin >> life;
			cout << "Customize max number:";
			cin >> maxnum;
			break;
		default:
			life = 0;
			maxnum = 0; 
			cout << "Please input the right level! " << endl;
	}
//	cout << life << " " << maxnum;
	if (life != 0){
		game(life, maxnum);
	}
	return 0;
}

可以直接复制粘贴到devcpp里运行哦~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值