This commit is contained in:
Willem Haffmans 2025-05-25 22:19:36 +02:00
parent 9375fc9a0e
commit 354d882ae7
3 changed files with 71 additions and 4 deletions

View File

@ -3,10 +3,10 @@
/* :::::::: */ /* :::::::: */
/* game.h :+: :+: */ /* game.h :+: :+: */
/* +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/15 15:46:16 by qmennen #+# #+# */ /* Created: 2025/04/15 15:46:16 by qmennen #+# #+# */
/* Updated: 2025/04/23 11:56:48 by whaffman ######## odam.nl */ /* Updated: 2025/05/25 21:01:17 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,5 +20,6 @@ void game_loop(void *param);
void game_free(t_game *game); void game_free(t_game *game);
void game_terminate(t_game *game); void game_terminate(t_game *game);
void free_game(t_game **game); void free_game(t_game **game);
void print_scores(t_game *game);
#endif #endif

View File

@ -3,10 +3,10 @@
/* :::::::: */ /* :::::::: */
/* game.c :+: :+: */ /* game.c :+: :+: */
/* +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */ /* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
/* Updated: 2025/05/23 17:20:34 by whaffman ######## odam.nl */ /* Updated: 2025/05/25 21:02:05 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -161,6 +161,7 @@ void game_free(t_game *game)
void game_terminate(t_game *game) void game_terminate(t_game *game)
{ {
print_scores(game);
game_free(game); game_free(game);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

65
src/util/score.c Normal file
View File

@ -0,0 +1,65 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* score.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/25 20:54:23 by whaffman #+# #+# */
/* Updated: 2025/05/25 21:00:49 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int count_tiles(t_map *map, t_tile tile_type)
{
int count;
int x;
int y;
count = 0;
y = 0;
while (y < map->height)
{
x = 0;
while (x < map->width)
{
if (map->grid[y][x] == tile_type)
count++;
x++;
}
y++;
}
return (count);
}
int count_collected(t_game *game)
{
int collected;
int i;
i = 0;
collected = 0;
while (i < game->map->n_sprites)
{
if (game->map->sprites[i].collectible && !game->map->sprites[i].visible)
collected++;
i++;
}
return (collected);
}
void print_scores(t_game *game)
{
int empty;
int visited;
int collected;
empty = count_tiles(game->map, TILE_EMPTY);
visited = count_tiles(game->map, TILE_VISITED);
collected = count_collected(game);
printf("Score:\n");
printf("Seen %d of %d tiles\n", visited, visited + empty);
printf("Collected items: %d\n", collected);
}