Advertisement
IvanITD

5 - Choose Your Own Adventure

Jan 17th, 2024
1,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.40 KB | Source Code | 0 0
  1. using System.Net.NetworkInformation;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Choose_Your_Own_Adventure
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             /* THE MYSTERIOUS NOISE */
  11.  
  12.             // Start by asking for the user's name:
  13.             Console.Write("What is your name?: ");
  14.             string name = Console.ReadLine();
  15.             Console.WriteLine($"Hello, {name}! Welcome to our story.");
  16.  
  17.  
  18.             // Here I am printing the first sentence needed for the project!
  19.             Console.WriteLine("It begins on a cold rainy night. " +
  20.                 "You're sitting in your room and hear a noise coming from down the hall. Do you go investigate?");
  21.  
  22.             // Here I'm using 'Console.WriteLine();' in order to ask the user to type the needed answer!
  23.             Console.Write("Type YES or NO: ");
  24.  
  25.             // Here I am going to get the user's answer and then put it in a string variable named "noiseChoice"
  26.             string noiseChoice = Console.ReadLine();
  27.  
  28.             // Here I made a little tweak, in case the user desides to use lower case letters. This function is going to, automaticaly change the letters to upper case!
  29.             string upperNoiseChoice = noiseChoice.ToUpper(); // => UPPER CASE LETTER
  30.  
  31.             // Decided to add a little change to the code! Rather than keeping the new string variable, I decided that I'm going to keep it simple and return it to the old variable, with a slight change!
  32.             // I've marked each similar change with => *x => (x) for number
  33.             // *1
  34.             noiseChoice = upperNoiseChoice;
  35.  
  36.             // Here I added an if-else statement in order the user to have more options, after the YES or NO answer!
  37.             if (noiseChoice == "NO")
  38.             {
  39.                 Console.WriteLine("Not much of an adventure if we don't leave our room! \nTHE END.");
  40.             }
  41.             else if (noiseChoice == "YES") // Here we wrote an else if statement to have a second option if the user chooses to answer YES
  42.             {
  43.                 // Added some more story to the game in order for the user to be able to continue!
  44.                 Console.WriteLine("You walk into the hallway and see a light coming from under a door down the hall. \nYou walk towards it. Do you open it or knock?");
  45.  
  46.                 /* Here we are asking the user to type the answer he prefers!
  47.                  * After we get the user's answer we have to save it in a string variable named doorChoice! Later on we change the case letters into upper case! */
  48.                 Console.Write("Type OPEN or KNOCK: ");
  49.                 string doorChoice = Console.ReadLine();
  50.                 string upperDoorChoice = doorChoice.ToUpper(); // => UPPER CASE LETTER
  51.  
  52.                 //*2
  53.                 doorChoice = upperDoorChoice;
  54.  
  55.                 // Now we wrote and if/if-else statement in order to give multiple answers to the user's answer choice!
  56.                 if (upperDoorChoice == "KNOCK")
  57.                 {
  58.                     // Here I wrote an print code in order to print the text for the story
  59.                     Console.WriteLine("A voice behind the door speaks. It says, \"Answer this riddle: \" \nPoor people have it. " +
  60.                     "Rich people need it. If you eat it you die. What is it?");
  61.  
  62.  
  63.                     // We ask the user to answer the riddle by typing his prefered answer!
  64.                     // After that we save the answer in a string variable named riddleAnswer!
  65.                     Console.Write("Type your answer: ");
  66.                     string riddleAnswer = Console.ReadLine();
  67.  
  68.                     // Added this code so that when the user types the write answer, so that it prints with upper case letters!
  69.                     string upperRiddleAnswer = riddleAnswer.ToUpper();  // => UPPER CASE LETTER
  70.  
  71.                     //*3
  72.                     riddleAnswer = upperRiddleAnswer;
  73.  
  74.                     // The right answer to this question is "NOTHING", and now an if-else statement is going to make that work corectly
  75.                     if (upperRiddleAnswer == "NOTHING")
  76.                     {
  77.                         Console.WriteLine($"The door opens and {upperRiddleAnswer} is there. \nYou turn off the lights and run back to your room and lock the door. \nTHE END.");
  78.                     }
  79.                     else // If the user answers anything else we should print this text
  80.                     {
  81.                         Console.WriteLine("You answered incorrectly. The door doesn't open. \nTHE END.");
  82.                     }
  83.  
  84.                 }
  85.                 else if (upperDoorChoice == "OPEN")
  86.                 {
  87.                     // Now we have to check IF the condition is true, then we need to print the written text to the user!
  88.                     Console.WriteLine("The door is locked! See if one of your three keys will open it.");
  89.  
  90.                     // Here we aks the user for a number that represents the key he wants to use
  91.                     // We also made sure that the data saved in the string variable keyChoice is always with upper case letters!
  92.                     Console.Write("Enter a number (1-3): ");
  93.                     string keyChoice = Console.ReadLine();
  94.                     string upperKeyChoice = keyChoice.ToUpper(); // => UPPER CASE LETTER
  95.  
  96.                     //*4
  97.                     keyChoice = upperKeyChoice;
  98.  
  99.                     // Now we've written a switch-case statement that checks if the surten value is equal to either of the "1", "2" or "3"!
  100.                     switch (keyChoice)
  101.                     {
  102.                         // Now that the cases are written, we can write the text ment to be printed!
  103.                         case "1":
  104.                             Console.WriteLine("You choose the first key. Lucky choice! " +
  105.                                 "\nThe door opens and NOTHING is there. Strange... \nTHE END.");
  106.                             break;
  107.  
  108.                         case "2":
  109.                             Console.WriteLine("You choose the second key. The door doesn't open. \nTHE END.");
  110.                             break;
  111.  
  112.                         case "3":
  113.                             Console.WriteLine("You choose the third key. The door doesn't open. \nTHE END.");
  114.                             break;
  115.                     }
  116.  
  117.  
  118.  
  119.                 }
  120.  
  121.  
  122.             }
  123.  
  124.  
  125.         }
  126.     }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement