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?
asciiGame/fight.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
102 lines (90 sloc)
3.02 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
#ifndef FIGHT_H | |
#define FIGHT_H | |
#include <iostream> | |
#include <chrono> | |
#include <thread> | |
#include <ncurses.h> | |
#include "random.h" | |
using namespace std; | |
string win(string monsterName,bool playerWin,int HP); | |
void fight(int strength, int speed, int HP,int monsterStrength, int monsterSpeed, | |
int monsterHP, string monsterName, string monsterDescriptions) { | |
initscr(); | |
noecho(); | |
int x=5,y=3; | |
mvprintw(y,x,monsterDescriptions.c_str()); | |
y+=2; | |
mvprintw(y,x, "Press c to continue"); | |
y+=2; | |
while(true){ | |
if(randomNum(0, monsterSpeed)>randomNum(0, speed)){ | |
int damage = randomNum(0, monsterStrength); | |
mvprintw(y,x, ("The " + monsterName +" attacks doing " + to_string(damage) + " damage.").c_str()); | |
y+=1; | |
HP-=damage; | |
if(HP<=0){ | |
mvprintw(y,x,(win(monsterName, false, HP)).c_str()); | |
y+=1; | |
break; | |
} | |
mvprintw(y,x, ("You have " + to_string(HP) + " hp left.").c_str() ); | |
y+=2; | |
damage = randomNum(0, monsterStrength); | |
mvprintw(y,x,("You attack doing " + to_string(damage) + " damage.").c_str()); | |
y+=1; | |
monsterHP-=damage; | |
if(monsterHP<=0){ | |
mvprintw(y,x,(win(monsterName, true, HP)).c_str()); | |
y+=1; | |
break; | |
} | |
mvprintw(y,x, ("The " + monsterName + " has " + to_string(monsterHP) + " hp left.").c_str() ); | |
y+=2; | |
}else{ | |
int damage = randomNum(0, monsterStrength); | |
mvprintw(y,x, ("You attack doing " + to_string(damage) + " damage.").c_str()); | |
y+=1; | |
monsterHP-=damage; | |
if(monsterHP<=0){ | |
mvprintw(y,x,(win(monsterName, true, HP)).c_str()); | |
y+=1; | |
break; | |
} | |
mvprintw(y,x, ("The " + monsterName + " has " + to_string(HP) + " hp left.").c_str() ); | |
y+=2; | |
damage = randomNum(0, monsterStrength); | |
mvprintw(y,x, ("The "+monsterName+" attacks doing "+ to_string(damage) + " damage.").c_str()); | |
y+=1; | |
HP-=damage; | |
if(HP<=0){ | |
mvprintw(y,x,(win(monsterName, false, HP)).c_str()); | |
y+=1; | |
break; | |
} | |
mvprintw(y,x, ("You have " + to_string(HP) + " hp left.").c_str() ); | |
y+=2; | |
} | |
refresh(); | |
char cont='s'; | |
while(cont!='c' && cont!='C'){ | |
cont=getch(); | |
} | |
} | |
char cont='s'; | |
while(cont!='c' && cont!='C'){ | |
cont=getch(); | |
} | |
endwin(); | |
} | |
string win(string monsterName,bool playerWin,int HP){ | |
string win; | |
if(playerWin){ | |
win = "The " + monsterName + | |
" is defeated and start to sink to the bottom of the ocean." + | |
"You have " + to_string(HP) + " hp left"; | |
}else{ | |
win = "The " + monsterName + " celebrates as you are defeated"; | |
} | |
return win; | |
} | |
#endif |