Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include "Monster.h"
#include "GameClasses.h"
using std::cout;
namespace Game {
void Monster::set_combat_data(int a, int d, int H)
{
if (HP > 0)
throw Monster_errors{};
atk = a;
dfs = d;
HP = H;
}
double Monster::read_atk()
{
return atk;
}
double Monster::read_dfs()
{
return dfs;
}
bool Monster::try_fight(int p_HP, int p_atk,int p_dfs)
//return 1 for a triumph, 0 for a defeat
{
//able = ( (p_atk > dfs) && ((HP * (atk - p_dfs)) <= (p_HP * (p_atk - dfs)))) ? true : false; // player can harm monster; monster die first
// I am also wondering about lowering the fighting requirements to 'causing harm' only. Then the player could die and the game process
// would be saved. So if the player have something like 'a 2nd life', he could resume his game.
able = (p_atk > dfs);
return able;
}
bool Monster::fight(int& p_HP, int p_atk, int p_dfs)
// return 1 for a tiumph, 0 for a defeat
{
if (!able)
throw Monster_errors{};
// draw fighting page. Here I print the fighting process out
cout << "Start fighting " << name << "!\n";
cout << "PlayerHP: " << p_HP << "\tMonsterHP: " << HP << '\n';
while (p_HP > 0) {
HP -= p_atk - dfs; // animation here; sleep(1000)
cout << "PlayerHP: " << p_HP << "\tMonsterHP: " << HP << '\n';
if (HP <= 0) {
alive = false; // monster died
cout << "Remarkable job!\n";
return 1;
}
p_HP -= (atk - p_dfs >= 0) ? atk - p_dfs : 0; // animation here; sleep(1000)
cout << "PlayerHP: " << p_HP << "\tMonsterHP: " << HP << '\n';
}
cout << "Ahhhh! I am dead.\n";
return 0; // player died
}
}