annulation & hist

This commit is contained in:
Tropicananass 2016-05-11 16:34:16 +02:00
parent 893a5cb38b
commit 097c3f9ec2
10 changed files with 93 additions and 25 deletions

BIN
bin/hex

Binary file not shown.

View File

@ -245,6 +245,8 @@ int selection_menu (menu_t m)
{ {
case 01: case 01:
return M_LEFT; return M_LEFT;
case 02:
return M7_DOWN;
case 10: case 10:
return M_UP; return M_UP;
case 11: case 11:
@ -258,6 +260,8 @@ int selection_menu (menu_t m)
return M_MID; return M_MID;
case 12: case 12:
return M_DOWN; return M_DOWN;
case 20:
return M7_UP;
case 21: case 21:
return M_RIGHT; return M_RIGHT;
default: default:

View File

@ -9,6 +9,18 @@
#include "sound.h" #include "sound.h"
#include "testJeu.h" #include "testJeu.h"
void annuler (plateau_t p)
{
if (p->annule)
{
p->grid [p->hist [--p->nb_coups]] = 0;
//Affiche_hexagon(p, p->hist [p->nb_coups] / NBSIDE, p->hist [p->nb_coups] % NBSIDE, NORMAL);
p->hist [p->nb_coups] = -1;
p->player = !p->player;
p->annule = false;
}
}
int selection (plateau_t p, curseur_t c) int selection (plateau_t p, curseur_t c)
{ {
if (0 <= c.x && c.x < NBSIDE && 0 <= c.y && c.y < NBSIDE && p->grid [c.x * NBSIDE + c.y] == 0) if (0 <= c.x && c.x < NBSIDE && 0 <= c.y && c.y < NBSIDE && p->grid [c.x * NBSIDE + c.y] == 0)
@ -16,6 +28,7 @@ int selection (plateau_t p, curseur_t c)
p->grid [c.x * NBSIDE + c.y] = PLAYER(p->player); p->grid [c.x * NBSIDE + c.y] = PLAYER(p->player);
p->hist [p->nb_coups++] = c.x * NBSIDE + c.y; p->hist [p->nb_coups++] = c.x * NBSIDE + c.y;
p->player = !p->player; p->player = !p->player;
p->annule = true;
Affiche_hexagon(p, c.x, c.y, PLAYER(p->player)); Affiche_hexagon(p, c.x, c.y, PLAYER(p->player));
return testGagne (p->grid, PLAYER(!p->player)); return testGagne (p->grid, PLAYER(!p->player));
}/* }/*

View File

@ -5,6 +5,8 @@
#include "globals.h" #include "globals.h"
void annuler (plateau_t p);
int selection (plateau_t p, curseur_t c); int selection (plateau_t p, curseur_t c);
void deplacement_mouse (plateau_t p, SDL_MouseMotionEvent motion, curseur_t* c); void deplacement_mouse (plateau_t p, SDL_MouseMotionEvent motion, curseur_t* c);

View File

@ -263,6 +263,7 @@ plateau_t init_plateau (SDL_Surface* window)
p->nb_coups = 0; p->nb_coups = 0;
p->window = window; p->window = window;
p->player = false; p->player = false;
p->annule = false;
Quadrille (p); Quadrille (p);
return p; return p;
} }
@ -273,6 +274,7 @@ plateau_t load_plateau (SDL_Surface* window, int* hist)
p->grid = malloc (sizeof (int) * NBSIDE * NBSIDE); p->grid = malloc (sizeof (int) * NBSIDE * NBSIDE);
p->hist = hist; p->hist = hist;
p->player = false; p->player = false;
p->annule = false;
for (int i = 0; i < NBSIDE * NBSIDE; ++i) for (int i = 0; i < NBSIDE * NBSIDE; ++i)
p->grid [i] = 0; p->grid [i] = 0;
for (p->nb_coups = 0; p->nb_coups < NBSIDE * NBSIDE && hist [p->nb_coups] != -1; ++p->nb_coups) for (p->nb_coups = 0; p->nb_coups < NBSIDE * NBSIDE && hist [p->nb_coups] != -1; ++p->nb_coups)

View File

@ -47,14 +47,20 @@ void en_jeu (SDL_Surface* window, int* hist)
Reset_window(window); Reset_window(window);
Mix_PlayMusic(param->music, -1); Mix_PlayMusic(param->music, -1);
plateau_t plateau; plateau_t plateau;
d_scrolling_t d;
if (hist == NULL) if (hist == NULL)
{
plateau = init_plateau (window); plateau = init_plateau (window);
d = init_dynamic_scroll (window, plateau);
}
else else
{
plateau = load_plateau (window, hist); plateau = load_plateau (window, hist);
d = resize_dynamic_scroll (window, NULL, plateau);
}
vec2 c = {0, 0}; vec2 c = {0, 0};
bool end = false; bool end = false;
bool gagne = false; bool gagne = false;
d_scrolling_t d = init_dynamic_scroll (window, plateau);
bool button = false; bool button = false;
while (!end) while (!end)
{ {
@ -131,8 +137,6 @@ void en_jeu (SDL_Surface* window, int* hist)
} }
if (gagne) if (gagne)
{ {
while (!end)
{
char new [50]; char new [50];
sprintf (new, "Joueur %d Gagne !!", PLAYER(!plateau->player)); sprintf (new, "Joueur %d Gagne !!", PLAYER(!plateau->player));
SDL_Surface* txt; SDL_Surface* txt;
@ -140,13 +144,15 @@ void en_jeu (SDL_Surface* window, int* hist)
txt = TTF_RenderUTF8_Blended (param->font, new, param->rgb_j1); txt = TTF_RenderUTF8_Blended (param->font, new, param->rgb_j1);
else else
txt = TTF_RenderUTF8_Blended (param->font, new, param->rgb_j2); txt = TTF_RenderUTF8_Blended (param->font, new, param->rgb_j2);
SDL_Surface* final = rotozoomSurface (txt, .0, window->w / txt->w, 1); SDL_Surface* final = rotozoomSurface (txt, .0, window->w / (float)txt->w, 1);
SDL_FreeSurface (txt); SDL_FreeSurface (txt);
SDL_BlitSurface (final, NULL , window, NULL); SDL_BlitSurface (final, NULL , window, NULL);
SDL_FreeSurface (final); SDL_FreeSurface (final);
SDL_Event e; SDL_Flip (window);
SDL_WaitEvent (&e); while (!end)
if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) {
SDL_WaitEvent (&event);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
end = true; end = true;
} }
} }

View File

@ -67,6 +67,7 @@ typedef struct s_plateau {
int *hist; int *hist;
int nb_coups; int nb_coups;
bool player; bool player;
bool annule;
int ia; int ia;
SDL_Rect menu; SDL_Rect menu;
}* plateau_t; }* plateau_t;

View File

@ -33,8 +33,16 @@ bool d_menu_mouse (plateau_t p, SDL_MouseMotionEvent motion)
int menu_hist (plateau_t p) int menu_hist (plateau_t p)
{ {
char* entries [5] = {"<", "", "", "Retour", ">"}; char* entries [7] = {"Case", "", "", "Retour", ">", "<", ""};//{"Case", "Joueur 1", " 6 - 4 ", "Retour", ">", "<", " Coup 4 "};
entries [1] = malloc (sizeof (char) * 9);
entries [2] = malloc (sizeof (char) * 8);
entries [6] = malloc (sizeof (char) * 9);
int cur = p->nb_coups - 1;
sprintf (entries [1], "Joueur %d", PLAYER(cur%2));
sprintf (entries [2], " %2d - %2d ", p->hist[cur] / NBSIDE + 1, p->hist[cur] % NBSIDE + 1);
sprintf (entries [6], " Coup %3d ", cur);
menu_t m = init_menu (p->window, entries); menu_t m = init_menu (p->window, entries);
m->nb_entries = 7;
Affiche_menu(m); Affiche_menu(m);
int retour; int retour;
bool end = false; bool end = false;
@ -52,29 +60,42 @@ int menu_hist (plateau_t p)
switch (retour) switch (retour)
{ {
case M_UP: case M_UP:
menu_music (p->window, NULL); break;
m->cur.x = 1; case M7_UP:
m->cur.y = 1; if (cur <= 0)
Affiche_menu(m); cur = p->nb_coups - 1;
else
--cur;
sprintf (entries [1], "Joueur %d", PLAYER(cur%2));
sprintf (entries [2], " %2d - %2d ", p->hist[cur] / NBSIDE + 1, p->hist[cur] % NBSIDE + 1);
sprintf (entries [6], " Coup %3d ", cur);
Affiche_menu (m);
break; break;
case M_LEFT : case M_LEFT :
end = true;
break; break;
case M_RIGHT : case M_RIGHT :
menu_son (p->window, NULL); if (cur >= p->nb_coups - 1)
m->cur.x = 1; cur = 0;
m->cur.y = 1; else
Affiche_menu(m); ++cur;
sprintf (entries [1], "Joueur %d", PLAYER(cur%2));
sprintf (entries [2], " %2d - %2d ", p->hist[cur] / NBSIDE + 1, p->hist[cur] % NBSIDE + 1);
sprintf (entries [6], " Coup %3d ", cur);
Affiche_menu (m);
break; break;
case M_DOWN : case M_DOWN :
end = true; end = true;
break; break;
case M7_DOWN :
break;
case M_MID : case M_MID :
end = true;
break; break;
} }
} }
free_menu(m); free_menu(m);
free (entries[1]);
free (entries[2]);
free (entries[6]);
return retour; return retour;
} }
@ -265,7 +286,7 @@ int menu_en_jeu_part1 (plateau_t p)
SDL_Surface* save = SDL_CreateRGBSurface (SDL_HWSURFACE, p->window->w, p->window->h, p->window->format->BitsPerPixel, 0, 0, 0, 0); SDL_Surface* save = SDL_CreateRGBSurface (SDL_HWSURFACE, p->window->w, p->window->h, p->window->format->BitsPerPixel, 0, 0, 0, 0);
SDL_BlitSurface (p->window, NULL, save, NULL); SDL_BlitSurface (p->window, NULL, save, NULL);
vec2 resize = {p->window->w, p->window->h}; vec2 resize = {p->window->w, p->window->h};
char* entries [7] = {"Hist", "Save", "HEX", "Quitter", ">", "sdoul", "7"}; char* entries [7] = {"Hist", "Save", "HEX", "Quitter", ">", "Cancel", "Retour"};
menu_t m = init_menu (p->window, entries); menu_t m = init_menu (p->window, entries);
m->nb_entries = 7; m->nb_entries = 7;
Affiche_menu(m); Affiche_menu(m);
@ -282,7 +303,7 @@ int menu_en_jeu_part1 (plateau_t p)
retour = M_DOWN; retour = M_DOWN;
else else
retour = evenement_menu(p->window, m, event, 0); retour = evenement_menu(p->window, m, event, 0);
if (retour != M_NOT) if (retour == M_UP || retour == M_RIGHT)
{ {
if (resize.x == p->window->w && resize.y == p->window->h) if (resize.x == p->window->w && resize.y == p->window->h)
SDL_BlitSurface (save, NULL, p->window, NULL); SDL_BlitSurface (save, NULL, p->window, NULL);
@ -298,6 +319,13 @@ int menu_en_jeu_part1 (plateau_t p)
Affiche_menu(m); Affiche_menu(m);
break; break;
case M_LEFT : case M_LEFT :
if (p->nb_coups > 0)
{
menu_hist (p);
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
}
break; break;
case M_RIGHT : case M_RIGHT :
end = true; end = true;
@ -306,8 +334,13 @@ int menu_en_jeu_part1 (plateau_t p)
end = true; end = true;
break; break;
case M_MID : case M_MID :
break;
case M7_DOWN :
end = true; end = true;
break; break;
case M7_UP :
annuler (p);
break;
} }
} }
free_menu(m); free_menu(m);
@ -332,7 +365,7 @@ int menu_en_jeu (plateau_t p)
retour = menu_en_jeu_part1(p); retour = menu_en_jeu_part1(p);
else if (retour == M_RIGHT) else if (retour == M_RIGHT)
retour = menu_en_jeu_part2(p); retour = menu_en_jeu_part2(p);
} while (retour != M_MID && retour != M_DOWN); } while (retour != M_MID && retour != M_DOWN && retour != M7_DOWN);
SDL_BlitSurface (save, NULL, p->window, NULL); SDL_BlitSurface (save, NULL, p->window, NULL);
SDL_FreeSurface (save); SDL_FreeSurface (save);

View File

@ -202,7 +202,7 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
case M_MID : case M_MID :
supprimer (entries [2]); supprimer (entries [2]);
free_liste (liste, nb_sav); free_liste (liste, nb_sav);
int nb_sav = listeSauvegarde(&liste); nb_sav = listeSauvegarde(&liste);
if (nb_sav == 0) if (nb_sav == 0)
{ {
liste = malloc(sizeof(char*)); liste = malloc(sizeof(char*));

View File

@ -195,7 +195,7 @@ d_scrolling_t init_dynamic_scroll (SDL_Surface* window, plateau_t p)
SDL_Surface* j1 = d->s->msg [1]; SDL_Surface* j1 = d->s->msg [1];
char new [50] = "Dernier coup : joueur 2 en 00 - 00"; char new [50] = "Dernier coup : joueur 2 en 00 - 00 ";
d->s->msg[1] = create_one_surface (new, param->rgb_j1, d->s->msg[0]->h, window->format->BitsPerPixel); d->s->msg[1] = create_one_surface (new, param->rgb_j1, d->s->msg[0]->h, window->format->BitsPerPixel);
@ -222,7 +222,7 @@ SDL_Event dynamic_scroll (SDL_Surface* window, d_scrolling_t d, plateau_t p)
Cadre_scroll (window); Cadre_scroll (window);
d->id = !d->id; d->id = !d->id;
char new [50]; char new [50];
sprintf (new, "Dernier coup : joueur %d en %2d - %2d", PLAYER(!p->player), p->hist[p->nb_coups - 1] / NBSIDE + 1, p->hist[p->nb_coups - 1] % NBSIDE + 1); sprintf (new, "Dernier coup : joueur %d en %2d - %2d ", PLAYER(!p->player), p->hist[p->nb_coups - 1] / NBSIDE + 1, p->hist[p->nb_coups - 1] % NBSIDE + 1);
if (p->player) if (p->player)
d->s->msg[1] = create_one_surface (new, param->rgb_j1, d->s->msg[0]->h, window->format->BitsPerPixel); d->s->msg[1] = create_one_surface (new, param->rgb_j1, d->s->msg[0]->h, window->format->BitsPerPixel);
else else
@ -250,7 +250,14 @@ SDL_Event dynamic_scroll (SDL_Surface* window, d_scrolling_t d, plateau_t p)
d_scrolling_t resize_dynamic_scroll (SDL_Surface* window, d_scrolling_t d, plateau_t p) d_scrolling_t resize_dynamic_scroll (SDL_Surface* window, d_scrolling_t d, plateau_t p)
{ {
free_scroll (d->s); if (d == NULL)
d = malloc (sizeof (struct s_d_scrolling));
else
{
if (d->precedent != NULL && d->precedent != d->s->msg [1])
SDL_FreeSurface (d->precedent);
free_scroll (d->s);
}
d->s = malloc (sizeof (struct s_scrolling)); d->s = malloc (sizeof (struct s_scrolling));
char* msg [2] = {"Au tour du Joueur 2", "Au tour du Joueur 1"}; char* msg [2] = {"Au tour du Joueur 2", "Au tour du Joueur 1"};
SDL_Color c [2] = {param->rgb_j2, param->rgb_j1}; SDL_Color c [2] = {param->rgb_j2, param->rgb_j1};