Exemple #1
0
	// Function that displays a screen for the experience and levels
	// gained from the previous battle
	void reward()
	{
		display.Clear();
		cout << "Previous Level: " << Play1.level << " Previous XP: " << Play1.experience << endl;
		cout << "Gained " << Enem1.xpvalue << " experience!!!" << endl;
		Play1.setXP(Enem1.xpvalue);
		cout << endl << "Current Experience: " << Play1.experience << endl;
		display.pause();
	};
Exemple #2
0
	// CurGame's primary method, this encapsulates the entire battle
	// routine, the routine ends as soon as the enemy or the player
	// reach 0 or less hit points. Returns a boolean to determine if
	// the player died during combat or an attempt to run away.
	bool battle()
	{
		// Initialize battle()'s variables to NULL
		// maxhp stores the players original max health so the value
		// can be restored if the player survives the encounter
		int select=0, maxhp=Play1.health;
		bool playDeath=false, enemDeath=false;
		
		// Keep fighting until the player runs or someone dies
		do
		{
			// Clear the display to draw the next frame
			display.Clear();
			
			// Display the battle screen
			select = battleMenu();
			
			// Check which option was chosen
			// The enemy is implemented without AI and will follow
			// suit with the player, a simple AI would evaluate 
			// which of its stats are greater than the player's
			switch( select )
			{
				// Strength based attack
				case 1:
					enemDeath = playAttRound(1);
					playDeath = enemAttRound(1);
					display.pause();
					break;
				// Dexterity based attack
				case 2:
					enemDeath = playAttRound(2);
					playDeath = enemAttRound(2);
					display.pause();
					break;
				// Spellcasting (Intelligence based attack)
				case 3:
					enemDeath = playAttRound(3);
					playDeath = enemAttRound(3);
					display.pause();
					break;
				// Attempt to run away from combat	
				case 4:
					// If they successfully run away
					if ( run() )
					{
						Enem1.xpvalue = 0;
						cout << "\nYou ran away successfully!!!\n";
						display.pause();
						return true;
					}
					// Or else the enemy gets a free attack on the player
					else
					{
						cout << "\nYou failed to get away, the enemy hits you!\n";
						playDeath = enemAttRound( randnum(3, 127) );
						display.pause();
					}
					break;
				// Let the user know their input is invalid	
				default:
					cout << "\nPlease enter a correct choice!!!\n";
                    display.pause();
					break;
			}

			// Check to see if either or both of our competitors have died
			if( playDeath && enemDeath )
			{
				cout << "\n\nYou simultaneously strike each other fatally!!! A true warrior's death...\n";
				display.pause();
				return false;
			}
			else if( playDeath && !enemDeath )
			{
				cout << "\n\nYou died!!!\n";
				display.pause();
				return false;
			}
			
			else if( enemDeath && !playDeath )
			{
				cout << "\n\nYou have slain the " << Enem1.ename << "!!!\n";
				// Reset the players health to maximum after combat
				Play1.health=maxhp;
				display.pause();
				return true;
			}
	
		}while( !playDeath && !enemDeath );
	};