[ create a new paste ] login | about

Link: http://codepad.org/pC0kMZvs    [ raw code | output | fork ]

outoftime - C++, pasted on Feb 12:
#include <iostream>
#include <string>
 
using namespace std;
 
class Actor
{
protected:
        int health;
        int damage;
        string name;
public:
        Actor (string name = "Actor") 
        { 
                health = damage = 0;
                this->name = name;
        }
 
        void setParam(const int &health, const int &damage)
        {
                this->health = health;
                this->damage = damage;
        }
        
        void showStates()
        {
                cout << this->name << "\n\rHealth: " << this->health 
                     << ", damage: " << this->damage << endl;
        }
        
        void Attack(Actor *destination)
        {
                destination->health -= this->damage;
        }
};
 
class Player : public Actor
{
public:
        Player (string name) : Actor(name) { }
};
 
class Enemy : public Actor 
{
public:
        Enemy (string name) : Actor(name) { }
};
 
int main()
{
        Player player("Player");
        Enemy enemy("Enemy");
        player.setParam(100, 50);
        enemy.setParam(100,30);
        
        player.showStates();
        enemy.showStates();
 
        player.Attack(&enemy);
        
        player.showStates();
        enemy.showStates();
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
Player

Health: 100, damage: 50
Enemy

Health: 100, damage: 30
Player

Health: 100, damage: 50
Enemy

Health: 50, damage: 30


Create a new paste based on this one


Comments: