diff --git a/as2/ex2/container.cpp b/as2/ex2/container.cpp index 620712e..4f1719c 100644 --- a/as2/ex2/container.cpp +++ b/as2/ex2/container.cpp @@ -1,7 +1,9 @@ //======================= // container.cpp //======================= +#include "container.h" +using namespace std; // default constructor initialise the inventory as empty container::container() { @@ -38,7 +40,7 @@ void container::display() //use heal bool container::useHeal() { - 2_???????? + numOfHeal--; return 1; // use heal successfully } diff --git a/as2/ex2/container.h b/as2/ex2/container.h index a98dc00..33e27be 100644 --- a/as2/ex2/container.h +++ b/as2/ex2/container.h @@ -5,9 +5,11 @@ // The so-called inventory of a player in RPG games // contains two items, heal and magic water -1_????????????? // Conditional compilation +#ifndef _CONTAINER // Conditional compilation #define _CONTAINER +#include + class container // Inventory { protected: diff --git a/as2/ex2/container.h.gch b/as2/ex2/container.h.gch new file mode 100644 index 0000000..0236601 Binary files /dev/null and b/as2/ex2/container.h.gch differ diff --git a/as2/ex2/main.cpp b/as2/ex2/main.cpp index 0a60ef9..8471c8e 100644 --- a/as2/ex2/main.cpp +++ b/as2/ex2/main.cpp @@ -97,13 +97,13 @@ int main() { system("cls"); cout<bag.set(this->bag.nOfHeal() + p.bag.nOfHeal(), this->bag.nOfMW() + p.bag.nOfMW()); // set the character's bag, get opponent's items } @@ -99,7 +102,7 @@ void player::showRole() // display character's job -4_?????????????? +void showinfo(player &p1, player &p2) { system("cls"); cout<<"##############################################################"< #include // use for setting field width #include // use for generating random factor +#include #include "container.h" enum job {sw, ar, mg}; /* define 3 jobs by enumerate type @@ -22,7 +24,8 @@ class player protected: int HP, HPmax, MP, MPmax, AP, DP, speed, EXP, LV; // General properties of all characters - string name; // character name +protected: + std::string name; // character name job role; /* character's job, one of swordman, archer and mage, as defined by the enumerate type */ container bag; // character's inventory diff --git a/as2/ex2/player.h.gch b/as2/ex2/player.h.gch new file mode 100644 index 0000000..a08ba5b Binary files /dev/null and b/as2/ex2/player.h.gch differ diff --git a/as2/ex2/swordsman.cpp b/as2/ex2/swordsman.cpp index 67a1fba..44c266f 100644 --- a/as2/ex2/swordsman.cpp +++ b/as2/ex2/swordsman.cpp @@ -1,7 +1,11 @@ //======================= // swordsman.cpp //======================= - +#include "swordsman.h" +#include // use for setting field width +#include // use for generating random factor +#include +using namespace std; // constructor. default values don't need to be repeated here swordsman::swordsman(int lv_in, string name_in) { diff --git a/as2/ex2/swordsman.h b/as2/ex2/swordsman.h index b7df1d1..46be57d 100644 --- a/as2/ex2/swordsman.h +++ b/as2/ex2/swordsman.h @@ -4,12 +4,12 @@ // Derived from base class player // For the job Swordsman - +#include #include "player.h" -class swordsman : 5_????????? // subclass swordsman publicly inherited from base player +class swordsman : public player // subclass swordsman publicly inherited from base player { public: - swordsman(int lv_in=1, string name_in="Not Given"); + swordsman(int lv_in=1, std::string name_in="Not Given"); // constructor with default level of 1 and name of "Not given" void isLevelUp(); bool attack (player &p); diff --git a/as2/ex2/swordsman.h.gch b/as2/ex2/swordsman.h.gch new file mode 100644 index 0000000..4504020 Binary files /dev/null and b/as2/ex2/swordsman.h.gch differ