Hello,
I'm trying to make a simple text console RPG in C++.
So far I have created player and enemy class. It compiles fine btw.
The header file:
declarations.h
#include <iostream>
#include <string>
#include <vector>
class Player
{
public:
// default constructor initialization
Player (std::string name = "Fro", int healthMax = 10, int health = 10, int attack = 4, int defence = 4, int speed = 3);
void ShowStats() const; // show the player's stats (health, attack etc)
void Attack(); // attack an enemy
void RunAway(); // run away
void DecreaseHealth (int damage); //decrease the player's health when he has been attacked
private:
std::string m_Name;
int m_Level, m_Experience;
int m_HealthMax, m_Health, m_Attack, m_Defence, m_Speed;
//needs a vector of Items
};
class Enemy
{
public:
void ShowStats() const;
void Attack();
void RunAway();
void DecreaseHealth();
private:
int m_Level;
int m_HealthMax, m_Health, m_Attack, m_Defence, m_Speed;
};
player.cpp -> Where I put functions for player and enemy (thinking of putting enemy in another file)
#include "declarations.h"
using namespace std;
Player::Player (string name, int healthMax, int health, int attack, int defence, int speed)
: m_Name( name ), m_HealthMax( healthMax ), m_Health( m_HealthMax ),
m_Attack( attack ), m_Defence( defence ), m_Speed( speed )
{
}
void Player::ShowStats() const
{
cout << "Your 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"
;
}
void Player::DecreaseHealth (int damage)
{
m_Health -= damage;
if (m_Health < 0)
m_Health = 0;
cout << "You've taken " << damage << " damage.\n"
<< "Your health has become " << m_Health << ".\n"
;
}
Am I taking a good OOP approach?
Thanks in advance.
[Edited by - sheep19 on January 6, 2008 3:07:21 AM]