diff --git a/a5/game.c b/a5/game.c index 08cad0e..d43ebe7 100644 --- a/a5/game.c +++ b/a5/game.c @@ -11,13 +11,13 @@ void* init_game(){ // Initialize cat st->catx = 0; st->caty = 0; - st->catx_position = 15; - st->caty_position = 15; + st->catx_position = 20; + st->caty_position = 10; st->caught_count = 0; - // Initialize 5 mice at random positions + // Initialize 5 mice at random positions (within boundaries) for(int i = 0; i < MOUSE_COUNT; i++){ - st->mousex[i] = 5 + rand() % 30; + st->mousex[i] = 5 + rand() % 50; st->mousey[i] = 5 + rand() % 15; st->mouse_state[i] = 0; // alive } @@ -58,8 +58,8 @@ int game_event(struct event* event,void* game){ int cx = state->catx_position + state->catx; int cy = state->caty_position + state->caty; - // Check boundaries - if (cx > 0 && cx < event->width && cy > 0 && cy < event->height){ + // Check boundaries (leave room for borders) + if (cx > 1 && cx < event->width - 2 && cy > 2 && cy < event->height - 2){ state->catx_position = cx; state->caty_position = cy; } @@ -76,8 +76,8 @@ int game_event(struct event* event,void* game){ else if (m == 2) mx -= 1; else if (m == 3) mx += 1; - // Check boundaries - if (mx > 0 && mx < event->width && my > 0 && my < event->height){ + // Check boundaries (leave room for borders) + if (mx > 1 && mx < event->width - 2 && my > 2 && my < event->height - 2){ state->mousex[i] = mx; state->mousey[i] = my; } @@ -107,20 +107,30 @@ int game_event(struct event* event,void* game){ // Draw world state clear_screen(); + // Draw borders + for(int x = 0; x < event->width; x++){ + set_cell('#', x, 1); + set_cell('#', x, event->height - 2); + } + for(int y = 1; y < event->height - 1; y++){ + set_cell('#', 0, y); + set_cell('#', event->width - 1, y); + } + // Draw cat - set_color_cell('c',state->catx_position,state->caty_position,COLOR_YELLOW,COLOR_RED); + set_cell('c', state->catx_position, state->caty_position); // Draw mice for(int i = 0; i < MOUSE_COUNT; i++){ if(state->mouse_state[i] == 0){ // only draw alive mice - set_cell('m',state->mousex[i],state->mousey[i]); + set_cell('m', state->mousex[i], state->mousey[i]); } } // Draw caught count char msg[100]; - sprintf(msg,"Chytene: %d/%d", state->caught_count, MOUSE_COUNT); - set_message(msg, 1, 0); + sprintf(msg, "Chytene: %d/%d", state->caught_count, MOUSE_COUNT); + set_message(msg, 2, 0); return 0; }