Here is my code below, my problem is i have it so enemys come up as random across the large 50 x 50 grid, only problem is when you battle with one the battle iniates he takes a swing i take a swing, then it goes right back out to epxploring makeing it impossible to kill an enemy (litereally impossible), i need to have it so when you enter combat you fight till the death, then go back to exploring, here is my code below
Code:
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <iomanip.h>
int RandInt(int a,int b)
{
return a + rand() % (b - a + 1);
}
int User_Health = 400;
int User_Max_Health = 400;
int User_Level = 1;
int User_Potions = 10;
int User_Exp = 0;
int Next_Level = 300;
int User_Gold = 0;
int User_Attack;
int name;
int Q = 0;
int USE_POTION;
int Y;
int User_Location_X = 0;
int User_Location_Y = 0;
int chalace = 0;
int septor = 0;
int end_game = 100;
char input;
int knight_Health = 200;
int knight_Max_Health = 200;
int knight_Gold = 60;
int knight_Exp = 60;
int main()
{
cout << "overview test";
getch();
system("cls");
do
{
system ("cls");
if(User_Exp >= Next_Level)
{
Next_Level = Next_Level * 2;
User_Max_Health = User_Max_Health + 20;
User_Level = User_Level++;
User_Health = User_Max_Health;
}
srand(time(NULL));
int Potion_Heal = RandInt(70,160);
srand(time(NULL));
int x = RandInt(1, 100);
srand(time(NULL));
int knight_Attack = RandInt(12,20);
srand(time(NULL));
int User_Attack = RandInt(15,42);
srand(time(NULL));
int knight_Exp = RandInt(30,90);
srand(time(NULL));
int knight_Gold = RandInt(1,3);
User_Attack = (User_Attack * User_Level) * 2;
cout << "-----------------------------------------------------\n";
cout << "Ludlow To Test Your Wits and Strength\n\n";
cout << "\nLeaving the gates of Ludlow, the guards surround the \n";
cout << "land, you will die unless you fight for survivol. Slay \n";
cout << "the Black Knights and collect the 15 jewls lost across\n";
cout << "the land and return to Ludlow, to the Impeareal Guard.\n\n";
cout << "Attack = A Quit = Q\n\n";
cout << "Health: " << User_Health << "/" << User_Max_Health << " Level: " << User_Level << "\n";
cout << "Exp: "<<User_Exp<<" Exp to next level: "<<Next_Level<<"\n";
cout << "Gold: "<<User_Gold<<" Potions: "<<User_Potions << "\n";
cout << "-----------------------------------------------------\n";
if (User_Location_Y == 50)
{
cout <<"You have reached the valley wall\n";
User_Location_Y = User_Location_Y--;
getch();
}
else if (User_Location_Y == -50)
{
cout <<"You have reached the valley wall\n";
User_Location_Y = User_Location_Y++;
getch();
}
else if (User_Location_X == 50)
{
cout <<"You have reached the valley wall\n";
User_Location_X = User_Location_X--;
getch();
}
else if (User_Location_X == -50)
{
cout <<"You have reached the valley wall\n";
User_Location_X = User_Location_X++;
}
end_game = end_game--;
if (end_game == 0)
{
system("cls");
cout <<"You have used all your energy, GAME OVER!\n";
return 0;
}
cout <<" North (8) " << User_Location_X << "/50 " << User_Location_Y << "/50\n";
cout <<"East (4) West (6)\n";
cout <<" South (2)\n";
cout <<"\n";
cin >>input;
cout <<"\n";
//Defines user keys
if (input == 'Q' || input == 'q')
{
system("cls");
cout <<"You have died in combat Warrior.\n";
return 0;
}
//Updates user position
if (input == '8')
{
User_Location_Y = User_Location_Y++;
}
else if (input == '2')
{
User_Location_Y = User_Location_Y--;
}
else if (input == '6')
{
User_Location_X = User_Location_X++;
}
else if (input == '4')
{
User_Location_X = User_Location_X--;
}
//directinal code
if (User_Location_X == -29 && User_Location_Y == 41)
{
if (chalace == 1)
{
cout <<"You have found The Ethereal Chalace.\n\n";
getch();
User_Location_X = 0;
User_Location_Y = 0;
}
else if (chalace == 0)
{
cout <<"You have found The Ethereal Chalace.\n\n";
chalace = 1;
User_Exp = User_Exp +10;
User_Gold = User_Gold + 75;
cout << "You have recieved " << User_Gold << " gold pieces, " << User_Exp << " Exp & The Ethereal Chalace.";
getch();
User_Location_X = 0;
User_Location_Y = 0;
}
}
if (User_Location_X == 21 && User_Location_Y == 20)
{
if (septor == 1)
{
cout <<"You have found a Golden Septor Of The Lord.\n\n";
getch();
User_Location_X = 0;
User_Location_Y = 0;
}
else if (septor == 0)
{
cout <<"You have found a Golden Septor Of The Lord.\n\n";
septor = 1;
User_Exp = User_Exp +21;
User_Gold = User_Gold + 15;
cout << "You have recieved " << User_Gold << " gold pieces, " << User_Exp << " Exp & The Golden Septor Of The Lord.";
getch();
User_Location_X = 0;
User_Location_Y = 0;
}
}
//Battleing with the black kngiht
if (x > 90)
{
cout << "You Have entered combat with a Black Knight\n\n";
cout << "\nBlack Knight attacks, does "<<knight_Attack<<" Damage.\n";
User_Health = User_Health - knight_Attack;
getch();
if (User_Health >=1)
cout << "\nYou attack, and do " <<User_Attack<<" damage.\n\n";
knight_Health = knight_Health - User_Attack;
getch();
if(User_Health <= 0)
{
User_Health = 0;
cout << "\nYou have been slayed in battle!\n";
cout << "Press any key to continue...\n";
getch();
return 0;
}
if(knight_Health <= 0)
{
cout << "\nYou have defeated a Black Knight.\n";
cout << "You gain "<< knight_Exp << " Exp and "<<knight_Gold<<" Gold.\n";
getch();
User_Exp = User_Exp + knight_Exp;
User_Gold = User_Gold + knight_Gold;
knight_Health = knight_Max_Health;
if(User_Potions == 1)
{
User_Potions = User_Potions++;
cout << "You found a potion\n";
getch();
system ("cls");
}
cout << "\nDo you wish to use a potion?\n1)Yes 2)No\n";
cin >> USE_POTION;
if(USE_POTION == 1 & User_Potions >= 1)
{
system ("cls");
cout << "You have been healed for "<<Potion_Heal<<"\n";
User_Potions = User_Potions--;
User_Health = User_Health + Potion_Heal;
if(User_Health >= User_Max_Health)
{
User_Health = User_Max_Health;
}
}
}
else
{
}
}
}
while(end_game!=1);
return 0;
}