-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectionEnum.cs
37 lines (36 loc) · 1.02 KB
/
DirectionEnum.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
public enum EntityAction
{
None,
Left,
Up,
Right,
Down,
Quit
}
public static class EntityActionExtensions
{
public static EntityAction FromConsoleKey(ConsoleKeyInfo key)
{
return key.Key switch
{
ConsoleKey.LeftArrow => EntityAction.Left,
ConsoleKey.RightArrow => EntityAction.Right,
ConsoleKey.UpArrow => EntityAction.Up,
ConsoleKey.DownArrow => EntityAction.Down,
ConsoleKey.Escape => EntityAction.Quit,
_ => key.KeyChar switch {
'a' => EntityAction.Left,
'A' => EntityAction.Left,
'w' => EntityAction.Up,
'W' => EntityAction.Up,
'd' => EntityAction.Right,
'D' => EntityAction.Right,
's' => EntityAction.Down,
'S' => EntityAction.Down,
'q' => EntityAction.Quit,
'Q' => EntityAction.Quit,
_ => EntityAction.None
}
};
}
}