#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main(int argc, char *argv[])
{
//The following are the variables for the player and monster stats
int playerhealth = 100;
int monsterhealth = 30;
int playerattack = 16;
int playerdefense = 13;
int monsterattack = 8;
int monsterdefense = 11;
int randomNumber = rand(); //generates random number
int die;
//The variable for the player's choice
int playerchoice;
cout << "During your travels, you have been attacked by a monster." << endl;
do
{
cout << "What will you do?" << endl;
cout << "1. Attack" << endl;
cout << "2. Defend" << endl;
cin >> playerchoice;//Grabs the user's choice to attack or defend
if (playerchoice = 1)
{
cout << "You lunge at the monster with your sword!" << endl;
//Random die role to add to player attack
die = (randomNumber % 6) + 1 ;
//Display the attack so the user knows how much damage they caused
cout << "You have done " << (die + playerattack) - monsterdefense << " damage to the monster!" << endl;
monsterhealth = (monsterhealth - (die + playerattack));//Reset the monster after the attack
if (monsterhealth > 0)
{
cout << "The monster attacks you!" << endl;
die = (randomNumber % 6) + 1 ;
if ( ((die + monsterattack) - playerdefense) > 0 )
{
cout << "The monster caused " << ( (die + monsterattack) - playerdefense)
<< " damage against you!" << endl;
playerhealth = playerhealth - ( (die + monsterhealth) - playerdefense);
cout << "You know have " << playerhealth << "HP..." << endl;
}
else if ( ( (die + monsterattack) - playerdefense) <= 0 )
{
cout << "The monster failed to cause you any harm with his attack!" << endl;
}
}
Basically, it just contains what happens when the player attacks. This code is unfinished.
I just want to make sure that I don't have any mistakes or am doing any bad habits.
I am relearning c++ and I wanted to give myself a challenge seeing as no one else has...lol
Left to finish:
What happens if the player chooses to defend rather than attack.
Finish the Do {} While () [I haven't done the While part yet].
Things to add later:
Maximum player and monster health.
Add items.
Add spells.
Add the ability to run away for both player and monster.
Add experience and leveling system.
Have more than one monster.
Implement this with my text adventure I once programmed to have a "random battle" effect.
EDIT:Damnit, there is already a problem....It lies in the randomNumber...!@#$%...
SECOND EDIT:Error fixed