-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cs
More file actions
62 lines (54 loc) · 1.84 KB
/
Menu.cs
File metadata and controls
62 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
namespace CYOA
{
public class Menu : IMenu
{
private string _prompt;
private List<MenuChoice> _choices;
public Menu(string prompt, List<MenuChoice> choices)
{
_prompt = prompt;
_choices = choices;
}
public string Display()
{
Settings.Color(FontColor.DEFAULT);
Console.WriteLine(_prompt);
bool isChoiceConfirmed = false;
int currentChoiceIndex = 0;
while (!isChoiceConfirmed)
{
for (var i = 0; i < _choices.Count; i++)
{
if (currentChoiceIndex == i)
{
Settings.Color(FontColor.SELECTION);
Console.Write("> ");
}
else
{
Console.Write(" ");
}
Console.WriteLine(_choices[i].Text);
Settings.Color(FontColor.MENU);
}
switch (Console.ReadKey(true).Key)
{
case ConsoleKey.UpArrow:
currentChoiceIndex -= 1;
if (currentChoiceIndex < 0) currentChoiceIndex += _choices.Count;
break;
case ConsoleKey.DownArrow:
currentChoiceIndex = (currentChoiceIndex + 1) % _choices.Count;
break;
case ConsoleKey.Enter:
isChoiceConfirmed = true;
break;
}
if (!isChoiceConfirmed) Console.CursorTop -= _choices.Count;
}
return "./" + _choices[currentChoiceIndex].Link;
}
}
}