概述
先点击左上方的“文件”,再点击“新建”,接着点击“项目”,就会有下面的样子:
再选Console,就会出现下面的样子:
接着选Jackpot,再点确定,C++就会打开一个mian,这时你运行就是了。
游戏意思:输入一个数字,杰克会告诉你太大了或太小了,直到猜中或次数用完。
懒的人可以复制下面的代码:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void Start();
void GetResults();
int i, j, life, maxrand;
char c;
void Start() {
i = 0;
j = 0;
life = 0;
maxrand = 6;
cout << "Select difficulty mode:n"; // the user has to select a difficutly level
cout << "1 : Easy (0-15)n";
cout << "2 : Medium (0-30)n";
cout << "3 : Difficult (0-50)n";
cout << "or type another key to quitn";
c = 30;
cin >> c; // read the user's choice
cout << "n";
switch (c) {
case '1':
maxrand = 15; // the random number will be between 0 and maxrand
break;
case '2':
maxrand = 30;
break;
case '3':
maxrand = 50;
break;
default:
exit(0);
break;
}
life = 5; // number of lifes of the player
srand((unsigned)time(NULL)); // init Rand() function
j = rand() % maxrand; // j get a random value between 0 and maxrand
GetResults();
}
void GetResults() {
if (life <= 0) { // if player has no more life then he loses
cout << "You lose !nn";
Start();
}
cout << "Type a number: n";
cin >> i;
if((i>maxrand) || (i<0)) { // if the user number isn't correct, restart
cout << "Error: number not between 0 and n" << maxrand;
GetResults();
}
if(i == j) {
cout << "YOU WIN!nn"; // the user found the secret number
Start();
} else if(i>j) {
cout << "Too BIGn";
life = life - 1;
cout << "Lives remaining: " << life << "nn";
GetResults();
} else if(i<j) {
cout << "Too SMALLn";
life = life - 1;
cout << "Lives remaining: " << life << "nn";
GetResults();
}
}
int main() {
cout << "** Jackpot game **n";
cout << "The goal of this game is to guess a number.n";
cout << "Jackpot will tell you if the number is too big or toon";
cout << "small compared to the secret number to find.nn";
Start();
return 0;
}
最后
以上就是斯文黑米为你收集整理的Dev c++自带小游戏的全部内容,希望文章能够帮你解决Dev c++自带小游戏所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复