From f713e6957681cda53da4f3d1f4933731c8c48b5e Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 9 Jan 2015 16:44:45 +0100 Subject: use a generic way to handle a turn from a cpu or a player Signed-off-by: Olivier Gayot --- jouer.c | 87 +++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/jouer.c b/jouer.c index e619c95..48be23b 100644 --- a/jouer.c +++ b/jouer.c @@ -175,14 +175,6 @@ enum action_state_t select_target(struct action_params_t *params, void *data, (*cb)(surfaces, positions, params->src, &target_team->chrs[selection], data); - SDL_Flip(surfaces->Pecran); - - SDL_Delay(1000); - - SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); - - SDL_Flip(surfaces->Pecran); - return ACTION_PERFORMED; default: break; @@ -239,6 +231,19 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st } } +static enum action_state_t character_play_turn(struct action_params_t *params) +{ + if (!params->src->team->cpu) { + return dig_entry(action_entries_g, countof(action_entries_g), params); + } + +#if 0 + Factionennemi(&Vtourennemi,surfaces,positions,ennemis,persos,Vnbennemis,&Vtour,Vtourallie); +#endif + + return ACTION_PERFORMED; +} + int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct team_t *t2) { struct team_t *playing_team; @@ -261,47 +266,37 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct while (continuer) { - if (!playing_team->cpu) //si un player joue - { - struct action_params_t params = { - .surfaces = surfaces, - .positions = positions, - - .t1 = t1, - .t2 = t2, - - .src = &playing_team->chrs[playing_team->chr_cur], - }; - - enum action_state_t state; - - state = dig_entry(action_entries_g, countof(action_entries_g), ¶ms); - switch (state) { - case ACTION_CANCELED: - continuer = 0; - break; - case ACTION_PERFORMED: - update_current_character(t1, t2, &playing_team); - blit_team(surfaces, t1); - blit_team(surfaces, t2); - break; - default: - break; - } - } - else { - /* TODO reactivate */ -#if 0 - Factionennemi(&Vtourennemi,surfaces,positions,ennemis,persos,Vnbennemis,&Vtour,Vtourallie); -#endif - SDL_Flip(surfaces->Pecran); + struct action_params_t params = { + .surfaces = surfaces, + .positions = positions, - update_current_character(t1, t2, &playing_team); + .t1 = t1, + .t2 = t2, - blit_team(surfaces, t1); - blit_team(surfaces, t2); - } + .src = &playing_team->chrs[playing_team->chr_cur], + }; + + switch (character_play_turn(¶ms)) { + case ACTION_CANCELED: + continuer = 0; + break; + case ACTION_PERFORMED: + + SDL_Flip(surfaces->Pecran); + + SDL_Delay(1000); + + SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); + + SDL_Flip(surfaces->Pecran); + update_current_character(t1, t2, &playing_team); + blit_team(surfaces, t1); + blit_team(surfaces, t2); + break; + default: + break; + } // on vérifie à présent si on a gagné ou si on a perdu ! gagne=1; -- cgit v1.2.3