master
IoTcat 5 years ago
parent e83e9bb1b5
commit a67d20706d
  1. 4
      as2/ex2/container.cpp
  2. 4
      as2/ex2/container.h
  3. BIN
      as2/ex2/container.h.gch
  4. 4
      as2/ex2/main.cpp
  5. 9
      as2/ex2/player.cpp
  6. 5
      as2/ex2/player.h
  7. BIN
      as2/ex2/player.h.gch
  8. 6
      as2/ex2/swordsman.cpp
  9. 6
      as2/ex2/swordsman.h
  10. BIN
      as2/ex2/swordsman.h.gch

@ -1,7 +1,9 @@
//======================= //=======================
// container.cpp // container.cpp
//======================= //=======================
#include "container.h"
using namespace std;
// default constructor initialise the inventory as empty // default constructor initialise the inventory as empty
container::container() container::container()
{ {
@ -38,7 +40,7 @@ void container::display()
//use heal //use heal
bool container::useHeal() bool container::useHeal()
{ {
2_???????? numOfHeal--;
return 1; // use heal successfully return 1; // use heal successfully
} }

@ -5,9 +5,11 @@
// The so-called inventory of a player in RPG games // The so-called inventory of a player in RPG games
// contains two items, heal and magic water // contains two items, heal and magic water
1_????????????? // Conditional compilation #ifndef _CONTAINER // Conditional compilation
#define _CONTAINER #define _CONTAINER
#include <iostream>
class container // Inventory class container // Inventory
{ {
protected: protected:

Binary file not shown.

@ -97,13 +97,13 @@ int main()
{ {
system("cls"); system("cls");
cout<<endl<<setw(50)<<"GAME OVER"<<endl; cout<<endl<<setw(50)<<"GAME OVER"<<endl;
6_??????????? // player is dead, program is getting to its end, what should we do here? delete human;//6_??????????? // player is dead, program is getting to its end, what should we do here?
system("pause"); system("pause");
return 0; return 0;
} }
} }
} }
7_????????? // You win, program is getting to its end, what should we do here? delete human;//7_????????? // You win, program is getting to its end, what should we do here?
system("cls"); system("cls");
cout<<"Congratulations! You defeated all opponents!!"<<endl; cout<<"Congratulations! You defeated all opponents!!"<<endl;
system("pause"); system("pause");

@ -2,7 +2,9 @@
// player.cpp // player.cpp
//======================= //=======================
#include "player.h"
using namespace std;
// character's HP and MP resume // character's HP and MP resume
void player::reFill() void player::reFill()
{ {
@ -21,7 +23,7 @@ void player::isDead()
{ {
if(HP<=0) // HP less than 0, character is dead if(HP<=0) // HP less than 0, character is dead
{ {
cout<<name<<" is Dead." <<endl; cout<< name <<" is Dead." <<endl;
system("pause"); system("pause");
playerdeath=1; // give the label of death value 1 playerdeath=1; // give the label of death value 1
} }
@ -74,7 +76,8 @@ void player::transfer(player &p)
{ {
cout<<name<<" got"<<p.bag.nOfHeal()<<" Heal, and "<<p.bag.nOfMW()<<" Magic Water."<<endl; cout<<name<<" got"<<p.bag.nOfHeal()<<" Heal, and "<<p.bag.nOfMW()<<" Magic Water."<<endl;
system("pause"); system("pause");
3_???????????
this->bag.set(this->bag.nOfHeal() + p.bag.nOfHeal(), this->bag.nOfMW() + p.bag.nOfMW());
// set the character's bag, get opponent's items // set the character's bag, get opponent's items
} }
@ -99,7 +102,7 @@ void player::showRole()
// display character's job // display character's job
4_?????????????? void showinfo(player &p1, player &p2)
{ {
system("cls"); system("cls");
cout<<"##############################################################"<<endl; cout<<"##############################################################"<<endl;

@ -8,8 +8,10 @@
#ifndef _PLAYER #ifndef _PLAYER
#define _PLAYER #define _PLAYER
#include <iostream>
#include <iomanip> // use for setting field width #include <iomanip> // use for setting field width
#include <time.h> // use for generating random factor #include <time.h> // use for generating random factor
#include <string>
#include "container.h" #include "container.h"
enum job {sw, ar, mg}; /* define 3 jobs by enumerate type enum job {sw, ar, mg}; /* define 3 jobs by enumerate type
@ -22,7 +24,8 @@ class player
protected: protected:
int HP, HPmax, MP, MPmax, AP, DP, speed, EXP, LV; int HP, HPmax, MP, MPmax, AP, DP, speed, EXP, LV;
// General properties of all characters // 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, job role; /* character's job, one of swordman, archer and mage,
as defined by the enumerate type */ as defined by the enumerate type */
container bag; // character's inventory container bag; // character's inventory

Binary file not shown.

@ -1,7 +1,11 @@
//======================= //=======================
// swordsman.cpp // swordsman.cpp
//======================= //=======================
#include "swordsman.h"
#include <iomanip> // use for setting field width
#include <ctime> // use for generating random factor
#include <stdlib.h>
using namespace std;
// constructor. default values don't need to be repeated here // constructor. default values don't need to be repeated here
swordsman::swordsman(int lv_in, string name_in) swordsman::swordsman(int lv_in, string name_in)
{ {

@ -4,12 +4,12 @@
// Derived from base class player // Derived from base class player
// For the job Swordsman // For the job Swordsman
#include <iostream>
#include "player.h" #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: 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" // constructor with default level of 1 and name of "Not given"
void isLevelUp(); void isLevelUp();
bool attack (player &p); bool attack (player &p);

Binary file not shown.
Loading…
Cancel
Save