#include<iostream>
#include<windows.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
using namespace
std;
class Monster /*subclasses are written first*/
{
public:
Monster( int=15, int=10, char*
= "Bob");
int get_health()
const {return
health;} /*declaring as a const so the function
cannot modify anything good for "get-" functions */
int get_attack()
const {return
attack;}
char
*get_name() const {return name;}
void
set_health ();
void
set_attack ();
~Monster();
private:
int health;
int attack;
char
*name;
};
Monster::Monster (int a, int b, char
*c)
{
cout<<"Would
you like to set the attributes of a monster?\n";
char
decision;
cout<<"Type
in Y/N\n";
cin>>decision;
if
(decision == 'Y')
{
set_health();
set_attack();
}
else
cout<<"You
now proceed.\n";
}
void Monster::set_health()
{
int
a;
cout<<"what
is the monster's health?\n";
cin>>a;
health=a;
}
void Monster::set_attack()
{
int
a;
cout<<"What
is the monster's attack?\n";
cin>>a;
attack=a;
}
Monster::~Monster()
{
delete
name; /*deletes and frees memory from pointers*/
}
class Mansion /*main class*/
{
public:
Mansion(int, int);
Mansion(int, int, int, int, char*); /*overloaded constructor*/
void
fight_monster();
private:
int p_att;
int p_hp;
Monster thing; /*make a private
data member a object of another class. */
};
Mansion::Mansion(int
x, int y, int i,
int j, char *k)
:thing(i ,j
,k) /*got to do that in the constructor of main class
if including subclasses*/
{
p_att=x;
p_hp=y;
int
chance=50+rand()%50;
char
a;
cout<<"Do
you want to fight this mansion's monster? 1 for yes, 2 for no.\n";
cin>>a;
if
(a=='2')
{
cout<<"But
the monster wants to fight you!";
fight_monster();
}
else
fight_monster();
}
Mansion::Mansion(int
x, int y)
:thing() /*got to do that in
the constructor of main class if including subclasses*/
{
p_att=x;
p_hp=y;
int
chance=50+rand()%50;
int
a;
cout<<"Do
you want to fight this mansion's monster? 1 for yes, 2 for no.\n";
cin>>a;
if
(a==2)
{
cout<<"But
the monster wants to fight you!\n";
fight_monster();
}
else
fight_monster();
}
void Mansion::fight_monster()
{
if ( (p_att + p_hp ) >= ( thing.get_health() + thing.get_attack()
) )
cout<<"You
win!\n";
else
cout<<"You
suck because monster won. Ha-ha!\n";
}
main()
{
Mansion One(11, 16);
return
0;
}
