Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- //Read user input
- //Parameters are acceptable choices
- int input(int c1 = 0,int c2 = 0,int c3 = 0,int c4 = 0,int c5 = 0,int c6 = 0)
- {
- int choice;
- if (cin >> choice)
- {
- //Check if the user's input is a valid option for this scene
- if(choice == c1 || choice == c2 || choice == c3 || choice == c4 || choice == c5 || choice == c6)
- {
- //User's choice is valid
- cin.clear();
- cin.sync();
- return choice;
- }
- else if (choice == 9)
- {
- //Quit
- cin.clear();
- cin.sync();
- return 8;
- }
- }
- else
- {
- //User's choice is not an integer
- cin.clear();
- cin.sync();
- return 9;
- }
- }
- int main()
- {
- //Declarations
- //Note: remember to declare AND DEFINE a variable for operating on it
- int stage = 0;
- int oldStage = 0;
- int selection = 0;
- bool done = false;
- char quit;
- //Main loop
- do
- {
- switch(stage)
- {
- //Initial text
- case 0:
- cout << "You wake in at the bottom of a narrow chasm.\nA narrow beam of soft light weaves its way through the impenetrable walls above,\nreflected in shallow rivulets meandering across the chasm floor." <<endl;
- cout << "The walls of your stone casket are slick with rain.\nThe entire world is silent save for the distant songs of birds,\nand the soft howl of wind through the chasm." << endl;
- cout << "\nYou stand up and take in your surroundings." << endl;
- cout << "\nAs your eyes adjust, you find a narrow passage before you. Behind you lies a cramped tunnel." << endl;
- cout << "\n1 - Squeeze through the narrow passage.\n3 - Crawl through the mysterious tunnel.\n5 - Look around.\n6 - Help." << endl;
- oldStage = stage;
- stage = input(1,3,5,6);
- break;
- //transitory case
- case 1:
- cout << "\nYou squeeze through the passage...\n";
- system("pause");
- cout << endl << endl;
- stage = 2;
- break;
- case 2:
- cout << "You find yourself in a large cavern.\nThe interior is aglow with a blue ceiling of foxfire. Mushrooms light the cavern well enough to see its dimensions.";
- cout << "\nAt the center of the cavern is a cistern of clean water. It's too dark to gauge its depth, though it seems it could be bottomless.\n";
- cout << "\n1 - Explore the cavern.\n3 - Return through the passage.\n5 - Look around.\n6 - Help." << endl;
- oldStage = stage;
- selection = input(1,3,5,6);
- //Direct each valid choice to the proper stage
- switch(selection)
- {
- case 1:
- stage = 3;
- break;
- case 3:
- stage = 4;
- break;
- case 5:
- stage = 5;
- break;
- case 6:
- stage = 6;
- break;
- case 8:
- stage = 8;
- default:
- cout << "\nPlease input a valid integer.\n\n";
- stage = oldStage;
- system("pause");
- break;
- }
- //Another transitory case. these may become redundant...
- case 4:
- cout << "\nYou squeeze through the passage...\n";
- system("pause");
- cout << endl << endl;
- stage = 5;
- //Revisitation text
- case 5:
- cout << "You're back at the chasm's entrance.\n" << endl;
- cout << "\n1 - Squeeze through the narrow passage.\n3 - Crawl through the mysterious tunnel.\n5 - Look around.\n6 - Help.";
- oldStage = stage;
- selection = input(1,3,5,6);
- stage = selection;
- break;
- //Help case
- case 6:
- cout << "\nMovement: 1,2,3,4\nLook: 5\nQuit: 9\n";
- stage = oldStage;
- system("pause");
- break;
- //Quit case
- case 8:
- cin.clear();
- cin.sync();
- cout << "Leaving so soon? Y/N" << endl;
- cin >> quit;
- cout << quit;
- if (quit == 'Y')
- {
- done == true;
- }
- else
- {
- cout << "I thought you'd stick around."<< endl;
- stage = oldStage;
- }
- break;
- case 9:
- cout << "\nPlease input a valid integer.\n\n";
- stage = oldStage;
- system("pause");
- break;
- default:
- cout << "\nUnrecognized command.\n\n";
- stage = oldStage;
- system("pause");
- break;
- }
- }while(!done);
- cout << endl << "Thanks for playing!" << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement