-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cs
68 lines (62 loc) · 2 KB
/
Menu.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csharp_roguelike
{
class Menu
{
public static void Run()
{
var IsRunning = false;
var MenuPointerPosition = 0;
var MenuOptions = new string[] { "Start game", "Options", "Quit game" };
do
{
Console.Clear();
Console.WriteLine("Welcome to Rogue-like game");
for (int i = 0; i < MenuOptions.Length; i++)
{
Console.WriteLine();
if (MenuPointerPosition == i)
{
Console.Write("> ");
}
else
{
Console.Write(" ");
}
Console.Write(MenuOptions[i]);
}
var button = Console.ReadKey();
switch (button.Key)
{
case System.ConsoleKey.Enter:
Show(MenuOptions[MenuPointerPosition]);
IsRunning = true;
break;
case System.ConsoleKey.UpArrow:
MenuPointerPosition--;
if (MenuPointerPosition < 0)
{
MenuPointerPosition = MenuOptions.Length - 1;
}
break;
case System.ConsoleKey.DownArrow:
MenuPointerPosition++;
if (MenuPointerPosition > MenuOptions.Length - 1)
{
MenuPointerPosition = 0;
}
break;
}
} while (!IsRunning);
}
static void Show(string title)
{
Console.Clear();
Console.WriteLine(title);
}
}
}