fin de partie

This commit is contained in:
Tropicananass 2016-05-03 19:23:11 +02:00
parent 339b363b24
commit 318baf5274
8 changed files with 112 additions and 7 deletions

BIN
bin/hex

Binary file not shown.

View File

@ -3,7 +3,7 @@ CFLAGS=-Wall -g -std=c99 -c
#-lm `sdl-config --cflags --libs` -lSDL_ttf
LDFLAGS=-std=c99 -lm `sdl-config --cflags --libs` -lSDL_ttf -lSDL_gfx -lSDL_mixer
EXEC=bin/hex
SRC=src/hex.c src/affichage_plateau.c src/action_plateau.c src/affichage_menu_principal.c src/window.c src/param.c src/en_jeu.c src/menu_principal.c src/draw.c src/action_menu_principal.c src/sound.c
SRC=src/hex.c src/affichage_plateau.c src/action_plateau.c src/affichage_menu_principal.c src/window.c src/param.c src/en_jeu.c src/menu_principal.c src/draw.c src/action_menu_principal.c src/sound.c src/testJeu.c
#$(wildcard src/*.c)
OBJ=$(SRC:.c=.o)

View File

@ -7,15 +7,18 @@
#include "affichage_plateau.h"
#include "globals.h"
#include "sound.h"
#include "testJeu.h"
void 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)
{
p->grid [c.x * NBSIDE + c.y] = PLAYER(p->player);
p->player = !p->player;
Affiche_hexagon(p, c.x, c.y, PLAYER(p->player));
return testGagne (p->grid, PLAYER(!p->player));
}
return 0;
/*for (int x = 0; x < NBSIDE; ++x)
{
for (int y = 0; y < NBSIDE; ++y)

View File

@ -5,7 +5,7 @@
#include "globals.h"
void selection (plateau_t p, curseur_t c);
int selection (plateau_t p, curseur_t c);
void deplacement (plateau_t p, SDL_Event* event, curseur_t* c);

View File

@ -134,10 +134,10 @@ void Affiche_entry (menu_t m, char* entry, bool pointe)
/* Menu options */
/* Interne */
void print_arrow (SDL_Surface* window, bool side, )
/*void print_arrow (SDL_Surface* window, bool side, )
{
SDL_Surface* arrow = SDL_CreateRGBSurface (SDL_HWSURFACE, 2*m->r, 2*m->r, window->format->BitsPerPixel, 0, 0, 0, 0);
}
}*/
SDL_Rect cadre_options (SDL_Surface* window, int l)
{

View File

@ -38,12 +38,12 @@ void en_jeu (SDL_Surface* window)
plateau = actu_plateau(plateau);
}
else if (event.key.keysym.sym == SDLK_RETURN)
selection (plateau, c);
end = selection (plateau, c);
else if (SDLK_UP <= event.key.keysym.sym && event.key.keysym.sym <= SDLK_LEFT)
deplacement(plateau, &event, &c);
break;
case SDL_MOUSEBUTTONUP:
selection (plateau, c);
end = selection (plateau, c);
break;
case SDL_MOUSEMOTION:
deplacement(plateau, &event, &c);

93
src/testJeu.c Normal file
View File

@ -0,0 +1,93 @@
#include "testJeu.h"
#include "globals.h"
static int taille_ligne = NBSIDE;
int testRecursif(int *tab, int i, int J);
int testCaseDessus(int *tab, int i, int J){
if(tab[i+taille_ligne]==J && testRecursif(tab, i+taille_ligne,J)){//la seconde condition est testée uniquement si la première est vrai donc le testRecursifJ1 sera appelé ssi tab[i+taille_ligne]==J1
return 1;
}
return 0;
}
int testCaseDessous(int *tab, int i, int J){
if(i/taille_ligne>0 && tab[i-taille_ligne]==J && testRecursif(tab, i-taille_ligne,J)){
return 1;
}
return 0;
}
int testCaseG(int *tab, int i, int J){
if(i%taille_ligne!=0){
if(tab[i-1]==J && testRecursif(tab, i-1, J)){
return 1;
}
if(tab[i+taille_ligne-1]==J && testRecursif(tab, i+taille_ligne-1, J)){
return 1;
}
}
return 0;
}
int testCaseD(int *tab, int i, int J){
if(i%taille_ligne!=taille_ligne-1){
if(i/taille_ligne>0 && tab[i-taille_ligne+1]==J && testRecursif(tab, i-taille_ligne+1, J)){
return 1;
}
if(tab[i+1]==J && testRecursif(tab, i+1, J)){
return 1;
}
}
return 0;
}
int testRecursif(int *tab, int i, int J){// ne peut être appelée qu'avec un indice ou il y a un pion du joueur 1 (J1)
tab[i]=tab[i]+2;
if(J==J1){
if(i/taille_ligne==taille_ligne-1){
return 1;
}
return testCaseDessus(tab,i,J) || testCaseG(tab,i,J) || testCaseD(tab,i,J) || testCaseDessous(tab,i,J);
}
else{
if(i%taille_ligne==taille_ligne-1){
return 1;
}
return testCaseD(tab,i,J) || testCaseDessus(tab,i,J) || testCaseDessous(tab,i,J) || testCaseG(tab,i,J);
}
}
int testGagne(int *tab, int J){
int i=0, a=0;
if(J==J1){
while(!a && i<taille_ligne){
if(tab[i]==J1){
a=testRecursif(tab, i, J);
//i++;//si une case à été testé la case adjacente aura forcément été testée donc on peut décaler de 2 cases
}
i++;
}
}
else{
while(!a && i<taille_ligne*taille_ligne){
if(tab[i]==J2){
a=testRecursif(tab, i, J2);
//i=i+taille_ligne;//si une case à été testé la case adjacente aura forcément été testée donc on peut décaler de 2 cases
}
i=i+taille_ligne;
}
}
for(i=0; i<taille_ligne*taille_ligne; i++){
if(tab[i]>J2){
tab[i]=tab[i]-2;
}
}
return a;
}

9
src/testJeu.h Normal file
View File

@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
//enum Joueur{CASEVIDE,J1,J2};
/* 1 si J gagne 0 sinon */
int testGagne(int *tab, int J);