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 "Player.h"
#include <random>
#include <ctime>
#include <iostream>
#include <Windows.h>
using namespace std;
//initializes player position to zero
Player::Player() {
_x = 0;
_y = 0;
}
//initializes the player with stats/properties
void Player::init(int level, int health, int attack, int defense, int experience) {
_level = level;
_health = health;
_attack = attack;
_defense = defense;
_experience = experience;
}
//Player attack
int Player::attack() {
static default_random_engine randomEngine(time(NULL)); //random number generator, static only generates 1 time
uniform_int_distribution <int>attackNumber(0, _attack);
return attackNumber(randomEngine);
}
//sets the position of the player
void Player::setPosition(int x, int y) {
_x = x;
_y = y;
}
//gets the position of the player using reference variables
void Player::getPosition(int &x, int &y) {
x = _x;
y = _y;
}
//add experience
void Player::addExPoints(int experiencePts) {
_experience = _experience + experiencePts;
//level up
while (_experience > 100) {
cout << "You just leveled up! Congratulations!" << endl;
_experience = _experience - 100;
_attack = _attack + 10;
_defense = _defense + 5;
_health = _health + 10;
_level++;
system("pause");
}
}
int Player::dmgTaken(int attack) {
attack = attack - _defense;
if (attack > 0) {
_health = _health - attack;
//check if player dies
if (_health <= 0) {
return 1;
}
}
return 0;
}