A4L

userInput

A4L
Apr 26th, 2020
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace testAdventure
  7. {
  8.     static class UserInput
  9.     {
  10.         //Public Variables
  11.         private static string rawInput;
  12.         private static string[] cleanedInputTokens;
  13.         private static string[] stemmedInputTokens;
  14.         #region Get-ers
  15.         public static string GetRawInput() => rawInput;
  16.         public static string[] GetCleanedInputTokens() => cleanedInputTokens;
  17.         public static string[] GetStemmedInputTokens() => stemmedInputTokens;
  18.         #endregion
  19.  
  20.         public static void GetInput(string input)
  21.         {
  22.             rawInput = Regex.Replace(input, @"\s+", " "); //make sure there is only 1 white space between each word.
  23.             cleanedInputTokens = TextUtils.TokenizeStringList(rawInput);
  24.             stemmedInputTokens = TextUtils.StemWordList(cleanedInputTokens);
  25.             ProcessCommands CmdProcessor = new ProcessCommands();
  26.             CmdProcessor.ProcessInputData();
  27.         }
  28.  
  29.         //*********************************************************************************
  30. //***************** Console Pause Code ********************************************
  31. //*********************************************************************************
  32.         public static void AnyKeyContinue()
  33.         {
  34.             Console.CursorVisible = false;
  35.             Console.Write("\n\n");
  36.             Pause_AnyKey();
  37.             Console.CursorVisible = true;
  38.         }
  39.  
  40.         public static void Pause_AnyKey()
  41.         {
  42.             do { } // do nothing in here.. just loop so it acts like a pause
  43.             while (!Console.KeyAvailable); // when a key is pressed it breaks the loop
  44.             ClearInput();
  45.         }
  46.  
  47.         public static void ClearInput()
  48.         {   //Loop through any inputs in the input buffer and "spends them" doing nothing.
  49.             while (Console.KeyAvailable) { Console.ReadKey(true); }
  50.         }
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment