Hi there I finished the Triple X lessons and tried to create the game from stretch again without watching the video to memorize everything. I come from 0 scripting experience… I am trying to add a few functions to my version of the game by giving the player coordinates after each correct solved task and at the end have the player type in all the collected coordinates to ultimately finish the game.
Question how can I improve this script and how do I add the function of checking if the player has entered the correct coordinates at the end. Pretty sure Ill have to declare the coordinates and then at the end add a if/else function to check if the correct numbers where typed in and send a message accordingly… Every-time I try doing it I get various errors…
Here is the script without any errors so far but with the last missing function.
#include<iostream>
#include<ctime>
void GameIntroduction() //Game Introduction Message
{
std::cout << "___________________________________________________________________\n";
std::cout << "| |\n";
std::cout << "| WELCOME STRANGER |\n";
std::cout << "| |\n";
std::cout << "| Looks like your Portal Navigation Processor broke down! |\n";
std::cout << "| You have to manually overwrite the system by decoding the last |\n";
std::cout << "| 5 module sequences in this Terminal |\n";
std::cout << "| |\n";
std::cout << "| If the Sequence is correct you will be givin the first numbers |\n";
std::cout << "| of the cooardinates. At the end you will have to fill in all |\n";
std::cout << "| numbers in the master console to rewrite the Portal Device. |\n";
std::cout << "| |\n";
std::cout << "| Once you have the cooardinates you will be able to teleport back|\n";
std::cout << "| to your ship! |\n";
std::cout << "| |\n";
std::cout << "| Good Luck Stranger! |\n";
std::cout << "|_________________________________________________________________|\n";
std::cout << std::endl;
std::cout << std::endl;
std::cout << "\n======================================================================\n";
std::cout << "| |\n";
std::cout << "| Press ENTER to start decoding... |\n";
std::cout << "| |\n";
std::cout << "======================================================================\n\n";
}
void GameStartMessage(int Difficulty) // Prints the Starting message with instructions on how to play
{
std::cout << "\nMODULE: " << Difficulty;
std::cout << "\n======================================================================\n";
std::cout << "| You need to decode this Module |\n";
std::cout << "| Enter the correct 3 digit code get access to the cooardinates |\n";
std::cout << "| Seperate each digit by one space |\n";
std::cout << "======================================================================\n\n";
}
bool PlayGame(int Difficulty)
{
const int CodeA = rand() % Difficulty + Difficulty;
const int CodeB = rand() % Difficulty + Difficulty;
const int CodeC = rand() % Difficulty + Difficulty;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeMulti = CodeA * CodeB * CodeC;
//print CodeSum and CodeMulti to the terminal
std::cout << std::endl;
std::cout << "\nMODULE: " << Difficulty;
std::cout << "\n======================================================================\n";
std::cout << "| You need to decode this Module |\n";
std::cout << "| Enter the correct 3 digit code get access to the cooardinates |\n";
std::cout << "| Seperate each digit by one space |\n";
std::cout << "| The code numbers add up to: " << CodeSum << " |\n";
std::cout << "| The code multiplies to " << CodeMulti << " |\n";
std::cout << "======================================================================\n\n";
std::cout << std::endl;
std::cout << std::endl;
//Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessMulti = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessMulti == CodeMulti && Difficulty == 1)
{
std::cout << "\n======================================================================\n";
std::cout << "| Cooardinates Decoding... 41 ### ## # ### |\n";
std::cout << "======================================================================\n\n";
return true;
}
else
{
std::cout << "\n======================================================================\n";
std::cout << "| Wrong Code! Decoding process canceled |\n";
std::cout << "======================================================================\n\n";
return false;
}
if (GuessSum == CodeSum && GuessMulti == CodeMulti && Difficulty == 2)
{
std::cout << "\n======================================================================\n";
std::cout << "| Cooardinates Decoding... 41 223 ## # ### |\n";
std::cout << "======================================================================\n\n";
return true;
}
else
{
std::cout << "\n======================================================================\n";
std::cout << "| Wrong Code! Decoding process canceled |\n";
std::cout << "======================================================================\n\n";
return false;
}
if (GuessSum == CodeSum && GuessMulti == CodeMulti && Difficulty == 3)
{
std::cout << "\n======================================================================\n";
std::cout << "| Cooardinates Decoding... 41 223 17 # ### |\n";
std::cout << "======================================================================\n\n";
return true;
}
else
{
std::cout << "\n======================================================================\n";
std::cout << "| Wrong Code! Decoding process canceled |\n";
std::cout << "======================================================================\n\n";
return false;
}
if (GuessSum == CodeSum && GuessMulti == CodeMulti && Difficulty == 4)
{
std::cout << "\n======================================================================\n";
std::cout << "| Cooardinates Decoding... 41 223 17 8 ### |\n";
std::cout << "======================================================================\n\n";
return true;
}
else
{
std::cout << "\n======================================================================\n";
std::cout << "| Wrong Code! Decoding process canceled |\n";
std::cout << "======================================================================\n\n";
return false;
}
if (GuessSum == CodeSum && GuessMulti == CodeMulti && Difficulty == 5)
{
std::cout << "\n======================================================================\n";
std::cout << "| Decoding Completed! 41 223 17 8 197 |\n";
std::cout << "| Please enter the Cooardinates below to activate the Portal |\n";
std::cout << "======================================================================\n\n";
return true;
}
else
{
std::cout << "\n======================================================================\n";
std::cout << "| Wrong Code! Decoding process canceled |\n";
std::cout << "======================================================================\n\n";
return false;
}
}
int main()
{
GameIntroduction();
{
std::cin.get(); // Waits for player input
}
srand(time(NULL));
int LevelDifficulty = 1;
int const MaxDifficulty = 5;
while (true)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty; // increase the level difficulty
}
}
std::cin.get(); // Waits for player input
return 0;
}