-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab.h
150 lines (132 loc) · 4.09 KB
/
lab.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
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
144
145
146
147
148
149
150
#ifndef _LABH_ //protectes from multiple including...
#define _LABH_ //... needs an #endif at bottom
#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
#include <locale.h>
#define false 0
#define true 1
#define MY_COLOR_BLACK 0
#define MY_COLOR_DARK_BLUE 1
#define MY_COLOR_SOFT_GREEN 2
#define MY_COLOR_SOFT_BLUE 3
#define MY_COLOR_DARK_RED 4
#define MY_COLOR_PURPLE 5
#define MY_COLOR_DARK_YELLOW 6
#define MY_COLOR_GRAY 7
#define MY_COLOR_DARK_GRAY 8
#define MY_COLOR_CYAN 9
#define MY_COLOR_LIGTH_GREEN 10
#define MY_COLOR_LIGTH_BLUE 11
#define MY_COLOR_LIGTH_RED 12
#define MY_COLOR_PINK 13
#define MY_COLOR_LIGTH_YELLOW 14
#define MY_COLOR_WHITE 15
#define AZUL 1
#define VERDE 2
#define VERMELHO 4
#define AMARELO 6
#define BRANCO 15
//changes both foreground and background colors
void setColor(int foreGround, int backGround) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), backGround*16 + foreGround);
}
//changes foreground color while keeping background color
void setForeColor(int foreGround) {
int backGround = MY_COLOR_BLACK;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
backGround = csbiInfo.wAttributes / 16;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), backGround * 16 + foreGround);
}
//changes background color while keeping foreground color
void setBackColor(int backGround) {
int foreGround = MY_COLOR_BLACK;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
foreGround = csbiInfo.wAttributes % 16;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), backGround*16 + foreGround);
}
//Colors reset: foreground white, background black
void resetColor() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), MY_COLOR_BLACK * 16 + MY_COLOR_WHITE);
}
//allows to place the cursor at any given position
void gotoxy(int x, int y) {
COORD c = { (SHORT)x, (SHORT)y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
//allows to draw a rectangle (double lines) at any given position
void showRectAt(int x, int y, int width, int height){
setlocale(LC_ALL, "C");
int i;
gotoxy(x, y);
printf("%c", 201);
for (i = 1; i < width; i++) {
printf("%c", 205);
}
printf("%c", 187);
gotoxy(x, height + y);
printf("%c", 200);
for (i = 1; i < width; i++) {
printf("%c", 205);
}
printf("%c", 188);
for (i = y + 1; i < height + y; i++){
gotoxy(x, i);
printf("%c", 186);
gotoxy(x + width, i);
printf("%c", 186);
}
setlocale(LC_ALL, "");
}
//allows to draw a rectangle (double lines) at any given position, rotated by 90º
void show90RectAt(int x, int y, int width, int height){
showRectAt(x,y,height*2,width/2);
}
//show a char at a designated position
void showCharAt(int x, int y, char c) {
setlocale(LC_ALL, "C");
gotoxy(x, y);
printf("%c", c);
setlocale(LC_ALL, "");
}
//write a 'string' verticaly at a designated position
void showVerticalWordAt(int x, int y, char c[], int charNumber) {
setlocale(LC_ALL, "C");
int i = 0;
for(i = 0; i < charNumber; i++){
gotoxy(x, y+i);
printf("%c", c[i]);
}
setlocale(LC_ALL, "");
}
//write an horizontal 'string' at a designated position
void printfAt(int x, int y, char c[]) {
setlocale(LC_ALL, "C");
gotoxy(x, y);
printf("%s", c);
setlocale(LC_ALL, "");
}
//visual of cards numbers
char numeros[][6]= {" ### "," # ","#####","#####","# #","#####",
"# #"," # "," #"," #","# #","# ",
" # "," # ","#####","#####","#####","#####",
" # "," # ","# "," #"," #"," #",
" # "," # ","#####","#####"," #","#####"};
//draws a number card
void drawNumberAt(int x,int y,int num)
{
int i;
for(i=0;i<5;i++)
printfAt(x,y+i,numeros[i*6+num]);
}
//draws a complete card
void drawCardAt(int x,int y,int num,int cor)
{
showRectAt(x,y,8,6);
setColor(cor,MY_COLOR_BLACK);
drawNumberAt(x+2,y+1,num);
resetColor();
}
#endif