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?
Dungeon-Game/player.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (51 sloc)
954 Bytes
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 "player.h" | |
Player::Player(){ | |
//Default Constructor | |
} | |
Player::Player(string player_name){ | |
name = player_name; | |
health = 50; | |
attack = 10; | |
level = 1; | |
defense = 5; | |
weapon_equipped = "none"; | |
} | |
int Player::get_x(){ | |
return pos_x; | |
} | |
int Player::get_y(){ | |
return pos_y; | |
} | |
void Player::set_position(int x, int y){ | |
pos_x = x; | |
pos_y = y; | |
} | |
char Player::player_input(){ | |
char _key; | |
int key = mygetch(); | |
switch( key ) | |
{ | |
case 119: | |
_key = 'w'; | |
break; | |
case 97: | |
_key = 'a'; | |
break; | |
case 100: | |
_key = 'd'; | |
break; | |
case 115: | |
_key = 's'; | |
break; | |
case 27: | |
_key = '/'; | |
break; | |
} | |
return _key; | |
} | |
int Player::player_attack(){ | |
return rand() % attack; | |
} | |
void Player::take_damage(int attack){ | |
health -= round(attack - attack/defense); | |
} |