From 5d4f5aa5ae7b7b076151893cd68804cbf81d19ca Mon Sep 17 00:00:00 2001 From: serxoz Date: Sun, 24 Oct 2021 21:20:30 +0200 Subject: [PATCH] =?UTF-8?q?detecci=C3=B3n=20de=20capturas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 23 +++++------------------ screen.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/main.c b/main.c index 809f5b2..8675d00 100644 --- a/main.c +++ b/main.c @@ -6,25 +6,12 @@ struct coord fuxir(struct coord c, struct coord e); int screen(); int main(void) { - /* printf("Iniciando.\n"); */ - - /* struct coord cazador = {1,1}; */ - /* struct coord elefante = {3,3}; */ - - /* double d = distancia(cazador, elefante); */ - /* printf("Distancia: %lf\n", d); */ - - /* struct coord nova; */ - /* nova = fuxir(cazador, elefante); */ - - /* printf("Nova localización do elefante:\n"); */ - /* printf("x %i\n", nova.x); */ - /* printf("y %i\n", nova.y); */ - /* double novaD = distancia(cazador, nova); */ - /* printf("Nova Distancia: %lf\n", novaD); */ - - screen(); + int capturas = screen(); + printf("CAPTURAS: %i \n", capturas); + if (capturas > 0){ + printf("NORABOA!\n"); //indicar o tempo total + } return 0; } diff --git a/screen.c b/screen.c index 6779d2c..e0c14c2 100644 --- a/screen.c +++ b/screen.c @@ -3,14 +3,14 @@ #include #include "defs.h" -#define ELEFANTES 8 +#define ELEFANTES 6 const int height = 40; const int width = 80; double distancia(struct coord c, struct coord e); struct coord fuxir(struct coord c, struct coord e); -void cuadra(WINDOW * win, int width, int height){ +int* cuadra(WINDOW * win, int width, int height){ int medioX = width/2; int medioY = height/2; @@ -44,6 +44,14 @@ void cuadra(WINDOW * win, int width, int height){ mvwprintw(win, height/2+altoCaja, width/2+1, " "); wrefresh(win); + + static int esquinas[4]; + esquinas[0] = bordeL; + esquinas[1] = bordeU; + esquinas[2] = bordeR; + esquinas[3] = bordeD; + + return esquinas; } struct coord randomCoord(WINDOW * win){ @@ -72,7 +80,33 @@ void generarElefantes(WINDOW * win, struct coord *buff){ } } +int capturas(WINDOW * win, int *esquinas){ + // recorrer cada posición comprobando si existe un elefante en ela + // así cando puntuacion == ELEFANTES é que acabou a partida + // poñerlle un resumo do tempo que lle levou + // + /* esquinas = [xIni, yIni, xFin, yFin] */ + /* restolles 1 por que quero o interior do rectangulo */ + int xIni = esquinas[0]-1; + int xFin = esquinas[2]-1; + int yIni = esquinas[1]-1; + int yFin = esquinas[3]-1; + + int elef = 0; + for(int x = xIni; x <= xFin; x++ ){ + for(int y = yIni; y <= yFin; y++ ){ + if (mvwinch(win, y, x) == '?'){ + elef++; + } + } + } + + return elef; +} + int screen() { + int capt = 0; //capturas + initscr(); noecho(); curs_set(0); //cursor invisible @@ -90,7 +124,7 @@ int screen() { refresh(); box(win, 0, 0); - cuadra(win, width, height); + int* esquinasCaja = cuadra(win, width, height); /* struct coord cazador = {height/3,width/2}; */ struct coord cazador = {10,10}; @@ -105,6 +139,16 @@ int screen() { } while(true){ + // Puntuacion + capt = capturas(win, esquinasCaja); + mvwprintw(win, 1, 2, "Capturados: %i", capt); + + // Fin + if (capt == ELEFANTES) { + break; + } + + // Movemento int c = wgetch(win); switch(c){ case KEY_UP: @@ -167,5 +211,5 @@ int screen() { endwin(); // dealocate memory and end ncurses - return 0; + return capt; }