Question: Assignment Details This assignment will continue with the choose your own adventure game. You're going to follow the same premise (3 choices resulting in 8
Assignment Details
This assignment will continue with the choose your own adventure game. You're going to follow the same premise (3 choices resulting in 8 scenarios), but all of the text from the game will be saved in a .txt file. You'll create a filestream, read each line and store it in an array (there are better objects to us, but this is the one we know), and then you'll refer to that array when you call 'Console.WriteLine'. Hint: Your programming will be easier if you have (for example) 3 lines for each possible choice or outcome (for a total of 15 (2^4-1: 8 outcomes, 4 third level choices, 2 second level choices, and 1 first level choice) and any introductory text at the very end of the file. When you want to print a line for a given scenario, can you figure out an appropriate algorithm to figure out the appropriate choice is? If not, you can just hardcode which line/array element goes where.
Assignment Instructions
You will create a C# project, complete the assignment, zip the resulting project into an archive, and submit it according to the TA's instructions. Assignments submitted should be your own work. While working with peers and others is encouraged, the final code should be yours and you should be able to demonstrate how it works when asked.
HERE IS THE ORIGINAL C# CODE:
using System;
namespace ChooseYourOwnAdventure { class Program { static void Main(string[] args) { string[] outputs = new string[3];
outputs[0] = "You decide to look for a way out."; outputs[1] = "You come across a river. What do you do?"; outputs[2] = "1. Attempt to swim across the river 2. Follow the river upstream";
Console.WriteLine("Welcome to Choose Your Own Adventure!"); Console.WriteLine("Written by
int choice = Convert.ToInt32(Console.ReadLine());
if (choice == 1) { for (int i = 0; i < outputs.Length; i++) { Console.WriteLine(outputs[i]); }
choice = Convert.ToInt32(Console.ReadLine());
if (choice == 1) { Console.WriteLine("You attempt to swim across the river."); Console.WriteLine("Unfortunately, the river was too strong and you were swept away."); Console.WriteLine("Game Over"); } else if (choice == 2) { Console.WriteLine("You follow the river upstream and come across a village."); Console.WriteLine("You are finally rescued and able to return home."); Console.WriteLine("Congratulations! You have successfully completed the game."); } else { Console.WriteLine("Invalid choice. Please try again."); } } else if (choice == 2) { outputs[0] = "You decide to build a shelter and wait for a rescue team to find you."; outputs[1] = "Days pass and you start to run out of food."; outputs[2] = "1. Attempt to catch fish in the river 2. Try to find fruits and berries in the jungle";
for (int i = 0; i < outputs.Length; i++) { Console.WriteLine(outputs[i]); }
choice = Convert.ToInt32(Console.ReadLine());
if (choice == 1) { Console.WriteLine("You attempt to catch fish in the river."); Console.WriteLine("You are successful and are able to sustain yourself until rescue arrives."); Console.WriteLine("Congratulations! You have successfully completed the game."); } else if (choice == 2) { Console.WriteLine("You try to find fruits and berries in the jungle."); Console.WriteLine("Unfortunately, you were unable to find enough food and eventually starve to death."); Console.WriteLine("Game Over"); } else { Console.WriteLine("Invalid choice. Please try again."); } } else { Console.WriteLine("Invalid choice. Please try again."); }
Console.ReadLine(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
