Sign in to follow this  
Schade

How to loop this to beginning?

Recommended Posts

Hello every one im haveing a problem trying to get this to loop back to forest. when your inside the bool darkroad. I think you might beable to tell me off this if not im going to have to past alot of stuff in here, hopefully someone has an idea. Thanks

#include "Library.h"
//Forest

bool DarkRoad(PLAYER *player);
bool StoneRoad(PLAYER *player);
bool EnemyCamp(PLAYER *player);

bool Forest(PLAYER* player)
{
	cout <<  " You begin walking down a road\n";

	cout << "All of a sudden two wolves jump out and attack you\n";
	Wait();

	MONSTER wolfgroup[2];
	wolfgroup[0].CreateMonster("Wolf",10,0,3,0,2,1);
	wolfgroup[1].CreateMonster("Wolf",10,0,3,0,2,1);

	if (Battle(player,wolfgroup,2) == false)
	{
		cout << "You have been defated by the wolfs.\n";
		return false;
	}

	int choice = 0;

	if (choice != 2)
	{
		cout << "After slaying the two wolves you notice a fork in the road ahead of you.\n";
		cout << "To the left the road looks rocky and dangerous.\n";
		cout << "To the right the road looks straight and wide.\n\n";

		cout << "Which path do you want to take?\n";

		cout << "Press Enter To Continue";
		cin.get();
		cout << endl;

		cout << "What would you like to do?\n";
		cout << "1: Take Left path.\n";
		cout << "2: Take Right path\n";
		

		cout << ">";

		cin >> choice;
		cin.clear();
		cin.ignore(INT_MAX,'\n');

		cout << endl;
	}

	//player choose an option
	

	if (choice == 1) // left
	{
		//player chooses to go down the dark road.
		if (DarkRoad(player) == true)
			return true;

	}
	else
	{
		//player goes down the stone and wide path
		if (StoneRoad(player) == true)
			return true;
	}

	//Generic you have defeated the forest area
	return true;
}

bool DarkRoad(PLAYER *player)
{
	cout << "As you start walking down the Rockyroad a old man steps out of the forest.\n";
	cout << "Old man: Hello sir there are some Giant Snake's right up the road thats causing trouble for the travelers!\n\n";

	cout << "Do you wish to help the old man? (y/n)\n";
	
	char answer[10];

	while (true)
	{
		cout << ">";
		cin >> answer;
		cin.ignore(20,'\n');

		if (answer[0] == 'n')
		{
			//display generic exit
			cout << "You turn around and walk back towards the Citygates.\n";
			Wait();
			cout << endl;
			return false;
		}
		if (answer[0] == 'y')
			break;
	}
	//this is the Dark road
	MONSTER snakegroup[2];
	snakegroup[0].CreateMonster("Giant Snake",10,0,3,0,2,1);
	snakegroup[1].CreateMonster("Giant snake",10,0,3,0,2,1);

	if (Battle(player,snakegroup,2) == false)
	return false;

	return true;
}

bool StoneRoad(PLAYER *player)
{
	//this is the stone road

	cout << "This road is crawling with enemie. Should have chosen the other path...\n\n";
	
	MONSTER snakegroup[2];
	snakegroup[0].CreateMonster("Giant Snake",10,0,3,0,2,1);
	snakegroup[1].CreateMonster("Giant snake",10,0,3,0,2,1);
	
	if (Battle(player,snakegroup,2) == false)
	{
		//youve been captured. what do you want to do.
		if (EnemyJail(player) == false)
			return false;

		//Now that you've escaped, you head back to the first path
		return true;
	}
	
	return true;
}

bool EnemyCamp(PLAYER *player)
{
	//You manage to take the key from guard

	//if the player dies somewhere inside the jail
	//return false;

	return true;
}


Share this post


Link to post
Share on other sites
Hmm. It's difficult. There so many things wrong with this program I don't know where to begin :)

That being said though. Having the different locations as functions are not the way to go. You need a game mainloop that switches between locations, as well as keeping track of your current location.

Also locations specifics (text, monsters etc) should be in data structures.
Having hardcoded encounters/text will lead to a repetetive experiences (each time you enter the forest you have to kill 2 wolves)

Also you do not keep track of whether or not you talked to the old man. So you will be asked the same each time.

This way of doing the locations will never work as you have just discovered yourself :)

Having the battle function and the MONSTER structure is good and hints what you should be doing with the rest of the program :)

Look at some of the many text adventure tutorials that can be found on the web.

Other than that it sounds like a cool game, so keep going and good luck :)

Share this post


Link to post
Share on other sites
yea i know it didnt compile i didnt give you everything as its a lot, so here it is all of it, an it work on my computer.


// CityGates.cpp
#include "Library.h"

// GLOBAL VARIABLES

bool glcomplete = false;
bool fcomplete = false;
bool scomplete = false;
bool gcomplete = false;
bool ccomplete = false;

PLAYER player;


bool CityGate()
{
//set player default values


cout << "What is your name hero?\n";
char name[32];
cout << ">";
cin.getline(name,32,'\n');
player.SetName(name);

cout << "\n\n";

int choice = 0;

while (choice != 10)
{
cout << "You stand at the gate's of the city of Izmore there are\nserveral road's you can take.\n\n";
cout << "The huge city of Izmore stand's infront of you.\n\n";

cout << "Which path do you want to choose?\n";
cout << "1: Town\n";
cout << "2: Summoning Portal\n";

if (!glcomplete)
cout << "3: Grasslands (QUEST)\n";

if (glcomplete && !fcomplete)
cout << "4: Forest Road (QUEST)\n";

if (fcomplete && !scomplete)
cout << "5: Swamp Road (QUEST)\n";

if (scomplete && !gcomplete)
cout << "6: Graveyard Road (QUEST)\n";

if (gcomplete && !ccomplete)
cout << "7: Castle Road (QUEST)\n";

cout << "9: View Players Stats\n";
cout << "10: Exit Game\n";

cout << ">";

cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');

cout << "\n";

switch (choice)
{
case 1:
{
Town(&player);
break;
}
case 2:
{
//determine which level the player is on
int level = 1;
if (glcomplete)
level = 2;
else if (fcomplete)
level = 3;
else if (scomplete)
level = 4;

SummonPortal(&player,level);
break;
}
case 3:
{
if(!glcomplete)
{
if (Grasslands(&player))
glcomplete = true;
else
{
cout << "A wandering farmer finds you bod and takes you back to town.\n";
Wait();
Town(&player);
}
}
break;
}
case 4:
{
//if (glcomplete && !fcomplete)
//Forest();
break;
}
case 5:
{
//if (fcomplete && !scomplete)
//Swamp();
break;
}
case 6:
{
//if (scomplete && !gcomplete)
//Graveyard();
break;
}
case 7:
{
//if (gcomplete && !ccomplete)
//Castle();
break;
}
case 9:
{
DisplayStats(&player);
break;
}
case 10:
{
//quit
break;
}
default:
{
choice = -1;
}break;
}
}
return true;
}





//Town.cpp
#include "Library.h"

//Town

void Inn(PLAYER*);
void Armory(PLAYER*);
void ItemShop(PLAYER*);

bool Town(PLAYER* player)
{
int choice = 0;

while (choice != 5)
{
cout << "\nYou walk into town.\n";
cout << "All around you there are people going about their daily lives.\n";
cout << "To your left you spot an INN and to your right you spot the ARMORY\nand ITEM SHOP.\n\n";

cout << "Press Enter To Continue";
cin.get();
cout << endl;

cout << "What would you like to do?\n";
cout << "1: Enter INN\n";
cout << "2: Enter ARMORY\n";
cout << "3 Enter ITEM SHOP\n";
cout << "4: Check Stats\n";
cout << "5: Leave TOWN\n";

cout << ">";

cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');

cout << endl;

switch (choice)
{
case 1:
{
cout << "You walk into the inn.\n";
Wait();
Inn(player);
break;
}
case 2:
{
cout << "You walk towards the Armory\n\n";
Wait();
Armory(player);
break;
}
case 3:
{
ItemShop(player);
break;
}
case 4:
{
DisplayStats(player);
break;
}
default: break;
}
}
return true;
}

void Inn(PLAYER *player)
{
cout << "\nYou stand in a vacant bar. One man is having a good\ntime drinking his brew. Except for an old man standing behind the\ncounter.\n";
cout << "There are some room's open for the night.\n\n";
cout << "You walk over to the old man. He grins, delighted to see a visitor.\n";
cout << "Hello and Welcome, would you like to stay in my inn for only 10 gold coins?\n";

char answer;
answer = 'm';

while (true)
{
cout << "Stay? (10 gold) y/n\n";
cout << ">";
cin >> answer;
cin.ignore(10,'\n');

if (answer == 'y' || answer == 'n')
break;
}

cout << endl;

if (answer == 'y')
{
if (player ->GetGold() >= 10)
{
player ->SpendGold(10);
cout << "You find a nice bed an fall fast asleep.\n";
cout << "Press Enter to Continue";
cin.get();
cout << "\n(HP and MP restored)\n\n";
player->SetHealth(player->GetMaxHealth());
player->SetMana(player->GetMaxMana());
cout << "HP: " << player->GetHealth() << " / " << player->GetMaxHealth() << " ";
cout << "MP: " << player->GetMana() << " / " << player->GetMaxMana() << "\n";

Wait();
}
else
{
cout << "It looks like you don't have enough gold.\n\n";
Wait();
answer = 'n';
}
}

if (answer == 'n')
{
cout << "You turn around and walk out of the inn.\n";
Wait();
}
}


void Armory(PLAYER* player)
{
cout << "You walk into throu the entrance of the armory. All along the walls are various.\n";
cout << "Weapons and armor. You can hear the blacksmith forging somewhere.\n";
cout << "behind the armory. To your left stands the armory merchant.\n\n";

cout << "MERCHANT: Interested in anything?\n";
Wait();

int answer = 0;

while (true)
{
cout << "1: Buy Weapons\n";
cout << "2: Buy Armor\n";
cout << "3: Leave\n\n";

cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

cout << "\n\n";


if (answer == 1)
{
//display weapons
WEAPON* weaponlist = new WEAPON[7];

weaponlist[0].CreateWeapon("Dagger",4,15);
weaponlist[1].CreateWeapon("hatchet",8,200);
weaponlist[2].CreateWeapon("Bronze Sword",15,1000);
weaponlist[3].CreateWeapon("Battle Axe",30,10000);
weaponlist[4].CreateWeapon("Great Sword",50,20000);
weaponlist[5].CreateWeapon("Master Sword",70,50000);
weaponlist[6].CreateWeapon("XCalibur",150,150000);

cout << "Weapons" << endl;

for (int loop = 0; loop < 7; loop++)
{
cout << loop+1 << ": " << weaponlist[loop].GetName() << " - DMG:" << weaponlist[loop].GetDamage() << ", Price: " << weaponlist[loop].GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Whih wepon would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 8 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > weaponlist[answer-1].GetPrice())
{
//player can afford
player->SpendGold(weaponlist[answer-1].GetPrice());
player->SetWeapon(weaponlist[answer-1]);

cout << "You now have the " << player->GetWeapon()->GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}
}

delete [] weaponlist;
} //end if buy weapon
else if (answer == 2)
{
//display armor
ARMOR* armorlist = new ARMOR[5];

armorlist[0].CreateArmor("Cloth",1,10);
armorlist[1].CreateArmor("Leather",3,150);
armorlist[2].CreateArmor("Chain Mail",5,400);
armorlist[3].CreateArmor("Plate",10,1500);
armorlist[4].CreateArmor("Dragon Scale",20,10000);

cout << "Armor" << endl;

for (int loop = 0; loop < 5; loop++)
{
cout << loop+1 << ": " << armorlist[loop].GetName() << " -DMG:" << armorlist[loop].GetAP() << ", Price: " << armorlist[loop].GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Which Armor set would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 6 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > armorlist[answer-1].GetPrice())
{
//player can afford
player->SpendGold(armorlist[answer-1].GetPrice());
player->SetArmor(armorlist[answer-1]);

cout << "You now have the " << player->GetArmor()->GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}
}

delete [] armorlist;
}
else if (answer == 3)
{
cout << "You turn arond an leave the store.\n";
Wait();
cout <<endl;
break;
}
else
{
cout << "Invalid command.\n";
}
}// End While in shop
}

//Item Shop

void ItemShop(PLAYER* player)
{
cout << "You stand in the item shop. As you look you see potions filling the countertops and scrolls\n";
cout << "lay tacked to the walls.\n\n";

int answer = 0;
while (true)
{
cout << "1: Buy Potions\n";
cout << "2: Buy Spells\n";
cout << "3: Leace\n";

cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer == 1)
{
//buy potions
POTION* potionlist = new POTION[10];

//health potions
potionlist[0].CreateHealthPotion("Small Health Potion",10,5);
potionlist[1].CreateHealthPotion("Medium Health Potion",25,50);
potionlist[2].CreateHealthPotion("Large Health Potion",75,500);
potionlist[3].CreateHealthPotion("Elixer",200,5000);
potionlist[4].CreateHealthPotion("Grand Elixer",500,15000);
potionlist[5].CreateHealthPotion("Elixer of Life",player->GetMaxHealth(),50000);

//mana potions
potionlist[6].CreateManaPotion("Small Mana Potion", 10,20);
potionlist[7].CreateManaPotion("Medium Mana Potion", 25,50);
potionlist[8].CreateManaPotion("Large Mana Potion",40,500);
potionlist[9].CreateManaPotion("Grand Mana Potion",60,5000);

cout << "Potions" << endl;

for (int loop = 0; loop < 10; loop++)
{
cout << loop+1 << ": " << potionlist[loop].GetName() << " - Health:" << potionlist[loop].GetHealthRestore() << ", Mana: " << potionlist[loop].GetManaRestore() << ", Price:" << potionlist[loop].GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Which potion would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 11 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > potionlist[answer-1].GetPrice())
{
//player can afford
player->SpendGold(potionlist[answer-1].GetPrice());
//Give potion
player->AddPotion(&potionlist[answer-1]);

cout << "You purchased a " << potionlist[answer-1].GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}
}
delete [] potionlist;
}
else if (answer == 2)
{
//buy spells

SPELL* slist[10];

for (int clear = 0; clear < 10; clear++)
slist[clear] = NULL;

slist[0] = new FIREBALL();
slist[1] = new HEAL();
slist[2] = new POISON();
slist[3] = new LIGHTNING();
slist[4] = new FROSTBOLT();

cout << "Spells" << endl;

for (int loop = 0; loop < 10; loop++)
{
if (slist[loop] != NULL)
cout << loop+1 << ": " << slist[loop]->GetName() << ", Mana: " << slist[loop]->GetManaCost() << ", Price:" << slist[loop]->GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Which spell would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 11 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > slist[answer-1]->GetPrice())
{
//player can afford
player->SpendGold(slist[answer-1]->GetPrice());
//Give spell
player->AddSpell(slist[answer-1]);

cout << "You purchased the spell " << slist[answer-1]->GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}

}
for (int del=0;del < 10;del++)
{
if (slist[del] != NULL)
delete slist[del];
}

}
else if (answer == 3)
{
cout << "You turn arond an leave the store.\n";
Wait();
cout <<endl;
break;
}
else
{
cout << "Invalid command.\n";
}

cout << "\n";
}//while in item shop
}









//SummonPortal.cpp
#include "Library.h"

//Town

void Inn(PLAYER*);
void Armory(PLAYER*);
void ItemShop(PLAYER*);

bool Town(PLAYER* player)
{
int choice = 0;

while (choice != 5)
{
cout << "\nYou walk into town.\n";
cout << "All around you there are people going about their daily lives.\n";
cout << "To your left you spot an INN and to your right you spot the ARMORY\nand ITEM SHOP.\n\n";

cout << "Press Enter To Continue";
cin.get();
cout << endl;

cout << "What would you like to do?\n";
cout << "1: Enter INN\n";
cout << "2: Enter ARMORY\n";
cout << "3 Enter ITEM SHOP\n";
cout << "4: Check Stats\n";
cout << "5: Leave TOWN\n";

cout << ">";

cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');

cout << endl;

switch (choice)
{
case 1:
{
cout << "You walk into the inn.\n";
Wait();
Inn(player);
break;
}
case 2:
{
cout << "You walk towards the Armory\n\n";
Wait();
Armory(player);
break;
}
case 3:
{
ItemShop(player);
break;
}
case 4:
{
DisplayStats(player);
break;
}
default: break;
}
}
return true;
}

void Inn(PLAYER *player)
{
cout << "\nYou stand in a vacant bar. One man is having a good\ntime drinking his brew. Except for an old man standing behind the\ncounter.\n";
cout << "There are some room's open for the night.\n\n";
cout << "You walk over to the old man. He grins, delighted to see a visitor.\n";
cout << "Hello and Welcome, would you like to stay in my inn for only 10 gold coins?\n";

char answer;
answer = 'm';

while (true)
{
cout << "Stay? (10 gold) y/n\n";
cout << ">";
cin >> answer;
cin.ignore(10,'\n');

if (answer == 'y' || answer == 'n')
break;
}

cout << endl;

if (answer == 'y')
{
if (player ->GetGold() >= 10)
{
player ->SpendGold(10);
cout << "You find a nice bed an fall fast asleep.\n";
cout << "Press Enter to Continue";
cin.get();
cout << "\n(HP and MP restored)\n\n";
player->SetHealth(player->GetMaxHealth());
player->SetMana(player->GetMaxMana());
cout << "HP: " << player->GetHealth() << " / " << player->GetMaxHealth() << " ";
cout << "MP: " << player->GetMana() << " / " << player->GetMaxMana() << "\n";

Wait();
}
else
{
cout << "It looks like you don't have enough gold.\n\n";
Wait();
answer = 'n';
}
}

if (answer == 'n')
{
cout << "You turn around and walk out of the inn.\n";
Wait();
}
}


void Armory(PLAYER* player)
{
cout << "You walk into throu the entrance of the armory. All along the walls are various.\n";
cout << "Weapons and armor. You can hear the blacksmith forging somewhere.\n";
cout << "behind the armory. To your left stands the armory merchant.\n\n";

cout << "MERCHANT: Interested in anything?\n";
Wait();

int answer = 0;

while (true)
{
cout << "1: Buy Weapons\n";
cout << "2: Buy Armor\n";
cout << "3: Leave\n\n";

cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

cout << "\n\n";


if (answer == 1)
{
//display weapons
WEAPON* weaponlist = new WEAPON[7];

weaponlist[0].CreateWeapon("Dagger",4,15);
weaponlist[1].CreateWeapon("hatchet",8,200);
weaponlist[2].CreateWeapon("Bronze Sword",15,1000);
weaponlist[3].CreateWeapon("Battle Axe",30,10000);
weaponlist[4].CreateWeapon("Great Sword",50,20000);
weaponlist[5].CreateWeapon("Master Sword",70,50000);
weaponlist[6].CreateWeapon("XCalibur",150,150000);

cout << "Weapons" << endl;

for (int loop = 0; loop < 7; loop++)
{
cout << loop+1 << ": " << weaponlist[loop].GetName() << " - DMG:" << weaponlist[loop].GetDamage() << ", Price: " << weaponlist[loop].GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Whih wepon would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 8 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > weaponlist[answer-1].GetPrice())
{
//player can afford
player->SpendGold(weaponlist[answer-1].GetPrice());
player->SetWeapon(weaponlist[answer-1]);

cout << "You now have the " << player->GetWeapon()->GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}
}

delete [] weaponlist;
} //end if buy weapon
else if (answer == 2)
{
//display armor
ARMOR* armorlist = new ARMOR[5];

armorlist[0].CreateArmor("Cloth",1,10);
armorlist[1].CreateArmor("Leather",3,150);
armorlist[2].CreateArmor("Chain Mail",5,400);
armorlist[3].CreateArmor("Plate",10,1500);
armorlist[4].CreateArmor("Dragon Scale",20,10000);

cout << "Armor" << endl;

for (int loop = 0; loop < 5; loop++)
{
cout << loop+1 << ": " << armorlist[loop].GetName() << " -DMG:" << armorlist[loop].GetAP() << ", Price: " << armorlist[loop].GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Which Armor set would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 6 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > armorlist[answer-1].GetPrice())
{
//player can afford
player->SpendGold(armorlist[answer-1].GetPrice());
player->SetArmor(armorlist[answer-1]);

cout << "You now have the " << player->GetArmor()->GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}
}

delete [] armorlist;
}
else if (answer == 3)
{
cout << "You turn arond an leave the store.\n";
Wait();
cout <<endl;
break;
}
else
{
cout << "Invalid command.\n";
}
}// End While in shop
}

//Item Shop

void ItemShop(PLAYER* player)
{
cout << "You stand in the item shop. As you look you see potions filling the countertops and scrolls\n";
cout << "lay tacked to the walls.\n\n";

int answer = 0;
while (true)
{
cout << "1: Buy Potions\n";
cout << "2: Buy Spells\n";
cout << "3: Leace\n";

cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer == 1)
{
//buy potions
POTION* potionlist = new POTION[10];

//health potions
potionlist[0].CreateHealthPotion("Small Health Potion",10,5);
potionlist[1].CreateHealthPotion("Medium Health Potion",25,50);
potionlist[2].CreateHealthPotion("Large Health Potion",75,500);
potionlist[3].CreateHealthPotion("Elixer",200,5000);
potionlist[4].CreateHealthPotion("Grand Elixer",500,15000);
potionlist[5].CreateHealthPotion("Elixer of Life",player->GetMaxHealth(),50000);

//mana potions
potionlist[6].CreateManaPotion("Small Mana Potion", 10,20);
potionlist[7].CreateManaPotion("Medium Mana Potion", 25,50);
potionlist[8].CreateManaPotion("Large Mana Potion",40,500);
potionlist[9].CreateManaPotion("Grand Mana Potion",60,5000);

cout << "Potions" << endl;

for (int loop = 0; loop < 10; loop++)
{
cout << loop+1 << ": " << potionlist[loop].GetName() << " - Health:" << potionlist[loop].GetHealthRestore() << ", Mana: " << potionlist[loop].GetManaRestore() << ", Price:" << potionlist[loop].GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Which potion would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 11 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > potionlist[answer-1].GetPrice())
{
//player can afford
player->SpendGold(potionlist[answer-1].GetPrice());
//Give potion
player->AddPotion(&potionlist[answer-1]);

cout << "You purchased a " << potionlist[answer-1].GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}
}
delete [] potionlist;
}
else if (answer == 2)
{
//buy spells

SPELL* slist[10];

for (int clear = 0; clear < 10; clear++)
slist[clear] = NULL;

slist[0] = new FIREBALL();
slist[1] = new HEAL();
slist[2] = new POISON();
slist[3] = new LIGHTNING();
slist[4] = new FROSTBOLT();

cout << "Spells" << endl;

for (int loop = 0; loop < 10; loop++)
{
if (slist[loop] != NULL)
cout << loop+1 << ": " << slist[loop]->GetName() << ", Mana: " << slist[loop]->GetManaCost() << ", Price:" << slist[loop]->GetPrice() << endl;
}

cout << endl << "0: Cancel\n\n";

int answer = -1;
cout << "Which spell would you like to purchase?\n";

while(true)
{
cout << ">";
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');

if (answer < 11 && answer > 0)
{
//check if the player can purchase the item
if (player->GetGold() > slist[answer-1]->GetPrice())
{
//player can afford
player->SpendGold(slist[answer-1]->GetPrice());
//Give spell
player->AddSpell(slist[answer-1]);

cout << "You purchased the spell " << slist[answer-1]->GetName() << ".\n";
Wait();
cout << endl;
break;
}
else
{
//player cant afford
cout << "You don't have enough money.\n";
Wait();
cout << endl;
break;
}
}

if (answer == 0)
{
break;
}

}
for (int del=0;del < 10;del++)
{
if (slist[del] != NULL)
delete slist[del];
}

}
else if (answer == 3)
{
cout << "You turn arond an leave the store.\n";
Wait();
cout <<endl;
break;
}
else
{
cout << "Invalid command.\n";
}

cout << "\n";
}//while in item shop
}









//Grasslands.cpp
#include "Library.h"
//Grasslands

bool RockyRoad(PLAYER *player);
bool StraightRoad(PLAYER *player);
bool EnemyJail(PLAYER *player);

bool Grasslands(PLAYER* player)
{
cout << " You begin walking down a road\n";

cout << "All of a sudden two wolves jump out and attack you\n";
Wait();

MONSTER wolfgroup[2];
wolfgroup[0].CreateMonster("Wolf",10,0,3,0,2,1);
wolfgroup[1].CreateMonster("Wolf",10,0,3,0,2,1);

if (Battle(player,wolfgroup,2) == false)
{
cout << "You have been defated by the wolfs.\n";
return false;
}

int choice = 0;

if (choice != 2)
{
cout << "After slaying the two wolves you notice a fork in the road ahead of you.\n";
cout << "To the left the road looks rocky and dangerous.\n";
cout << "To the right the road looks straight and wide.\n\n";

cout << "Which path do you want to take?\n";

cout << "Press Enter To Continue";
cin.get();
cout << endl;

cout << "What would you like to do?\n";
cout << "1: Take Left path.\n";
cout << "2: Take Right path\n";


cout << ">";

cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');

cout << endl;
}

//player choose an option


if (choice == 1) // left
{
//player chooses to go down the rocky road.
if (RockyRoad(player) == true)
return true;

}
else
{
//player goes down the straight and wide path
if (StraightRoad(player) == true)
return true;
}

//Generic you have defeated the grasslands area
return true;
}

bool RockyRoad(PLAYER *player)
{
cout << "As you start walking down the Rockyroad a old man steps out of the forest.\n";
cout << "Old man: Hello sir there are some Giant Snake's right up the road thats causing trouble for the travelers!\n\n";

cout << "Do you wish to help the old man? (y/n)\n";

char answer[10];

while (true)
{
cout << ">";
cin >> answer;
cin.ignore(20,'\n');

if (answer[0] == 'n')
{
//display generic exit
cout << "You turn around and walk back towards the Citygates.\n";
Wait();
cout << endl;
return false;
}
if (answer[0] == 'y')
break;
}
//this is the rocky road
MONSTER snakegroup[2];
snakegroup[0].CreateMonster("Giant Snake",10,0,3,0,2,1);
snakegroup[1].CreateMonster("Giant snake",10,0,3,0,2,1);

if (Battle(player,snakegroup,2) == false)
return false;

return true;
}

bool StraightRoad(PLAYER *player)
{
//this is the straight road

cout << "This road is crawling with enemie. Should have chosen the other path...\n\n";

MONSTER snakegroup[2];
snakegroup[0].CreateMonster("Giant Snake",10,0,3,0,2,1);
snakegroup[1].CreateMonster("Giant snake",10,0,3,0,2,1);

if (Battle(player,snakegroup,2) == false)
{
//youve been captured. what do you want to do.
if (EnemyJail(player) == false)
return false;

//Now that you've escaped, you head back to the first path
return true;
}

return true;
}

bool EnemyJail(PLAYER *player)
{
//You manage to take the key from guard

//if the player dies somewhere inside the jail
//return false;

return true;
}






//Battle.cpp

#include "Library.h"

void ListMonsters(MONSTER* list,int count);
bool AttackMonster(PLAYER* player,MONSTER* monster);
bool MonsterAttack(MONSTER* monster,PLAYER* player);

bool Battle(PLAYER* player,MONSTER* list, int count)
{
cout << "You clench your " << player->GetWeapon()->GetName() << " tightly and face the enemy.\n\n";

while (player->GetHealth() > 0)
{
//player goes first
bool actionused = false;

//display enemy count
if (count == 1)
{
cout << "The " << list->GetName() << " stares at you menacingly.\n";

//Temporary
cout << "Health: " << list->GetHealth() << endl;
Wait();
}
else
{
ListMonsters(list,count);
}


cout << "\n";

//display player stats
cout << player->GetName() << endl;
//health / maxhealth, mana / maxmana
cout << "Health: " << player->GetHealth() << " / " << player->GetMaxHealth() << endl;
cout << "Mana: " << player->GetMana() << " / " << player->GetMaxMana() << endl;

cout << endl;

int action = 0;

while (true)
{
cout << "1: Attack\n";
cout << "2: Spell\n";
cout << "3: Item\n";

cout << ">";

cin >> action;
cin.ignore(10,'\n');

//action?
if (action == 1) //attack
{
if (count == 1)
{
//attack single monster

AttackMonster(player,list);

Wait();

cout << endl;
}
else
{
//ask for target
int target = 0;

while (true)
{
ListMonsters(list,count);

cout << "\n0: cancel\n\n";

cout << "Which monster?\n";
cout << ">";

cin >> target;
cin.ignore(10,'\n');

if ( target > 0 && target <= count)
{
//check if the target is alive
if (list[target-1].GetHealth() > 0)
{
//attack the target
AttackMonster(player,&list[target-1]);

Wait();

cout << endl;

//check if alive and award points if not
if (list[target-1].GetHealth() <= 0)
{
cout << "You killed the " << list[target-1].GetName() << "\n";
cout << "You gain " << list[target-1].GetExperience() << " experience and " << list[target-1].GetGold() << " gold.\n";
player->AddExperience(list[target-1].GetExperience());
player->AddGold(list[target-1].GetGold());

cout << endl;
}
break;
}
else
{
cout << "Invalid monster.\n\n";
}
}
else if(target == 0)
{
//cancelled attack
action = 0;
break;
}
//end while target not chosen
}
//
}

if (action == 1) //followed through with attack
break;
}
else if (action ==2) //spell
{
//display players spells

//get the list
SPELL** spelllist = player->GetSpellList();

for (int loop = 0; loop < 10; loop++)
{
if (spelllist[loop] != NULL)
{
cout << loop+1 << ": " << spelllist[loop]->GetName() << " MP: " << spelllist[loop]->GetManaCost() << endl;
}
}
cout << "0: Cancel\n\n";

// check for spell input
int which = 0;
while (true)
{
cout << "Which Spell?\n";
cout << ">";
cin >> which;
cin.ignore(10,'\n');

if (which == 0)
{
//cancel
break;
}
else if (which > 0 && which < 11)
{
//valid?
if (spelllist[which-1] != NULL)
{
//spell is valid

//enough mp?
if (player->GetMana() >= spelllist[which-1]->GetManaCost())
{
//cast a spell
player->LoseMana(spelllist[which-1]->GetManaCost());

//which target?
if (count > 1)
{
ListMonsters(list, count);
}
else
{
cout << "1: " << list->GetName() << endl;
}
cout << "0: " << "Self\n";

int choice = 0;
while (true)
{
cout << "Which target?\n";
cout << ">";
cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');

//validate
if (choice == 0)
{
spelllist[which-1]->Cast((ENTITY*)player,1);
actionused = true;
break;
}
else if (count > 1 && choice < count+1)
{
if (list[choice-1].GetHealth() > 0)
{
//cast
spelllist[which-1]->Cast((ENTITY*)(&list[choice-1]),1);
actionused = true;
break;
}
else
cout << "Invalid Target\n";
}
else if (count == 1 && choice == 1)
{
//cast
spelllist[which-1]->Cast((ENTITY*)(list),1);
actionused = true;
break;
}
else
{
cout << "Invalid Target\n";
}
}//end while choose target

break;
}
else
{
cout << "Not enoguh mana\n";
}
}
}
}

if (actionused)
break;
}
else if (action == 3) //item
{
//display players potion list

//getlist
POTION** potionlist = player->GetPotionList();

for (int loop = 0; loop < 15; loop++)
{
if (potionlist[loop] != NULL)
{
cout << loop+1 << ": " << potionlist[loop]->GetName() << " (" << potionlist[loop]->GetQuantity() << ")\n";
}

}
cout << "0: Cancel\n\n";

//check for potion input
int which = 0;
while (true)
{
cout << "Which potion?\n";
cout << ">";
cin >> which;
cin.ignore(10,'\n');

if (which == 0)
{
//cancel
break;
}
else if (which > 0 && which < 16)
{
//errorcheck
if (potionlist[which-1] == NULL)
cout << "Invalide Potion.\n";
else
{
if (potionlist[which-1]->GetHealthRestore() > 0)
cout << "You gain " << potionlist[which-1]->GetHealthRestore() << " health.\n";

if (potionlist[which-1]->GetManaRestore() > 0)
cout << "You gain " << potionlist[which-1]->GetManaRestore() << " mana.\n";

player->AddHealth(potionlist[which-1]->GetHealthRestore());
player->AddMana(potionlist[which-1]->GetManaRestore());

potionlist[which-1]->SubtractQuantity(1);

//error check
if (potionlist[which-1]->GetQuantity() < 1)
{
//remove potion
delete potionlist[which-1];
potionlist[which-1] = NULL;
}

actionused = true;

Wait();
cout << endl;
break;
}
}
}

if (actionused)
break;
}
}//while attacking

//check poison
if (player->IsPoisoned())
{
cout << "Poison does 5 damage to you.\n\n";
player->LoseHealth(5);
Wait();
}
//monster poisoned?
if (count == 1)
{
if (list->IsPoisoned())
{
cout << list->GetName() << " takes 5 damage from poison.\n";
list->LoseHealth(5);
Wait();
}
}
else if (count > 1)
{
for (int ploop = 0; ploop < count; ploop++)
{
if (list[ploop].GetHealth() > 0)
{
if (list[ploop].IsPoisoned())
{
cout << list[ploop].GetName() << " takes 5 damage from poison.\n";
list[ploop].LoseHealth(5);
Wait();
}
}
}
}

//is enemy dead?
if (count == 1)
{
if (list->GetHealth() <= 0)
{
//dead
//battle over

cout << "You Win!\n";
cout << "You gain " << list->GetExperience() << " experience and " << list->GetGold() << " gold.\n";
Wait();

//award experience
player->AddExperience(list->GetExperience());
player->AddGold(list->GetGold());

player->CheckForLevelUp();
return true;
}
}
else if(count > 1)
{
bool alldead = true;
//are all enemies dead
for (int check=0;check < count;check++)
{
if (list[check].GetHealth() > 0)
{
alldead = false;
check = count;
}
}

if (alldead)
{
//end the battle
cout << "\nYou WIN!\n";
Wait();

player->CheckForLevelUp();

return true;
}
}

//enemies turn

if (count == 1)
{
//have enemy fight
MonsterAttack(list,player);

}
else
{
//loop
for (int loop = 0; loop < count; loop++)
{
if (list[loop].GetHealth() > 0)
MonsterAttack(&list[loop],player);
}
}
}

cout << "You hast been slayed.\n\n";

return false; //you died
}

void ListMonsters(MONSTER* list,int count)
{
cout << "Enemies\n";
for (int loopname = 0;loopname < count; loopname++)
{
if (list[loopname].GetHealth() > 0)
{
cout << loopname+1 << ": " << list[loopname].GetName();

// output status effect
//Goblin - posioned

cout << " - " << list[loopname].GetHealth();

cout << endl;
}
}
}

bool AttackMonster(PLAYER* player,MONSTER* monster)
{
/*
Damage Taken = ATT – AP
Damage Given = ( (ATT+Strength) / 2) TO (ATT+Strength) WITH (10-Strength)% Chance miss
*/


//calculate miss?
if (player->GetStrength() < 10)
{
//generate random number
int random = rand()%(10-player->GetStrength())+1;

if (random == 1) //miss
{
cout << "You swing as hard as you can but miss horribly\n";
return false;
}
}

//attack single monster
int pstr = player->GetStrength();
int damagelow =( (player->GetWeapon()->GetDamage() + pstr) /2 );
int damagehigh = ( player->GetWeapon()->GetDamage() + pstr);

//generate damage
int damagegiven = (rand()% (damagehigh-damagelow)+damagelow);
int totaldamage = damagegiven - monster->GetArmor();

cout << "You injure the " << monster->GetName() << " for " << totaldamage << " health.\n";
monster->LoseHealth(totaldamage);

return true;
}

bool MonsterAttack(MONSTER* monster,PLAYER* player)
{
/*
Damage Taken = ATT – AP
Damage Given = ( ATT - (ATT) / 5) TO ATT
*/


//slightly modified formula

int damagelow = monster->GetAttack() - (monster->GetAttack() / 5);
int damagehigh = monster->GetAttack();

int damagegiven = (rand()%damagehigh-damagelow)+damagelow;
int totaldamage = damagegiven - player->GetArmor()->GetAP();

if (totaldamage < 0)
totaldamage = 0;

cout << "The " << monster->GetName() << " attacks you for " << totaldamage << " health.\n";
player->LoseHealth(totaldamage);

Wait();

return true;
}




//Armor.h

class ARMOR: public ITEM
{
private:
int ap;
public:
ARMOR()
{
ap = 0;
}

void CreateArmor(char* newname, int newap, int newprice)
{
SetName(newname);
SetAP(newap);
SetPrice(newprice);
}
int GetAP()
{
return ap;
}
void SetAP(int amount)
{
ap = amount;
}
};




//Entity.cpp

#include "Library.h"

void ENTITY::AddExperience(int amount)
{
SetExperience(experience + amount);
}

void ENTITY::AddGold(int amount)
{
SetGold(gold + amount);
}

void ENTITY::AddHealth(int amount)
{
SetHealth(health + amount);
}

void ENTITY::AddMana(int amount)
{
SetMana(mana + amount);
}

int ENTITY::GetExperience()
{
return experience;
}

int ENTITY::GetGold()
{
return gold;
}

int ENTITY::GetHealth()
{
return health;
}
int ENTITY::GetMana()
{
return mana;
}

int ENTITY::GetMaxHealth()
{
return maxhealth;
}

int ENTITY::GetMaxMana()
{
return maxmana;
}
char* ENTITY::GetName()
{
return name;
}

void ENTITY::SetExperience(int newexperience)
{
experience = newexperience;
}

void ENTITY::SetGold(int newgold)
{
gold = newgold;
}

void ENTITY::SetHealth(int newhealth)
{
health = newhealth;

if (health > maxhealth)
health = maxhealth;

if (health < 0)
health = 0;
}
void ENTITY::SetMana(int newmana)
{
mana = newmana;

if (mana > maxmana)
mana = maxmana;

if ( mana < 0)
mana = 0;
}

void ENTITY::SetMaxHealth(int newmaxhealth)
{
maxhealth = newmaxhealth;
}

void ENTITY::SetMaxMana(int newmaxmana)
{
maxmana = newmaxmana;
}

bool ENTITY::SetName(char *newname)
{
if (strlen(newname) == 0)
return false;
if(strlen(newname) > 32)
return false;

strcpy_s(name,newname);

return true;
}
void ENTITY::LoseHealth(int amount)
{
SetHealth(health - amount);
}

void ENTITY::LoseMana(int amount)
{
SetMana(mana - amount);
}

void ENTITY::SpendGold(int amount)
{
SetGold(gold - amount);
}

void ENTITY::SetPoisoned(bool value)
{
poisoned = value;
}

bool ENTITY::IsPoisoned()
{
return poisoned;
}






//Entity.h

class ENTITY
{
private:
char name[32];
int gold;
int experience;
int health;
int maxhealth;
int mana;
int maxmana;

bool poisoned;
public:
bool SetName(char* newname);
char* GetName();
void SetGold(int newgold);
void AddGold(int amount);
void SpendGold(int amount);
int GetGold();
void SetExperience(int newexperience);
void AddExperience(int amount);
int GetExperience();
void SetHealth(int newhealth);
void AddHealth(int amount);
void LoseHealth(int amount);
int GetHealth();
void SetMaxHealth(int newmaxhealth);
int GetMaxHealth();
void SetMana(int newmana);
void AddMana(int amount);
void LoseMana(int amount);
int GetMana();
void SetMaxMana(int newmana);
int GetMaxMana();
void SetPoisoned(bool value);
bool IsPoisoned();
};




//Item.h
class ITEM
{
private:
char name[32];
int price;
public:
ITEM()
{
price = 0;
}
void SetName(char* newname)
{
strcpy_s(name, newname);
}
char* GetName()
{
return name;
}
int GetPrice()
{
return price;
}
void SetPrice(int amount)
{
price = amount;
}

};




//Monster.cpp
#include "Library.h"

MONSTER::MONSTER()
{
//do something later
}

MONSTER::MONSTER(MONSTER* monster)
{
SetName(monster->GetName());
SetMaxHealth(monster->GetMaxHealth());
SetHealth(monster->GetHealth());
SetArmor(monster->GetArmor());
SetGold(monster->GetGold());
SetExperience(monster->GetExperience());
SetAttack(monster->GetAttack());
SetPoisoned(false);
}

void MONSTER::CreateMonster(char* newname,int hp, int mp,int att,int ap,int gp,int xp)
{
SetName(newname);
SetMaxHealth(hp);
SetHealth(hp);
SetMaxMana(mp);
SetMana(mp);
SetAttack(att);
SetArmor(ap);
SetGold(gp);
SetExperience(xp);
SetPoisoned(false);
}


void MONSTER::SetAttack(int amount)
{
attack = amount;
}
int MONSTER::GetAttack()
{
return attack;
}

void MONSTER::SetArmor(int amount)
{
armor = amount;
}
int MONSTER::GetArmor()
{
return armor;
}




//Monster.h

class MONSTER: public ENTITY
{
private:
int attack;
int armor;
public:
MONSTER();
MONSTER(MONSTER*);
void CreateMonster(char*,int,int,int,int,int,int);
void SetAttack(int amount);
int GetAttack();
void SetArmor(int amount);
int GetArmor();
};




//Player.cpp
#include "Library.h"

PLAYER::PLAYER()
{
SetName("Hero");
strength = 1;
intelligence = 1;
level = 1;
SetGold(100000);
SetExperience(0);
SetMaxHealth(25);
SetHealth(25);
SetMaxMana(500);
SetMana(500);
SetPoisoned(false);


weapon.SetName("Rusty Dagger");
weapon.SetDamage(2);
weapon.SetPrice(0);

armor.SetName("None");
armor.SetAP(0);
armor.SetPrice(0);

//FIREBALL fireball;
//HEAL heal;
//POISON poison;

//AddSpell(&fireball);
//AddSpell(&heal);
//AddSpell(&poison);
}


int PLAYER::GetIntelligence()
{
return intelligence;
}

int PLAYER::GetStrength()
{
return strength;
}

void PLAYER::SetIntelligence(int newint)
{
intelligence = newint;
}

void PLAYER::SetStrength(int newstr)
{
strength = newstr;
}

void PLAYER::SetLevel(int newlevel)
{
level = newlevel;
}

int PLAYER::GetLevel()
{
return level;
}

WEAPON* PLAYER::GetWeapon()
{
return &weapon;
}

void PLAYER::SetWeapon(WEAPON newweapon)
{
weapon = newweapon;
}

ARMOR* PLAYER::GetArmor()
{
return &armor;
}

void PLAYER::SetArmor(ARMOR newarmor)
{
armor = newarmor;
}

void PLAYER::AddPotion(POTION* potion)
{
if (potion == NULL)
return;

//check for duplicate
for (int check = 0; check < 15; check++)
{
if (potionlist[check] != NULL)
{
if (strcmp(potionlist[check]->GetName(),potion->GetName()) == 0)
{
//names are same
potionlist[check]->AddQuantity(1);
return;
}
}
}

//no duplicates found

for (int loop = 0; loop < 15; loop++)
{
if (potionlist[loop] == NULL)
{
//create a potion here
potionlist[loop] = new POTION(potion);
return;
}
}

cout << "There is no room in your inventory.\n";
Wait();
cout << endl;
}

POTION** PLAYER::GetPotionList()
{
return potionlist;
}

void PLAYER::AddSpell(SPELL *newspell)
{
//check for open spot

for (int loop = 0; loop < 10; loop++)
{
if (spelllist[loop] == NULL)
{
//openspot

//which type?
switch (newspell->GetSpellType())
{
case ST_GENERIC:
{
spelllist[loop] = new SPELL(newspell);
break;
}
case ST_FIREBALL:
{
spelllist[loop] = new FIREBALL((FIREBALL*)newspell);
break;
}
case ST_HEAL:
{
spelllist[loop] = new HEAL((HEAL*)newspell);
break;
}
case ST_POISON:
{
spelllist[loop] = new POISON((POISON*)newspell);
break;
}
case ST_LIGHTNING:
{
spelllist[loop] = new LIGHTNING((LIGHTNING*)newspell);
break;
}
case ST_FROSTBOLT:
{
spelllist[loop] = new FROSTBOLT((FROSTBOLT*)newspell);
break;
}
}

loop = 10;
}
}
}


SPELL** PLAYER::GetSpellList()
{
return spelllist;
}

void PLAYER::CheckForLevelUp()
{
//formula
// (level * (level * 10))

if (GetExperience() >= (level * (level * 10)))
{
//level up!
cout << "You have gained a level!\n\n";
level++;

int choice = -1;

while (choice < 1 || choice > 2)
{
cout << "Pick a stat to increase.\n";
cout << "1: Strength\n";
cout << "2: Intelligence\n";
cout << ">";

cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');
}

if (choice == 1)
{
cout << "You feel much stronger.\n";
strength++;

SetMaxHealth(strength * 25);
}
if (choice == 2)
{
cout << "You ferl much smarter.\n";
intelligence++;

SetMaxMana(intelligence * 5);
}

SetHealth(GetMaxHealth());
SetMana(GetMaxMana());

Wait();
}
}




//Player.h

#define XPL_1 10
#define XPL_2 30
#define XPL_3 90
#define XPL_4 150
#define XPL_5 320
#define XPL_6 700
#define XPL_7 2000
#define XPL_8 5000
#define XPL_9 12000

class PLAYER: public ENTITY
{
private:

int strength;
int intelligence;
int level;
WEAPON weapon;
ARMOR armor;
POTION* potionlist[15];
SPELL* spelllist[10];
public:
PLAYER();

void SetStrength(int newstr);
int GetStrength();

void SetIntelligence(int newint);
int GetIntelligence();

void SetLevel(int newlevel);
int GetLevel();

WEAPON* GetWeapon();
void SetWeapon(WEAPON weapon);

ARMOR* GetArmor();
void SetArmor(ARMOR armor);

void AddPotion(POTION* potion);
POTION** GetPotionList();

void AddSpell(SPELL* newspell);
SPELL** GetSpellList();

void CheckForLevelUp();

};




//Weapon.h

class WEAPON: public ITEM
{
private:
int damage;
public:
WEAPON()
{
damage = 0;
}
void CreateWeapon(char* newname, int newdamage, int newprice )
{
SetName(newname);
SetPrice(newprice);
SetDamage(newdamage);

}
int GetDamage()
{
return damage;
}
void SetDamage(int amount)
{
damage = amount;
}
};




//Fireball.h
class FIREBALL: public SPELL
{
public:
FIREBALL()
{
SetName("Fireball");
SetPrice(50);
SetManaCost(3);
SetMagnitude(15);
SetSpellType(ST_FIREBALL);
}

FIREBALL(FIREBALL* newspell)
{
SetName(newspell->GetName());
SetPrice(newspell->GetPrice());
SetManaCost(newspell->GetManaCost());
SetMagnitude(newspell->GetMagnitude());
SetSpellType(newspell->GetSpellType());
}

void Cast(ENTITY* elist, int ecount)
{
//assumes elist and ecount =1

cout << "From your fingetips a great ball of fire erupts and flies at the.\n";
cout << elist->GetName() << endl;

cout << " You damage the " << elist->GetName() << " for " << GetMagnitude() << " damage!\n";
elist->LoseHealth(GetMagnitude());
}
};




//FrostBolt.h
class FROSTBOLT: public SPELL
{
public:
FROSTBOLT()
{
SetName("FrostBolt");
SetPrice(10000);
SetManaCost(50);
SetMagnitude(250);
SetSpellType(ST_FROSTBOLT);
}

FROSTBOLT(FROSTBOLT* newspell)
{
SetName(newspell->GetName());
SetPrice(newspell->GetPrice());
SetManaCost(newspell->GetManaCost());
SetMagnitude(newspell->GetMagnitude());
SetSpellType(newspell->GetSpellType());
}

void Cast(ENTITY* elist, int ecount)
{
//assumes elist and ecount =1

cout << "Cold vapors permeate from you hands and leaps out at the";
cout << elist->GetName() << endl;

cout << " You damage the " << elist->GetName() << " for " << GetMagnitude() << " damage!\n";
elist->LoseHealth(GetMagnitude());
}
};




//Heal.h

class HEAL: public SPELL
{
public:
HEAL()
{
//DEFAULT VALUES

SetName("Heal");
SetManaCost(5);
SetMagnitude(25);
SetPrice(200);
SetSpellType(ST_HEAL);
}

HEAL(HEAL* sepll)
{
//copy

SetName("Heal");
SetManaCost(5);
SetMagnitude(25);
SetPrice(200);
SetSpellType(ST_HEAL);

//HEAL();

}
void Cast(ENTITY *elist, int ecount)
{
cout << "You cast heal on " << elist->GetName() << " and they regain " << GetMagnitude() << " health.\n";

elist->AddHealth(GetMagnitude());

if (elist->IsPoisoned())
{
cout << elist->GetName() << " is no longer poisoned.\n";
elist->SetPoisoned(false);
}
}
};




//Lightning.h
class LIGHTNING: public SPELL
{
public:
LIGHTNING()
{
SetName("Lightning");
SetPrice(4000);
SetManaCost(30);
SetMagnitude(150);
SetSpellType(ST_LIGHTNING);
}

LIGHTNING(LIGHTNING* newspell)
{
SetName(newspell->GetName());
SetPrice(newspell->GetPrice());
SetManaCost(newspell->GetManaCost());
SetMagnitude(newspell->GetMagnitude());
SetSpellType(newspell->GetSpellType());
}

void Cast(ENTITY* elist, int ecount)
{
//assumes elist and ecount =1

cout << "From your fingetips a great streak of Lightning erupts and blast's at the.\n";
cout << elist->GetName() << endl;

cout << " You damage the " << elist->GetName() << " for " << GetMagnitude() << " damage!\n";
elist->LoseHealth(GetMagnitude());
}
};




//Poison.h

class POISON: public SPELL
{
public:
POISON()
{
//default
SetName("Poison");
SetManaCost(10);
SetMagnitude(0);
SetPrice(1000);
SetSpellType(ST_POISON);
}

POISON(POISON* spell)
{
//copy
SetName("Poison");
SetManaCost(10);
SetMagnitude(0);
SetPrice(1000);
SetSpellType(ST_POISON);
//POISON();
}

void Cast(ENTITY* elist, int ecount)
{
//assumes single target

cout << elist->GetName() << " is now poisoned.\n";
elist->SetPoisoned(true);
}
};




//Spell.h

enum SPELL_TYPE
{
ST_GENERIC = 0,
ST_FIREBALL,
ST_HEAL,
ST_POISON,
ST_LIGHTNING,
ST_FROSTBOLT,
};

class SPELL: public ITEM
{
private:
SPELL_TYPE type;
int manacost;
int magnitude;
public:

SPELL()
{
manacost = 0;
magnitude = 0;
type = ST_GENERIC;
}

SPELL(SPELL* newspell)
{
SetName(newspell->GetName());
SetPrice(newspell->GetPrice());
SetManaCost(newspell->GetManaCost());
SetMagnitude(newspell->GetMagnitude());
SetSpellType(newspell->GetSpellType());
}

int GetManaCost()
{
return manacost;
}

int GetMagnitude()
{
return magnitude;
}

void SetManaCost(int value)
{
manacost = value;
}

void SetMagnitude(int value)
{
magnitude = value;
}

void SetSpellType(SPELL_TYPE st)
{
type = st;
}

SPELL_TYPE GetSpellType()
{
return type;
}


virtual void Cast(ENTITY* elist, int ecount)
{
//nothing
}

};




//Globals.h
#ifndef GLOBAL_DEFINE
#define GLOBAL_DEFINE


// Prototypes
void Wait();
void DisplayStats(PLAYER*);

bool Battle(PLAYER*,MONSTER*,int);

bool CityGate();
bool Town(PLAYER*);
bool SummonPortal(PLAYER*,int);
bool Grasslands(PLAYER*);


#endif




//Helper.cpp
#include "Library.h"

// Helper functions

void Wait()
{
cout << "Press Enter to Continue\n";

cin.ignore(1,'\n');

}

void DisplayStats(PLAYER* player)
{
//Display stats
cout << "Hero: " << player->GetName() << endl;
cout << "Level: " << player->GetLevel() << endl;
cout << "HP: " << player->GetHealth() << " / " << player->GetMaxHealth() << endl;
cout << "MP: " << player->GetMana() << " / " << player->GetMaxMana() << endl << endl;

cout << "strength: " << player->GetStrength() << endl;
cout << "Intelligence: " << player->GetIntelligence() << endl << endl;

cout << "Gold: " << player->GetGold() << endl;
cout << "Experience: " << player->GetExperience() << endl;
cout << endl;
cout << "Weapon: " << player->GetWeapon()->GetName() << endl;
cout << "Armor: " << player->GetArmor()->GetName() << endl;
cout << endl;

//list potions

cout << "POTIONS\n\n";
POTION** potionlist = player->GetPotionList();

for (int loop = 0; loop < 15; loop++)
{
if (potionlist[loop] != NULL)
{
cout << potionlist[loop]->GetQuantity() << " x " << potionlist[loop]->GetName() << endl;
}
}

cout << endl;

//list spells

cout << "SPELLS\n\n";
SPELL** spelllist = player->GetSpellList();
for (int loop2 = 0; loop2 < 10; loop2++)
{
if (spelllist[loop2] != NULL)
{
cout << spelllist[loop2]->GetName() << " - MP: " << spelllist[loop2]->GetManaCost() << endl;
}
}

cout << endl;

Wait();
cout << endl;

}




//Library.h
#include <iostream>
#include <ctime>
using namespace std;

#include "Entity.h"

#include "Item.h"
#include "Spell.h"

#include "Potion.h"
#include "Armor.h"
#include "Weapon.h"

#include "Monster.h"
#include "Player.h"

#include "Globals.h"

#include "Fireball.h"
#include "Heal.h"
#include "Poison.h"
#include "Lightning.h"
#include "FrostBolt.h"




//Main.cpp
#include "Library.h"

int main(void)
{
//Generic Welcome Screen
srand((unsigned int)time(0));

cout << "\n\t\tWelcome to Relic's of Sanguine\n";
cout << "\t\tProgrammed by Derric Schade\n\n";

cout << "The world of Sanguine has collapsed by the Wrath of\nthe Orc's. Many people flee from there home's looking\nfor hope. Intill the solider's formed one powerfull army.\n\n";

cout << "Press Enter to Continue";
cin.get();

cout << "\n\n";

CityGate();

cout << "\n\nThank your for playing Relic's of Sanguine\n\n";
}





//Potion.h

class POTION: public ITEM
{
private:
int quantity;
int healthrestore;
int manarestore;
public:
POTION()
{
//does nothing
}
POTION(POTION* newpotion)
{
CreatePotion(newpotion->GetName(), newpotion->GetHealthRestore(), newpotion->GetManaRestore(), newpotion->GetPrice());
quantity = 1;
}
void CreatePotion(char* newname, int health, int mana, int cost)
{
SetName(newname);
healthrestore = health;
manarestore = mana;
SetPrice(cost);
}
void CreateHealthPotion(char* newname, int health, int cost)
{
CreatePotion(newname,health,0,cost);
}

void CreateManaPotion(char* newname, int mana , int cost)
{
CreatePotion(newname,0,mana,cost);
}

int GetHealthRestore()
{
return healthrestore;
}

int GetManaRestore()
{
return manarestore;
}

int GetQuantity()
{
return quantity;
}

void SetQuantity(int value)
{
quantity = value;
}

void AddQuantity(int value)
{
quantity += value;
}

void SubtractQuantity(int value)
{
quantity -= value;
}
};



I think that should be all of it. Let me know if you get any problems

Share this post


Link to post
Share on other sites
Ok so grasslands is the second level, when under the bool rockyroad, the little quest i added with the choice. well i want it so when you choose no it will loop back to the beginning of grasslands. For some reason its taking me to the beginnig of citygates.

Share this post


Link to post
Share on other sites
I'm not going to read those 25 source files, but from what I can gather from your first post in this thread, your code isn't communicating enough about the local state of an encounter with the rest of the program. Try using function pointers like this:


void Forest();
void CityGate();
void DarkRoad();

PLAYER* player;
void (*nextEncounter)() = &CityGate;

while(nextEncounter != NULL) {
(*nextEncounter)();
}

void CityGate() {
// display menu
switch(userInput) {
case 1:
nextEncounter = &Forest;
break;
case 2:
nextEncounter = &DarkRoad;
break;
case 0: //quit
nextEncounter = NULL;
break;
}
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this