-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (67 loc) · 2.26 KB
/
Copy pathProgram.cs
File metadata and controls
76 lines (67 loc) · 2.26 KB
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
using System;
using System.Text;
using System.Timers;
using System.Threading;
namespace Tetris_Game
{
internal class Program
{
private static System.Timers.Timer aTimer;
private static Board board;
private static Display displayBoard;
private static void Main(string[] args)
{
Console.SetWindowSize(50, 50);
Console.SetBufferSize(80, 80);
board = new Board();
board.PlaceBlock();
displayBoard = new Display();
displayBoard.PrintBoad(board);
SetTimer();
while (true)
{
displayBoard.PrintBoad(board);
Thread.Sleep(200); //allow main thread delay for 0.2 second
while (Console.KeyAvailable)
{
switch (Console.ReadKey(true).Key)
{
case ConsoleKey.LeftArrow:
board.keyPress(Board.Key.Left);
break;
case ConsoleKey.RightArrow:
board.keyPress(Board.Key.Right);
break;
case ConsoleKey.DownArrow:
board.keyPress(Board.Key.Down);
break;
case ConsoleKey.A:
board.keyPress(Board.Key.rLeft);
break;
case ConsoleKey.D:
board.keyPress(Board.Key.rRight);
break;
default:
break;
}
}
}
aTimer.Stop();
aTimer.Dispose();
}
private static void SetTimer()
{
// Create a timer with a one second interval.
aTimer = new System.Timers.Timer(500);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += Tick;
aTimer.AutoReset = true;
aTimer.Enabled = true;
}
private static void Tick(Object source, ElapsedEventArgs e)
{
board.DropBlock();
//displayBoard.PrintBoad(board);
}
}
}