Jul 28, 2009 at 11:39pm UTC
Weapon doesn't need to access player, but player needs to access weapon.
See the attack. "weap.damage" is a private member.
Thus, I add friendness.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <iostream>
#include <ctime>
#include <cmath>
#include "SDL.h" // Access to 2d graphics API
#include <vector>
#include <algorithm>
#include "weapon.hpp"
class Player {
friend class weapon;
public :
explicit Player ( unsigned initial_health = 100, const std::vector<weapon>& weapons = std::vector<weapon>() )
: health_ ( initial_health ), isDead ( false ), max_health ( initial_health ), weaponry (weapons) { }
void heal( unsigned cure ) { health_ = std::min( health_ + cure, max_health); }
void quickAttack( const weapon &weap, Player &who) { if ( who.health_ > weap.damage ) who.health_ -= weap.damage; else who.isDead = true ; }
void addWeapon ( const weapon &new_weapon ) { weaponry.push_back( new_weapon ); }
private :
std::vector<weapon> weaponry;
unsigned health_;
unsigned max_health;
bool isDead;
};
int main(int argc, char *argv[])
{
Player Havoc(75, std::vector<weapon>(pistol));
srand( time(0) );
int i;
int rNum = rand() % 10 + 1;
// Do-while loop to
do {
return EXIT_SUCCESS;
}
1 2 3 4 5 6
class weapon
{
private :
std::string name;
int damage;
};
Last edited on Jul 28, 2009 at 11:46pm UTC
Jul 29, 2009 at 12:10am UTC
If rNum is even we can do something with it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <iostream>
#include <ctime>
#include <cmath>
#include "SDL.h" // Access to 2d graphics API
#include <vector>
#include <algorithm>
#include "weapon.hpp"
class Player {
friend class weapon;
public :
explicit Player ( unsigned initial_health = 100, const std::vector<weapon>& weapons = std::vector<weapon>() )
: health_ ( initial_health ), isDead ( false ), max_health ( initial_health ), weaponry (weapons) { }
void heal( unsigned cure ) { health_ = std::min( health_ + cure, max_health); }
void quickAttack( const weapon &weap, Player &who) { if ( who.health_ > weap.damage ) who.health_ -= weap.damage; else who.isDead = true ; }
void addWeapon ( const weapon &new_weapon ) { weaponry.push_back( new_weapon ); }
private :
std::vector<weapon> weaponry;
unsigned health_;
unsigned max_health;
bool isDead;
};
int main(int argc, char *argv[])
{
Player Havoc(75, std::vector<weapon>("pistol" ));
srand( time(0) );
int i;
int rNum = rand() % 10 + 1;
if (rNum % 2 == 0){
// Do-while loop to
return EXIT_SUCCESS;
}
Aaaaaand...constructah!
1 2 3 4 5 6 7 8 9
class weapon
{
private :
std::string name;
int damage;
public :
explicit weapon(std::string m_name = "sword" , int m_damage = 5) : name (m_name), damage (m_damage);
};
Last edited on Jul 29, 2009 at 12:11am UTC
Jul 29, 2009 at 8:56am UTC
Removed the constructor overload as a
char *
can be passed to the
std::string constructor
1 2 3 4 5 6 7 8 9
class weapon
{
private :
std::string name;
int damage;
public :
explicit weapon(std::string m_name = "sword" , int m_damage = 5) : name (m_name), damage (m_damage);
};
Last edited on Jul 29, 2009 at 8:56am UTC
Aug 6, 2009 at 1:15am UTC
50 health? I think 10 is enough for a first enemy. I won't change it unless someone agrees.
Aug 6, 2009 at 2:36am UTC
That was just a random value, i find that it is best just choose a value until the game is playable then modify the values to adjust difficulty, but that is just the way i do it...
Aug 6, 2009 at 3:28am UTC
This will end up as a new WoW, or as a remake of old Bard's Tale!
Aug 8, 2009 at 9:19pm UTC
Added 'range' and missing braces to the constructor
1 2 3 4 5 6 7 8 9
class weapon
{
private :
std::string name;
int damage, range;
public :
explicit weapon(std::string m_name = "sword" , int m_damage = 5 int range = 2) : name (m_name), damage (m_damage), range (range) {}
};
Last edited on Aug 8, 2009 at 9:20pm UTC