#include<iostream>
using namespace std;
class hero
{
public:
hero();//基础属性
hero(int w = 80, int f = 800) :defense(w), bas(f) {}
int jieshu();
int judge();
int jineng();
int blood;
int c;
int bas;
int defense;
};
hero::hero() {
defense = 200;
bas = 3200;
};
int hero::judge() {
if (defense <= 0) {
defense = 0;
blood = bas;
}
else blood = bas + defense;
return 0;
}
int hero::jineng()
{
char t;
cout << "请输入" << endl;
cin >> t;
if (t == 'a')
blood = blood - 340;
defense = defense - 40;
if (t == 'b')
blood = blood - 420;
defense = defense - 30;
if (t == 'c')
blood = blood - 520;
defense = defense - 60;
return 0;
}
int hero::jieshu()
{
if (blood <= 0) {
cout << "game over" << endl;
c = 1;
}
if (blood > 0) {
c = 0;
}
;
return 0;
};
class herox :public hero
{
public:
int beidong()
{
if (blood % 50 == 0)
{
defense = defense + 230;
cout << "b护盾增加230" << endl;
}
else defense = defense;
return 0;
}
};
int main()
{
int n = 0;
int c;
hero a(300, 2400);
hero b(400, 6000);
a.judge();
b.judge();
cout << "a :" << a.blood << endl;
cout << "b :" << b.blood << endl;
for (n = 0; n <= 25; n++) {
a.judge();
b.judge();
a.jineng();
b.jineng();
//b.beidong();
a.jieshu();
b.jieshu();
if (a.c == 1) {
cout << "b is winer" << endl;
break;
}
else if (b.c == 1) {
cout << "a is winer" << endl;
break;
}
else {
cout << "a 血量剩余:" << a.blood << endl;
cout << "b 血量剩余:" << b.blood << endl;
}
if (a.c == 1 || b.c == 1) {
break;
}
else continue;
}
return 0;
}
这是一个使用C++编写的小型的双人对战回合制游戏,每名角色血量技能,被动,护盾等属性。当血量小于等于0时,游戏便会结束。