-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
140 lines (131 loc) · 4.52 KB
/
Program.cs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
public class Program
{
const int length = 5;
const int width = 5;
public static string[,] options = new string[length, width] { { "a ", "b ", "c ", "d ", "e " }, { "f ", "g ", "h ", "i ", "j " }, { "k ", "l ", "m ", "n ", "o " }, { "p ", "q ", "r ", "s ", "t " }, { "u ", "v ", "w ", "x ", "y " } };
static void Main(string[] args)
{
// Create options that you want your menu to have
//options = new Option[][]
// Set the default index of the selected item to be the first
int indexX = 2;
int indexY = 2;
// Write the menu out
WriteMenu(options, options[indexX, indexY]);
List<string> list = new List<string>();
// Store key info in here
ConsoleKeyInfo keyinfo;
do
{
keyinfo = Console.ReadKey();
// Handle each key input (down arrow will write the menu again with a different selected item)
switch (keyinfo.Key)
{
case ConsoleKey.DownArrow:
if (indexX + 1 < width)
{
indexX++;
WriteMenu(options, options[indexX, indexY]);
}
break;
case ConsoleKey.UpArrow:
if (indexX - 1 >= 0)
{
indexX--;
WriteMenu(options, options[indexX, indexY]);
}
break;
case ConsoleKey.RightArrow:
if (indexY + 1 < length)
{
indexY++;
WriteMenu(options, options[indexX, indexY]);
}
break;
case ConsoleKey.LeftArrow:
if (indexY - 1 >= 0)
{
indexY--;
WriteMenu(options, options[indexX, indexY]);
}
break;
case ConsoleKey.S:
//Console.WriteLine("You selected " + options[indexX, indexY]);
// indexX = 2;
// indexY = 2;
list.Add(options[indexX, indexY]);
break;
case ConsoleKey.Enter:
Console.WriteLine($"You selected {string.Join(" ", list)}");
// indexX = 2;
// indexY = 2;
//list.Add(options[indexX, indexY]);
break;
}
}
while (keyinfo.Key != ConsoleKey.X);
Console.ReadKey();
}
// Default action of all the options. You can create more methods
static void WriteTemporaryMessage(string message)
{
Console.Clear();
Console.WriteLine(message);
Thread.Sleep(3000);
WriteMenu(options, options[0, 0]);
}
///<summary>
///Writes the menu to the console
///</summary>
///<remarks>
///<param name="options">The options to write</param>
///<param name="selected">The selected option</param>
///<example>
///This shows how to call the <see cref="WriteMenu"/> method from your code.
/// <code>
/// string[,] options = new string[2, 2] { { "a ", "b " }, { "c ", "d " } };
/// WriteMenu(options, options[0, 0]);
///</code>
///</example>
///</remarks>
static void WriteMenu(string[,] options, string selected)
{
Console.Clear();
for (int i = 0; i < options.GetLength(0); i++)
{
for (int j = 0; j < options.GetLength(1); j++)
{
if (options[i, j] == selected)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Write(options[i, j]);
Console.ResetColor();
}
else
{
Console.Write(options[i, j]);
}
}
Console.WriteLine();
}
Console.Write("> ");
}
/// <summary>
/// This method changes the point's location by the given x- and y-offsets.
/// </summary>
/// <remarks>
/// <example>
/// For example:
/// <code>
/// Point p = new Point(3,5);
/// p.Translate(-1,3);
/// </code>
/// results in <c>p</c>'s having the value (2,8).
/// </example>
/// </remarks>
public void Credit(int amount)
{
int Balance = amount;
}
}