So I am new to C++ and I took a class on it last semester in School. I am very interested in programming and would like to become a Game Developer I made this very early "Text Game" but I have a lot of errors I can't solve any help is appreciated
Here is my code
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
usingnamespace std;
int main()
{
srand(static_cast<unsignedint>(time(0)));
int lives = 3;
int random = rand();
int random1 = rand();
int random2 = rand();
class Player
{
public:
int PLayerHealth;
int PlayerDamage;
Player (int P_Health = 100);
Player (int BattleDamage = (random1 % 10) + 5);
}
class Skeleton
{
public:
int (SkeletonHealth = (random2 % 100) + 50);
int (SkeletonD = 1);
}
//Classes and declares all random functions
int WhatToDo;
PlayerHealth = P_Health;
PlayerDamage = BattleDamage;
Player P1;
Player p2;
Skeleton S1;
Skeleton S2;
/* This secton declares all the intergers in the game accordingly
and will also decide the randome functions of the game
*/
cout<<"WELCOME To Ryan's Text based RPG! V 1.0 \n";
do {
int ExploreFunc = (random % 2) + 1; //Decdides what will happen while exploring
int BattleToDo;
cout<<"Choose your action \n 1: Explore \n 2: Shop \n 3: Exit\n";
cin>>WhatToDo;
switch(WhatToDo) // Player decides what to do
{
case 1:
if (ExploreFunc = 1 || ExploreFunc = 2)
{
cout<<"A skeleton ATTACKS!\n";
cout<<"Your health is: \n"<<P1.P_Health;
cout<<"Enemy health is: \n"<<S1.SkeletonHealth;
while (S1.SkeletonHealth > 0)
{
cout<<"What do you do!?\n";
cin>>BattleToDo;
switch (BattleToDo)
{
case 1:
cout<<"You did: "<<P2.BattleDamage<<" To the enemy\n";
S1.SkeletonHealth = S1.SkeletonHealth - P2.BattleDamage;
cout<<"Enemy Health is now: \n"<<S1.SkeletonHealth;
cout<<"Enemy is now attacking it did: \n"<<S1.SkeletonD;
P1.P_Health = P1.P_Health - S2.SkeletonD;
cout<<"Your Health is now: \n"<<P1.P_Health;
if (S1.SkeletonHealth <= 0)
{
cout<<"YOU WON!\n";
}
}
}
break;
}
}while(WhatToDo != 3);
system("pause");
return 0;
}
Class declarations are usually outside of functions. Where you have declared class Player, and class skeleton, you need to move these outside the main function, preferably before where you typed it out.
Line 48 also seems a bit odd to me as well.. if (ExploreFunc = 1 || ExploreFunc = 2)
This isn't checking the values of ExploreFunc, but it is assigning two different values to ExploreFunc. I presume you wanted the == to check the value.
Other than that, why not separate your game into different functions? Maybe it's just me, but I go crazy if main() is filled with so much clutter. It makes debugging very difficult if things are smashed all into one function like that.