From 7f5eeb3e4d17ddebd92bd9a2fa46ad5e268dd07b Mon Sep 17 00:00:00 2001 From: IoTcat Date: Wed, 10 Apr 2019 18:16:40 +0800 Subject: [PATCH] find change --- as2/ex2/archer.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++ as2/ex2/archer.h | 20 ++++++ as2/ex2/mage.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++ as2/ex2/mage.h | 20 ++++++ 4 files changed, 350 insertions(+) create mode 100644 as2/ex2/archer.cpp create mode 100644 as2/ex2/archer.h create mode 100644 as2/ex2/mage.cpp create mode 100644 as2/ex2/mage.h diff --git a/as2/ex2/archer.cpp b/as2/ex2/archer.cpp new file mode 100644 index 0000000..67a1fba --- /dev/null +++ b/as2/ex2/archer.cpp @@ -0,0 +1,155 @@ +//======================= +// swordsman.cpp +//======================= + +// constructor. default values don't need to be repeated here +swordsman::swordsman(int lv_in, string name_in) +{ + role=sw; // enumerate type of job + LV=lv_in; + name=name_in; + + // Initialising the character's properties, based on his level + HPmax=150+8*(LV-1); // HP increases 8 point2 per level + HP=HPmax; + MPmax=75+2*(LV-1); // MP increases 2 points per level + MP=MPmax; + AP=25+4*(LV-1); // AP increases 4 points per level + DP=25+4*(LV-1); // DP increases 4 points per level + speed=25+2*(LV-1); // speed increases 2 points per level + + playerdeath=0; + EXP=LV*LV*75; + bag.set(lv_in, lv_in); +} + +void swordsman::isLevelUp() +{ + if(EXP>=LV*LV*75) + { + LV++; + AP+=4; + DP+=4; + HPmax+=8; + MPmax+=2; + speed+=2; + cout<p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100 + { + HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance + cout<0)&&(HP>(int)((1.0*p.AP/DP)*p.AP*0.5))) + // AI's HP cannot sustain 3 rounds && not too lavish && still has heal && won't be killed in next round + { + useHeal(); + } + else + { + if(MP>=40 && HP>0.5*HPmax && rand()%100<=30) + // AI has enough MP, it has 30% to make special attack + { + specialatt(p); + p.isDead(); // check whether player is dead + } + else + { + if (MP<40 && HP>0.5*HPmax && bag.nOfMW()) + // Not enough MP && HP is safe && still has magic water + { + useMW(); + } + else + { + attack(p); // normal attack + p.isDead(); + } + } + } +} + diff --git a/as2/ex2/archer.h b/as2/ex2/archer.h new file mode 100644 index 0000000..b7df1d1 --- /dev/null +++ b/as2/ex2/archer.h @@ -0,0 +1,20 @@ +//======================= +// swordsman.h +//======================= + +// Derived from base class player +// For the job Swordsman + +#include "player.h" +class swordsman : 5_????????? // subclass swordsman publicly inherited from base player +{ +public: + swordsman(int lv_in=1, string name_in="Not Given"); + // constructor with default level of 1 and name of "Not given" + void isLevelUp(); + bool attack (player &p); + bool specialatt(player &p); + /* These three are derived from the pure virtual functions of base class + The definition of them will be given in this subclass. */ + void AI(player &p); // Computer opponent +}; diff --git a/as2/ex2/mage.cpp b/as2/ex2/mage.cpp new file mode 100644 index 0000000..67a1fba --- /dev/null +++ b/as2/ex2/mage.cpp @@ -0,0 +1,155 @@ +//======================= +// swordsman.cpp +//======================= + +// constructor. default values don't need to be repeated here +swordsman::swordsman(int lv_in, string name_in) +{ + role=sw; // enumerate type of job + LV=lv_in; + name=name_in; + + // Initialising the character's properties, based on his level + HPmax=150+8*(LV-1); // HP increases 8 point2 per level + HP=HPmax; + MPmax=75+2*(LV-1); // MP increases 2 points per level + MP=MPmax; + AP=25+4*(LV-1); // AP increases 4 points per level + DP=25+4*(LV-1); // DP increases 4 points per level + speed=25+2*(LV-1); // speed increases 2 points per level + + playerdeath=0; + EXP=LV*LV*75; + bag.set(lv_in, lv_in); +} + +void swordsman::isLevelUp() +{ + if(EXP>=LV*LV*75) + { + LV++; + AP+=4; + DP+=4; + HPmax+=8; + MPmax+=2; + speed+=2; + cout<p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100 + { + HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance + cout<0)&&(HP>(int)((1.0*p.AP/DP)*p.AP*0.5))) + // AI's HP cannot sustain 3 rounds && not too lavish && still has heal && won't be killed in next round + { + useHeal(); + } + else + { + if(MP>=40 && HP>0.5*HPmax && rand()%100<=30) + // AI has enough MP, it has 30% to make special attack + { + specialatt(p); + p.isDead(); // check whether player is dead + } + else + { + if (MP<40 && HP>0.5*HPmax && bag.nOfMW()) + // Not enough MP && HP is safe && still has magic water + { + useMW(); + } + else + { + attack(p); // normal attack + p.isDead(); + } + } + } +} + diff --git a/as2/ex2/mage.h b/as2/ex2/mage.h new file mode 100644 index 0000000..b7df1d1 --- /dev/null +++ b/as2/ex2/mage.h @@ -0,0 +1,20 @@ +//======================= +// swordsman.h +//======================= + +// Derived from base class player +// For the job Swordsman + +#include "player.h" +class swordsman : 5_????????? // subclass swordsman publicly inherited from base player +{ +public: + swordsman(int lv_in=1, string name_in="Not Given"); + // constructor with default level of 1 and name of "Not given" + void isLevelUp(); + bool attack (player &p); + bool specialatt(player &p); + /* These three are derived from the pure virtual functions of base class + The definition of them will be given in this subclass. */ + void AI(player &p); // Computer opponent +};