A repeatable series of random numbers is important to me for another project so I thought I’d give the player some level of control over their randomness. Introducing the infinite hallway.
There are only 5 levels per door, but you have up to another 5 chances to try again. You can choose the same door to get the same sequence you initially tried, or go through a new door to get another. I could have made it harder but I needed to solve it myself
#include <iostream>
const int ENDING_LEAVE = 0;
const int ENDING_FAIL = -1;
const int ENDING_WIN = 1;
void AskSequence(int Difficulty, int CodeSum, int CodeProduct)
{
if (Difficulty > 1)
{
std::cout << "> You've made it to level " << Difficulty << ".\n";
std::cout << "> Another terminal requests you enter three numbers to continue.\n";
}
else
{
std::cout << "> A terminal requests you enter three numbers to continue.\n";
}
std::cout << "> The codes add up to: " << CodeSum << "\n";
std::cout << "> The codes multiply to give: " << CodeProduct << "\n";
}
int GetRandom(int Difficulty)
{
return rand() % (Difficulty * 2) + 2;
}
bool BeginSequence(int Difficulty)
{
// decare
int CodeA = GetRandom(Difficulty);
int CodeB = GetRandom(Difficulty);
int CodeC = GetRandom(Difficulty);
int CodeSum = CodeA + CodeB + CodeC;
int CodeProduct = CodeA * CodeB * CodeC;
AskSequence(Difficulty, CodeSum, CodeProduct);
int PlayerGuessA, PlayerGuessB, PlayerGuessC;
std::cin >> PlayerGuessA >> PlayerGuessB >> PlayerGuessC;
std::cin.clear();
std::cin.ignore();
// std::cout << "You entered: " << PlayerGuessA << " " << PlayerGuessB << " " << PlayerGuessC << std::endl;
int GuessSum = PlayerGuessA + PlayerGuessB + PlayerGuessC;
int GuessProduct = PlayerGuessA * PlayerGuessB * PlayerGuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
// Success
return true;
}
else
{
return false;
}
}
bool EnterDoor()
{
const int MaxDifficulty = 5;
int Difficulty = 1;
do
{
bool bSequenceComplete = BeginSequence(Difficulty);
if (bSequenceComplete)
{
Difficulty++;
}
else
{
return false;
}
} while (Difficulty <= MaxDifficulty);
return true;
}
void PrintIntroduction(int DoorLength)
{
std::cout
<< ". .\n"
<< ". \n"
<< " \n"
<< " .'. .'' \n"
<< " .;:;. .::, \n"
<< " .,:c. ,c:,. \n"
<< " .lxo. ;xxc. \n"
<< " .d0x. .. .,;,,'...,,;;. .. :O0o. \n"
<< " 'kXk. .;. . ;KNXXK00KXNNKc .. .;' :0Xd. \n"
<< " 'ONk' .c. .. .;0NNXKKKKXNNK:. .. .c; :KNx. \n"
<< " ,0Nk' .l' ....;ONXXNNNXXXN0:. .. .c; :KNx. \n"
<< " ,0NO' .l' ....;0NNXNWWNXNN0:. .. .c; :XNx. \n"
<< " ,0WO' .l' ....:0NNNWMMWNNNKc.... .l: :XWk. \n"
<< ". ,0W0' .o' ....'llllloolllll,.... .l: cXWk. .\n"
<< ". ,KW0' 'o' .. .. .l: cNWO. .\n"
<< "'. ,KW0, 'o' .l: lNWO. .'\n"
<< ":'. ,KMK, . .. oNWO. ..':\n"
<< "l:,.. ;KMK; .oWWO. ..;co\n"
<< "dol:'.. ;KNk' :0WO' ..,:lox\n"
<< "kxdlc;'.. 'c,. .:c. ..,;codxk\n"
<< "Okkxdoc:,.. ..;:lodxkO0\n"
<< "K0OOkxdl;. .;lxkO00K\n"
<< "XK00Okl' .'ck0KXX\n";
if (DoorLength == 0)
{
std::cout << "In a hallway of infinite doors, time stands still.\n";
}
else
{
std::cout << "You must have entered incorrectly as you're back in the hallway.\n";
}
std::cout << "Each door has a unique integer above the door frame.\n";
std::cout << "One particular door stands out above the rest. Door Zero.\n";
std::cout << "Select the door that you wish to enter:\n\n";
}
int EnterHallway()
{
const int MaxDoors = 5;
int Doors[MaxDoors]{0};
int DoorLength = 0;
int *DoorIndex = 0;
int SelectedDoor;
// get input. What door. Upon door, if door exists in array, show
do
{
// Show intro
PrintIntroduction(DoorLength);
// Get the door the player wants to go into.
std::cin >> SelectedDoor;
std::cin.clear();
std::cin.ignore();
// You selected the exit door
if (SelectedDoor == 0)
{
return ENDING_LEAVE;
}
// Check if selected door was already selected.
// std::cout << "Current Door Length: " << DoorLength << std::endl;
for (int i = 0; i < DoorLength; i++)
{
// std::cout << "Checking: Doors[" << i << "] = " << Doors[i] << " = " << SelectedDoor << std::endl;
if (Doors[i] == SelectedDoor)
{
std::cout << "Something feels off. Like an odd sense of deja vu.\n";
}
}
std::cout << "\n";
// Add the door to the list of all doors previously selected.
Doors[DoorLength++] = SelectedDoor;
// std::cout << "Added: " << SelectedDoor << " = " << Doors[DoorLength - 1] << " to Doors[" << DoorLength - 1 << "]\n";
srand(SelectedDoor);
bool bCompletedSequence = EnterDoor();
if (bCompletedSequence)
{
return ENDING_WIN;
}
// begin reset Dificulty, start door(dificulty);
} while (DoorLength <= MaxDoors);
std::cout << "You find yourself back home unexpectedly.\n";
return ENDING_FAIL;
}
/**
*
*/
int main()
{
int Status = EnterHallway();
if (Status == ENDING_WIN)
{
std::cout << "With the tasks complete, you are taken to a distant paradise.\n";
}
else if (Status == ENDING_LEAVE)
{
std::cout << "Wondering if you will ever get a chance in the infinite hallway again, you return home.\n";
}
else
{
std::cout << "Disappointed, you find yourself back home unexpectedly.\n";
}
return 0;
}