-
Notifications
You must be signed in to change notification settings - Fork 0
/
consoleFunction.c
76 lines (63 loc) · 1.16 KB
/
consoleFunction.c
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
#include "common.h"
void setTitle()
{
SetConsoleTitle(TEXT(programName));
}
void clearScreen()
{
system("cls");
}
void setConsoleSize(int cols, int lines)
{
char command[100];
sprintf(command, "MODE CON COLS=%d LINES=%d", cols, lines);
system(command);
}
void hideCursor()
{
CONSOLE_CURSOR_INFO ConCurInf;
ConCurInf.dwSize = 10;
ConCurInf.bVisible = FALSE;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ConCurInf);
}
void setConsolePreference()
{
setTitle();
setConsoleSize(consoleCols, consoleLines);
hideCursor();
}
void setCursorPosition(int x, int y)
{
COORD Pos = { x - 1, y - 1 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void setTextColor(int Color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), Color);
}
int getKeyInput()
{
int input;
while ((input = getch()) != 27)
{
if (input == 224)
{
input = getch();
if (input == 72)
return KEY_UP;
else if (input == 75)
return KEY_LEFT;
else if (input == 77)
return KEY_RIGHT;
else if (input == 80)
return KEY_DOWN;
}
else if (input == 13)
return KEY_RETURN;
}
return 0;
}
void playShortBeep()
{
Beep(523, 500);
}