Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
RogueLegends/Monster.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (40 sloc)
1.02 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Monster.h" | |
#include <random> | |
#include <ctime> | |
Monster::Monster(string name, char tile, int attack, int health, int defense, int experience) | |
{ | |
_name = name; | |
_tile = tile; | |
_health = health; | |
_attack = attack; | |
_defense = defense; | |
_expPts = experience; | |
} | |
//sets the position of the monster | |
void Monster::setPosition(int x, int y) { | |
_x = x; | |
_y = y; | |
} | |
//gets the position of the monster using reference variables | |
void Monster::getPosition(int &x, int &y) { | |
x = _x; | |
y = _y; | |
} | |
//Monster attack | |
int Monster::attack() { | |
static default_random_engine randomEngine(time(NULL)); //random number generator, static only generates 1 time | |
uniform_int_distribution <int> attackNumber(0, _attack); // number betweeen 0 and _attack | |
return attackNumber(randomEngine); | |
} | |
//monster take dmg | |
int Monster::dmgTaken(int attack) { | |
attack = attack - _defense; | |
if (attack > 0) { | |
_health = _health - attack; | |
//check if player dies | |
if (_health <= 0) { | |
return _expPts; | |
} | |
} | |
return 0; | |
} |