You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
5.6 KiB

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <string>
#include <fstream>
using namespace std;
//<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0A3AC>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>
class game {
public:
char name[100]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string sex; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>
int sex_choice; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
void show();
};
void game::show() {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
cin >> name;
int tag = 1;
while (tag) {
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD>Ա<EFBFBD>:(0.<2E><> 1.Ů)<29><>" << endl;;
cin >> sex_choice;
switch (sex_choice) {
case 0:
sex = "<EFBFBD><EFBFBD>";
tag = 0;
break;
case 1:
sex = "Ů";
tag = 0;
break;
default:
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
break;
}
}
}
//game2<65><32><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ
class game2: public game {
public:
string race; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string occupation; //<2F><><EFBFBD><EFBFBD>ְҵ
int race_choice; //<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
int occupation_choice; //ְҵѡ<D2B5><D1A1>
void Rrace();
};
void game2::Rrace() { //<2F><>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ
int tag = 1;
while (tag) {
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壺0.<2E><><EFBFBD><EFBFBD> 1.<2E><><EFBFBD><EFBFBD> 2.<2E><><EFBFBD><EFBFBD> 3.<2E><><EFBFBD><EFBFBD> 4.Ԫ<><D4AA>" << endl;
cin >> race_choice;
switch (race_choice) {
case 0:
race = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
tag = 0;
break;
case 1:
race = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
tag = 0;
break;
case 2:
race = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
tag = 0;
break;
case 3:
race = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
tag = 0;
break;
case 4:
race = "Ԫ<EFBFBD><EFBFBD>";
tag = 0;
break;
default:
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
break;
}
}
while (1) {
switch (race_choice) {
case 1:
cout << "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ<EFBFBD><EFBFBD>0.<2E><>սʿ 1.ʥ<><CAA5>ʿ 2.<2E>̿<EFBFBD> 3.<2E><><EFBFBD><EFBFBD> 4.<2E><>˾ 5.<2E><>ʦ" << endl;
break;
case 2:
cout << "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ<EFBFBD><EFBFBD>2.<2E>̿<EFBFBD> 3.<2E><><EFBFBD><EFBFBD> 4.<2E><>˾ 5.<2E><>ʦ" << endl;
break;
case 3:
cout << "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ<EFBFBD><EFBFBD>0.<2E><>սʿ 3.<2E><><EFBFBD><EFBFBD> 4.<2E><>˾ " << endl;
break;
case 4:
cout << "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ<EFBFBD><EFBFBD>0.<2E><>սʿ 1.ʥ<><CAA5>ʿ 4.<2E><>˾ " << endl;
break;
case 5:
cout << "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְҵ<EFBFBD><EFBFBD>4.<2E><>˾ 5.<2E><>ʦ" << endl;
break;
}
cin >> occupation_choice;
if (race_choice == 0 && (occupation_choice >= 0 && occupation_choice <= 5))
break;
else if (race_choice == 1 && (occupation_choice > 1 && occupation_choice < 6))
break;
else if (race_choice == 2 && (occupation_choice == 0 || occupation_choice == 3 || occupation_choice == 4))
break;
else if (race_choice == 3 && (occupation_choice == 0 || occupation_choice == 1 || occupation_choice == 4))
break;
else if (race_choice == 4 && (occupation_choice > 3 && occupation_choice < 6))
break;
else
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
}
if (occupation_choice == 0)
occupation = "<EFBFBD><EFBFBD>սʿ";
if (occupation_choice == 1)
occupation = "ʥ<EFBFBD><EFBFBD>ʿ";
if (occupation_choice == 2)
occupation = "<EFBFBD>̿<EFBFBD>";
if (occupation_choice == 3)
occupation = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
if (occupation_choice == 4)
occupation = "<EFBFBD><EFBFBD>˾";
if (occupation_choice == 5)
occupation = "<EFBFBD><EFBFBD>ʦ";
}
class Attribute : public game2 { //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public:
int strength;//<2F><><EFBFBD><EFBFBD>
int agility;//<2F><><EFBFBD><EFBFBD>
int physical;//<2F><><EFBFBD><EFBFBD>
int intelligence;//<2F><><EFBFBD><EFBFBD>
int wisdom;//<2F>ǻ<EFBFBD>
int HP;//<2F><><EFBFBD><EFBFBD>ֵ
int MP;//ħ<><C4A7>ֵ
void output_attribute();//ȡ<><C8A1><EFBFBD><EFBFBD>ְҵ<D6B0><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void rad(int rand1, int rand2, int rand3, int rand4, int rand5);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
void Attribute::rad(int rand1, int rand2, int rand3, int rand4, int rand5) {
int sum;
srand((unsigned)time(NULL)); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
do {
strength = rand() % 10 + rand1;
agility = rand() % 10 + rand2;
physical = rand() % 10 + rand3;
intelligence = rand() % 10 + rand4;
wisdom = rand() % 10 + rand5;
sum = strength + agility + physical + intelligence + wisdom;
} while (sum != 100);//5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ100
HP = physical * 20;//<2F><><EFBFBD><EFBFBD>ֵΪ<D6B5><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>20<32><30>
MP = (wisdom + intelligence) * 10;//ħ<><C4A7>ֵΪ<D6B5><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǻ۵<C7BB>10<31><30>
}
void Attribute::output_attribute() { //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
if (occupation == "<EFBFBD><EFBFBD>սʿ")
rad(35, 15, 25, 5, 5);
if (occupation == "ʥ<EFBFBD><EFBFBD>ʿ")
rad(20, 10, 25, 15, 15);
if (occupation == "<EFBFBD>̿<EFBFBD>")
rad(15, 30, 15, 10, 15);
if (occupation == "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
rad(10, 35, 10, 5, 25);
if (occupation == "<EFBFBD><EFBFBD>˾")
rad(10, 25, 10, 30, 20);
if (occupation == "<EFBFBD><EFBFBD>ʦ")
rad(5, 15, 5, 15, 45);
}
class Battle : public Attribute {
public:
void fight(Attribute &me, Attribute &opponent);
};
void Battle::fight(Attribute &me, Attribute &opponent) {
cout << "ս<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>" << endl;
while (me.HP > 0 && opponent.HP > 0) {
int attack = rand() % me.strength;
int defense = rand() % opponent.agility;
int damage = max(0, attack - defense);
opponent.HP -= damage;
cout << me.name << " <20><><EFBFBD><EFBFBD> " << opponent.name << " <20><><EFBFBD><EFBFBD> " << damage << " <20><><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>" << endl;
if (opponent.HP <= 0) {
cout << opponent.name << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>" << endl;
break;
}
// <20><><EFBFBD><EFBFBD>
attack = rand() % opponent.strength;
defense = rand() % me.agility;
damage = max(0, attack - defense);
me.HP -= damage;
cout << opponent.name << " <20><><EFBFBD><EFBFBD> " << me.name << " <20><><EFBFBD><EFBFBD> " << damage << " <20><><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>" << endl;
if (me.HP <= 0) {
cout << me.name << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>" << endl;
break;
}
}
}
int main() {
srand((unsigned)time(NULL)); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Attribute player1, player2;
player1.show(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ɫ
player1.Rrace();
player1.output_attribute();
player2.show(); // <20><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>ɫ
player2.Rrace();
player2.output_attribute();
Battle battle;
battle.fight(player1, player2); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>ս
return 0;
}