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/mainCombat.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
155 lines (145 sloc)
5.27 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 "mainCombat.h" | |
Character mainCombat(int luck, int pAtk, int mAtk, int con, Character character, int dex, int lvl){ | |
Monster wolf = createWolf(); | |
string choice; | |
string choiceS; | |
int hit; | |
int damageDealt; | |
int totalDefense; | |
int damageReceived; | |
int atk; | |
int ch; | |
int position = 0; | |
array<int, 3> infoW = wolf.giveInfo(); | |
vector<string> skills; | |
array<int, 2> skillInfo; | |
vector<string> passives; | |
while(wolf.hp > 0){ | |
erase(); | |
character.showStats(); | |
mvprintw(LINES/2 - 6,(COLS-strlen("Enemy info: "))/2,"%s","Enemy info: "); | |
mvprintw(LINES/2 - 5,(COLS-strlen("Monster: wolf"))/2,"%s","Monster: wolf"); | |
mvprintw(LINES/2 - 4,(COLS-strlen(("Level: " + to_string(infoW[0])).c_str()))/2,"%s",("Level: " + to_string(infoW[0])).c_str()); | |
mvprintw(LINES/2 - 3,(COLS-strlen(("Attack: " + to_string(infoW[1])).c_str()))/2,"%s",("Attack: " + to_string(infoW[1])).c_str()); | |
mvprintw(LINES/2 - 2,(COLS-strlen(("Health: " + to_string(infoW[2])).c_str()))/2,"%s",("Health: " + to_string(infoW[2])).c_str()); | |
mvprintw(LINES/2 - 1,(COLS-strlen(("Defence: " + to_string(wolf.giveDef())).c_str()))/2,"%s",("Defence: " + to_string(wolf.giveDef())).c_str()); | |
mvprintw(LINES/2,(COLS-strlen("Attack"))/2,"%s", "Attack"); | |
mvprintw(LINES/2 + 1,(COLS-strlen("Item"))/2,"%s", "Item"); | |
mvprintw(LINES/2 + 2,(COLS-strlen("Run"))/2,"%s", "Run"); | |
mvprintw((LINES/2 + position), COLS/2 - 8, ">"); | |
mvprintw((LINES/2 + position), COLS/2 + 7, "<"); | |
refresh(); | |
ch = getch(); | |
if(ch == KEY_UP && position <= 2 && position > 0){ | |
position--; | |
} | |
else if(ch == KEY_DOWN && position < 2 && position >= 0){ | |
position++; | |
} | |
if(ch == SPACEBAR && position == 0){ | |
skills = character.getSkills(); | |
while(1){ | |
erase(); | |
for( int i = 0; i < skills.size();i++){ | |
mvprintw(LINES/2 + i,(COLS-strlen(skills[i].c_str()))/2,"%s", skills[i].c_str()); | |
} | |
mvprintw(LINES/2 + skills.size(),(COLS-strlen("Back"))/2,"%s", "Back"); | |
mvprintw((LINES/2 + position), COLS/2 - 8, ">"); | |
mvprintw((LINES/2 + position), COLS/2 + 7, "<"); | |
refresh(); | |
ch = getch(); | |
if(ch == KEY_UP && position <= skills.size() && position > 0){ | |
position--; | |
} | |
else if(ch == KEY_DOWN && position < skills.size() && position >= 0){ | |
position++; | |
} | |
if (ch == SPACEBAR && position == 0){ | |
if (skills[0] == "slash"){ | |
passives = character.getPassives(); | |
skillInfo = character.slash(); | |
character.update(); | |
atk = pAtk * skillInfo[0]; | |
hit = landHit(luck); | |
damageDealt = playerAttackDamage(atk, hit); | |
wolf.takeDamage(damageDealt); | |
totalDefense = playerDefense(con, 0); | |
if(passives[0] == "tough skin"){ | |
totalDefense = totalDefense + 0.1; | |
if(totalDefense >= 1){ | |
totalDefense = 1; | |
} | |
} | |
damageReceived = infoW[1] * (1 - totalDefense); | |
int deadCharacter = character.takeDamage(damageReceived); | |
if (deadCharacter == 1){ | |
return character; | |
} | |
break; | |
} | |
else{ | |
passives = character.getPassives(); | |
skillInfo = character.fireball(); | |
character.update(); | |
if(skillInfo[1] == 0){ | |
erase(); | |
mvprintw(LINES/2,(COLS-strlen("You attack with your fists"))/2,"%s", "You attack with your fists"); | |
refresh(); | |
getch(); | |
atk = pAtk; | |
} | |
else{ | |
atk = mAtk * skillInfo[0]; | |
} | |
hit = landHit(luck); | |
damageDealt = playerAttackDamage(atk, hit); | |
wolf.takeDamage(damageDealt); | |
totalDefense = playerDefense(con, 0); | |
damageReceived = infoW[1] * (1 - totalDefense); | |
int deadCharacter = character.takeDamage(damageReceived); | |
if (deadCharacter == 1){ | |
return character; | |
} | |
break; | |
} | |
} | |
else if(ch == SPACEBAR && position == skills.size()){ | |
break; | |
} | |
} | |
} | |
else if (ch == SPACEBAR && position == 1){ | |
erase(); | |
mvprintw(LINES/2,(COLS-strlen("No items available"))/2,"%s", "No items available"); | |
refresh(); | |
getch(); | |
} | |
else if (ch == SPACEBAR && position == 2){ | |
srand ( time(NULL) ); | |
int lvlDif = abs(wolf.lvl - lvl); | |
if ( dex >= ((rand() % dex) + lvlDif)){ | |
erase(); | |
mvprintw(LINES/2,(COLS-strlen("You escaped"))/2,"%s", "You escaped"); | |
refresh(); | |
getch(); | |
return character; | |
} | |
erase(); | |
mvprintw(LINES/2,(COLS-strlen("You couldn't escape"))/2,"%s", "You couldn't escape"); | |
refresh(); | |
getch(); | |
character.update(); | |
totalDefense = playerDefense(con, 0); | |
damageReceived = infoW[1] * (1 - totalDefense); | |
int deadCharacter = character.takeDamage(damageReceived); | |
if (deadCharacter == 1){ | |
return character; | |
} | |
} | |
} | |
erase(); | |
mvprintw(LINES/2,(COLS-strlen("Wolf has died"))/2,"%s", "Wolf has died"); | |
refresh(); | |
character.updateExp(wolf.expGiven, wolf.lvl); | |
return character; | |
} |