-
Notifications
You must be signed in to change notification settings - Fork 0
/
TetrisHelper.h
42 lines (36 loc) · 1.01 KB
/
TetrisHelper.h
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
#ifndef __TETRIS_HELPER_H__
#define __TETRIS_HELPER_H__
#include <Windows.h>
#include <cstdio>
KEY_EVENT_RECORD krec;
void putStringOnPosition(int x, int y, const char* content) {
// Move Cursor
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
// Print string
printf("%s", content);
}
void showConsoleCursor(bool showFlag) {
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = showFlag; // set the cursor visibility
SetConsoleCursorInfo(out, &cursorInfo);
}
void drawPosition(int x, int y, bool filled) {
putStringOnPosition(x * 2, y, filled ? "¡á" : "¡à");
}
bool keyState(char c) {
short ret;
switch (c) {
case 'a': ret = GetKeyState(0x41); break;
case 'd': ret = GetKeyState(0x44); break;
case 's': ret = GetKeyState(0x53); break;
case 'w': ret = GetKeyState(0x57); break;
default: return false;
}
return ret != 0 && ret != 1;
}
#endif // !__TETRIS_HELPER_H__