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 "Battle.h"
//Battle function
//Edited some code from https://cplusplus.happycodings.com/games/code11.html
void Battle(Player::Player playr, Enemy::Enemy enemy)
{
while ( (playr.health > 0) && (enemy.health > 0) )
//Player attacks
cout << enemy.name << " HP: " << enemy.health << endl << "hp: " << playr.health << endl << "Press Enter to Attack" << endl;
move = mygetch()
if ( move == 10 )
cout << "You attacked";
enemy.health -= playr.attack - round(playr.attack/enemy.defense);
//check if enemy health goes below zero
if ( enemy.health < 0 )
enemy.health = 0;
//enemy attacks
if ( enemy.health > 0 )
cout << enemy.name << " HP: " << enemy.health << endl << "HP: " << playr.health << endl;
cout << enemy.name << " attacked!" << endl;
playr.health -= enemy.attack - round(enemy.attack/playr.defense);
//check if player health goes below zero
if ( playr.health < 0 )
playr.health = 0;
if ( playr.health == 0 )
{
cout << enemy.name << " HP: " << enemy.health << endl << "HP: " << playr.health << endl;
cout << "You lose";
}
else if ( enemy.health == 0)
{
cout << enemy.name << " HP: " << enemy.health << endl << "HP: " << playr.health << endl;
cout << "You win!";
}
}