My Skyrim Inspired triplex game pt 3

#include <iostream>

void PrintIntroduction(int Difficulty)
{
    //Story of the Dragonborn
    std::cout <<  "\n\n\n" "Hello Adventurer! \n\n";
    std::cout << "+ You have been caught by the Imperials at the Pale pass.\n";
    std::cout << "+ Then you were brought to Helgen to execute alongside with Ulfric Stormcloak. \n";
    std::cout << "+ While the execution, a dragon came and unleashed its fury on Helgen. \n";
    std::cout << "+ A soldier named Hadvar helped you to escape while the dragon attacked. \n";
    std::cout << "+ Now you have to unlock the level "<< Difficulty << " door of the Helgen keep to escape from the dragonfire. \n\n";

}


bool PlayGame(int Difficulty)
{   
    PrintIntroduction(Difficulty);
    
    
    const int CodeA = 4;
    const int CodeB = 3;
    const int CodeC = 2; 

    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    std::cout << "++ The door has 3 numbered rune lock. \n";
    std::cout << "++ You must insert the correct combination of numbers to unlock the door. \n";
    std::cout << "++ Here are the hints. \n \n";
    
    std::cout<<  "The numbers add up to: " << CodeSum << "\n"; 
    std::cout<< "The numbers multiply to give: "<< CodeProduct << "\n";

    //stores player data
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;

    //std::cout << "You entered: " << GuessA << " " << GuessB << " " << GuessC;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    

    //Check if the players code is correct
    if (GuessSum == CodeSum && GuessProduct== CodeProduct && Difficulty < 5)
    {
        std::cout << "Good work. You entered the correct combination of numbers and unlocked the door. You are now Going to level " << Difficulty +1;
        return true;
    }
    if (GuessSum == CodeSum && GuessProduct== CodeProduct && Difficulty == 5)
    {
        std::cout << "Good work. You entered the correct combination of numbers and unlocked the door."; 
        return true;
    }

    else
    {
        std::cout << "Wrong combination! Retry the level!";
        return false;
    } 

}



int main()
{   
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
   
    while (LevelDifficulty <= MaxDifficulty) //Loop the game until all the levels are completed

    {   
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); //clears any errors
        std::cin.ignore(); //discards the buffer

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    
    std::cout << "\n\nCongratulations Adventurer! You completed all the levels and got out of Helgen!\n\n";
    
    
    return 0;
}




2 Likes

This is perfection

1 Like

Privacy & Terms