diff --git a/新文件1.cpp b/新文件1.cpp new file mode 100644 index 0000000..50c0552 --- /dev/null +++ b/新文件1.cpp @@ -0,0 +1,222 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +//ÏȽ¨Á¢»ùÀ࣬¼Ç¼ÐÕÃûÐÔ±ð +class game { + public: + char name[100]; //¶¨ÒåÐÕÃû + string sex; //¶¨ÒåÐÔ±ð + int sex_choice; //ÕûÐÍÊý¾Ý¶ÔÐÔ±ð½øÐÐÑ¡Ôñ + void show(); +}; + +void game::show() { + cout << "ÇëÊäÈëÄúËùÒª´´½¨µÄ½ÇÉ«ÐÕÃû£º"; + cin >> name; + int tag = 1; + while (tag) { + cout << "ÇëÑ¡Ôñ½ÇÉ«ÐÔ±ð:(0.ÄÐ 1.Å®)£º" << endl;; + cin >> sex_choice; + switch (sex_choice) { + case 0: + sex = "ÄÐ"; + tag = 0; + break; + case 1: + sex = "Å®"; + tag = 0; + break; + default: + cout << "ÊäÈë´íÎó£¬ÇëÖØÐÂÊäÈë" << endl; + break; + } + } +} +//game2Àà¼Ç¼ÖÖ×åºÍÖ°Òµ + +class game2: public game { + public: + string race; //¶¨ÒåÖÖ×å + string occupation; //¶¨ÒåÖ°Òµ + int race_choice; //ÖÖ×åÑ¡Ôñ + int occupation_choice; //ְҵѡÔñ + void Rrace(); +}; + +void game2::Rrace() { //³ÉÔ±º¯ÊýÑ¡ÔñÖÖ×åºÍÖ°Òµ + int tag = 1; + while (tag) { + cout << "ÇëÑ¡ÔñÖÖ×壺0.ÈËÀà 1.¾«Áé 2.ÊÞÈË 3.°«ÈË 4.ÔªËØ" << endl; + cin >> race_choice; + switch (race_choice) { + case 0: + race = "ÈËÀà"; + tag = 0; + break; + case 1: + race = "¾«Áé"; + tag = 0; + break; + case 2: + race = "ÊÞÈË"; + tag = 0; + break; + case 3: + race = "°«ÈË"; + tag = 0; + break; + case 4: + race = "ÔªËØ"; + tag = 0; + break; + default: + cout << "ÊäÈë´íÎó£¬ÇëÖØÐÂÊäÈ룡" << endl; + break; + } + } + while (1) { + switch (race_choice) { + case 1: + cout << "Ñ¡ÔñÄúµÄÖ°Òµ£º0.¿ñսʿ 1.Ê¥ÆïÊ¿ 2.´Ì¿Í 3.ÁÔÊÖ 4.¼À˾ 5.Î×ʦ" << endl; + break; + case 2: + cout << "Ñ¡ÔñÄúµÄÖ°Òµ£º2.´Ì¿Í 3.ÁÔÊÖ 4.¼À˾ 5.Î×ʦ" << endl; + break; + case 3: + cout << "Ñ¡ÔñÄúµÄÖ°Òµ£º0.¿ñսʿ 3.ÁÔÊÖ 4.¼À˾ " << endl; + break; + case 4: + cout << "Ñ¡ÔñÄúµÄÖ°Òµ£º0.¿ñսʿ 1.Ê¥ÆïÊ¿ 4.¼À˾ " << endl; + break; + case 5: + cout << "Ñ¡ÔñÄúµÄÖ°Òµ£º4.¼À˾ 5.Î×ʦ" << 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 << "ÊäÈë´íÎó£¬ÇëÖØÐÂÊäÈë" << endl; + } + if (occupation_choice == 0) + occupation = "¿ñսʿ"; + if (occupation_choice == 1) + occupation = "Ê¥ÆïÊ¿"; + if (occupation_choice == 2) + occupation = "´Ì¿Í"; + if (occupation_choice == 3) + occupation = "ÁÔÊÖ"; + if (occupation_choice == 4) + occupation = "¼À˾"; + if (occupation_choice == 5) + occupation = "Î×ʦ"; +} + + +class Attribute : public game2 { //¶¨ÒåÖÖ×åÀàµÄÅÉÉúÀ࣬Éú³ÉËæ»úÊôÐÔ + public: + int strength;//Á¦Á¿ + int agility;//Ãô½Ý + int physical;//ÌåÁ¦ + int intelligence;//ÖÇÁ¦ + int wisdom;//ÖÇ»Û + int HP;//ÉúÃüÖµ + int MP;//ħ·¨Öµ + void output_attribute();//È¡¾öÓÚÖ°ÒµµÄÊôÐÔÈ·¶¨º¯Êý + void rad(int rand1, int rand2, int rand3, int rand4, int rand5);//Ëæ»úÉú³ÉÊýº¯Êý +}; + +void Attribute::rad(int rand1, int rand2, int rand3, int rand4, int rand5) { + int sum; + srand((unsigned)time(NULL)); //Ëæ»úÊôÐÔÖµ + 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ÏîÊôÐÔ×ÜֵΪ100 + HP = physical * 20;//ÉúÃüֵΪÌåÁ¦µÄ20±¶ + MP = (wisdom + intelligence) * 10;//ħ·¨ÖµÎªÖÇÁ¦ÓëÖǻ۵Ä10±¶ + +} + +void Attribute::output_attribute() { //³õʼÊôÐÔ + if (occupation == "¿ñսʿ") + rad(35, 15, 25, 5, 5); + if (occupation == "Ê¥ÆïÊ¿") + rad(20, 10, 25, 15, 15); + if (occupation == "´Ì¿Í") + rad(15, 30, 15, 10, 15); + if (occupation == "ÁÔÊÖ") + rad(10, 35, 10, 5, 25); + if (occupation == "¼À˾") + rad(10, 25, 10, 30, 20); + if (occupation == "Î×ʦ") + 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 << "Õ½¶·¿ªÊ¼£¡" << 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 << " ¹¥»÷ " << opponent.name << " Ôì³É " << damage << " µãÉ˺¦£¡" << endl; + + if (opponent.HP <= 0) { + cout << opponent.name << " ±»»÷°ÜÁË£¡" << endl; + break; + } + + // ·´»÷ + attack = rand() % opponent.strength; + defense = rand() % me.agility; + damage = max(0, attack - defense); + me.HP -= damage; + cout << opponent.name << " ·´»÷ " << me.name << " Ôì³É " << damage << " µãÉ˺¦£¡" << endl; + + if (me.HP <= 0) { + cout << me.name << " ±»»÷°ÜÁË£¡" << endl; + break; + } + } +} + +int main() { + srand((unsigned)time(NULL)); // ³õʼ»¯Ëæ»úÊýÖÖ×Ó + + Attribute player1, player2; + player1.show(); // ´´½¨µÚÒ»¸ö½ÇÉ« + player1.Rrace(); + player1.output_attribute(); + + player2.show(); // ´´½¨µÚ¶þ¸ö½ÇÉ« + player2.Rrace(); + player2.output_attribute(); + + Battle battle; + battle.fight(player1, player2); // Á½¸ö½ÇÉ«¶ÔÕ½ + + return 0; +} \ No newline at end of file