Hello all, I am currently making an rpg type game in C++. The code is bellow:

#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;

int main()
{
	int person, opponent, atk, asuccess, msuccess, game = 1, counter1=1, level = 1, atr, a, b, c = 0, d;
	//opponent
	int attackop, defenseop, speedop, healthop = 100, opac;
	//user
	int magicus, attackus, defenseus, speedus, healthus = 100;

	//names
	string nameus, nameop;

	//Random Number Generator
	int rand0, rand1, rand2, rand3, rand4, rand5, rand6, rand7, rand8, rand9, rand10, rand11, rand12, rand13, rand14, rand15, rand16, rand17, rand18, rand19, rand20, rand21, random, random2;
	srand(time(0));
	rand0 = rand() % 100;
	rand1 = rand() % 100;
	rand2 = rand() % 100;
	rand3 = rand() % 100;
	rand4 = rand() % 100;
	rand5 = rand() % 100;
	rand6 = rand() % 100;
	rand7 = rand() % 100;
	rand8 = rand() % 100;
	rand9 = rand() % 100;
	rand10 = rand() % 100;
	rand11 = rand() % 100;
	rand12 = rand() % 100;
	rand13 = rand() % 100;
	rand14 = rand() % 100;
	rand15 = rand() % 100;
	rand16 = rand() % 100;
	rand17 = rand() % 100;
	rand18 = rand() % 100;
	rand19 = rand() % 100;
	rand20 = rand() % 100;
	rand21 = rand() % 100;

	//classes
	int healus = 0;
	do{
		cout << "(1)\n***************\nThe Wizard:\n attack - 30\n defense - 40\n magic - 60\n speed - 60\n***************" << endl << endl
			<< "(2)\n***************\nThe Knight:\n attack - 50\n defense - 75\n magic - 40\n speed - 30\n***************" << endl << endl
			<< "(3)\n***************\nThe Berzerker:\n attack - 60\n defense - 50\n magic - 30\n speed - 50\n***************" << endl << endl;
		cout << "Which Class would you like to be?: ";
		cin >> person;
		if(person > 3)
		{
			system("cls");
			cout << "You must enter an integer between 1 and 3!!!!\n\n";
			system("pause");
			system("cls");
		}
	}while(person > 3);
	//information for user
	switch(person)
	{
	case 1:
		attackus = 30, defenseus = 40, magicus = 60, speedus = 60, nameus = "Wizard";
		break;
	case 2:
		attackus = 50, defenseus = 60, magicus = 40, speedus = 40, nameus = "Knight";
		break;
	case 3:
		attackus = 60, defenseus = 50, magicus = 30, speedus = 50, nameus = "Berzerker";
		break;
	default:
		cout << "No One";
	}
	do{
		if(healthop == 0)
			healthop = 100;
		system("cls");
		do{
			cout << "Welcome " << nameus << ", which opponent would you like to face?" << endl;
			d = (c * -1);
			if(level <= 1)
			{
				cout << "(" << d + 1 << ")\n***************\nThe Tree(lvl 1):\n attack - 0\n defense - 50\n speed - 0\n***************\n"; 
				cout << endl;
			}
			if(level <= 2)
			{
				cout << "(" << d + 2 << ")\n***************\nThe Rat(lvl 2):\n attack - 30\n defense - 20\n speed - 30\n***************\n"; 
				cout << endl;
			}
			if(level <= 3)
			{
				cout<< "(" << d + 3 << ")\n***************\nThe Mage(lvl 3):\n attack - 65\n defense - 45\n speed - 45\n***************\n";
				cout << endl;
			}
			if((level <= 4)&&(level >= 2))
			{
				cout<< "(" << d + 4 << ")\n***************\nThe Warlock(lvl 4):\n attack - 70\n defense - 40\n speed - 50\n***************\n";
				cout << endl;
			}
			if((level <= 5)&&(level >= 3))
			{
				cout<< "(" << d + 5 << ")\n***************\nThe King(lvl 5):\n attack - 75\n defense - 45\n speed - 50\n***************\n";
				cout << endl;
			}
			if((level <= 6)&&(level >= 4))
			{
				cout<< "(" << d + 6 << ")\n***************\nMike Bladino(lvl 5):\n attack - 85\n defense - 55\n speed - 60\n***************\n";
				cout << endl;
			}
			cout << ":";
			cin >> opponent;
			if(opponent > 3)
			{
				system("cls");
				cout << "You must enter an integer between 1 and 3!!!!\n\n";
				system("pause");
				system("cls");
			}
		}while(opponent > 3);
		system("cls");
		opponent = opponent + c;
		switch(opponent)
		{
		case 1:
			attackop = 0, defenseop = 30, speedop = 0, nameop = "Tree";
			break;
		case 2:
			attackop = 30, defenseop = 20, speedop = 30, nameop = "Rat";
			break;
		case 3:
			attackop = 65, defenseop = 45, speedop = 45, nameop = "Mage";
			break;
		case 4:
			attackop = 70, defenseop = 40, speedop = 50, nameop = "Warlock";
			break;
		case 5:
			attackop = 75, defenseop = 45, speedop = 50, nameop = "King";
			break;
		case 6:
			attackop = 85, defenseop = 55, speedop = 60, nameop = "Baldino";
			break;
		default:
			cout << "No One";
		}
		//success rate
		asuccess = speedus - defenseop + 50;
		msuccess = speedus - defenseop + 50;
		cout << "First Round is: " << nameus << " vs. " << nameop << "!!!";
		if(opponent != 6)
			Sleep(1000);
		if(opponent == 6)
		{
			Beep(350,200);
			Beep(300,300);
			Beep(400,200);
			Beep(350,250);
			Beep(400,400);
			Beep(450,600);
		}
		//amount of damage dealt
		a = attackus - defenseop;
		b = magicus - defenseop;
		opac = 100 - defenseus;
		attackop = attackop - defenseus;
		if (attackop < 0)
			attackop = 0;
		else
			attackop = attackop;
		do{
			counter1++;
			switch(counter1)
			{
			case 1:
				random = rand0;
				random2 = rand1;
				break;
			case 2:
				random = rand2;
				random2 = rand3;
				break;
			case 3:
				random = rand4;
				random2 = rand5;
				break;
			case 4:
				random = rand6;
				random2 = rand7;
				break;
			case 5:
				random = rand8;
				random2 = rand9;
				break;
			case 6:
				random = rand10;
				random2 = rand11;
				break;
			case 7:
				random = rand12;
				random2 = rand13;
				break;
			case 8:
				random = rand14;
				random2 = rand15;
				break;
			case 9:
				random = rand16;
				random2 = rand17;
				break;
			case 10:
				random = rand18;
				random2 = rand19;
				break;
			default:
				random = rand20;
				random2 = rand21;
			}
			system("CLS");

			//limitation
			if(asuccess > 100)
				asuccess = 100;
			else
				asuccess = asuccess;
			if(msuccess > 100)
				msuccess = 100;
			else
				msuccess = msuccess;

			//options
			do{
				healus = attackop -5;
				if(healus < 0)
					healus = 0;
				cout << "What would you like to use?\n\n"
					<< "(1)\n***************\nattack: " << asuccess << "% chance of success\n***************\n\n"
					<< "(2)\n***************\nmagic: " << msuccess << "% chance of success\n***************\n\n"
					<< "(3)\n***************\nheal + " << healus << "hp\n***************\n\n";
				cout << ": ";
				cin >> atk;
				if(atk > 3)
				{
					system("cls");
					cout << "You MUST enter a number between 1 and 3!!!\n\n";
					system("pause");
					system("cls");
				}
			}while(atk > 3);
			system("CLS");
			cout << "Calculating results";
			for(int counter = 0; counter <= 6; counter++)
			{
				Sleep(00);
				cout << ".";
			}
			system("CLS");
			switch(atk)
			{
			case 1:
				if(random<=asuccess)
				{
					if(random<=10)
					{
						cout << "CRITICAL!!!!\n\n\a";
						a = a * 2;
					}
					if(a < 0)
						a = 5;
					cout << "You took away " << a << " health points from the " << nameop << "!\n\n";
					healthop = healthop - a;
					cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
					if(random<=10)
					a = a/2;
				}
				else
				{
					cout << "You missed!\n\n";
					cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
				}
				break;
			case 2:
				if(random<=msuccess)
				{
					if(random<=10)
					{
						cout << "CRITICAL!!!!\n\n\a";
						b = b * 2;
					}
					if(b < 0)
						b = 5;
					cout << "You took away " << b << " health points from the " << nameop << "!\n\n";
					healthop = healthop - b;
					if(healthop < 0)
						healthop = 0;
					cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
					if(random<=10)
					b = b/2;
				}
				else
				{
					cout << "You missed!\n\n";
					cout << "The " << nameop << "'s health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
				}
				break;
			case 3:
				if(healthus < 100)
				{
					healthus = healthus + healus;
					cout << "Your health rose from " << healthus-healus << ", to " << healthus << "!!!" << endl << endl;
				}
				else
					cout << "Your health is already 100%!!!" << endl << endl;
				break;
			default:
				cout << "Attack Not available";
			}
			system("pause");
			system("cls");
			if(healthop > 0)
			{
				cout << "Opponent is now attacking";
				for(int counter = 6; counter >= 0; counter--)
				{
					Sleep(00);
					cout << ".";
				}
				system("cls");
				if(opac <= random2)
				{
					if(random2<=5)
					{
						cout << "CRITICAL!!!!\n\n\a";
						attackop = attackop + 15;
					}
					if(attackop < 0)
						attackop = 5;
					cout << "The opponent took away " << attackop << " health points from you!\n\n";
					healthus = healthus - attackop;
					if(healthus < 0)
						healthus = 0;
					cout << "Opponent's health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
					if(random2<=5)
					attackop = attackop - 15;
				}
				else
				{
					cout << "The opponent missed!\n\n";
					cout << "Opponent's health is: " << healthop << endl << "Your health is: " << healthus << endl << endl;
				}
				system("pause");
			}
		}while((healthop >= 1)&&(healthus >= 1));
		system("cls");
		if(healthop >= 1)
		{
			cout << "You were beat by the " << nameop << "!!! Whhaaaahaahaaaaa\n\n";
			Beep(180,500);
			Beep(160,500);
			Beep(140,500);
			Beep(120,500);
			Beep(100,800);
		}
		else
		{
			level++;
			c++;
			cout << "Congratulations on your victory! You have graduated to level " << level << "!!!.\n\n";
			cout << "Which attribute would you like to increase by 5 points?\n";
			cout << endl << "(1)\n*****\nattack\n*****\n\n(2)\n*****\nmagic\n*****\n\n(3)\n*****\nspeed\n*****\n\n(4)\n*****\ndefense\n*****\n:";
			cin >> atr;
			switch(atr)
			{
			case 1:
				attackus = attackus + 5;
				break;
			case 2:
				magicus = magicus + 5;
				break;
			case 3:
				speedus = speedus + 5;
				break;
			case 4:
				defenseus = defenseus + 5;
				break;
			default:
				defenseus = defenseus;
				break;
			}
			system("cls");
			cout << "Your current Stats are:\nattack - " << attackus << endl << "magic - " << magicus << endl << "speed - " << speedus << endl << "defense - " << defenseus << endl << endl;
			system("pause");
			system("cls");
		}
		system("pause");
	}while(healthus >= 1);
	cout << endl << endl;
}

*Quite a few bugs still, and I need to add more random events as well as equalize the character vs. enemy battles.*

Anyway, I was wondering if you guys ever made any rpg games, or any game at all in C++. If you did, please post it!

BTW, I am a newby at coding, so if you find any errors in my code or anything, please point them out so I can correct them...only if you want to.

Here is a DOS console roulette game with ascii graphics.

Here is DOS console Blackjack game.

Here is a Blackjack windows app.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.