#include <iostream>
#include <time.h>
using namespace std;
int roll(int sides);
int coinToss();
int rollD20();
int playerOneTurn(int twoHp, int twoArmor);
int playerTwoTurn(int oneHp, int oneArmor);
int theRoll;
int playerDamage;
int cumulativeDMGTwo;
int cumulativeDMGOne;
int main() {
srand (time(NULL));
int playerOneHp = ((rand() % 15) + 10);
int playerOneArmor = (rand() % 9) + 8;
int playerTwoHp = ((rand() % 15) + 10);
int playerTwoArmor = (rand() % 9) + 8;
cout<<"Player one begins with " << playerOneHp << " hitpoints." << endl;
cout<<"Player one begins with " << playerOneArmor << " armor points." << endl;
cout<<"Player two begins with " << playerTwoHp << " hitpoints." << endl;
cout<<"Player two begins with " << playerTwoArmor << " armor points." << endl;
if(coinToss() == 1) {
cout<<"Player one starts."<<endl;
while(playerOneHp > 0 && playerTwoHp > 0) { //This while statement
playerOneTurn(playerTwoHp, playerTwoArmor);
playerTwoTurn(playerOneHp, playerOneArmor);
}
} else {
cout<<"Player two starts."<<endl;
while(playerOneHp > 0 && playerTwoHp > 0) { //This while statement
playerTwoTurn(playerOneHp, playerOneArmor);
playerOneTurn(playerTwoHp, playerTwoArmor);
}
}
} //for int main
int playerOneTurn(int twoHp, int twoArmor) {
theRoll = rollD20();
if(theRoll > twoArmor) {
playerDamage = (roll((6) - 1) + 1) + playerDamage;
cout<<"Player one deals " << playerDamage << " total damage to player two!"<<endl;
twoHp = twoHp - playerDamage;
cout<<"Player two has " << twoHp << " hitpoints left!"<<endl;
if(twoHp <= 0){
cout<<"Player One wins!!"<<endl;
} return twoHp;
} else {
cout<<"Player one missed!"<<endl;
}
}
int playerTwoTurn(int oneHp, int oneArmor) {
theRoll = rollD20();
if(theRoll > oneArmor) {
playerDamage = (roll((6) - 1) + 1) + playerDamage;
cout<<"Player two deals " << playerDamage << " total damage to player one!"<<endl;
oneHp = oneHp - playerDamage;
cout<<"Player one has " << oneHp << " hitpoints left!"<<endl;
if(oneHp <= 0){
cout<<"Player Two wins!!"<<endl;
} return oneHp;
} else {
cout<<"Player two missed!"<<endl;
}
}
int rollD20() {
return (rand() % 20) + 1;
}
int roll(int sides) {
return (rand() % (sides)) + 1;
}
int coinToss() {
return (rand() % 2) + 1;
}