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?
Tactics/character.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
185 lines (157 sloc)
3.85 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 "character.hh" | |
using namespace std; | |
Character::Character() | |
{ | |
/* sets the attributes of the created character */ | |
/* sets the name of the created caracter according to the random file */ | |
name = "bob"; | |
dmg = 5; | |
def = 5; | |
hp = 10; | |
maxHp = 10; | |
stm = 5; | |
gold = 0; | |
xCo = 4; | |
yCo = 4; | |
} | |
void Character::sayStats() | |
{ | |
/* returns the stats of a specified character including the position (x and y coordinate) */ | |
cout << "My name is " << name << "\n" | |
<< "dmg: " << dmg << "\n" | |
<< "def: " << def << "\n" | |
<< "max hp: " << maxHp << "\n" | |
<< "hp: " << hp << "\n" | |
<< "stm: " << stm << "\n" | |
<< "gold: " << gold << "\n" | |
<< "x: " << xCo << "\n" | |
<< "y: " << yCo << "\n" | |
<< endl; | |
} | |
int Character::Stamina(int val) | |
{ | |
/* stamina cannot go below 0 */ | |
if ((stm - val) < 0) | |
{ | |
return stm; | |
} | |
else | |
{ | |
return stm - val; | |
} | |
} | |
/* changes player's damage | |
input is change in damage | |
output is new damage value */ | |
int Character::changeDmg(int val) | |
{ | |
return dmg += val; | |
} | |
/* changes player's defence | |
input is change in defence | |
output is new defence value */ | |
int Character::changeDef(int val) | |
{ | |
return def += val; | |
} | |
/* changes player's gold amount | |
input is change in gold | |
output is new gold value */ | |
int Character::changeGold(int val) | |
{ | |
return gold + val; | |
} | |
/* changes player's health | |
input is health change | |
output is new health value */ | |
int Character::health(int val) | |
{ | |
if ((hp + val) < 0) | |
{ | |
return 0; | |
} | |
/* health cannot go above max health */ | |
else if ((hp + val) > maxHp) | |
{ | |
return maxHp; | |
cout << "ALERT! Max hp reached." << "\n"; | |
} | |
else | |
{ | |
return (hp + val); | |
} | |
} | |
/* changes player's maximum allowed health | |
input is change in max health | |
output is new maxhealth value */ | |
int Character::healthMax(int val) | |
{ | |
maxHp += val; | |
return 0; | |
} | |
void Character::nextTurn() | |
{ | |
stm = 5; | |
health(3); | |
} | |
int Character::movement(int pos, int move) | |
{ | |
/* allows the map to wrap in on itself if the boundry is breached */ | |
if ((pos + move) > 7) | |
{ | |
return ((pos + move) - 8); | |
} | |
else if ((pos + move) < 0) | |
{ | |
return (8 + (pos + move)); | |
} | |
else | |
{ | |
return (pos + move); | |
} | |
} | |
int Character::direction(int max) | |
{ | |
/* user input for direction determined by the stamina left on the player */ | |
int dist; | |
cout << "Choose a distance (max " << max << "): "; | |
cin >> dist; | |
/* calls itself if the input is too large or lower than 1 */ | |
if (dist > max || dist < 1) | |
{ | |
cout << "Not valid! You may not have enough stamina." << "\n"; | |
direction(max); | |
} | |
else | |
{ | |
/* user input for direction */ | |
char direc; | |
cout << "Choose a direction:" << "\n" | |
<< "w = north" << "\n" | |
<< "s = south" << "\n" | |
<< "d = east" << "\n" | |
<< "a = west" << "\n"; | |
cin >> direc; | |
/* changes the user input to lower case for the switch case below */ | |
direc = tolower(direc); | |
switch(direc) | |
{ | |
/* calls the movement function with inputs as variables */ | |
case 'w': | |
yCo = movement(yCo,-dist); | |
break; | |
case 's': | |
yCo = movement(yCo,dist); | |
break; | |
case 'd': | |
xCo = movement(xCo,dist); | |
break; | |
case 'a': | |
xCo = movement(xCo,-dist); | |
break; | |
} | |
} | |
/* changes the player stamina according to the movement inputted by user */ | |
stm = Stamina(dist); | |
return(0); | |
} | |