Sign in to follow this  
Ryan Atkins

Statements in while loop not working

Recommended Posts

Ryan Atkins    100
I figured it out. I'll never be thorough enough.


[s]I know there are probably plenty of things in this code unfinished. My current problem is that when ever I defeat the goblin in (on of the) case 1, it unravels my entire, original while(ourHero.getStr()>0) loop and goes to the game over text. I don't get it. Then when ever I go to give myself a 50/50 chance of making my health actually go to 0, it refuses to go to the game over page. Here's a video of exactly what's going on and the code.

[media]http://www.youtube.com/watch?v=kSKW5UfCgUk[/media][/s]


[code]#include <iostream>
#include <string>
#include "Character.h"
#include "weapon.h"
#include <windows.h>
#include "functions.h"
#include <cstdlib>
#include <ctime>

using namespace std;

character chooseClass();
weapon chooseWeapon1();
void startScreen();
void theGame();



int main()
{
startScreen();
cout << "Greetings, adventurer! What be thy name? \n";
string name;
cin >> name;
system("cls");
character ourHero = chooseClass();
cout << "\n\nPlease press enter to continue...";
cin.ignore();
cin.get();
system("cls");
weapon ourWeapon = chooseWeapon1();
cout << "\n\nPlease press enter to continue...";
cin.ignore();
cin.get();
system("cls");

while(ourHero.getHealth()>0)
{
cout << "Please make a selection:\n\n[1]The Armory\n\n[2]The Pit\n\n[3]Item Shop\n\n[4]Stats\n\n[5]Quit Game\n";
int menuSelect;
srand(time(0));
cin >> menuSelect;
system("cls");
switch(menuSelect)
{
case 1:
{
system("cls");
cout << "Welcome to The Frorth City Armory\n\n";
Sleep(1500);
cout << "What would you like to do?\n\n[1]Upgrade Main-hand Weapon\n\n[2]Upgrade Off-hand Weapon\n\n[3]Exit\n";
int choice;
cin >> choice;
system("cls");
switch(choice)
{
case 1:
{
ourWeapon.sharpenWeapon1();
cout << "Main-hand sharpened!";
cin.ignore();
cin.get();
system("cls");
break;
}
case 2:
{
if(ourWeapon.getDamageMultiplier2()>0)
{
ourWeapon.sharpenWeapon2();
cout << "Off-hand sharpened!";
cin.ignore();
cin.get();
system("cls");
break;
}
else
{
cout << "No off-hand weapon to upgrade.";
cin.ignore();
cin.get();
system("cls");
break;
}
}
case 3:
{

break;
}
default:
{
cout << "Invalid selection.\n\n";
cout << "Please press enter to continue...\n";
cin.ignore();
cin.get();
system("cls");
}
}
break;
}
case 2:
{
cout << "YOU HAVE ENTERED THE PIT\n\nChoose your opponent:\n\n[1] Goblin\n\n[2] Kobold\n\n[3] Ork \n\n[4] Pit Fighter\n";
int thePitChoice;
int combatChoice;
int theHit;
int currentHealth;
character goblin("goblin", 20, 7, 11, 0, 0);
cin >> thePitChoice;
system("cls");
if(ourHero.getLevel() < 2)
switch(thePitChoice)
{
case 1:
{
cout << "A goblin enters The Pit.\n";

while(goblin.getHealth()>0)
{
cout << "Which action would you like to take?\n\n[1]Attack\n\n[2]Beg for mercy\n";
cin >> combatChoice;
system("cls");
switch(combatChoice)
{
case 1:
{
if((ourHero.getStr()+(rand()%11))>(goblin.getDex()+(rand()%11)))
{
theHit=ourHero.getStr()*(ourWeapon.getDamageMultiplier1()+ourWeapon.getDamageMultiplier2());
cout << "You have hit the goblin for " << theHit <<"!\n\n";
currentHealth=goblin.getHealth()-theHit;
goblin.setHealth(currentHealth);
if(0 < goblin.getHealth())
cout << "This message doesn't show up";
cout << "You have slain a goblin!\n\nPlease press enter to continue...\n";
cin.ignore();
cin.get();
system("cls");
ourHero.setHealth(0);
break;
}
else
{
cout << "The goblin has dodged your swing!";
}
if((goblin.getStr()+(rand()%11))>(ourHero.getDex()+(rand()%11)))
{
theHit=goblin.getStr()*1.5;
}
else
{
cout << "You have dodged the goblin's attack!";
}
Sleep(2500);
system("cls");
break;
}
case 2:
{
if((rand()%3) < 2)
{
cout << "For some odd reason, the goblin allows you to keep your life.";
}
else
{
cout << "Poor decision. The goblin executes you!";
Sleep(3000);
system("cls");
ourHero.setHealth(0);
}
break;
}
default:
{
cout << "Invalid selection.\n\n";
cout << "Please press enter to continue...\n";
cin.ignore();
cin.get();
system("cls");
}

}
}
break;
}
case 2:
{
cout << "A kobold enters The Pit.\n";
break;
}
case 3:
{
cout << "An ork enters The Pit.\n";
break;
}
case 4:
{
cout << "You hear a gate from beyond creak open, from within emerging a tall, slim \nfigure.\n\n";
Sleep(2450);
cout << "As the figure enters in the mild, torch light you hear a whisper...\n\n";
cout << "Please press enter to continue...\n";
cin.ignore();
cin.get();
system("cls");
cout << "\"PSSSssst! Over hear!\"\n\nYou lean forward and see two beady eyes staring back at you.\n\n";
Sleep(4000);
cout << "\"I can help you defeat your enemy... just do what I say.\"\n\nYou are unsure if you trust this " <<
"voice as you ready yourself for battle.\n\n";
cout << "Please press enter to continue...\n";
cin.ignore();
cin.get();
break;
}
default:
{
cout << "Invalid selection.\n\n";
cout << "Please press enter to continue...\n";
cin.ignore();
cin.get();
system("cls");
}
}
break;
}
case 3:
{
cout << "Out to lunch";
cin.ignore();
cin.get();
system("cls");
break;
}
case 4:
{
cout << "Here are the stats for our " << ourHero.getClass() << ", " <<
name << "." << endl <<endl;
cout << "Health: " << ourHero.getHealth() << endl << "Strength: " << ourHero.getStr() <<
endl << "Dexterity: " << ourHero.getDex() << endl << endl;
cout << "Weapon stats for " << ourWeapon.getWeaponName() << "." << endl << endl;
cout << "Main-hand Damage: " << ourWeapon.getDamageMultiplier1() << endl <<
"Off-hand Damage: " << ourWeapon.getDamageMultiplier2();
cin.ignore();
cin.get();
system("cls");
break;
}
case 5:
{
cout << "Are you sure you wish to exit Sabra?\n[Y]es?";
cin.ignore();
cin.get();
break;
}
default:
{
cout << "Invalid selection.\n\n";
cout << "Please press enter to continue...\n";
cin.ignore();
cin.get();
system("cls");
}
}
}
if (ourHero.getHealth()<1)
cout << "Game Over!\n";
cin.get();

return 0;
}
[/code]

Share this post


Link to post
Share on other sites
Washu    7829
You should learn some debugging skills: http://www.gamedev.net/page/resources/_/technical/general-programming/introduction-to-debugging-r2322

Share this post


Link to post
Share on other sites
Ryan Atkins    100
Thanks for the advice. I really needed to stop having my hand held. I went back, checked everything, and, minus balancing stuff, finished most of the game. Thanks for the help. Hopefully you'll see less post from me.

[url="http://youtu.be/kAinjXWL51g"]http://youtu.be/kAinjXWL51g[/url]

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