affichage score
This commit is contained in:
@@ -52,6 +52,7 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
int nbr_targets, dis *display_user, score *score_user, bool menu);
|
int nbr_targets, dis *display_user, score *score_user, bool menu);
|
||||||
char *timeToText(time_t time);
|
char *timeToText(time_t time);
|
||||||
void nullScore(score *player_score);
|
void nullScore(score *player_score);
|
||||||
void winOrLoseLoop(dis *display_user, bool win);
|
void winOrLoseLoop(dis *display_user,score *score_user, bool win);
|
||||||
|
unsigned int scoreCalculator(score *score_user, bool win);
|
||||||
|
|
||||||
#endif // FONCTION_H
|
#endif // FONCTION_H
|
||||||
|
|||||||
@@ -636,7 +636,7 @@ void nullScore(score *player_score)
|
|||||||
* \param display_user Tout les information du display de l'utilisateur utile.
|
* \param display_user Tout les information du display de l'utilisateur utile.
|
||||||
* \param win Si on veut un affichage de victoire ou non.
|
* \param win Si on veut un affichage de victoire ou non.
|
||||||
*/
|
*/
|
||||||
void winOrLoseLoop(dis *display_user, bool win)
|
void winOrLoseLoop(dis *display_user,score *score_user, bool win)
|
||||||
{
|
{
|
||||||
SDL_Surface *img;
|
SDL_Surface *img;
|
||||||
SDL_Texture *texture;
|
SDL_Texture *texture;
|
||||||
@@ -648,6 +648,12 @@ void winOrLoseLoop(dis *display_user, bool win)
|
|||||||
|
|
||||||
vect pos = {0, 0};
|
vect pos = {0, 0};
|
||||||
displayImage(display_user->renderer, texture, pos, display_user->size_window);
|
displayImage(display_user->renderer, texture, pos, display_user->size_window);
|
||||||
|
|
||||||
|
char text[50] = "";
|
||||||
|
snprintf(text, 50, "Score : %u",scoreCalculator(score_user, win));
|
||||||
|
vect pos_score = {10, (display_user->size_window*3) / 4};
|
||||||
|
vect size_score = {display_user->size_window / 4, display_user->size_window - 10};
|
||||||
|
displayTextSDL(display_user, text , pos_score, size_score, 80);
|
||||||
SDL_RenderPresent (display_user->renderer);
|
SDL_RenderPresent (display_user->renderer);
|
||||||
|
|
||||||
bool finish = false;
|
bool finish = false;
|
||||||
@@ -660,7 +666,22 @@ void winOrLoseLoop(dis *display_user, bool win)
|
|||||||
SDL_Delay(16);
|
SDL_Delay(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_FreeSurface (img);
|
SDL_FreeSurface (img);
|
||||||
SDL_DestroyTexture (texture);
|
SDL_DestroyTexture (texture);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int scoreCalculator(score *score_user, bool win)
|
||||||
|
{
|
||||||
|
unsigned short int result = 65535; //plus grand nombre
|
||||||
|
int time = score_user->after - score_user->before;
|
||||||
|
printf("%d\n", time);
|
||||||
|
result -= (score_user->move_box + score_user->move_player) * time;
|
||||||
|
if (!win)
|
||||||
|
{
|
||||||
|
result /= 50;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ int main ()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
score_user.before = time(NULL);
|
||||||
char txt[30] = "";
|
char txt[30] = "";
|
||||||
if(output <= 3)
|
if(output <= 3)
|
||||||
{
|
{
|
||||||
@@ -72,7 +73,8 @@ int main ()
|
|||||||
targets = fileToTab2D(txt, tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
targets = fileToTab2D(txt, tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
||||||
output = inGameLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user, &score_user, false);
|
output = inGameLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user, &score_user, false);
|
||||||
SDL_RenderClear(display_user.renderer);
|
SDL_RenderClear(display_user.renderer);
|
||||||
if(output != -1000) winOrLoseLoop(&display_user, output==1);
|
score_user.after = time(NULL);
|
||||||
|
if(output != -1000) winOrLoseLoop(&display_user, &score_user, output==1);
|
||||||
output = -1;
|
output = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user