-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsoleInputHandler.cs
51 lines (48 loc) · 1.4 KB
/
ConsoleInputHandler.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyPersonalTetris
{
public class ConsoleInputHandler : IInputHandler
{
public TetrisGameInput GetInput()
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key == ConsoleKey.Escape)
{
return TetrisGameInput.Exit;
}
if (key.Key == ConsoleKey.LeftArrow || key.Key == ConsoleKey.A)
{
return TetrisGameInput.Left;
}
if (key.Key == ConsoleKey.RightArrow || key.Key == ConsoleKey.D)
{
return TetrisGameInput.Right;
}
if (key.Key == ConsoleKey.DownArrow || key.Key == ConsoleKey.S)
{
return TetrisGameInput.Down;
}
if (key.Key == ConsoleKey.Spacebar || key.Key == ConsoleKey.UpArrow || key.Key == ConsoleKey.W)
{
return TetrisGameInput.Rotate;
}
}
return TetrisGameInput.None;
}
}
public enum TetrisGameInput
{
None = 0,
Left = 1,
Right = 2,
Down = 3,
Rotate = 4,
Exit = 9,
}
}