annulation & hist
This commit is contained in:
parent
893a5cb38b
commit
097c3f9ec2
@ -245,6 +245,8 @@ int selection_menu (menu_t m)
|
||||
{
|
||||
case 01:
|
||||
return M_LEFT;
|
||||
case 02:
|
||||
return M7_DOWN;
|
||||
case 10:
|
||||
return M_UP;
|
||||
case 11:
|
||||
@ -258,6 +260,8 @@ int selection_menu (menu_t m)
|
||||
return M_MID;
|
||||
case 12:
|
||||
return M_DOWN;
|
||||
case 20:
|
||||
return M7_UP;
|
||||
case 21:
|
||||
return M_RIGHT;
|
||||
default:
|
||||
|
@ -9,6 +9,18 @@
|
||||
#include "sound.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)
|
||||
{
|
||||
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->hist [p->nb_coups++] = c.x * NBSIDE + c.y;
|
||||
p->player = !p->player;
|
||||
p->annule = true;
|
||||
Affiche_hexagon(p, c.x, c.y, PLAYER(p->player));
|
||||
return testGagne (p->grid, PLAYER(!p->player));
|
||||
}/*
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
void annuler (plateau_t p);
|
||||
|
||||
int selection (plateau_t p, curseur_t c);
|
||||
|
||||
void deplacement_mouse (plateau_t p, SDL_MouseMotionEvent motion, curseur_t* c);
|
||||
|
@ -263,6 +263,7 @@ plateau_t init_plateau (SDL_Surface* window)
|
||||
p->nb_coups = 0;
|
||||
p->window = window;
|
||||
p->player = false;
|
||||
p->annule = false;
|
||||
Quadrille (p);
|
||||
return p;
|
||||
}
|
||||
@ -273,6 +274,7 @@ plateau_t load_plateau (SDL_Surface* window, int* hist)
|
||||
p->grid = malloc (sizeof (int) * NBSIDE * NBSIDE);
|
||||
p->hist = hist;
|
||||
p->player = false;
|
||||
p->annule = false;
|
||||
for (int i = 0; i < NBSIDE * NBSIDE; ++i)
|
||||
p->grid [i] = 0;
|
||||
for (p->nb_coups = 0; p->nb_coups < NBSIDE * NBSIDE && hist [p->nb_coups] != -1; ++p->nb_coups)
|
||||
|
20
src/en_jeu.c
20
src/en_jeu.c
@ -47,14 +47,20 @@ void en_jeu (SDL_Surface* window, int* hist)
|
||||
Reset_window(window);
|
||||
Mix_PlayMusic(param->music, -1);
|
||||
plateau_t plateau;
|
||||
d_scrolling_t d;
|
||||
if (hist == NULL)
|
||||
{
|
||||
plateau = init_plateau (window);
|
||||
d = init_dynamic_scroll (window, plateau);
|
||||
}
|
||||
else
|
||||
{
|
||||
plateau = load_plateau (window, hist);
|
||||
d = resize_dynamic_scroll (window, NULL, plateau);
|
||||
}
|
||||
vec2 c = {0, 0};
|
||||
bool end = false;
|
||||
bool gagne = false;
|
||||
d_scrolling_t d = init_dynamic_scroll (window, plateau);
|
||||
bool button = false;
|
||||
while (!end)
|
||||
{
|
||||
@ -131,8 +137,6 @@ void en_jeu (SDL_Surface* window, int* hist)
|
||||
}
|
||||
if (gagne)
|
||||
{
|
||||
while (!end)
|
||||
{
|
||||
char new [50];
|
||||
sprintf (new, "Joueur %d Gagne !!", PLAYER(!plateau->player));
|
||||
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);
|
||||
else
|
||||
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_BlitSurface (final, NULL , window, NULL);
|
||||
SDL_FreeSurface (final);
|
||||
SDL_Event e;
|
||||
SDL_WaitEvent (&e);
|
||||
if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
|
||||
SDL_Flip (window);
|
||||
while (!end)
|
||||
{
|
||||
SDL_WaitEvent (&event);
|
||||
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ typedef struct s_plateau {
|
||||
int *hist;
|
||||
int nb_coups;
|
||||
bool player;
|
||||
bool annule;
|
||||
int ia;
|
||||
SDL_Rect menu;
|
||||
}* plateau_t;
|
||||
|
@ -33,8 +33,16 @@ bool d_menu_mouse (plateau_t p, SDL_MouseMotionEvent motion)
|
||||
|
||||
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);
|
||||
m->nb_entries = 7;
|
||||
Affiche_menu(m);
|
||||
int retour;
|
||||
bool end = false;
|
||||
@ -52,29 +60,42 @@ int menu_hist (plateau_t p)
|
||||
switch (retour)
|
||||
{
|
||||
case M_UP:
|
||||
menu_music (p->window, NULL);
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_menu(m);
|
||||
break;
|
||||
case M7_UP:
|
||||
if (cur <= 0)
|
||||
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;
|
||||
case M_LEFT :
|
||||
end = true;
|
||||
break;
|
||||
case M_RIGHT :
|
||||
menu_son (p->window, NULL);
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_menu(m);
|
||||
if (cur >= p->nb_coups - 1)
|
||||
cur = 0;
|
||||
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;
|
||||
case M_DOWN :
|
||||
end = true;
|
||||
break;
|
||||
case M7_DOWN :
|
||||
break;
|
||||
case M_MID :
|
||||
end = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free_menu(m);
|
||||
free (entries[1]);
|
||||
free (entries[2]);
|
||||
free (entries[6]);
|
||||
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_BlitSurface (p->window, NULL, save, NULL);
|
||||
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);
|
||||
m->nb_entries = 7;
|
||||
Affiche_menu(m);
|
||||
@ -282,7 +303,7 @@ int menu_en_jeu_part1 (plateau_t p)
|
||||
retour = M_DOWN;
|
||||
else
|
||||
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)
|
||||
SDL_BlitSurface (save, NULL, p->window, NULL);
|
||||
@ -298,6 +319,13 @@ int menu_en_jeu_part1 (plateau_t p)
|
||||
Affiche_menu(m);
|
||||
break;
|
||||
case M_LEFT :
|
||||
if (p->nb_coups > 0)
|
||||
{
|
||||
menu_hist (p);
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_menu(m);
|
||||
}
|
||||
break;
|
||||
case M_RIGHT :
|
||||
end = true;
|
||||
@ -306,8 +334,13 @@ int menu_en_jeu_part1 (plateau_t p)
|
||||
end = true;
|
||||
break;
|
||||
case M_MID :
|
||||
break;
|
||||
case M7_DOWN :
|
||||
end = true;
|
||||
break;
|
||||
case M7_UP :
|
||||
annuler (p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free_menu(m);
|
||||
@ -332,7 +365,7 @@ int menu_en_jeu (plateau_t p)
|
||||
retour = menu_en_jeu_part1(p);
|
||||
else if (retour == M_RIGHT)
|
||||
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_FreeSurface (save);
|
||||
|
@ -202,7 +202,7 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
|
||||
case M_MID :
|
||||
supprimer (entries [2]);
|
||||
free_liste (liste, nb_sav);
|
||||
int nb_sav = listeSauvegarde(&liste);
|
||||
nb_sav = listeSauvegarde(&liste);
|
||||
if (nb_sav == 0)
|
||||
{
|
||||
liste = malloc(sizeof(char*));
|
||||
|
@ -195,7 +195,7 @@ d_scrolling_t init_dynamic_scroll (SDL_Surface* window, plateau_t p)
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@ -222,7 +222,7 @@ SDL_Event dynamic_scroll (SDL_Surface* window, d_scrolling_t d, plateau_t p)
|
||||
Cadre_scroll (window);
|
||||
d->id = !d->id;
|
||||
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)
|
||||
d->s->msg[1] = create_one_surface (new, param->rgb_j1, d->s->msg[0]->h, window->format->BitsPerPixel);
|
||||
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)
|
||||
{
|
||||
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));
|
||||
char* msg [2] = {"Au tour du Joueur 2", "Au tour du Joueur 1"};
|
||||
SDL_Color c [2] = {param->rgb_j2, param->rgb_j1};
|
||||
|
Loading…
Reference in New Issue
Block a user