-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTetris CMD.cpp
92 lines (74 loc) · 2.16 KB
/
Tetris CMD.cpp
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
#include <iostream>
#include <Windows.h>
using namespace std;
wstring tetromino[7];
int nFieldWidth = 12;
int nFieldHeight = 18;
unsigned char* pField = nullptr;
int nScreenWidth = 80; //Console window screen size (columns)
int nScreenHeight = 30; //Console window screen size (rows)
int Rotate(int px, int py, int r)
{
switch (r % 4)
{
case 0: return py * 4 + px; // 0 degrees
case 1: return 12 + py - (px * 4); // 90 degrees
case 2: return 15 - (py * 4) - px; //180 degrees
case 3:return 3 - py + (px * 4);
}
return 0;
}
int main()
{
//Creating assets
tetromino[0].append(L"..X.");
tetromino[0].append(L"..X.");
tetromino[0].append(L"..X.");
tetromino[0].append(L"..X.");
tetromino[1].append(L"..X.");
tetromino[1].append(L".XX.");
tetromino[1].append(L".X..");
tetromino[1].append(L"....");
tetromino[2].append(L".X..");
tetromino[2].append(L".XX.");
tetromino[2].append(L"..X.");
tetromino[2].append(L"....");
tetromino[3].append(L"....");
tetromino[3].append(L".XX.");
tetromino[3].append(L".XX.");
tetromino[3].append(L"....");
tetromino[4].append(L"..X.");
tetromino[4].append(L".XX.");
tetromino[4].append(L"..X.");
tetromino[4].append(L"....");
tetromino[5].append(L"....");
tetromino[5].append(L".XX.");
tetromino[5].append(L"..X.");
tetromino[5].append(L"..X.");
tetromino[6].append(L"....");
tetromino[6].append(L".XX.");
tetromino[6].append(L".X..");
tetromino[6].append(L".X..");
pField = new unsigned char[nFieldWidth * nFieldHeight];
for (int x = 0; x < nFieldWidth; x++)
{
for (int y = 0; y < nFieldHeight; y++)
{
pField[y * nFieldWidth + x] = (x == 0 || x == nFieldWidth - 1 || y == nFieldHeight - 1) ? 9 : 0;
}
}
wchar_t* screen = new wchar_t[nScreenWidth * nScreenHeight];
for (int i = 0; i < nScreenWidth * nScreenHeight; i++)
{
screen[i] = L'';
HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
SetConsoleActiveScreenBuffer(hConsole);
DWORD dwBytesWritten = 0;
}
bool bGameOver = false;
while (!bGameOver)
{
WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, {0,0}, &dwBytesWritter)
}
return 0;
}