elefantes sobre sitios vacíos

This commit is contained in:
serxoz 2021-10-24 19:17:22 +02:00
parent 56024607f7
commit bc099eef10

View File

@ -46,19 +46,28 @@ void cuadra(WINDOW * win, int width, int height){
wrefresh(win);
}
void generarElefantes(struct coord *buff){
srand ( time(NULL) );
struct coord randomCoord(WINDOW * win){
int nWidthMax=width-10;
int nWidthMin=10;
int nHeightMax=height-10;
int nHeightMin=10;
int rX = rand() % ((nWidthMax+1)-nWidthMin) + nWidthMin;
int rY = rand() % ((nHeightMax+1)-nHeightMin) + nHeightMin;
struct coord res = {rX, rY};
if (mvwinch(win, res.y, res.x) == ' '){
return res;
} else {
randomCoord(win);
}
}
void generarElefantes(WINDOW * win, struct coord *buff){
for(int i = 0; i < ELEFANTES; ++i) {
int nWidthMax=width-10;
int nWidthMin=10;
int nHeightMax=height-10;
int nHeightMin=10;
int rX = rand() % ((nWidthMax+1)-nWidthMin) + nWidthMin;
int rY = rand() % ((nHeightMax+1)-nHeightMin) + nHeightMin;
struct coord elefante = {rX+2,rY+2};
struct coord elefante = randomCoord(win);
buff[i] = elefante;
}
}
@ -67,6 +76,7 @@ int screen() {
initscr();
noecho();
curs_set(0); //cursor invisible
srand ( time(NULL) ); //semilla para rand
/* int height, width, start_y, start_x; */
/* height = 40; */
@ -87,11 +97,10 @@ int screen() {
mvwprintw(win, cazador.y, cazador.x, "^");
struct coord elefantes[ELEFANTES] = {0};
generarElefantes(elefantes);
generarElefantes(win, elefantes);
for(int i = 0; i < ELEFANTES; i++){
mvwprintw(win, elefantes[i].y, elefantes[i].x, "?");
/* mvwprintw(win, i+1, 1, "elefante x:%i, y:%i",elefantes[i].x, elefantes[i].y); */
}
@ -154,8 +163,6 @@ int screen() {
}
}
}
}
endwin(); // dealocate memory and end ncurses