im still new to c++.
love it but gosh i get so frustrated sometimes and want to give up!
but i haven't yet.
im trying to work on a small rpg for my first big project.
self/friend taught.
i had a good working system and lost it due to
c drive delete accident :'(
im new to classes and im trying to get my basic
name/hp down.
would like to have an enemy class but im not understanding inheritance.
anyways here is my base code.
my problem is getting the enemy to attack and revive damage from the attack.
goblins hp never goes down but mikeys does.
any help will be greatly appreciated :)
plus any tips on inheritance in this program will be appreciated
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <stdlib.h>
using std::cout;
using std::cin;
using std::string;
using std::endl;
class player
{
private:
//player name
string playername;
int health;
public:
//player info
int money;
player(int hp, const string & name)
{
health = hp;
playername = name;
money = 100;
}
//player stats
void stats(std::ostream & out)
{
out << "name: " << playername << " | hp: " << health << " | money: " << money << endl;
}
//attack system
int attack(player & enemy)
{
int damage = rand()%20+1;
health -= damage;
return health;
}
};
int main()
{
//random seed
srand(unsigned (time(0)));
//creating player and enemy
player mikey(100,"mikey");
player enemy(100, "goblin");
mikey.attack(enemy);
enemy.stats(cout);
enemy.attack(mikey);
mikey.stats(cout);
return 0;
}
|