-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathProgram.cs
98 lines (85 loc) · 2.72 KB
/
Program.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
using System;
using System.Threading;
namespace Tetris
{
class Program
{
// Settings
static int TetrisRows = 20;
static int TetrisCols = 10;
static int InfoCols = 10;
static int ConsoleRows = 1 + TetrisRows + 1;
static int ConsoleCols = 1 + TetrisCols + 1 + InfoCols + 1;
// State
static int Score = 0;
static void Main(string[] args)
{
Console.Title = "Tetris v1.0";
Console.CursorVisible = false;
Console.WindowHeight = ConsoleRows + 1;
Console.WindowWidth = ConsoleCols;
Console.BufferHeight = ConsoleRows + 1;
Console.BufferWidth = ConsoleCols;
while (true)
{
Score++;
if (Console.KeyAvailable)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Escape)
{
// Environment.Exit(0);
return; // Becase of Main()
}
}
// user input
// change state
// Redraw UI
DrawBorder();
DrawInfo();
Thread.Sleep(40);
}
}
static void DrawBorder()
{
Console.SetCursorPosition(0, 0);
string line = "╔";
line += new string('═', TetrisCols);
/* for (int i = 0; i < TetrisCols; i++)
{
line += "═";
} */
line += "╦";
line += new string('═', InfoCols);
line += "╗";
Console.Write(line);
for (int i = 0; i < TetrisRows; i++)
{
string middleLine = "║";
middleLine += new string(' ', TetrisCols);
middleLine += "║";
middleLine += new string(' ', InfoCols);
middleLine += "║";
Console.Write(middleLine);
}
string endLine = "╚";
endLine += new string('═', TetrisCols);
endLine += "╩";
endLine += new string('═', InfoCols);
endLine += "╝";
Console.Write(endLine);
}
static void DrawInfo()
{
Write("Score:", 1, 3 + TetrisCols);
Write(Score.ToString(), 2, 3 + TetrisCols);
}
static void Write(string text, int row, int col, ConsoleColor color = ConsoleColor.Yellow)
{
Console.ForegroundColor = color;
Console.SetCursorPosition(col, row);
Console.Write(text);
Console.ResetColor();
}
}
}