diff options
author | Olivier Gayot <og@satcom1.com> | 2016-09-04 17:20:59 +0200 |
---|---|---|
committer | Olivier Gayot <og@satcom1.com> | 2016-09-04 17:20:59 +0200 |
commit | c6a8032e93deddb70e268b2ef6521410cbb8afac (patch) | |
tree | c44d9593126da6688f6a41ac9141037b8438b373 | |
parent | bf00587e9f9b4eda766b136754ef53b71f85701e (diff) |
refactored battle function
Signed-off-by: Olivier Gayot <og@satcom1.com>
-rw-r--r-- | battle.c (renamed from jouer.c) | 52 | ||||
-rw-r--r-- | map.c | 5 | ||||
-rw-r--r-- | prototypes.h | 1 |
3 files changed, 20 insertions, 38 deletions
@@ -452,16 +452,21 @@ static void hook_post_action(struct action_params_t *params) } } -int Fjouer(SURFACES *surfaces, POSITIONS *positions, +static bool is_battle_over(const struct team_t *t1, const struct team_t *t2) +{ + if (get_first_alive_character(t1) == NULL) { + return true; + } + + return get_first_alive_character(t2) == NULL; +} + +int battle(SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct team_t *t2) { struct team_t *playing_team; - unsigned int continuer=1; - int i; - - unsigned int gagne,perdu; - SDL_BlitSurface(surfaces->background, NULL, surfaces->Pecran, NULL); + SDL_BlitSurface(surfaces->background, NULL, surfaces->screen, NULL); /* compute whether the allies or the enemies should begin */ playing_team = (rand() % 2) ? t1 : t2; @@ -471,10 +476,9 @@ int Fjouer(SURFACES *surfaces, POSITIONS *positions, blit_team(surfaces, t1); blit_team(surfaces, t2); - SDL_Flip(surfaces->Pecran); + SDL_Flip(surfaces->screen); - while (continuer) - { + while (!is_battle_over(t1, t2)) { struct action_params_t params = { .surfaces = surfaces, .positions = positions, @@ -487,18 +491,17 @@ int Fjouer(SURFACES *surfaces, POSITIONS *positions, switch (character_play_turn(¶ms)) { case ACTION_CANCELED: - continuer = 0; - break; + return -1; case ACTION_PERFORMED: - SDL_Flip(surfaces->Pecran); + SDL_Flip(surfaces->screen); SDL_Delay(1000); SDL_BlitSurface(surfaces->background, &positions->degats, surfaces->screen, &positions->degats); - SDL_Flip(surfaces->Pecran); + SDL_Flip(surfaces->screen); hook_post_action(¶ms); @@ -509,29 +512,6 @@ int Fjouer(SURFACES *surfaces, POSITIONS *positions, default: break; } - - /* TODO rewrite */ - gagne=1; - perdu=1; - for (i = 0; i < t2->chr_cnt; i++) { - if (t2->chrs[i].alive) - gagne=0; - } - for (i = 0; i < t1->chr_cnt; i++) { - if (t1->chrs[i].alive) - perdu=0; - } - - if(perdu) - { - SDL_Delay(2000); - continuer=0; - } - else if(gagne) - { - SDL_Delay(2000); - continuer=0; - } } return 0; } @@ -6,6 +6,9 @@ #include "structures.h" #include "prototypes.h" +int battle(SURFACES *surfaces, POSITIONS *positions, + struct team_t *t1, struct team_t *t2); + void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *t1, struct team_t *t2) { @@ -41,7 +44,7 @@ void Fmap (SURFACES*surfaces, POSITIONS* positions, //une fois le jeu quitté ! Fdechargersurfaces_map(surfaces); #else - Fjouer(surfaces, positions, t1, t2); + battle(surfaces, positions, t1, t2); #endif } diff --git a/prototypes.h b/prototypes.h index 1feb053..ff7e1d8 100644 --- a/prototypes.h +++ b/prototypes.h @@ -8,7 +8,6 @@ void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions); int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions); void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions); -int Fjouer(SURFACES *, POSITIONS *, struct team_t *, struct team_t *); void Fgetmap (int map[][11]); void Fmap (SURFACES *, POSITIONS *, struct team_t *, struct team_t *); |