Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#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;
}