/// <summary> /// Initializes Maze and World /// </summary> public static void SetupMaze() { int interiorScale = -1; int boundScale = -1; int openingScale = -1; int[] dInfo; GenOption genOption = GetGenOption(); CellOption cellOption = GetCellOption(); //Get input Console.WriteLine("Please input:"); switch (genOption) { case GenOption.userDefined: dInfo = DSizeAndCountByInput(); break; case GenOption.defineDNum: dInfo = InputDCount(); break; case GenOption.maxCellsDNum: dInfo = InputMaxCellsAndCount(); break; case GenOption.maxCells: dInfo = InputMaxCellsAndGenCount(); break; default: dInfo = GenDCountAndSizes(); break; } if (cellOption == CellOption.predefined) { interiorScale = DefaultInteriorScale; boundScale = DefaultBoundScale; openingScale = DefaultOpeningScale; goto Initialize; } //Get interior scale while (interiorScale < 2) { try { Console.Write(" Cell Interior Scale: "); interiorScale = Convert.ToInt32(Console.ReadLine()); if (interiorScale < 2) { Console.WriteLine("Please input an integer greater than 1."); } } catch (FormatException e) { Console.WriteLine("Please input an integer greater than 1."); } } //Get bound scale while (boundScale <= 0) { try { Console.Write(" Cell Bound Scale: "); boundScale = Convert.ToInt32(Console.ReadLine()); if (boundScale <= 0) { Console.WriteLine("Please input a positive numerical value."); } } catch (FormatException e) { Console.WriteLine("Please input a positive numerical value."); } } //Get opening scale while (openingScale <= 0) { try { Console.Write(" Cell Opening Scale "); openingScale = Convert.ToInt32(Console.ReadLine()); if (openingScale <= 0) { Console.WriteLine("Please input a positive numerical value."); } } catch (FormatException e) { Console.WriteLine("Please input a positive numerical value."); } } Initialize: //Initialize maze, or world, or both, depending World.Initialize(dInfo, interiorScale, boundScale, openingScale); //Clear and Wait to start Console.Clear(); Console.WriteLine("Press [enter] to begin.\n"); while (ConsoleKey.Enter != Console.ReadKey().Key) { //Spinning while input not [enter] } }
/// <summary> /// Gets generation option from user /// </summary> /// <returns>Generation option</returns> public static GenOption GetGenOption() { GenOption _selected = GenOption.predefined; Console.Clear(); Console.ResetColor(); /*Console.SetCursorPosition(0, 0); * Console.Write("Choose generation method:"); * Console.SetCursorPosition(0, OptionLinesDisplayed + 2); * Console.Write("Use arrow keys to select option. [Enter] to confirm selection.");*/ while (true) { Console.Clear(); Console.SetCursorPosition(0, 0); Console.Write("Choose generation method:"); Console.SetCursorPosition(0, OptionLinesDisplayed + 2); Console.Write("Use arrow keys to select option. [Enter] to confirm selection."); //Write Options int _start = (GenOptionCount - 1) - (int)_selected < OptionLinesDisplayed ? ((GenOptionCount - 1) - OptionLinesDisplayed < 0 ? 0 : (GenOptionCount - 1) - OptionLinesDisplayed) : (int)_selected; int _end = (GenOptionCount - 1) - (int)_selected > OptionLinesDisplayed ? (int)_selected + OptionLinesDisplayed : (GenOptionCount - 1); int _lineCount = 0; for (int _i = (int)_selected; _i < ((int)_selected + OptionLinesDisplayed < GenOptionCount ? (int)_selected + OptionLinesDisplayed : GenOptionCount); _i++) { if (_i == (int)_selected) { Console.ForegroundColor = HighlightFG; Console.BackgroundColor = HighlightBG; } else { Console.ResetColor(); } Console.SetCursorPosition(0, 1 + _i - (int)_selected); Console.Write(" {0}", GenOptionString[_i]); _lineCount++; Console.ResetColor(); if (_lineCount >= OptionLinesDisplayed) { goto Input; } /*for (int _j = 0; _j <= GenOptionString[_i].Length / (Console.BufferWidth - 6); _j++) * { * Console.SetCursorPosition(0, 1 + _i + _j - (int)_selected); * Console.Write(" {0}", GenOptionString[_i].Substring(_j * (Console.BufferWidth - 6), (Console.BufferWidth - 6))); * _lineCount++; * if (_lineCount >= OptionLinesDisplayed) * goto Input; * }*/ } Input: //Get input switch (Console.ReadKey().Key) { case ConsoleKey.Enter: goto Done; case ConsoleKey.UpArrow: if ((int)_selected != 0) { _selected = (GenOption)((int)_selected - 1); } break; case ConsoleKey.DownArrow: if ((int)_selected != GenOptionCount - 1) { _selected = (GenOption)((int)_selected + 1); } break; } } Done: Console.Clear(); Console.ResetColor(); return(_selected); }