-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_score.c
46 lines (42 loc) · 1.11 KB
/
display_score.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
** EPITECH PROJECT, 2022
** display_score.c
** File description:
** display_score
*/
#include "my_runner.h"
#include "my.h"
int find_power_itc(int nb)
{
int i = 0;
for (i = 0; nb > 0; i++)
nb /= 10;
return i;
}
char *int_to_char(int nb)
{
int size = find_power_itc(nb);
char *nbr = malloc(sizeof(char) * size + 1);
int current = 0;
int i = 0;
for (i = 0; i < size; i++) {
current = nb % 10;
nbr[i] = current + '0';
nb /= 10;
}
nbr[i] = '\0';
my_revstr(nbr);
return nbr;
}
void display_score(sfRenderWindow *window, player_t *player)
{
char *char_score = int_to_char(player->score->score);
char *life_nb = int_to_char(player->life);
sfRenderWindow_drawText(window, player->score->text, NULL);
sfText_setString(player->score->text_score, char_score);
sfRenderWindow_drawText(window, player->score->text_score, NULL);
sfRenderWindow_drawText(window, player->score->life, NULL);
sfText_setString(player->score->life_nb, life_nb);
sfRenderWindow_drawText(window, player->score->life_nb, NULL);
free(char_score);
}