Created
November 18, 2024 04:39
-
-
Save jorarmarfin/d8be3860f660ba450b09713003a2f511 to your computer and use it in GitHub Desktop.
Contadore regresivo de depredador
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "miniwin.h" | |
#include <string> | |
using namespace miniwin; | |
using namespace std; | |
void numDep0(int x, int y) { | |
color(VERDE); | |
linea(x + 5, y, x + 20, y); | |
linea(x - 5, y, x - 20, y); | |
linea(x, y, x, y - 20); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
linea(x + 4, y + 5, x + 20, y + 20); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
linea(x + 20, y + 20, x + 5, y + 30); | |
} | |
void numDep1(int x, int y) { | |
color(VERDE); | |
linea(x + 5, y, x + 20, y); | |
linea(x - 5, y, x - 20, y); | |
linea(x, y, x, y - 20); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
} | |
void numDep2(int x, int y) { | |
color(VERDE); | |
linea(x + 5, y, x + 20, y); | |
linea(x - 5, y, x - 20, y); | |
linea(x, y, x, y - 20); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
linea(x + 4, y + 5, x + 20, y + 20); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
} | |
void numDep3(int x, int y) { | |
color(VERDE); | |
linea(x + 5, y, x + 20, y); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
} | |
void numDep4(int x, int y) { | |
color(VERDE); | |
linea(x + 5, y, x + 20, y); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
linea(x + 4, y + 5, x + 20, y + 20); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
} | |
void numDep5(int x, int y) { | |
color(VERDE); | |
linea(x - 5, y, x - 20, y); | |
linea(x, y, x, y - 20); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
linea(x + 20, y + 20, x + 5, y + 30); | |
} | |
void numDep6(int x, int y) { | |
color(VERDE); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
linea(x + 4, y + 5, x + 20, y + 20); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
linea(x + 20, y + 20, x + 5, y + 30); | |
} | |
void numDep7(int x, int y) { | |
color(VERDE); | |
linea(x - 5, y, x - 20, y); | |
linea(x, y, x, y - 20); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
linea(x + 20, y + 20, x + 5, y + 30); | |
} | |
void numDep8(int x, int y) { | |
color(VERDE); | |
linea(x + 5, y, x + 20, y); | |
linea(x - 5, y, x - 20, y); | |
linea(x, y, x, y - 20); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
linea(x + 20, y + 20, x + 5, y + 30); | |
} | |
void numDep9(int x, int y) { | |
color(VERDE); | |
linea(x, y, x, y - 20); | |
linea(x - 4, y + 5, x - 20, y + 20); | |
linea(x + 4, y + 5, x + 20, y + 20); | |
linea(x - 20, y + 20, x - 5, y + 30); | |
linea(x + 20, y + 20, x + 5, y + 30); | |
} | |
void dibujarContador(int contador, int x, int y) { | |
int decenas = contador / 10; | |
int unidades = contador % 10; | |
switch (decenas) { | |
case 0: numDep0(x, y); break; | |
case 1: numDep1(x, y); break; | |
case 2: numDep2(x, y); break; | |
case 3: numDep3(x, y); break; | |
case 4: numDep4(x, y); break; | |
case 5: numDep5(x, y); break; | |
case 6: numDep6(x, y); break; | |
case 7: numDep7(x, y); break; | |
case 8: numDep8(x, y); break; | |
case 9: numDep9(x, y); break; | |
} | |
switch (unidades) { | |
case 0: numDep0(x + 50, y); break; | |
case 1: numDep1(x + 50, y); break; | |
case 2: numDep2(x + 50, y); break; | |
case 3: numDep3(x + 50, y); break; | |
case 4: numDep4(x + 50, y); break; | |
case 5: numDep5(x + 50, y); break; | |
case 6: numDep6(x + 50, y); break; | |
case 7: numDep7(x + 50, y); break; | |
case 8: numDep8(x + 50, y); break; | |
case 9: numDep9(x + 50, y); break; | |
} | |
} | |
int main() { | |
int t = tecla(); | |
vredimensiona(500, 500); | |
int contador = 100; // Contador inicial que decrece | |
bool visibles[10] = {true, true, true, true, true, true, true, true, true, true}; // Estado de visibilidad de los números del 0 al 9 | |
while (t != ESCAPE) { | |
borra(); | |
// Dibujar el contador de 100 usando los símbolos personalizados | |
dibujarContador(contador, 150, 50); | |
// Dibujar los números del 0 al 9 | |
int x_pos[] = {100, 100, 100, 100, 100, 300, 300, 300, 300, 300}; | |
int y_pos[] = {100, 150, 200, 250, 300, 100, 150, 200, 250, 300}; | |
for (int i = 0; i < 10; i++) { | |
if (visibles[i]) { | |
switch (i) { | |
case 0: numDep0(x_pos[i], y_pos[i]); break; | |
case 1: numDep1(x_pos[i], y_pos[i]); break; | |
case 2: numDep2(x_pos[i], y_pos[i]); break; | |
case 3: numDep3(x_pos[i], y_pos[i]); break; | |
case 4: numDep4(x_pos[i], y_pos[i]); break; | |
case 5: numDep5(x_pos[i], y_pos[i]); break; | |
case 6: numDep6(x_pos[i], y_pos[i]); break; | |
case 7: numDep7(x_pos[i], y_pos[i]); break; | |
case 8: numDep8(x_pos[i], y_pos[i]); break; | |
case 9: numDep9(x_pos[i], y_pos[i]); break; | |
} | |
} | |
} | |
// Actualizar el contador | |
if (contador > 0) { | |
contador--; | |
} | |
// Hacer desaparecer los números cuando el contador llegue a decenas exactas | |
if (contador % 10 == 0 && contador / 10 < 10) { | |
visibles[contador / 10] = false; | |
} | |
refresca(); | |
espera(500); // Espera para decrementar el contador cada 500 ms | |
t = tecla(); | |
} | |
vcierra(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment