-
Notifications
You must be signed in to change notification settings - Fork 1
/
function_utils.cpp
225 lines (180 loc) · 5.04 KB
/
function_utils.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include <vector>
#include <ctype.h>
#include <stdio.h>
#ifdef _WIN32
// Inclua as bibliotecas específicas do Windows aqui
#include <conio.h>
#elif __linux__
// Inclua as bibliotecas específicas do Linux aqui
#include <termios.h>
#endif
#ifndef FUNCTION_UTILS_H
#define FUNCTION_UTILS_H
using namespace std;
void limparTela(){
//Limpa tela do terminal
#ifdef _WIN32
system("CLS");
#elif defined __unix__
system("clear");
#endif
}
void pressione(string texto) {
//Verifica qual o sistema e captura
cout << "Pressione enter para " << texto << " ...";
#ifdef _WIN32
getch();
#elif defined __unix__
getchar();
#endif
limparTela();
}
void load(){
//A função imprime na tela loading de 0% até 100%
int totalTicks = 20;
int numero = 2;
for (int i = 0; i < totalTicks; ++i){
cout << "\r[";
for (int j = 0; j <= i; ++j)
cout << "=";
for (int j = i + 1; j < totalTicks; ++j)
cout << " ";
cout << "] " << (i + 1) * 5 << "%";
cout.flush();
sleep(numero);
if (numero == 2) {
numero = 0.5;
}
}
cout << endl;
limparTela();
}
string corLetra(string cor) {
// Recebe um argumento de cor
// Disponiveis
//cores letras
string vermelho = "\033[1;31m";
string verde = "\033[1;32m";
string azul = "\033[1;34m";
string branco = "\033[1;37m";
string magenta = "\033[1;35m";
string ciano = "\033[1;36m";
if (cor == "vermelho"){
return vermelho;
}else if (cor == "verde"){
return verde;
}else if (cor == "azul"){
return azul;
}else if (cor == "branco"){
return branco;
}else if (cor == "magenta"){
return magenta;
}else if (cor == "ciano"){
return ciano;
}else{"";}
return "";
}
string corFundo(string cor) {
// Recebe um argumento de cor
//cores fundo
string vermelho = "\033[1;41m";
string verde = "\033[1;42m";
string azul = "\033[1;44m";
string branco = "\033[1;47m";
string magenta = "\033[1;45m";
string ciano = "\033[1;46m";
if (cor == "vermelho"){
return vermelho;
}else if (cor == "verde"){
return verde;
}else if (cor == "azul"){
return azul;
}else if (cor == "branco"){
return branco;
}else if (cor == "magenta"){
return magenta;
}else if (cor == "ciano"){
return ciano;
}else{"";}
return "";
}
string resetCor(){
//Reseta a cor
string reset = "\033[0m";
return reset;
}
string calcularEspaco(int tamanho) {
string espaco = " ";
string resultado;
int multiplicador = 21 - tamanho;
for (int i = 0; i < multiplicador; i++) {
resultado += espaco;
}
return resultado;
}
int tempo(){
//A função imprime na tela o tempo
int segundos = 4;
int segundosFinais = segundos / 2;
int resposta;
for (int cont = segundos; cont > -1; cont--){
sleep(1);
if (cont > segundosFinais) {
cout << corLetra("branco") << "00:" << cont << " >>";
cout.flush();
cout << "\033[2K"; // Limpa a linha atual
cout << "\033[0G"; // Retorna para a coluna inicial
} else {
cout << corLetra("vermelho") << "00:" << cont << " >>";
cout.flush();
cout << "\033[2K"; // Limpa a linha atual
cout << "\033[0G"; // Retorna para a coluna inicial
}
}
cout << resetCor();
cout << ">>> ";
cin >> resposta;
return resposta;
}
void cabecalho(string texto){
size_t tamanhoString = texto.size();
cout << corLetra("azul") << corFundo("branco") << " " << endl;
cout << corLetra("azul") << corFundo("branco") << calcularEspaco(tamanhoString);
cout << texto << " QuizVerse " << resetCor() << endl;
cout << corLetra("azul") << corFundo("branco") << " "<< resetCor() << endl;
}
//Tela Inicial
void telaInicial(){
cout << "" << endl;
cout << "" << endl;
cout << "" << endl;
cabecalho("Bem-Vindo ao");
cout << "" << endl;
cout << "" << endl;
cout << "" << endl;
cout << "" << endl;
cout << "" << endl;
pressione("continuar");
}
//Tela de Saida
void telaSaida(){
limparTela();
cin.ignore();
cout << "" << endl;
cout << "" << endl;
cabecalho("Um adeus do");
cout << "" << endl;
cout << "" << endl;
cout << "Projeto Realizado por: " << endl;
cout << "" << endl;
cout << "Hugo Magalhaes |Github/ HugMagalhaes" << endl;
cout << "Jose Junior |Github/ joseevilasio" << endl;
cout << "Patricia Correia |Github/ tijgadixa"<< endl;
cout << "" << endl;
pressione("sair");
}
#endif