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?
Dungeon-Game/Battle.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (34 sloc)
1.51 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 "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!"; | |
} | |
} |