ok lets see if anyone can find the problem i have searched long and hard for this. i have a battle function and for some odd reason when ever i win the battle it loops the if statement saying that i am victorious 3 times (doing all the math and boosting the charecter stats as well). here is my complete code that i got sofar.
#pragma hdrstop
#include <condefs.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <mmsystem.h> // mciSendString()
//---------------------------------------------------------------------------
#pragma argsused
struct charecter
{
int maxhp;
int hp;
int gp;
int exp;
int nextlevel;
int level;
int agilitylvl;
int def;
int dammage;
char *name;
};
struct misc
{
int lvl1potions;
int lvl2potions;
int lvl3potions;
int demonpotions;
int secretitems;
int score;
int blocked;
char *nextweapon;
char *townname;
int draynorquestnumber;
};
struct opponent
{
int hp;
int gp;
int exp;
int dammage;
char *name;
};
struct opponentstats
{
int hp;
int gp;
int exp;
int dammage;
char *name;
};
void questone (charecter & me, opponent & c, misc & misc);
void battle (charecter & me, opponent & c, misc & misc);
void apothecary (charecter & me,opponent & c, misc & misc);
void town (charecter & me,opponent & c, misc & misc);
void gameplaychoice (charecter & me,opponent c, opponentstats b, misc & misc);
void attack (charecter & me,opponent & c);
void usepotion (charecter & me,opponent & c,misc & misc);
int main(int argc, char **argv)
{
mciSendString("play C:\\onestop.mid",NULL,0,NULL);
cout << "**************************************" << endl;
cout << "* *" << endl;
cout << "* A role playing game by Nate Nelson *" << endl;
cout << "* *" << endl;
cout << "**************************************" << endl << endl;
int choice;
int charecterchoice;
cout << "choose your character" << endl;
cout << "1: Barbarian" << endl;
cout << "2: Wizard of The Old Teachings" << endl;
cout << "3: Gnome" << endl << endl;
cin >> charecterchoice;
if (charecterchoice == 1){
cout << "You have chosen the nobelist and fiercest warrior in all the land!" << endl;
cout << "the time has now come to choose you mode of battle." << endl << endl;
cout << "Press any key to continue..." << endl << endl;
getch();
cout << "input name (less than 100 charecters):";
charecter me;
me.hp = 50;
me.maxhp = 50;
me.def = 2;
me.dammage = 10;
me.exp = 0;
me.nextlevel=80;
me.level=1;
me.name = new char [100];
cin >> me.name;
cout << "1: I would like to fight with a Giant Axe." << endl;
cout << "2: I would like to fight with a Sword and Shield." << endl;
cin >> choice;
if (choice == 1){
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
me.hp = 50;
me.maxhp = 50;
me.def = 2;
me.dammage = 10;
me.exp = 0;
me.nextlevel=80;
me.level=1;
me.agilitylvl = 0;
me.gp = 120;
cout << "Your weapon shall be an Axe like tree root." << endl << endl;
cout << "As your adventure begins you decide to randomly choose a direction" << endl;
cout << "You have stumbled upon a Goblin Warrior, he has spoted you and" << endl;
cout << "wishes to fight!" << endl;
cout << "You Valiantly fight the monster for your life." << endl << endl;
int goblinhp = 20;
int goblingp = 20;
int hplost;
//1st attack
hplost = me.hp;
goblinhp = goblinhp-10;
me.hp = me.hp-5+me.def;
goblinhp = goblinhp-10;
me.hp = me.hp-5+me.def;
hplost = hplost-me.hp;
me.gp = me.gp+goblingp;
me.hp = me.hp+5;
me.exp = me.exp + 20;
cout << "you have fought valiently and killed the beast!" << endl;
cout << "your Hit points are now at " << me.hp << "." << endl;
cout << "you lost " << hplost << " hit points, but gain " << "5" << " life back from a potion the goblin had." << endl;
cout << "you have gained " << me.exp << "/" << me.nextlevel << " till your next level." << endl;
cout << "you have gained " << goblingp << " GP from the goblin. Your GP is at " << me.gp << "." << endl << endl;
getch();
opponent c;
c.hp = 20;
c.gp = 20;
c.exp = 20;
c.dammage = 5;
c.name = "Goblin";
opponentstats b;
b.hp = c.hp;
b.gp = c.gp;
b.exp = c.exp;
b.dammage = c.dammage;
b.name = c.name;
misc misc;
misc.blocked = 0;
misc.nextweapon = "A Giant Stick with a rock tied to the end of it";
misc.townname = "Falador";
misc.lvl1potions = 0;
misc.lvl2potions = 0;
misc.lvl3potions = 0;
misc.demonpotions = 0;
misc.secretitems = 0;
misc.score = 0;
misc.blocked = 0;
gameplaychoice (me, c, b, misc);
//display a:\battle340.jpeg here
cout << "Goblin Warlord: I hear you have been harrassing my goblin troops!" << endl;
cout << "Abdazar: yeah i have been training with your troops, but i haven't been "<< endl << " Harrassing them!" << endl;
cout << "Goblin Warlord: That's not the way I heard it, prepare yourself for revenge!" << endl;
cout << "Abdazar: Alright if it is a battle you want, a battle you shall have." << endl;
misc.nextweapon = "Acid edged Gothic Axe";
misc.townname = "Falador";
c.hp=60;
c.gp=200;
c.exp=200;
c.dammage=14;
c.name = "Goblin Warlord";
me.nextlevel = me.nextlevel + 200;
battle (me, c, misc);
cout << "The Goblin Warlord in, return for mercy, gives you the Ring of Agility!" << endl << endl;
cout << "As you slowly slide the ring over your knuckle, you seem to notice " << endl << "things a little faster and react with better timeing." << endl << endl;
cout << "your agility level has risen by 3 points!!!" << endl;
misc.secretitems++;
getch();
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
town (me, c, misc);
mciSendString("stop C:\\town.mid",NULL,0,NULL);
mciSendString("play C:\\onestop.mid",NULL,0,NULL);
}
getch ();
mciSendString("stop C:\\onestop.mid",NULL,0,NULL);
mciSendString("stop C:\\town.mid",NULL,0,NULL);
}
return 0;
}
void battle (charecter & me, opponent & c, misc & misc)
{
int choice;
int blockyesno;
int attackedxtimes=0;
if (c.hp <=0) {
return;
}
if (me.exp >= me.nextlevel) {
cout << "you have gained enough expierience to level up!!!" << endl << endl;
me.exp = 0;
me.nextlevel = me.nextlevel*2;
me.maxhp = me.maxhp * 1.5;
me.def = me.def + 3;
me.hp = me.maxhp;
me.agilitylvl++;
me.level++;
me.dammage = me.dammage+5;
cout << "your max hp is now " << me.maxhp << endl;
cout << "your defense is now " << me.def << endl;
cout << "your agility level is now " << me.agilitylvl << endl;
cout << "you find a new weapon on " << c.name << ". you decide to use this instead of your old weapon." << endl;
cout << "your weapon shall now be a " << misc.nextweapon << endl << endl;
me.level++;
return;
}
cout << "what should i do?" << endl << endl;
cout << "1: Attack" << endl;
cout << "2: Use potion" << endl;
cout << "3: Attempt to block" << endl;
cin >> choice;
if (choice == 1){
attackedxtimes++;
if (attackedxtimes != 2 && attackedxtimes != 5 && attackedxtimes != 3 && attackedxtimes != 6){
attack (me, c);
if (c.hp && me.hp > 0){
battle (me, c, misc);
}
}
if (attackedxtimes == 2 || attackedxtimes == 5) {
attack (me, c);
if (c.hp && me.hp > 0){
battle (me, c, misc);
}
cout << c.name << " apears to be getting ready for some sort of special attack." << endl << endl;
}
if (attackedxtimes == (3 || 6)) {
c.dammage = c.dammage*2;
attack (me, c);
c.dammage = c.dammage/2;
if (c.hp && me.hp > 0){
battle (me, c, misc);
}
}
}
else if (choice == 2){
usepotion (me, c, misc);
if (c.hp && me.hp > 0){
battle (me, c, misc);
}
}
else if (choice == 3){
blockyesno = rand() % 100 + 1;
if (blockyesno <= (me.agilitylvl*10)){
cout << "all dammage was successfully blocked this turn!" << endl << endl;
cout << me.name << " " << c.name << endl;
cout << me.hp << " " << c.hp << endl << endl;
misc.blocked++;
battle (me, c, misc);
getch();
}
else if (blockyesno >= ((me.agilitylvl*10)+1)){
cout << "you accedentally take a wrong step as you attempt to block and still take" << endl <<" dammage."<< endl << endl;
me.hp = me.hp - c.dammage;
cout << me.name << " " << c.name << endl;
cout << me.hp << " " << c.hp << endl << endl;
getch();
battle (me, c, misc);
}
}
}
void usepotion (charecter & me,opponent & c, misc & misc)
{
int potionchoice;
if (misc.lvl1potions == 0 && misc.lvl2potions == 0 && misc.lvl3potions == 0 && misc.demonpotions == 0) {
cout << "you have no potions, quick pick a battle move before " << c.name << " attacks you!" << endl;
return ;
}
cout << "Use which potion?" << endl << endl;
if (misc.lvl1potions >= 1) {
cout << "1: level 1 potion" << endl;
}
if (misc.lvl2potions >= 1){
cout << "2: level 2 potion" << endl;
}
if (misc.lvl3potions >= 1) {
cout << "3: level 3 potion" << endl;
}
if (misc.demonpotions >= 1) {
cout << "4: Demonic potion" << endl;
}
cin >> potionchoice;
if (potionchoice == 1) {
misc.lvl1potions--;
me.hp = me.hp + 20;
if (me.hp > me.maxhp ){
me.hp = me.maxhp;
}
cout << "you have gained 20 hp, your hp is now at " << me.hp << endl << endl;
}
else if (potionchoice == 2) {
misc.lvl2potions--;
me.hp = me.hp + 30;
if (me.hp > me.maxhp ){
me.hp = me.maxhp;
}
cout << "you have gained 30 hp, your hp is now at " << me.hp << endl << endl;
}
else if (potionchoice == 3) {
misc.lvl3potions--;
me.hp = me.hp + 40;
if (me.hp > me.maxhp ){
me.hp = me.maxhp;
}
cout << "you have gained 40 hp, your hp is now at " << me.hp << endl << endl;
}
else if (potionchoice == 4) {
misc.demonpotions--;
me.hp = me.hp + 120;
if (me.hp > me.maxhp ){
me.hp = me.maxhp;
}
cout << "you have gained 120 hp, you hp is now at " << me.hp << endl << endl;
}
}
void attack (charecter & me,opponent & c)
{
int hplost;
hplost = me.hp;
c.hp = c.hp - me.dammage;
if (c.hp <= 0 ) {
cout << "You are victorious!!!" << endl << endl;
me.exp = me.exp + c.exp;
hplost = hplost - me.hp;
me.hp = me.hp + c.dammage;
me.gp = me.gp + c.gp;
cout << "you lost " << hplost << " hit points, but gain " << c.dammage << " life back from a potion the " << c.name << " had." << endl;
cout << "your Hit points are now at " << me.hp << "." << endl;
cout << "you have gained " << me.exp << "/" << me.nextlevel << " till your next level." << endl;
cout << "you have gained " << c.gp << " GP from the " << c.name << ". Your GP is at " << me.gp << "." << endl << endl;
return;
}
me.hp = me.hp - c.dammage;
if (me.hp <= 0 ) {
hplost = hplost - me.hp;
me.gp = me.gp - c.gp;
cout << "you have " << me.exp << "/" << me.nextlevel << " till your next level." << endl;
cout << "you have lost" << c.gp << " GP from the " << c.name << " Your GP is at " << me.gp << "." << endl << endl;
cout << "the " << c.name << " shows you great mercy and spares your life. Your life is now at " << me.maxhp << "." << endl;
me.hp = me.maxhp;
}
cout << me.name << " " << c.name << endl;
cout << me.hp << " " << c.hp << endl << endl;
}
void gameplaychoice (charecter & me,opponent c, opponentstats b, misc & misc)
{
int attackedmonsters=0;
int choice;
c.hp = b.hp;
c.gp = b.gp;
c.exp = b.exp;
c.dammage = b.dammage;
c.name = b.name;
cout << "What would you like to do now then?" << endl << endl;
if (attackedmonsters < 5){
cout << "1: Look for a training partner." << endl;
}
cout << "2: Goto " << misc.townname << "." << endl;
cout << "3: Quit game" << endl << endl;
cin >> choice;
if (choice == 1){
cout << me.name << " " << c.name << endl;
cout << me.hp << " " << c.hp << endl << endl;
attackedmonsters++;
battle (me, c, misc);
gameplaychoice (me, c, b, misc);
}
else if (choice == 2){
return;
}
else if (choice == 3){
mciSendString("stop C:\\onestop.mid",NULL,0,NULL);
mciSendString("stop C:\\town.mid",NULL,0,NULL);
exit(0);
}
}
void town(charecter & me, opponent & c, misc & misc)
{
mciSendString("stop C:\\onestop.mid",NULL,0,NULL);
mciSendString("play C:\\town.mid",NULL,0,NULL);
int choice;
cout << " |--------------| " << endl;
cout << " | Bank of |\\ " << endl;
cout << " | Solum | \\ " << endl;
cout << " |--------------| | |---| | | " << endl;
cout << " | Apothecary |\\ | |-|-| | | " << endl;
cout << " | | \\ | |---| | | " << endl;
cout << " | | | | |---| | | " << endl;
cout << " /-----------| | | /--------| |-|-| |---------------\\ " << endl;
cout << " / | | |/ | |---| | Blue Moon /\\ " << endl;
cout << " / | | / | |---| | Inn / \\ " << endl;
cout << "/______________| _________ |/___________| |-|-| |_____________/ \\" << endl;
cout << "| |---| | | __ | __ | | |---| | |---| | |---|| |" << endl;
cout << "| |-|-| | |(__)|(__)| | |-|-| | | |-|-|| |" << endl;
cout << "| |---| |---|| |(__)|(__)| | |---| || |-----| | |-----||---|| |" << endl;
cout << "| |+ || | 0|0 | | || | | | | | o|o | | |" << endl;
cout << "|_________|___||_|____|____|__|___________||____|__|__|___|_|__|__|_____|____|" << endl;
cout << "Welcome to " << misc.townname << "!!!" << endl << endl;
cout << "what would you like to do now then?" << endl;
cout << "1: Rest at the local Inn and continue one my jurney." << endl;
cout << "2: Visit the local Apothecary for potions." << endl;
cout << "3: Go visit with the local towns people." << endl;
cout << "4: Quit game." << endl;
cin >> choice;
if (choice == 1){
cout << "As you slowly drift into that unreal yet very believable realm of sleep" << endl << "images of a man in red robes reaking havock on the world" << endl << "flash infront of your face." << endl;
cout << "Images of complete death and destruction that follows him as he slowly," << endl << "unswayingly, and almost hypnoticly floats through the mortal world." << endl << endl;
cout << "you awaken in a cold sweat panting in the brightness of the new day discarding" << endl << "the dream as nothing more than a nightmare." << endl << endl;
getch();
return;
}
else if (choice == 2){
mciSendString("play C:\\town.mid",NULL,0,NULL);
apothecary (me, c, misc);
town (me, c, misc);
}
/*
else if (choice == 3){
if (misc.townname == "Falador") {
questone (me, c, misc);
town (me, c, misc);
}
else if (misc.townname == "Al Kahlid") {
questtwo (me, c, misc);
town (me, c, misc);
}
else if (misc.townname == "Varroc") {
questthree (me, c, misc);
town (me, c, misc);
}
else if (misc.townname == "Draynor Village") {
if (misc.draynorquestnumber != 2) {
questfour (me, c, misc);
town (me, c, misc);
}
else if (misc.draynorquestnumber == 2) {
questfive (me, c, misc);
town (me, c, misc);
}
}
}
*/
else if (choice == 4){
mciSendString("stop C:\\lndnchip.mid",NULL,0,NULL);
mciSendString("stop C:\\town.mid",NULL,0,NULL);
exit(0);
}
}
void apothecary (charecter & me, opponent & c, misc & misc)
{
mciSendString("play C:\\town.mid",NULL,0,NULL);
int choice;
int cost;
cout << "your gp is currently at: " << me.gp << endl;
cout << "you have " << misc.lvl1potions << "level 1 potions." << endl;
cout << "you have " << misc.lvl2potions << "level 2 potions." << endl;
cout << "you have " << misc.lvl3potions << "level 3 potions." << endl;
cout << "your health is at " << me.hp << "/" << me.maxhp << endl << endl;
cout << "What would you like to purchase?" << endl << endl;
cout << "1: Regenerate completely (1gp per level)" << endl;
cout << "2: Purchase a level 1 potion (20gp ea.)" << endl;
cout << "3: Purchase a level 2 potion (30gp ea.)" << endl;
cout << "4: Purchase a level 3 potion (40gp ea.)" << endl;
cout << "5: Leave Apothecary." << endl;
cin >> choice;
if (choice == 1){
int cost;
cost = me.maxhp - me.hp;
if (me.gp < cost) {
cout << " you don't have enough money for this." << endl;
cout << " would you like to heal health as much as you can?" << endl;
cout << "1: yes" << endl;
cout << "2: no" << endl;
cin >> choice;
if (choice == 1) {
me.hp = me.hp + me.gp;
me.gp = me.gp - me.gp;
apothecary (me, c, misc);
}
else if (choice == 2) {
apothecary (me, c, misc);
}
}
else if (me.gp >= cost) {
me.gp = me.gp-cost;
me.hp = me.maxhp;
apothecary (me, c, misc);
}
}
else if (choice == 2){
cost = 20;
if (me.gp < cost) {
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "you don't have enough gp for this item." << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
getch();
apothecary (me, c, misc);
}
else if (me.gp >= cost){
me.gp = me.gp - 20;
misc.lvl1potions++;
apothecary (me, c, misc);
}
}
else if (choice == 3) {
cost = 30;
if (me.gp < cost) {
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "you don't have enough gp for this item." << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
getch();
apothecary (me, c, misc);
}
else if (me.gp >= cost){
me.gp = me.gp - 30;
misc.lvl2potions++;
apothecary (me, c, misc);
}
}
else if (choice == 4) {
cost = 40;
if (me.gp < cost) {
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "you don't have enough gp for this item." << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
getch();
apothecary (me, c, misc);
}
else if (me.gp >= cost){
me.gp = me.gp - 40;
misc.lvl3potions++;
apothecary (me, c, misc);
}
}
else if (choice == 5) {
return;
}
}