-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cs
113 lines (107 loc) · 4.14 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
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
using System;
using System.Collections.Generic;
namespace ttc_wtc
{
class Menu
{
public static Menu StartMenu = new Menu(new string[] { "Сюжетная игра", "Бесконечный режим", "Загрузить", "Выйти" });
public static Menu PauseMenu = new Menu(new string[] { "Продолжить игру", "Сохранить", "Загрузить", "Выйти в главное меню" });
public static Menu TarotMenu = new Menu(new string[] { "The Fool", "Silver Chariot", "The World" });
public static Menu NPCMenu = new Menu(new string[] { "Поговорить", "Обокрасть", "Ударить", "Выйти" });
public static Menu BattleMenu = new Menu(new string[] { "АТАКОВАТЬ", "ИСПОЛЬЗОВАТЬ СПОСОБНОСТЬ", "ОТКРЫТЬ ИНВЕНТАРЬ" });
public string[] MenuItems { get; set; }
public int Cursor { get; set; }
public Menu(string[] menuItems)
{
MenuItems = menuItems;
}
public Menu(List<string> menuItems)
{
MenuItems = menuItems.ToArray();
}
public void ClearMenu(int x, int y, int length)
{
Console.SetCursorPosition(x, y);
for (int i = 0; i < length; i++)
{
for (int z = 0; z < 222; z++)
{
Console.Write(" ");
}
Console.SetCursorPosition(x, y + 1 + i);
}
}
public int GetChoice(bool centre = true, bool clearConsole = true)
{
Cursor = 0;
if (clearConsole) Console.Clear();
ConsoleKeyInfo key;
bool exit = false;
do
{
for (int i = 0; i < MenuItems.Length; i++)
{
Console.SetCursorPosition(centre ? (45 - ((MenuItems[i].Length + 1) / 2)) : 4, centre ? (16 - ((MenuItems.Length - 1) / 2) + i) : (2 + i));
if (Cursor == i)
{
Console.ForegroundColor = ConsoleColor.Magenta;
}
Console.WriteLine(MenuItems[i]);
Console.ResetColor();
}
key = Console.ReadKey(true);
if (key.Key == ConsoleKey.Enter) exit = true;
else
{
if (key.Key == ConsoleKey.UpArrow)
{
Cursor--;
if (Cursor == -1) Cursor = MenuItems.Length - 1;
}
else if (key.Key == ConsoleKey.DownArrow)
{
Cursor++;
if (Cursor == MenuItems.Length) Cursor = 0;
}
}
} while (!exit);
return Cursor;
}
public int GetChoice(bool centre, bool clearConsole, int x, int y)
{
Cursor = 0;
if (clearConsole) Console.Clear();
ConsoleKeyInfo key;
bool exit = false;
do
{
for (int i = 0; i < MenuItems.Length; i++)
{
Console.SetCursorPosition(x, y + i);
if (Cursor == i)
{
Console.ForegroundColor = ConsoleColor.Magenta;
}
Console.WriteLine(MenuItems[i]);
Console.ResetColor();
}
key = Console.ReadKey(true);
if (key.Key == ConsoleKey.Enter) exit = true;
else
{
if (key.Key == ConsoleKey.UpArrow)
{
Cursor--;
if (Cursor == -1) Cursor = MenuItems.Length - 1;
}
else if (key.Key == ConsoleKey.DownArrow)
{
Cursor++;
if (Cursor == MenuItems.Length) Cursor = 0;
}
}
} while (!exit);
return Cursor;
}
}
}