C# Text Adventure
About Escape
Escape is the original idea for the Gears of War map of the same name that I designed here. The ship’s power grids are offline and it is the player’s job to reset all of the power in order to escape the wreckage of the ship. Players must puzzle their way through the ship’s rooms and corridors, only to find that they are not the only survivor left.
Code Exerpts
Text validation
At the heart of the program is the text validator which looks through the input and deciphers whether or not it is a valid command. The function takes the player's input and breaks it down into small tokens to compare with the command library. Once the tokens have been checked and formatted, the string is passed to handle the correct command.
//********************************************************************* //Parse input and check for valid commands //********************************************************************* static ListGetValidCommand() { string userLine = ""; int validCounter = 0; List listString = new List (); int x = 0; while (x < 1) { Console.Write(">"); userLine = Console.ReadLine().ToLower(); validCounter = 0; string[] tokens = userLine.Split(); foreach (string token in tokens) { if (isValidToken(token)) { string correctToken = tokenConverter(token); listString.Add(correctToken); if (listString[0] == "north" || listString[0] == "south" || listString[0] == "east" || listString[0] == "west") { listString.Insert(0, "go"); } } else { Console.WriteLine("I do not recognize the word " + token); listString.Clear(); validCounter++; break; } } if (validCounter > 0) { continue; } listString.Add(""); listString.Add(""); return listString; } return listString; }