Thread: Help with tiny bug spent hours and cant figure it out!

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    26

    Exclamation Help with tiny bug spent hours and cant figure it out!

    I have this combat program and if the monsters hitpoints hit 0 or -# on the players swing, it always fires off 1 more monster swing before victory is declared and i cant seem to find whats wrong, ive tried else if, and ive tried adding another tier of if else and still nothing and its driving me nuts lol


    Code:
    int CombatZombie()
    	{
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosMusic1.mid" ,NULL,0,NULL); // Open Midi Music	
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosIntro.mid" ,NULL,0,NULL); // Open Midi Music
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosInn.mid" ,NULL,0,NULL); // Open Midi Music
    	mciSendString("play C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Open Midi Music	
    	//Initialize function
    	int ExperienceCalculator();
    	
    	// Strings and extra variables
    	string MonsterName = "Zombie";  // Monster name or type
    	char NextRound;  // Continue to next combat cycle
    
    	// Monster variables
    	int MonsterLevel = 1;
    	int MonsterHitPoints = 10;
    	int MonsterAttack = 6;
    	int MonsterDefense = 3;
    	int MonsterHitRate = 50;
    
    	// Temporary player variables to check for equipment
    	int TempPlayerAttack = PlayerAttack + PlayerWeapon;
    	int TempPlayerDefense = PlayerDefense + PlayerArmorShield + PlayerArmorBody + PlayerArmorLegs + PlayerArmorHands + PlayerArmorFeet;
    	
    	// Monster damage variables using rand
    	// Also subtracts player defense from monsters damage
    	int LowMonster = 2;
    	int HighMonster = MonsterAttack - TempPlayerDefense;
    
    	// Player damage variables using rand
    	// Also subtraces monster defense from players damage
    	int LowPlayer = 2;
    	int HighPlayer = TempPlayerAttack - MonsterDefense;
    
    	// Variable to see if player or monster land a blow
    	int PlayerHitCheck = 0;
    	int MonsterHitCheck = 0;
    
    	// Player % chance to hit high and low
    	int PlayerHitLow = 1;
    	int PlayerHitHigh = 100;
    
    	// Monster % chance to hit high and low
    	int MonsterHitLow = 1;
    	int MonsterHitHigh = 100;
    
    	// Player & Monster damage results die 1 + die 2
    	int MonsterDamageResults = 0;
    	int PlayerDamageResults = 0;
    
    	//Variables to hold random values for the first and the second die on each roll.
    	int first_die, sec_die;
    
    	//Declare variable to hold seconds on clock.
    	time_t seconds;
    	//Get value from system clock and place in seconds variable.
    	time(&seconds);
    	//Convert seconds to a unsigned integer.
    	srand((unsigned int) seconds);
    	
    	/// COMBAT SCRIPT BELOW
    	cout << "You encounter a Level 1 Zombie. Prepare to fight!\n";
    	cout << "Press <c> and hit enter to continue.\n";
    	cin >> NextRound;
    	while ( ( PlayerHitPoints >= 1 ) && ( MonsterHitPoints >= 1 ) )
    	{
    		if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    		{
    			cout << "\nStarting combat round between [" << PlayerName <<"] & [" << MonsterName <<"]!\n";
    			PlayerHitCheck = rand() % (PlayerHitHigh - PlayerHitLow +1) + PlayerHitLow;
    			MonsterHitCheck = rand() % (MonsterHitHigh - MonsterHitLow +1) + MonsterHitLow;
    			
    			if (PlayerHitCheck <= 25)
    			{
    				cout << "" << PlayerName <<" swing's at the " << MonsterName << " and misses!\n";
    				cout << "Press <c> and enter to continue to the next combat round.\n";
    				cin >> NextRound;
    			}
    			else
    			{
    				cout << "" << PlayerName <<" swing's at the " << MonsterName <<" and lands a blow!\n";
    				first_die = rand() % (HighPlayer - LowPlayer + 1) + LowPlayer;  // Calculate player damage of first dice roll
    				sec_die = rand() % (HighPlayer - LowPlayer +1) + LowPlayer;     // Calculate player damage of second dice roll
    				cout << "" << PlayerName <<"'s attack is (" << first_die << ", "
    				<< sec_die << "}\n\n";
    				PlayerDamageResults = sec_die + first_die; // Calculate total damage done by player
    				cout << "" << PlayerName << " hits " << MonsterName << " for " << PlayerDamageResults << " damage.\n";
    				MonsterHitPoints = MonsterHitPoints - PlayerDamageResults; // Subtract damage from monsters hitpoints
    				cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
    				cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
    				cout << "Press <c> and enter to continue to the next combat round.\n";
    				cin >> NextRound;
    			}	
    					if (MonsterHitCheck <= 40)
    					{
    						cout << "" << MonsterName <<" swing's at " << PlayerName << " and misses!\n";
    						cout << "Press <c> and enter to continue to the next combat round.\n";
    						cin >> NextRound;
    					}	
    					else
    					{
    						cout << "" << MonsterName <<" swing's at " << PlayerName <<" and lands a blow!\n";
    						first_die = rand() % (HighMonster - LowMonster + 1) + LowMonster; // Calculate monster damage of first dice roll
    						sec_die = rand() % (HighMonster - LowMonster + 1) + LowMonster;   // Calculate monster damage of second dice roll
    						cout << "" << MonsterName <<"'s attack is (" << first_die << ", "
    						<< sec_die << "}\n\n";
    						MonsterDamageResults = sec_die + first_die; // Calculate total damage done by monster
    						cout << "" << MonsterName <<" hits " << PlayerName <<" for " << MonsterDamageResults << " damage.\n";
    						PlayerHitPoints = PlayerHitPoints - MonsterDamageResults; // Subtract damage from players hitpoints
    						cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
    						cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
    						cout << "Press <c> and enter to continue to the next combat round.\n";
    						cin >> NextRound;
    					}
    		}
    			else
    			{   // If & Else statements in the event a 1 hit kill blow is scored
    			if (PlayerHitPoints <= 0)
    			{
    				cout << "" << PlayerName <<" has died! [GAME OVER]\n\n";
    				cout << "Do you wish to reload your saved game? (Currently Unsupported)\n\n";
    				cin >> NextRound;
    			}
    			else
    			{
    				cout << "" << MonsterName <<" has died! [VICTORY!]\n\n";
    				cout << "You find 8 gold pieces on the " << MonsterName <<"!\n";
    				cout << "You gain 10 experience points!\n";
    				PlayerGold = PlayerGold + 8;               // Award player gold
    				PlayerExperience = PlayerExperience + 10;  // Award player experience
    				cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    				cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    				cout << "Press <c> and hit enter to continue.\n";
    				cin >> NextRound;
    			}
    		}
    	}       // If & Else statements end of combat cycle
    	if ( (PlayerHitPoints <=0) && ( MonsterHitPoints >=1) )
    	{
    		cout << "" << PlayerName <<" has died! [GAME OVER]\n\n";
    		cout << "Do you wish to reload your saved game? (Currently Unsupported)\n\n";
    		cin >> NextRound;
    	}
    	else
    	{
    		cout << "" << MonsterName <<" has died! [VICTORY!]\n\n";
    		cout << "You find 8 gold pieces on the " << MonsterName <<"!\n";
    		cout << "You gain 10 experience points!\n";
    		PlayerGold = PlayerGold + 8;               // Award player gold
    		PlayerExperience = PlayerExperience + 10;  // Award player experience
    		cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    		cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    		cout << "Press <c> and hit enter to continue.\n";
    		cin >> NextRound;
    	}
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Open Midi Music
    	ExperienceCalculator();
    	return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You don't check to see if the monster is already dead.

    - player hits
    - check monster is alive
    - monster has a go
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    26
    This post is kinda outdated i fixed it but thanks for trying to help. I just got myself a notepad and wrote down the steps step by step what i wanted to do and it was much clearer in real words then code. There is still one tiny bit that needs correction to be perfect but a couple goto's fixed it.

    Code:
    mciSendString("stop C:/KingdomOfMythos/Midi/MythosMusic1.mid" ,NULL,0,NULL); // Open Midi Music	
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosIntro.mid" ,NULL,0,NULL); // Open Midi Music
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosInn.mid" ,NULL,0,NULL); // Open Midi Music
    	mciSendString("play C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Open Midi Music	
    	//Initialize function
    	int ExperienceCalculator();
    	
    	// Variable for next combat round
    	char NextRound;  // Continue to next combat cycle
    	// Temporary player variables to check for equipment
    	int TempPlayerAttack = PlayerAttack + PlayerWeapon;
    	int TempPlayerDefense = PlayerDefense + PlayerArmorShield + PlayerArmorBody + PlayerArmorLegs + PlayerArmorHands + PlayerArmorFeet;
    	// Monster damage variables using rand
    	// Also subtracts player defense from monsters damage
    	int LowMonster = 2;
    	int HighMonster = MonsterAttack - TempPlayerDefense;	
    	// Player damage variables using rand
    	// Also subtraces monster defense from players damage
    	int LowPlayer = 2;
    	int HighPlayer = TempPlayerAttack - MonsterDefense;
    	// Variable to see if player or monster land a blow
    	int PlayerHitCheck = 0;	
    	int MonsterHitCheck = 0;	
    	// Player % chance to hit high and low
    	int PlayerHitLow = 1;	
    	int PlayerHitHigh = 100;	
    	// Monster % chance to hit high and low
    	int MonsterHitLow = 1;	
    	int MonsterHitHigh = 100;	
    	// Player & Monster damage results die 1 + die 2
    	int MonsterDamageResults = 0;		
    	int PlayerDamageResults = 0;	
    	//Variables to hold random values for the first and the second die on each roll.
    	int first_die, sec_die;
    	//Declare variable to hold seconds on clock.
    	time_t seconds;
    	//Get value from system clock and place in seconds variable.
    	time(&seconds);
    	//Convert seconds to a unsigned integer.
    	srand((unsigned int) seconds);
    	
    	HANDLE hConsole; // Code for colored text
    	hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Code for colored text
    	{
    	SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
    	}
    	cout << "\nYou encounter a Level " << MonsterLevel << " " << MonsterName <<" Prepare to fight!\n\n";
    	{
    	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    	}
    	cout << "Press <c> and hit enter to continue.\n";
    	cin >> NextRound;
    	
    	while ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    	
    		if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    		{
    			{
    			SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
    			}
    			cout << "\nStarting combat round between [" << PlayerName <<"] & [" << MonsterName <<"]!\n\n";
    			{
    			SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    			}
    			if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    			{
    				PlayerHitCheck = rand() % (PlayerLevel * 2) + PlayerHitHigh;
    				if (PlayerHitCheck >= 50)
    				{
    					{
    					SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
    					}
    					cout << "" << PlayerName <<" swing's at the " << MonsterName <<" and lands a blow!\n";
    					first_die = rand() % (HighPlayer - LowPlayer + 1) + LowPlayer;  // Calculate player damage of first dice roll
    					sec_die = rand() % (HighPlayer - LowPlayer +1) + LowPlayer;     // Calculate player damage of second dice roll
    					cout << "" << PlayerName <<"'s attack is (" << first_die << ", "
    					<< sec_die << "}\n\n";
    					PlayerDamageResults = sec_die + first_die; // Calculate total damage done by player
    					cout << "" << PlayerName << " hits " << MonsterName << " for " << PlayerDamageResults << " damage.\n";
    					MonsterHitPoints = MonsterHitPoints - PlayerDamageResults; // Subtract damage from monsters hitpoints
    					{
    					SetConsoleTextAttribute(hConsole, 14); // Colored Text Yellow
    					}
    					cout << "------------------------------\n";
    					cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
    					cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
    					cout << "------------------------------\n\n";
    					{
    					SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    					}
    					cout << "Press <c> and hit enter to continue.\n";
    					cin >> NextRound;
    PLAYERMISS:					
    					if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    					{
    						MonsterHitCheck = rand() % (MonsterLevel * 2) + MonsterHitHigh;
    						if (MonsterHitCheck >= 50)
    						{
    							{
    							SetConsoleTextAttribute(hConsole, 11); // Colored Text Blue
    							}
    							cout << "" << MonsterName <<" swing's at " << PlayerName <<" and lands a blow!\n";
    							first_die = rand() % (HighMonster - LowMonster + 1) + LowMonster; // Calculate monster damage of first dice roll
    							sec_die = rand() % (HighMonster - LowMonster + 1) + LowMonster;   // Calculate monster damage of second dice roll
    							cout << "" << MonsterName <<"'s attack is (" << first_die << ", "
    							<< sec_die << "}\n\n";
    							MonsterDamageResults = sec_die + first_die; // Calculate total damage done by monster
    							cout << "" << MonsterName <<" hits " << PlayerName <<" for " << MonsterDamageResults << " damage.\n";
    							PlayerHitPoints = PlayerHitPoints - MonsterDamageResults; // Subtract damage from players hitpoints
    							{
    							SetConsoleTextAttribute(hConsole, 14); // Colored Text Yellow
    							}
    							cout << "------------------------------\n";
    							cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
    							cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
    							cout << "------------------------------\n\n";
    							{
    							SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    							}
    							cout << "Press <c> and hit enter to continue to the next combat round.\n";
    							cin >> NextRound;
    						}
    						else
    						{
    							{
    							SetConsoleTextAttribute(hConsole, 11); // Colored Text Blue
    							}
    							cout << "\n" << MonsterName <<" swing's at " << PlayerName << " and misses!\n\n";
    							{
    							SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    							}
    							cout << "Press <c> and hit enter to continue to the next combat round.\n";
    							cin >> NextRound;
    						}
    					}
    					else
    					{
    						if (MonsterHitPoints >= 1)
    						{
    							cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
    							cout << "Do you wish to reload your saved game? (Currently Unsupported)\n\n";
    							cin >> NextRound;
    						}
    						else
    						{
    							cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
    							cout << "You find " << MonsterGold <<" gold pieces!\n";
    							cout << "You gain " << MonsterExperience <<" experience!\n";
    							PlayerGold = PlayerGold + MonsterGold;                    // Award player gold
    							PlayerExperience = PlayerExperience + MonsterExperience;  // Award player experience
    							cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    							cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    							cout << "Press <c> and hit enter to continue.\n";
    							cin >> NextRound;
    							goto COMBATEND;
    						}
    					}
    				}
    				else
    				{
    					{
    					SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
    					}
    					cout << "\n" << PlayerName <<" swing's at the " << MonsterName << " and misses!\n\n";
    					{
    					SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    					}
    					cout << "Press <c> and hit enter to continue.\n";
    					cin >> NextRound;
    					goto PLAYERMISS;
    				}
    			}
    			else
    			{
    				if (MonsterHitPoints >= 1)
    				{
    					cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
    					cout << "Do you wish to reload your saved game? (Currently Unsupported)\n\n";
    					cin >> NextRound;
    				}
    				else
    				{
    					cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
    					cout << "You find " << MonsterGold <<" gold pieces!\n";
    					cout << "You gain " << MonsterExperience <<" experience!\n";
    					PlayerGold = PlayerGold + MonsterGold;                    // Award player gold
    					PlayerExperience = PlayerExperience + MonsterExperience;  // Award player experience
    					cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    					cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    					cout << "Press <c> and hit enter to continue.\n";
    					cin >> NextRound;
    					goto COMBATEND;
    				}
    			}
    		}
    		else
    		{
    			cout << "Error: [Player or Monster HP <= 0] This should never occur. Contact developer!";
    			cin >> NextRound;
    		}
    		
    	if (PlayerHitPoints >=1)
    	{
    		cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
    		cout << "You find " << MonsterGold <<" gold pieces!\n";
    		cout << "You gain " << MonsterExperience <<" experience!\n";
    		PlayerGold = PlayerGold + MonsterGold;                    // Award player gold
    		PlayerExperience = PlayerExperience + MonsterExperience;  // Award player experience
    		cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    		cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    		cout << "Press <c> and hit enter to continue.\n";
    		cin >> NextRound;
    	}
    	else
    	{
    		cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
    		cout << "Do you wish to reload your saved game? (Currently Unsupported)\n\n";
    		cin >> NextRound;
    	}
    COMBATEND:
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Close Midi Music
    	ExperienceCalculator();
    	return 0;
    Last edited by Snaef98; 09-03-2010 at 05:43 AM.

  4. #4
    Novice
    Join Date
    Jul 2009
    Posts
    568
    My friends, functions and structures, would like to have a word with you.

    You're showing a lot of effort, and that is commendable. But you're painfully lacking knowledge in some fundamental areas. Either that, or you're showing a lack of understanding for how they fit into your programs.

    If you could take some time to learn about functions, it would solve 80% of the issues you're having. Learning about structures would solve the remaining 80%.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    26
    Ummm better check your math again since 80%+80% doesn't equal 100%...


    The goto was kinda needed for the combat bug fix because otherwise it would return more of the nested ifelse before it hit the end properly, as for the use of it my main body is alot of redundant text for areas alot of nested switchs for selections so the goto function proves useful for some of the areas, and at the time of creating the main portion of my program i was having problems with functions until i learned to define them by declaring them within another function in order to launch it IE

    int Main()
    {
    int SecondFunction();
    cout "Text here";
    SecondFunction();
    return 0;
    }

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    26
    Functions are nothing but extensions of the main function they are "Subroutines"

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    sub

    subroutines effectively yes but i like to think the language provides a bit more room for abstraction than that... also if u dont start getting some functions and headers, additional source files in there you are going to be faced with a giant unweildly file as you develop the game and you will find that is not very easy to work with
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  8. #8
    Registered User
    Join Date
    Aug 2010
    Posts
    26
    I got most of my code in functions now, the only portion not divided up into seperate functions is the "text storyline" that represents each of the areas on the maps

    im using coords [0,0,0] first number is map 0 = world 1-9 = other maps...

    and 0,0 are left to right and up and down



    The problem with splitting it up into multiple functions is that sometimes i want to specifically put the user in a specific area of the text... and you can't goto from a different function i dont always want to start @ the top.

  9. #9
    Registered User
    Join Date
    Aug 2010
    Posts
    26
    What exactly can be stored in headers though? functions? global variables?

  10. #10
    Registered User
    Join Date
    Aug 2010
    Posts
    26
    Here is my even further updated combat routine, im always refining stuff lol.


    Code:
    mciSendString("stop C:/KingdomOfMythos/Midi/MythosMusic1.mid" ,NULL,0,NULL); // Open Midi Music	
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosIntro.mid" ,NULL,0,NULL); // Open Midi Music
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosInn.mid" ,NULL,0,NULL); // Open Midi Music
    	mciSendString("play C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Open Midi Music	
    	//Initialize function
    	int ExperienceCalculator();
    	
    	// Variable for next combat round
    	char NextRound;  // Continue to next combat cycle
    	// Temporary player variables to check for equipment
    	int TempPlayerAttack = PlayerAttack + PlayerWeapon;
    	int TempPlayerDefense = PlayerDefense + PlayerArmorShield + PlayerArmorBody + PlayerArmorLegs + PlayerArmorHands + PlayerArmorFeet;
    	// Monster damage variables using rand
    	// Also subtracts player defense from monsters damage
    	int LowMonster = 2;
    	int HighMonster = MonsterAttack - TempPlayerDefense;	
    	// Player damage variables using rand
    	// Also subtraces monster defense from players damage
    	int LowPlayer = 2;
    	int HighPlayer = TempPlayerAttack - MonsterDefense;
    	// Variable to see if player or monster land a blow
    	int PlayerHitCheck = 0;	
    	int MonsterHitCheck = 0;	
    	// Player % chance to hit high and low
    	int PlayerHitLow = 1;	
    	int PlayerHitHigh = 100;	
    	// Monster % chance to hit high and low
    	int MonsterHitLow = 1;	
    	int MonsterHitHigh = 100;	
    	// Player & Monster damage results die 1 + die 2
    	int MonsterDamageResults = 0;		
    	int PlayerDamageResults = 0;	
    	//Variables to hold random values for the first and the second die on each roll.
    	int first_die, sec_die;
    	//Declare variable to hold seconds on clock.
    	time_t seconds;
    	//Get value from system clock and place in seconds variable.
    	time(&seconds);
    	//Convert seconds to a unsigned integer.
    	srand((unsigned int) seconds);
    	
    	HANDLE hConsole; // Code for colored text
    	hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Code for colored text
    	{
    	SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
    	}
    	cout << "\nYou encounter a Level " << MonsterLevel << " " << MonsterName <<" Prepare to fight!\n\n";
    	{
    	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    	}
    	cout << "Press <c> and hit enter to continue.\n";
    	cin >> NextRound;
    	
    	while ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    	
    		if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    		{
    			{
    			SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
    			}
    			cout << "\nStarting combat round between [" << PlayerName <<"] & [" << MonsterName <<"]!\n\n";
    			{
    			SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    			}
    			if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    			{
    				PlayerHitCheck = rand() % (PlayerLevel * 2) + PlayerHitHigh;
    				if (PlayerHitCheck >= 50)
    				{
    					{
    					SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
    					}
    					cout << "" << PlayerName <<" swing's at the " << MonsterName <<" and lands a blow!\n";
    					first_die = rand() % (HighPlayer - LowPlayer + 1) + LowPlayer;  // Calculate player damage of first dice roll
    					sec_die = rand() % (HighPlayer - LowPlayer +1) + LowPlayer;     // Calculate player damage of second dice roll
    					cout << "" << PlayerName <<"'s attack is (" << first_die << ", "
    					<< sec_die << "}\n\n";
    					PlayerDamageResults = sec_die + first_die; // Calculate total damage done by player
    					cout << "" << PlayerName << " hits " << MonsterName << " for " << PlayerDamageResults << " damage.\n";
    					MonsterHitPoints = MonsterHitPoints - PlayerDamageResults; // Subtract damage from monsters hitpoints
    					{
    					SetConsoleTextAttribute(hConsole, 14); // Colored Text Yellow
    					}
    					cout << "------------------------------\n";
    					cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
    					cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
    					cout << "------------------------------\n\n";
    					{
    					SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    					}
    					cout << "Press <c> and hit enter to continue.\n";
    					cin >> NextRound;
    PLAYERMISS:					
    					if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
    					{
    						MonsterHitCheck = rand() % (MonsterLevel * 2) + MonsterHitHigh;
    						if (MonsterHitCheck >= 50)
    						{
    							{
    							SetConsoleTextAttribute(hConsole, 11); // Colored Text Blue
    							}
    							cout << "" << MonsterName <<" swing's at " << PlayerName <<" and lands a blow!\n";
    							first_die = rand() % (HighMonster - LowMonster + 1) + LowMonster; // Calculate monster damage of first dice roll
    							sec_die = rand() % (HighMonster - LowMonster + 1) + LowMonster;   // Calculate monster damage of second dice roll
    							cout << "" << MonsterName <<"'s attack is (" << first_die << ", "
    							<< sec_die << "}\n\n";
    							MonsterDamageResults = sec_die + first_die; // Calculate total damage done by monster
    							cout << "" << MonsterName <<" hits " << PlayerName <<" for " << MonsterDamageResults << " damage.\n";
    							PlayerHitPoints = PlayerHitPoints - MonsterDamageResults; // Subtract damage from players hitpoints
    							{
    							SetConsoleTextAttribute(hConsole, 14); // Colored Text Yellow
    							}
    							cout << "------------------------------\n";
    							cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
    							cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
    							cout << "------------------------------\n\n";
    							{
    							SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    							}
    							cout << "Press <c> and hit enter to continue to the next combat round.\n";
    							cin >> NextRound;
    						}
    						else
    						{
    							{
    							SetConsoleTextAttribute(hConsole, 11); // Colored Text Blue
    							}
    							cout << "\n" << MonsterName <<" swing's at " << PlayerName << " and misses!\n\n";
    							{
    							SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    							}
    							cout << "Press <c> and hit enter to continue to the next combat round.\n";
    							cin >> NextRound;
    						}
    					}
    					else
    					{
    						if (MonsterHitPoints >= 1)
    						{
    							cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
    							goto COMBATEND;
    						}
    						else
    						{
    							cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
    							cout << "You find " << MonsterGold <<" gold pieces!\n";
    							cout << "You gain " << MonsterExperience <<" experience!\n";
    							PlayerGold = PlayerGold + MonsterGold;                    // Award player gold
    							PlayerExperience = PlayerExperience + MonsterExperience;  // Award player experience
    							cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    							cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    							cout << "Press <c> and hit enter to continue.\n";
    							cin >> NextRound;
    							goto COMBATEND;
    						}
    					}
    				}
    				else
    				{
    					{
    					SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
    					}
    					cout << "\n" << PlayerName <<" swing's at the " << MonsterName << " and misses!\n\n";
    					{
    					SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    					}
    					cout << "Press <c> and hit enter to continue.\n";
    					cin >> NextRound;
    					goto PLAYERMISS;
    				}
    			}
    			else
    			{
    				if (MonsterHitPoints >= 1)
    				{
    					cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
    					goto COMBATEND;
    				}
    				else
    				{
    					cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
    					cout << "You find " << MonsterGold <<" gold pieces!\n";
    					cout << "You gain " << MonsterExperience <<" experience!\n";
    					PlayerGold = PlayerGold + MonsterGold;                    // Award player gold
    					PlayerExperience = PlayerExperience + MonsterExperience;  // Award player experience
    					cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    					cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    					cout << "Press <c> and hit enter to continue.\n";
    					cin >> NextRound;
    					goto COMBATEND;
    				}
    			}
    		}
    		else
    		{
    			cout << "Error: [Player or Monster HP <= 0] This should never occur. Contact developer!";
    			cin >> NextRound;
    		}
    		
    	if (PlayerHitPoints >=1)
    	{
    		cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
    		cout << "You find " << MonsterGold <<" gold pieces!\n";
    		cout << "You gain " << MonsterExperience <<" experience!\n";
    		PlayerGold = PlayerGold + MonsterGold;                    // Award player gold
    		PlayerExperience = PlayerExperience + MonsterExperience;  // Award player experience
    		cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
    		cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
    		cout << "Press <c> and hit enter to continue.\n";
    		cin >> NextRound;
    	}
    	else
    	{
    		cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
    		goto COMBATEND;
    	}
    COMBATEND:
    	mciSendString("stop C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Close Midi Music
    	if (PlayerHitPoints >= 1)
    	{
    		ExperienceCalculator();
    	}
    	else
    	{
    		{
    		SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    		}	
    		cout << "\n[";
    		{
    		SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
    		}	
    		cout << " SYSTEM MESSAGE: ";
    		{
    		SetConsoleTextAttribute(hConsole, 15); // Colored Text White
    		}	
    		cout << "Player Death ]\n";
    		cout << "\nExiting combat because player has died.\n\n";
    	}	
    	return 0;
    }

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Please stop posting reams of code. Post the relevant section that has the issue and/or attach the code to the post. Reams of code in your post will only cause people to ignore your posts.

  12. #12
    Registered User
    Join Date
    Sep 2010
    Posts
    2
    oh come on bubba, how else are the rest of us supposed to be able to steal code from him if he does not post reams of it?

  13. #13
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by crimsonwolf82 View Post
    oh come on bubba, how else are the rest of us supposed to be able to steal code from him if he does not post reams of it?
    First post, no capitalization, and on a dead topic. Way to go for a first impression!
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  14. #14
    Registered User
    Join Date
    Sep 2010
    Posts
    2
    what do you mean???

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed