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?
Text-based-Game/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.
42 lines (39 sloc)
869 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 "monster.h" | |
int Monster::takeDamage(int damage) | |
{ | |
hp = hp - damage; | |
if(hp <= 0){ | |
hp = 0; | |
} | |
mvprintw(LINES/2 + 1,(COLS-strlen(("Enemy hp left: " + to_string(hp)).c_str()))/2,"%s", ("Enemy hp left: " + to_string(hp)).c_str()); | |
refresh(); | |
} | |
array<int, 3> Monster::giveInfo() | |
{ | |
array<int, 3> info = {lvl, atk, hp}; | |
return info; | |
} | |
float Monster::giveDef() | |
{ | |
return def; | |
} | |
Monster createWolf(){ | |
Monster wolf; | |
srand ( time(NULL) ); | |
wolf.lvl = (rand() % 6) + 1; | |
wolf.atk = wolf.lvl * 2; | |
wolf.hp = wolf.lvl * 4; | |
wolf.def = 1 - (wolf.lvl * 0.05); | |
wolf.expGiven = 8; | |
return wolf; | |
} | |
Monster createOrc(){ | |
Monster orc; | |
srand ( time(NULL) ); | |
orc.lvl = (rand() % 6) + 15; | |
orc.atk = orc.lvl * 1.5; | |
orc.hp = orc.lvl * 7; | |
orc.def = 1 - (orc.lvl * 0.05); | |
orc.expGiven = 20; | |
return orc; | |
} |