---------
This is the new look of the game (still plenty of work to do)
declarations.h
#include <iostream>#include <string>#include <vector>//declare the classesclass Person;class Weapon;class Person{public: // default constructor initialization Person( int healthMax = 10, int health = 10, int attack = 4, int defence = 5, int speed = 3, std::string name = "The enemy" ); void ShowStats() const; // show the person's stats (health, attack etc) -> enemy or player void ShowWeaponPack() const; // show the weapon pack void Attack( Person& target); // attack an enemy void RunAway(); // run away void DecreaseHealth( int damage, Person& target ); //decrease the player's health when he has been attacked std::vector <Weapon> weaponPack;private: std::string m_Name; int m_Level, m_Experience; int m_HealthMax, m_Health, m_Attack, m_Defence, m_Speed; };class Weapon{public: //default constructor Weapon( int power = 1, int accuracy = 80, std::string name = "Sea Sword" ); //"accuracy" = % std::string ReturnName() const; // return name (name ONLY) in a string int ReturnPower() const; int ReturnAccuracy() const; void showStats() const; // show all of the weapon's statsprivate: int m_Power, m_Accuracy; std::string m_Name;};
player.cpp
#include "declarations.h"using namespace std;Person::Person (int healthMax, int health, int attack, int defence, int speed, string name): m_Name( name ), m_HealthMax( healthMax ), m_Health( m_HealthMax ), m_Attack( attack ), m_Defence( defence ), m_Speed( speed ){ Weapon weapon1( 2, 90, "Broom stick" ); // create a default weapon for the player weaponPack.push_back( weapon1 ); // add the weapon in the weapon pack}void Person::ShowStats() const{ cout << m_Name << "'s stats:\n" << "Name: " << m_Name << "\n" << "Health: " << m_Health << " of " << m_HealthMax << "\n" << "Attack: " << m_Attack << "\n" << "Defence: " << m_Defence << "\n" <<"Speed: " << m_Speed << "\n\n" ;}void Person::DecreaseHealth( int damage, Person& target ) { damage -= m_Defence / 2; damage -= 2; m_Health -= damage; if (m_Health < 0) m_Health = 0; cout << m_Name << " has taken " << damage << " damage.\n" << m_Name << "'s health has become " << m_Health << ".\n\n" ;}void Person::Attack( Person& target ){ cout << m_Name << " attacks!" << "\n\n"; int damage = m_Attack * 2; target.DecreaseHealth( damage, target );}void Person::ShowWeaponPack() const{ if( weaponPack.size() == 0 ) cout << "You don't have any weapons!!" << "\n\n"; else { for( int i = 0; i < weaponPack.size(); i++) cout << "Your weaponPack has these weapons: " << "\n" << i + 1 << ". " << weaponPack.ReturnName() << " (" << "power = " << weaponPack.ReturnPower() << ", " << "accuracy = " << weaponPack.ReturnAccuracy() << ")" << "\n"; cout << "\n"; }}
weapon.cpp
#include "declarations.h"using namespace std;Weapon::Weapon( int power, int accuracy, std::string name):m_Power( power ), m_Accuracy( accuracy ), m_Name( name ){}string Weapon::ReturnName() const{ return m_Name;}int Weapon::ReturnPower() const{ return m_Power;}int Weapon::ReturnAccuracy() const{ return m_Accuracy;}
main
#include "declarations.h"using namespace std;int main(){ //default constructor //identifier( healthMax, health, attack, defence, speed, name ); Person player( 10, 10, 10, 10, 10, "Hyrule"); Person enemy( 100 ); player.Attack( enemy ); enemy.ShowStats(); player.ShowStats(); player.ShowWeaponPack(); system ("PAUSE"); return 0;}
Much better now :-)