public static int classicSmallDialog( ChoiseContext choise, ConsoleWindowText decideWindow, ConsoleWindowText descriptionWindow) { Console.CursorVisible = false; if (choise.OptionsCount == 1) { return(0); } decideWindow.ClearLogWindow(); decideWindow.AddLog(choise.Question.Length == 0 ? "Make a descision:" : (choise.Question + ":")); int answer = 0, index = 0, lineIndex = 0; foreach (string v in choise.ChoiseOptions) { if (lineIndex == answer) { SwapColors(); } decideWindow.AddLogWithCurrentColor(String.Format(" {1}", ++index, v)); ++lineIndex; } ConsoleKey pressed = ConsoleKey.NoName; do { pressed = Console.ReadKey().Key; List <int> needRedraw = new List <int>(); if (pressed == ConsoleKey.DownArrow) { needRedraw.Add(answer); answer = (answer + 1) % choise.OptionsCount; needRedraw.Add(answer); } if (pressed == ConsoleKey.UpArrow) { needRedraw.Add(answer); answer = (answer == 0 ? choise.OptionsCount : answer) - 1; needRedraw.Add(answer); } if (needRedraw.Count > 0) { choise.HighlightSelected(answer); // if can find a card to preview, then use a funcyion // PreviewCard (below) // else just ask for a casual desciption and write it if (!choise.PreviewSelected(answer, descriptionWindow)) { descriptionWindow.ClearLogWindow(); descriptionWindow.AddLog(choise.DescriptionForOption(answer)); } } foreach (int i in needRedraw) { if (i == answer) { SwapColors(); } Console.SetCursorPosition(decideWindow.X, decideWindow.Y + i + 1); Console.Write(String.Format(" {1}", i + 1, choise.ChoiseOptions[i])); if (i == answer) { SwapColors(); } } } while (pressed != ConsoleKey.Enter); choise.HighlightSelected(-1); decideWindow.ClearLogWindow(); return(answer); }
protected virtual int makeDescision(ChoiseContext choiseContext) { return(rnd.Next(choiseContext.OptionsCount)); }
// with readings //protected override int makeDescision(ChoiseContext choise) //{ // if (choise.OptionsCount == 1) // return 0; // decideWindow.AddLog(choise.Question.Length == 0 ? "Make a descision:" : (choise.Question + ":")); // int index = 0; // foreach (string v in choise.ChoiseOptions) // decideWindow.AddLog(String.Format(" {0} >\t{1}", ++index, v)); // int answer = -1; // Console.WriteLine(); // do { // try { answer = int.Parse(Console.ReadLine()) - 1; } // catch (Exception e) { Console.Write("Try again: "); } // } while (answer < 0); // decideWindow.AddLog(choise.DescriptionForOption(answer)); // Console.ReadLine(); // decideWindow.ClearLogWindow(); // return answer; //} protected override int makeDescision(ChoiseContext choise) { return(PlayerChoiseDialog.classicSmallDialog(choise, decideWindow, descriptionWindow)); }