-
Notifications
You must be signed in to change notification settings - Fork 1
/
final_v2
562 lines (437 loc) · 10.1 KB
/
final_v2
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//Funcion gotoxy definida por que no existe en windows.h
void gotoxy(int x,int y){
HANDLE hcon;
hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X = x;
dwPos.Y= y;
SetConsoleCursorPosition(hcon,dwPos);
}
//Define de delay
#define DELAY_TIME 5000
#define TEXTO_VERDE SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN|FOREGROUND_INTENSITY);
#define TEXTO_NEGRO SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
#define TEXTO_ROJO SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED|FOREGROUND_INTENSITY);
#define FONDO_BLANCO SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
#define DEFAULT SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
//CONSTANTES
const int MIN_VEL = 2200; //Minima velocidad de refrescamiento de secuencia
const int MED_VEL = 4200; //Maxima velocidad de refrescamiento de secuencia
const int MAX_VEL = 5700; //Maxima velocidad de refrescamiento de secuencia
//Clave
char clave[5];
//Variable de estado de ejecuciones de secuencias
int ejecucion = 1;
//velocidades
int velocidades[] = {MED_VEL, MED_VEL, MED_VEL, MED_VEL, MED_VEL};
//Array de datos para la secuencia de luces de el choque
char datosElchoque[] = { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42};
//Array de datos del billar
char datosBillar[] = {
0x08,
0x09,
0x09,
0x0B,
0x0B,
0x09,
0x09,
0x08,
0x08,
0x09,
0x09,
0x0B,
0x0B,
0x09,
0x08,
0x09,
0x0B,
0x0F,
0x17,
0x23,
0x41,
0x80,
0x00
};
//Array de datos de tenis
char datosTenis[] = {
0x85,
0x86,
0x89,
0x89,
0x91,
0x91,
0xA1,
0x61,
0x91,
0x91,
0x89,
0x89
};
//Array de datos de canicas
char datosCanicas[] = {
0x3C,
0x3A,
0x39,
0x3A,
0x3C,
0x5C,
0x9C,
0x5C
};
//Declaraciones de firmas de funciones
void menu();
int ingreso();
void salida(unsigned char);
void autofantastico(int);
void elchoque(int);
void billar(int);
void tenis(int);
void canicas(int);
void delay(unsigned long int, int);
void medidor(int);
int main(int argc, char *argv[]) {
//Guardamos en clave un dato
strcpy(clave, "38411");
//Imprimimos mensaje
printf("Ingrese la clave: \n");
//Verificacion de ingreso de clave (3 intentos)
if(ingreso()){
menu();
}else{
printf("\n3 intentos mal, se cierra el programa");
}
return 0;
}
//Funcion de control de acceso
int ingreso(){
int error = 0;
char entrada[5];
char caracter;
int c = 0;
int comp;
do{
//Inicializamos al contador c = 0
c = 0;
do{
//guardamos la tecla presionada y verificamos si caracter > 0
if(caracter = getch()){
//Verificamos que la tecla no sea ni ENTER ni BACKSPACE y que el contador sea menor a 5
if(caracter != 13 && caracter != 8 && c < 5){
//Imprimimos un * por cada tecla presionada
printf("*");
//Guardamos en caracter en el char point
entrada[c] = caracter;
//Incrementamos al contador c
c++;
}
//Verificamos si la tecla presionada es BACKSPACE y que contador sea mayor a 0
if(caracter == 8 && c > 0){
//Retrocedemos
printf("%c", 8);
//Sobreescribimos con un espacio
printf(" ");
//Volvemos a retroceder
printf("%c", 8);
//Decrementamos al contador c
c--;
}
if(caracter == 13)
break;
}
}while(1);
//Comparamos la clave con la clave ingresada
comp = strcmp(clave, entrada);
//Verificamos que las claves sean iguales
if(!comp){
return 1;
}else{
//Limpiamos la pantalla
system("CLS");
//Incrementamos el contador error
error++;
//Imprimimos mensaje
printf("Intente nuevamente [ Intentos restantes: %d] : \n" ,3-error );
}
//Verificamos que el usuario coloco mas de 2 veces mal la clave
if(error > 2)
return 0;
}while(comp != 0); //Siempre y cuando la comparacion sea mayor a 0 (clave > entrada) o menor a 0 (clave < entrada)
return 0;
}
//Funcion de menu
void menu (){
//Limpiamos consola
system("CLS");
int seleccion = 1;
int dato;
int estado = 0;
unsigned char ch1, ch2;
do{
FONDO_BLANCO
printf("--------------MENU---------------\n");
DEFAULT
printf("- Auto fantastico\n");
printf("- El choque\n");
printf("- Billar\n");
printf("- Tenis\n");
printf("- Canicas\n");
printf("- Salir\n");
//Desplazamos en puntero
gotoxy(0, seleccion);
//Retornamos carro e imprimimos >>
printf("\r>>");
while(!estado){
if(kbhit()){
ch1 = getch();
if(ch1 == 224 || ch1 == 0){
printf("\r- ");
ch2 = getch();
switch (ch2)
{
case 72: // Arriba
if(seleccion > 1)
seleccion--;
break;
case 80: // Abajo
if(seleccion < 6)
seleccion++;
break;
default:
break;
}
gotoxy(0, seleccion);
printf("\r>>");
}else if(ch1 == 13)
estado = 1;
}
}
estado = 0;
ejecucion = 1;
//Switch de seleccion de opcion
switch(seleccion){
case 1:
//Llamamos a la funcion auto fantastico
autofantastico(seleccion-1);
break;
case 2:
//Llamamos a la funcion el choque
elchoque(seleccion-1);
break;
case 3:
//Llamamos a la funcion billar
billar(seleccion-1);
break;
case 4:
//Llamamos a la funcion tenis
tenis(seleccion-1);
break;
case 5:
//Llamamos a la funcion canicas
canicas(seleccion-1);
break;
case 6:
//Salimos
return;
break;
default:
system("CLS");
seleccion = 1;
printf("No seleccionaste ninguna opcion\n");
break;
}
}while(1);
return;
}
//Funcion de salida de las luces
void salida(unsigned char c){
gotoxy(0,2);
//For decremental
for(int i = 7; i >= 0; i--){
//Verificamos el resultado del corrimiento de c & 1
if((c >> i) & 1){
//Imprimimos un *
TEXTO_VERDE
printf("*");
DEFAULT
}else{
//Imprimimo un _
TEXTO_NEGRO
printf("_");
DEFAULT
}
}
}
//Funcion del auto fantastico
void autofantastico(int v){
//Limpiamos la consola
system("CLS");
//Imprimimos mensaje
printf("Auto Fantastico presiona enter para volver al menu\n");
//Imprimimos mensaje
printf("Flecha arriba aumenta velocidad, flecha abajo disminuye velocidad\n");
int estado = 0;
int i = 128;
do{
medidor(v);
salida(i);
delay(velocidades[v], v);
if(!estado)
i = i >> 1;
else
i = i << 1;
if(i == 128)
estado = 0;
if(i == 1)
estado = 1;
}while(ejecucion);
//Limpiamos la consola
system("CLS");
return;
}
//Funcion de el choque
void elchoque(int v){
//Limpiamos la consola
system("CLS");
//Imprimimos mensaje
printf("El choque presiona enter para volver al menu\n");
//Imprimimos mensaje
printf("Flecha arriba aumenta velocidad, flecha abajo disminuye velocidad\n");
int i = 0;
do{
medidor(v);
salida(datosElchoque[i]);
delay(velocidades[v], v);
if(i == sizeof(datosElchoque)-1)
i = 0;
else
i++;
}while(ejecucion);
//Limpiamos la consola
system("CLS");
return;
}
//Funcion billar
void billar(int v){
//Limpiamos la consola
system("CLS");
//Imprimimos mensaje
printf("Billar presiona enter para volver al menu\n");
//Imprimimos mensaje
printf("Flecha arriba aumenta velocidad, flecha abajo disminuye velocidad\n");
int i = 0;
do{
medidor(v);
salida(datosBillar[i]);
delay(velocidades[v], v);
if(i == sizeof(datosBillar)-1)
i = 0;
else
i++;
}while(ejecucion);
//Limpiamos la consola
system("CLS");
return;
}
//Funcion Tenis
void tenis(int v){
//Limpiamos la consola
system("CLS");
//Imprimimos mensaje
printf("Tenis presiona enter para volver al menu\n");
//Imprimimos mensaje
printf("Flecha arriba aumenta velocidad, flecha abajo disminuye velocidad\n");
int i = 0;
do{
medidor(v);
salida(datosTenis[i]);
delay(velocidades[v], v);
if(i == sizeof(datosTenis)-1)
i = 0;
else
i++;
}while(ejecucion);
//Limpiamos la consola
system("CLS");
return;
}
//Funcion Canicas
void canicas(int v){
//Limpiamos la consola
system("CLS");
//Imprimimos mensaje
printf("Canicas presiona enter para volver al menu\n");
//Imprimimos mensaje
printf("Flecha arriba aumenta velocidad, flecha abajo disminuye velocidad\n");
int i = 0;
do{
medidor(v);
salida(datosCanicas[i]);
delay(velocidades[v], v);
if(i == sizeof(datosCanicas)-1)
i = 0;
else
i++;
}while(ejecucion);
//Limpiamos la consola
system("CLS");
return;
}
//Funcion delay (retardo)
void delay(unsigned long int a, int v){
unsigned char ch1;
unsigned char ch2;
while(a){
a--;
if (kbhit())
{
ch1 = getch();
if(ch1 == 224 || ch1 == 0)
ch2 = getch();
if(ch1 == 13){ // Enter
a = 0;
ejecucion = 0;
return;
}
switch (ch2)
{
case 72: // Arriba
if(velocidades[v] > MIN_VEL)
velocidades[v] -= 100;
if(a > MIN_VEL)
a-=100;
break;
case 80: // Abajo
if(velocidades[v] < MAX_VEL)
velocidades[v] += 100;
if(a < MAX_VEL)
a+=100;
break;
default:
break;
}
}
}
}
void medidor(int v){
gotoxy(6,4);
printf("Velocidad de la secuencia");
gotoxy(0,5);
for(int i = MAX_VEL; i >= MIN_VEL; i-=100){
if(i < velocidades[v] || i > velocidades[v]){
TEXTO_VERDE
printf("=");
DEFAULT
}else{
TEXTO_ROJO
printf("#");
DEFAULT
}
}
gotoxy(0,2);
}