
C++ RPG Game
This is a game I made as part of my final project for my DVC computer science class. It contain all of the basic features of C++, including functions, arrays, and pointer variables.
// CPP Final Project by Kanishka Verose
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int oppo_choice() //Random Function
{
srand ( time(NULL) ); //initialize the random seed
int oppo_opt[2] = {1, 2}; //Array
int rand_choice = rand() % 2;
int oppoc = oppo_opt[rand_choice];
return oppoc;
}
int main()
{
int choice, oppotype, oppo_health, oppo_magic, oppo_attack_power, player_health = 100, player_magic = 10, playchoice;
//Menu:
cout << "--------------------------------------------------------------------------------------------------------------\n";
cout << "Welcome to FinalBattle by Kanishka Verose. To start a battle type '1'. To quit type '0'.\n";
cout << "--------------------------------------------------------------------------------------------------------------\n";
cin >> choice;
//If choice not within parameters:
while (choice != 0 && choice != 1)
{
cout << "You must enter either a '1' to start or a '0' to quit.\n";
cin >> choice;
}
//QUIT condition
if (choice == 0)
{
cout << "Quitting...\n";
return 0;
}
//START condition
else
{
//Allow User to choose opponents with 3 set difficulties:
cout << "Who do you want to battle? '1' for Thug (Easy Difficulty). '2' for Criminal (Medium Difficulty). '3' for Gangster(Hard Difficulty).\n";
cin >> oppotype;
//Input Validation
while (choice != 1 && choice != 2 && choice != 3)
{
cout << "You must enter either a '1', '2', or '3' to choose an opponent!\n";
cin >> oppotype;
}
//Opponent type Thug
if (oppotype == 1)
{
int oppo_health = 50, oppo_magic = 10, oppo_attack_power = 5;
cout << "You are battling the Thug!\n";
cout << "\nThe Battle has started!\n";
while (player_health > 0)
{
cout << "\nWhat will you do? '1' for attack or '2' for magic: \n";
cout << "Health is at " << player_health << ", magic is at " << player_magic << ".\n";
cout << "Opponent Health is at " << oppo_health << ", and magic is at " << oppo_magic << ".\n";
cin >> playchoice;
if (playchoice == 1)
{
cout << "\nYou attack!\n";
oppo_health -= 10;
}
else if (playchoice == 2)
{
//If player uses magic
if (player_magic > 0)
{
player_health += 10;
player_magic -= 1;
cout << player_magic << " magic left.\n";
}
else
{
//If magic is insufficient for player
cout << "Not enough magic!\n";
}
}
else
{
//Input Validation
cout << "Input not valid, please enter a '1' or '2'.";
cin >> playchoice;
}
int oppo_decis = oppo_choice(); //Call Opponent Function for Opponent choice
if (oppo_decis == 1)
{
//If Opponent Attacks
cout << "\nThe Opponent Attacks!\n";
player_health -= oppo_attack_power;
}
else
{
if (oppo_magic > 0)
{
//If Opponent Uses Magic:
cout << "\nThe Opponent uses Magic!\n";
oppo_health -= oppo_magic;
}
else
{
//If Opponent magic is insufficient
cout << "\nThe Opponent tried to use magic, but has none left!\n";
}
}
if (oppo_health == 0)
{
//Player wins by draining opponent's health
cout << "\nYou win!\n";
cout << "Player has " << player_health << " left with " << player_magic << " left.\n";
return 0;
}
}
if (player_health == 0)
{
//player loses by getting health drained
cout << "\nGame Over!\n" ;
return 0;
}
}
else if (oppotype == 2)
{
//Opponent type criminal : Med
int oppo_health = 100, oppo_magic = 5, oppo_attack_power = 10;
cout << "You are battling the Criminal!\n";
cout << "The Battle has started!\n";
while (player_health > 0)
{
cout << "\nWhat will you do? '1' for attack or '2' for magic: \n";
cout << "Health is at " << player_health << ", magic is at " << player_magic << ".\n";
cout << "Opponent Health is at " << oppo_health << ", and magic is at " << oppo_magic << ".\n";
cin >> playchoice;
if (playchoice == 1)
{
cout << "\nYou attack!\n";
oppo_health -= 10;
}
else if (playchoice == 2)
{
//If player uses magic
if (player_magic > 0)
{
player_health += 10;
player_magic -= 1;
cout << player_magic << " magic left.\n";
}
else
{
//If magic is insufficient for player
cout << "Not enough magic!\n";
}
}
else
{
//Input Validation
cout << "Input not valid, please enter a '1' or '2'.";
cin >> playchoice;
}
int oppo_decis = oppo_choice(); //Call Opponent Function for Opponent choice
if (oppo_decis == 1)
{
//If Opponent Attacks
cout << "\nThe Opponent Attacks!\n";
player_health -= oppo_attack_power;
}
else
{
if (oppo_magic > 0)
{
//If Opponent Uses Magic:
cout << "\nThe Opponent uses Magic!\n";
oppo_health -= oppo_magic;
}
else
{
//If Opponent magic is insufficient
cout << "\nThe Opponent tried to use magic, but has none left!\n";
}
}
if (oppo_health == 0)
{
//Player wins by draining opponent's health
cout << "\nYou win!\n";
cout << "Player has " << player_health << " left with " << player_magic << " left.\n";
return 0;
}
}
if (player_health == 0)
{
//player loses by getting health drained
cout << "\nGame Over!\n" ;
return 0;
}
}
else if (oppotype == 3)
{
//Opponent type Gangster: Hard
int oppo_health = 150, oppo_magic = 0, oppo_attack_power = 20;
cout << "You are battling the Gangster!\n";
cout << "The Battle has started!\n";
while (player_health > 0)
{
cout << "\nWhat will you do? '1' for attack or '2' for magic: \n";
cout << "Health is at " << player_health << ", magic is at " << player_magic << ".\n";
cout << "Opponent Health is at " << oppo_health << ", and magic is at " << oppo_magic << ".\n";
cin >> playchoice;
if (playchoice == 1)
{
cout << "\nYou attack!\n";
oppo_health -= 10;
}
else if (playchoice == 2)
{
//If player uses magic
if (player_magic > 0)
{
player_health += 10;
player_magic -= 1;
cout << player_magic << " magic left.\n";
}
else
{
//If magic is insufficient for player
cout << "Not enough magic!\n";
}
}
else
{
//Input Validation
cout << "Input not valid, please enter a '1' or '2'.";
cin >> playchoice;
}
int oppo_decis = oppo_choice(); //Call Opponent Function for Opponent choice
if (oppo_decis == 1)
{
//If Opponent Attacks
cout << "\nThe Opponent Attacks!\n";
player_health -= oppo_attack_power;
}
else
{
if (oppo_magic > 0)
{
//If Opponent Uses Magic:
cout << "\nThe Opponent uses Magic!\n";
oppo_health -= oppo_magic;
}
else
{
//If Opponent magic is insufficient
cout << "\nThe Opponent tried to use magic, but has none left!\n";
}
}
if (oppo_health == 0)
{
//Player wins by draining opponent's health
cout << "\nYou win!\n";
cout << "Player has " << player_health << " left with " << player_magic << " left.\n";
return 0;
}
}
if (player_health == 0)
{
//player loses by getting health drained
cout << "\nGame Over!\n" ;
return 0;
}
}
}
}