detección de capturas

This commit is contained in:
serxoz 2021-10-24 21:20:30 +02:00
parent 2870392cf3
commit 5d4f5aa5ae
2 changed files with 53 additions and 22 deletions

23
main.c
View File

@ -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;
}

View File

@ -3,14 +3,14 @@
#include <curses.h>
#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;
}