别想歪了,是我们自己做游戏哦~
先不告诉你游戏是什么,我们先来做做看
// 引入头文件,构建基本框架
#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里运行哦~