-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.c
More file actions
143 lines (121 loc) Β· 2.52 KB
/
modules.c
File metadata and controls
143 lines (121 loc) Β· 2.52 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
ο»Ώ#include "modules.h"
// _getch() value of arrow key (chohadam 21-03-11)
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
// move the cursor funtion (chohadam 21-03-11)
void gotoxy(int x, int y) {
COORD pos = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
// find out the pressed key function (chohadam 21-03-11)
int get_key(void) {
// if keyboard pressed
if (_kbhit()) {
// return pressed value
return _getch();
}
return 1;
}
// move to the arrow key function (chohadam 21-03-11)
void move_arrow_key(
char key,
int* x,
int* y,
int size,
int y_min,
int y_max,
int x_min,
int x_max
) {
const int Y_MIN = y_min;
const int Y_MAX = y_max;
const int X_MIN = x_min;
const int X_MAX = x_max;
switch (key) {
case UP:
*y -= size;
if (*y < Y_MIN) *y = Y_MAX;
break;
case DOWN:
*y += size;
if (*y > Y_MAX) *y = Y_MIN;
break;
case LEFT:
*x -= size;
if (*x < X_MIN) *x = X_MAX;
break;
case RIGHT:
*x += size;
if (*x > X_MAX) *x = X_MIN;
break;
}
}
void print_auto_y(int* x, int* y, char* str) {
gotoxy(*x, *y);
printf(str);
*y += 1;
}
void setColor(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void print_by_name(char* name) {
// set color : GREY
setColor(darkgray);
if (strlen(name) > 8) {
gotoxy(88, 28);
}
else {
gotoxy(105, 28);
}
printf("by %s", name);
setColor(white);
}
void print_by_text(char* text, char* color, int x, int y) {
// set color : RED
setColor(color);
gotoxy(x, y);
printf("TEAM [ %s ] WIN", text);
setColor(white);
}
void print_main_text(char* text, char* color, int x, int y) {
setColor(color);
gotoxy(x, y);
printf("%s", text);
setColor(white);
}
void rectangle(int width, int height, int x, int y) {
for (int i = 1; i < width / 2; i++) {
gotoxy((x + width) / 2 - i, y);
printf("β");
gotoxy((x + width) / 2 + i, y);
printf("β");
Sleep(1);
}
gotoxy(x, y);
printf("β");
gotoxy(x + width, y);
printf("β");
for (int i = 1; i < height; i++) {
gotoxy(x, y + i);
printf("β");
for (int j = 1; j < width - 1; j++) {
printf(" ");
}
printf(" ");
printf("β");
Sleep(1);
}
gotoxy(x, y + height);
printf("β");
gotoxy(x + width, y + height);
printf("β");
for (int i = 1; i < width / 2; i++) {
gotoxy(x + i, y + height);
printf("β");
gotoxy((x + width) - i, y + height);
printf("β");
Sleep(1);
}
}