summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-09 16:44:45 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-09 16:47:59 +0100
commitf713e6957681cda53da4f3d1f4933731c8c48b5e (patch)
tree4d89665fa5aee33755cd24067e156733dad98fae
parent4c826c50bb7a8d79201cc7d8f68b8805030aa98c (diff)
use a generic way to handle a turn from a cpu or a player
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--jouer.c87
1 files 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), &params);
- 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(&params)) {
+ 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;