`
include
include
include
using namespace std;
class Game {
public:
Game() {
this->energy = this->energy2 = 0;
this->HP = this->HP2 = 100;
this->round = 1;
}
void start() {
cout << "Welcome to magic fight!" << endl;
string command;
random_device r;
//用于获取随机数种子
mt19937 gen(r());
//以 rd() 作为种子初始化 Mersenne Twister 生成器
uniform_real_distribution<> dis(0.0, 1.0);
//创建一个均匀分布范围 [0.0, 1.0)
while (true) {
int command2;
if (energy2 == 0) {
command2 = int(dis(gen) * 10000) % 2 + 1;
} else {
command2 = int(dis(gen) * 10000) % 3 + 1;
}
signal:
menu();
cin >> command;
cout << "enemy:" << command2 << endl;
if (command2 == 1) {
this->energy2++;
}
if (command == "1") {
this->energy++;
if (command2 == 3) {
this->HP -= 5;
}
} else if (command == "2") {
//不能连续三回合使用defend
} else if (command == "3" && this->energy != 0) {
this->energy --;
if (command2 == 1) {
this->HP2 -= 5;
}
} else if (command == "4") {
cout << "See you next time!" << endl;
break;
} else {
help();
goto signal;
}
cout << "your hp:" << this->HP << endl;
cout << "enemy hp:" << this->HP2 << endl;
if (HP == 0) {
cout << "you lost!" << endl;
break;
}
if (HP2 == 0) {
cout << "you win!!!" << endl;
break;
}
}
}
private:
int round;//回合数
int HP;//your blood amount
int HP2;//enemy's blood amount
int energy;//how many energy you own
int energy2;
void menu() {
cout << "1.energy\n";
cout << "2.defend\n";
cout << "3.combat\n";
cout << "4.exit\n";
cout << "please choose a number" << endl;
}
void help() {
cout << "You cannot do that,maybe you need some help" << endl;
}
};
int main() {
Game game;
game.start();
return 0;
}
`
希望这不是一个短命游戏,希望我能把代码写的很长很长