Import release 0.12.
This commit is contained in:
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
750
src/Jeu.cpp
Normal file
750
src/Jeu.cpp
Normal file
@@ -0,0 +1,750 @@
|
||||
/********************************************************************************************/
|
||||
/* Jean-Baptiste NADAL, Jean-Gael REBOUL - PROJET PUISSANCE4 - CSII 3A - 2000/2001 */
|
||||
/********************************************************************************************/
|
||||
|
||||
#include "Jeu.h"
|
||||
#include "time.h"
|
||||
|
||||
// ===================================================================
|
||||
// Le CONSTRUCTEUR ===================================================
|
||||
// ===================================================================
|
||||
// Initialise la plateau : met à vide, poids et tableau colonne ======
|
||||
// ===================================================================
|
||||
Jeu::Jeu()
|
||||
{
|
||||
// initialisation du plateau
|
||||
int i, j;
|
||||
for(i=0; i < 9; i++)
|
||||
{
|
||||
Plateau[i][0][QUI] = BORD;
|
||||
Plateau[i][7][QUI] = BORD;
|
||||
Plateau[i][0][POIDS] = -100;
|
||||
Plateau[i][7][POIDS] = -100;
|
||||
}
|
||||
for (i=1; i < 7; i++)
|
||||
{
|
||||
Plateau[0][i][QUI] = BORD;
|
||||
Plateau[8][i][QUI] = BORD;
|
||||
Plateau[0][i][POIDS] = -100;
|
||||
Plateau[8][i][POIDS] = -100;
|
||||
}
|
||||
for (i=1; i < 8; i++)
|
||||
for(j = 1; j < 7; j++)
|
||||
Plateau[i][j][QUI] = VIDE;
|
||||
|
||||
|
||||
/*
|
||||
-100 -100 -100 -100 -100 -100 -100 -100 -100
|
||||
-100 L H G F G H L -100
|
||||
-100 K F E D E F K -100
|
||||
-100 J E C B C E J -100
|
||||
-100 I D B A B D I -100
|
||||
-100 H E C B C E H -100
|
||||
-100 G F E D E F G -100
|
||||
-100 -100 -100 -100 -100 -100 -100 -100 -100
|
||||
|
||||
*/
|
||||
|
||||
// col 1
|
||||
Plateau[1][1][POIDS] = L_CTE; Plateau[1][2][POIDS] = K_CTE; Plateau[1][3][POIDS] = J_CTE;
|
||||
Plateau[1][4][POIDS] = I_CTE; Plateau[1][5][POIDS] = H_CTE; Plateau[1][6][POIDS] = G_CTE;
|
||||
// col 2
|
||||
Plateau[2][1][POIDS] = H_CTE; Plateau[2][2][POIDS] = F_CTE; Plateau[2][3][POIDS] = E_CTE;
|
||||
Plateau[2][4][POIDS] = D_CTE; Plateau[2][5][POIDS] = E_CTE; Plateau[2][6][POIDS] = F_CTE;
|
||||
// col 3
|
||||
Plateau[3][1][POIDS] = G_CTE; Plateau[3][2][POIDS] = E_CTE; Plateau[3][3][POIDS] = C_CTE;
|
||||
Plateau[3][4][POIDS] = B_CTE; Plateau[3][5][POIDS] = C_CTE; Plateau[3][6][POIDS] = E_CTE;
|
||||
// col 4
|
||||
Plateau[4][1][POIDS] = F_CTE; Plateau[4][2][POIDS] = D_CTE; Plateau[4][3][POIDS] = B_CTE;
|
||||
Plateau[4][4][POIDS] = A_CTE; Plateau[4][5][POIDS] = B_CTE; Plateau[4][6][POIDS] = D_CTE;
|
||||
// col 5
|
||||
Plateau[5][1][POIDS] = G_CTE; Plateau[5][2][POIDS] = E_CTE; Plateau[5][3][POIDS] = C_CTE;
|
||||
Plateau[5][4][POIDS] = B_CTE; Plateau[5][5][POIDS] = C_CTE; Plateau[5][6][POIDS] = E_CTE;
|
||||
// col 6
|
||||
Plateau[6][1][POIDS] = H_CTE; Plateau[6][2][POIDS] = F_CTE; Plateau[6][3][POIDS] = E_CTE;
|
||||
Plateau[6][4][POIDS] = D_CTE; Plateau[6][5][POIDS] = E_CTE; Plateau[6][6][POIDS] = F_CTE;
|
||||
// col 7
|
||||
Plateau[7][1][POIDS] = L_CTE; Plateau[7][2][POIDS] = K_CTE; Plateau[7][3][POIDS] = J_CTE;
|
||||
Plateau[7][4][POIDS] = I_CTE; Plateau[7][5][POIDS] = H_CTE; Plateau[7][6][POIDS] = G_CTE;
|
||||
|
||||
// Pour les Colonnes
|
||||
for (i = 1; i < 8; i++)
|
||||
CaseCol[i] = 6;
|
||||
// Joueur Courant :
|
||||
JCo = J1;
|
||||
Fini = false;
|
||||
|
||||
// un petit random pour l'évaluation
|
||||
srand( (unsigned)time( NULL ) );
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Le DESTRUCTEUR ====================================================
|
||||
// ===================================================================
|
||||
Jeu::~Jeu()
|
||||
{
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// AFFICHE LE PLATEAU (pas beau !) ===================================
|
||||
// ===================================================================
|
||||
void Jeu::AffichePlateau()
|
||||
{
|
||||
int i, j;
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
//cout << "------------------------------------" << endl;
|
||||
for (i = 0; i < 9; i++)
|
||||
{
|
||||
cout << "| ";
|
||||
if (Plateau[i][j][QUI] == BORD) cout << "B";
|
||||
else
|
||||
if (Plateau[i][j][QUI] == VIDE) cout << " ";
|
||||
else
|
||||
if (Plateau[i][j][QUI] == J1) cout << "O";
|
||||
else
|
||||
if (Plateau[i][j][QUI] == J2) cout << "X";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===================================================================
|
||||
// AFFICHE LES POIDS DU PLATEAU (pas beau !) =========================
|
||||
// ===================================================================
|
||||
void Jeu::AffichePlateau_Poids()
|
||||
{
|
||||
int i, j;
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
cout << "------------------------------------" << endl;
|
||||
for (i = 0; i < 9; i++)
|
||||
{
|
||||
cout << "| ";
|
||||
cout << Plateau[i][j][POIDS];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// INITIALISE LE JOUEUR ORDINATEUR ===================================
|
||||
// ===================================================================
|
||||
void Jeu::setJO(int i)
|
||||
{
|
||||
if (i == 1)
|
||||
JO = J1;
|
||||
else
|
||||
JO = J2;
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// FONCTION DONNANT LA MAIN : ========================================
|
||||
// -> Soit fait jouer l'ordinateur ==================================
|
||||
// -> Soit interroge le joueur humain ===============================
|
||||
// ===================================================================
|
||||
void Jeu::DonneMain()
|
||||
{
|
||||
bool Pasjouer = true;
|
||||
int col=0;
|
||||
|
||||
AffichePlateau();
|
||||
if (JCo == JO)
|
||||
{
|
||||
// c'est l'ordi qui joue
|
||||
cout << "L'ordinateur doit jouer !" << endl;
|
||||
// ici, on met en place min-max (puis, l'alpha-beta)
|
||||
col = CalculCoup(Niv);
|
||||
Joue(JCo, col);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (Pasjouer)
|
||||
{
|
||||
// c'est l'humain
|
||||
cout << "---------------------------" << endl;
|
||||
cout << "| | 1| 2| 3| 4| 5| 6| 7| |" << endl;
|
||||
cout << "---------------------------" << endl;
|
||||
//cout << " Dans quelle colonne jouez-vous ?" << endl;
|
||||
cin >> col;
|
||||
// on vérifie que la colonne ne soit pas remplie
|
||||
if (col > 0 && col < 8 && CaseCol[col]!=0)
|
||||
{
|
||||
Joue(JCo, col);
|
||||
Pasjouer = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// on vérifie si le joueur courant n'a pas gagné.
|
||||
if (Gagne(col))
|
||||
{
|
||||
AffichePlateau();
|
||||
if (JCo == JO)
|
||||
cout << "Le joueur ORDINATEUR vous a ecrase." << endl;
|
||||
else
|
||||
cout << "Vous venez d'ecraser le joueur ORDINATEUR." << endl;
|
||||
setFini();
|
||||
}
|
||||
else
|
||||
// LE JOUEUR COURANT A JOUE ET N'A PAS GAGNE, LE JOUEUR COURANT CHANGE
|
||||
JCo *= -1;
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// Cette fonction fait joueur le joueur humain
|
||||
bool Jeu::JoueHumain( int numCol )
|
||||
{
|
||||
// -- Variables locales
|
||||
bool resultat=false;
|
||||
// -- Fin Variables locales
|
||||
|
||||
if (numCol > 0 && numCol < 8 && CaseCol[numCol]!=0)
|
||||
Joue(JCo, numCol);
|
||||
|
||||
// on vérifie si le joueur courant n'a pas gagné.
|
||||
//jige resultat = Gagne(numCol, CaseCol[numCol]+1);
|
||||
resultat = Gagne(numCol);
|
||||
|
||||
if (resultat)
|
||||
setFini();
|
||||
else
|
||||
JCo *= -1;
|
||||
|
||||
return resultat;
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// Cette fonction fait jouer l'ordi et retourne la case que
|
||||
// celui-ci a joué
|
||||
int Jeu::JoueOrdi()
|
||||
{
|
||||
// On calcul le coup qu'il va jouer
|
||||
return CalculCoup(Niv);
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// On finit de faire jouer l'ordinateur
|
||||
bool Jeu::FiniJoueOrdi( int numCol )
|
||||
{
|
||||
return JoueHumain(numCol);
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Vérifie si le Joueur courant n'a pas gagné ========================
|
||||
// ===================================================================
|
||||
bool Jeu::Gagne(const int x)
|
||||
{
|
||||
int i, j;
|
||||
int y = CaseCol[x] + 1;
|
||||
int JoueurCourant = Plateau[x][y][QUI];
|
||||
bool continuer = true;
|
||||
int naligner = 1;
|
||||
/*
|
||||
(i-1, j+1) | (i, j+1) | (i+1, j+1)
|
||||
(i-1, j) | (i=x, j=y) | (i+1, j)
|
||||
(i-1, j-1) | (i, j-1) | (i+1, j-1)
|
||||
|
||||
*/
|
||||
// direction 1 ----------------------------------- diag droite
|
||||
i = x+1;
|
||||
j = y+1;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i++][j++][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
continuer = true;
|
||||
i = x-1;
|
||||
j = y-1;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i--][j--][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
// direction 2 ---------------------------------- vert
|
||||
naligner = 1;
|
||||
continuer = true;
|
||||
i = x;
|
||||
j = y+1;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i][j++][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
continuer = true;
|
||||
i = x;
|
||||
j = y-1;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i][j--][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
// direction 3 ---------------------------------- diag gauche
|
||||
naligner = 1;
|
||||
continuer = true;
|
||||
i = x-1;
|
||||
j = y+1;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i--][j++][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
continuer = true;
|
||||
i = x+1;
|
||||
j = y-1;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i++][j--][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
// direction 4 ---------------------------------- horiz
|
||||
naligner = 1;
|
||||
continuer = true;
|
||||
i = x-1;
|
||||
j = y;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i--][j][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
continuer = true;
|
||||
i = x+1;
|
||||
j = y;
|
||||
while(continuer)
|
||||
{
|
||||
if (Plateau[i++][j][QUI] == JoueurCourant)
|
||||
naligner++;
|
||||
else
|
||||
continuer = false;
|
||||
}
|
||||
if (naligner >= 4)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Jeu::Joue(int joueur, int col)
|
||||
{
|
||||
if (CaseCol[col] != 0)
|
||||
{
|
||||
Plateau[col][CaseCol[col]][QUI] = joueur;
|
||||
CaseCol[col] = CaseCol[col] - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Jeu::DeJoue(int col)
|
||||
{
|
||||
if (CaseCol[col] != 6)
|
||||
{
|
||||
CaseCol[col] = CaseCol[col] + 1;
|
||||
Plateau[col][CaseCol[col]][QUI] = VIDE;
|
||||
}
|
||||
}
|
||||
|
||||
int Jeu::Evalue(const int& i, const int& j, const int& jo) const
|
||||
// retourne un incrément ou -1 quand il faut s'arrêter
|
||||
{
|
||||
int qui = Plateau[i][j][QUI];
|
||||
if (qui == VIDE)
|
||||
return 0;
|
||||
if (qui == jo)
|
||||
return Plateau[i][j][POIDS];
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int Jeu::Evalue(int col)
|
||||
// les gd principes de l'évaluation : il faut retourner la valeur max pour ce pion :
|
||||
// ==> si pas possible de gagner
|
||||
// si possibilité d'en aligner 4 :
|
||||
// poids + nb d'aligner avec poids des alignés + dliberté
|
||||
// sinon une valeur nulle.
|
||||
// ==> sinon, si gagne, alors retourne INFINI (nbaligner = 4)
|
||||
{
|
||||
// on a déjà posé le pion ici ==> x = col, y = CaseCol[col] + 1
|
||||
int x = col;
|
||||
int y = CaseCol[col] + 1;
|
||||
int joCo = Plateau[x][y][QUI];
|
||||
int joCopoids = Plateau[x][y][POIDS];
|
||||
// pour les variables locales
|
||||
int i, j;
|
||||
// nombre de pions alignés, nombre de vide aligné -------------
|
||||
int naligner = joCopoids,
|
||||
nalpion=1,
|
||||
nalignermax=1,
|
||||
nalignervidemax=0,
|
||||
nalignervide = 0,
|
||||
retEvalue;
|
||||
bool continuer = true;
|
||||
// direction 1 ----------------------------------- diag droite
|
||||
i = x+1;
|
||||
j = y+1;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 3)
|
||||
continuer = false;
|
||||
break;
|
||||
default:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
continuer = true;
|
||||
i = x-1;
|
||||
j = y-1;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 6)
|
||||
continuer = false;
|
||||
break;
|
||||
case 1:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
j--;
|
||||
}
|
||||
if (nalpion >= 4)
|
||||
return INFINI; // gagné !
|
||||
nalignermax = naligner;
|
||||
nalignervidemax = nalignervide;
|
||||
// direction 2 ---------------------------------- vert
|
||||
naligner=joCopoids;
|
||||
nalpion=1;
|
||||
nalignervide=0;
|
||||
continuer = true;
|
||||
i = x;
|
||||
j = y+1;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 3)
|
||||
continuer = false;
|
||||
break;
|
||||
case 1:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
continuer = true;
|
||||
i = x;
|
||||
j = y-1;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 6)
|
||||
continuer = false;
|
||||
break;
|
||||
case 1:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
j--;
|
||||
}
|
||||
if (nalpion >= 4)
|
||||
return INFINI; // gagné !
|
||||
if (nalignermax <= naligner)
|
||||
{
|
||||
nalignermax = naligner;
|
||||
if (nalignervidemax < nalignervide)
|
||||
nalignervidemax = nalignervide;
|
||||
}
|
||||
// direction 3 ---------------------------------- diag gauche
|
||||
naligner=joCopoids;
|
||||
nalpion=1;
|
||||
nalignervide=0;
|
||||
continuer = true;
|
||||
i = x-1;
|
||||
j = y+1;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 3)
|
||||
continuer = false;
|
||||
break;
|
||||
case 1:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
j++;
|
||||
}
|
||||
continuer = true;
|
||||
i = x+1;
|
||||
j = y-1;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 6)
|
||||
continuer = false;
|
||||
break;
|
||||
case 1:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
if (nalpion >= 4)
|
||||
return INFINI; // gagner
|
||||
if (nalignermax <= naligner)
|
||||
{
|
||||
nalignermax = naligner;
|
||||
if (nalignervidemax < nalignervide)
|
||||
nalignervidemax = nalignervide;
|
||||
}
|
||||
// direction 4 ---------------------------------- horiz
|
||||
naligner=joCopoids;
|
||||
nalpion=1;
|
||||
nalignervide=0;
|
||||
continuer = true;
|
||||
i = x-1;
|
||||
j = y;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 3)
|
||||
continuer = false;
|
||||
break;
|
||||
case 1:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
continuer = true;
|
||||
i = x+1;
|
||||
j = y;
|
||||
while(continuer)
|
||||
{
|
||||
retEvalue = Evalue(i, j, joCo);
|
||||
switch(retEvalue)
|
||||
{
|
||||
case -1:
|
||||
continuer = false;
|
||||
break;
|
||||
case 0:
|
||||
nalignervide++;
|
||||
if (nalignervide > 6)
|
||||
continuer = false;
|
||||
break;
|
||||
case 1:
|
||||
naligner+=retEvalue;
|
||||
nalpion++;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (nalpion >= 4)
|
||||
return INFINI; // gagner
|
||||
if (nalignermax <= naligner)
|
||||
{
|
||||
nalignermax = naligner;
|
||||
if (nalignervidemax < nalignervide)
|
||||
nalignervidemax = nalignervide;
|
||||
}
|
||||
|
||||
int dliberte=1;
|
||||
// nombre de degré de liberté ---------
|
||||
if (Plateau[x-1][y-1][QUI] == VIDE || Plateau[x-1][y-1][QUI] == joCo) dliberte++;
|
||||
if (Plateau[x][y-1][QUI] == VIDE || Plateau[x][y-1][QUI] == joCo) dliberte++;
|
||||
if (Plateau[x+1][y-1][QUI] == VIDE || Plateau[x+1][y-1][QUI] == joCo) dliberte++;
|
||||
if (Plateau[x-1][y][QUI] == VIDE || Plateau[x-1][y][QUI] == joCo) dliberte++;
|
||||
if (Plateau[x+1][y][QUI] == VIDE || Plateau[x+1][y][QUI] == joCo) dliberte++;
|
||||
if (Plateau[x-1][y+1][QUI] == VIDE || Plateau[x-1][y+1][QUI] == joCo) dliberte++;
|
||||
if (Plateau[x+1][y+1][QUI] == VIDE || Plateau[x+1][y+1][QUI] == joCo) dliberte++;
|
||||
|
||||
// on ajoute à tout ça le poids de la case
|
||||
//return (nalignermax+joCopoids)*joCopoids + (nalignervidemax * dliberte);
|
||||
//return (((nalignermax*joCopoids)+dliberte*joCopoids)+nalignervidemax)*joCopoids;
|
||||
//return nalignermax*joCopoids;
|
||||
//return ((nalignermax*joCopoids)+(nalignervidemax*dliberte))*joCopoids;
|
||||
//return ((nalignermax+(dliberte*joCopoids))+nalignervidemax)*joCopoids;
|
||||
//return ((((nalignermax*joCopoids)+dliberte)*joCopoids)+nalignervidemax)*joCopoids;
|
||||
//return ((nalignermax+dliberte*joCopoids)+nalignervidemax)*joCopoids;
|
||||
//return (nalignermax*joCopoids) + (dliberte+nalignervidemax)*joCopoids;
|
||||
//return ((nalignermax*joCopoids) + dliberte+nalignervidemax)*joCopoids;
|
||||
//return ((nalignermax+(nalpion*joCopoids)) + dliberte+nalignervidemax)*joCopoids;
|
||||
//return nalignervidemax + dliberte + nalpion + nalignermax*joCopoids;
|
||||
//return nalignervidemax + dliberte + nalpion + nalignermax*joCopoids;
|
||||
return nalignervidemax + dliberte + nalpion + nalignermax*joCopoids + rand()%30;
|
||||
}
|
||||
|
||||
|
||||
int Jeu::CalculCoup(int Niveau)
|
||||
{
|
||||
int col=-1, c=-1;
|
||||
JoueVirtuel_MinMax(Niveau, col, JCo, c, true);
|
||||
return col;
|
||||
}
|
||||
|
||||
int Jeu::JoueVirtuel_MinMax(int Niveau, int& col, int jCo, int &c, bool racine)
|
||||
{
|
||||
int i, M, T;
|
||||
bool continuer = true;
|
||||
if (Niveau%2==0)
|
||||
M = INFINI+1;
|
||||
else
|
||||
M = -INFINI-1;
|
||||
for (i = 1; i < 8; i++)
|
||||
// pour toutes les colonnes
|
||||
{
|
||||
if (CaseCol[i] != 0)
|
||||
// si colonne non remplie
|
||||
{
|
||||
c=-1;
|
||||
Joue(jCo, i);
|
||||
if (Gagne(i))
|
||||
{
|
||||
if (racine) // premier coup de l'ordinateur
|
||||
{ // l'ordinateur gagne. on réfléchit plus, on joue
|
||||
col = i;
|
||||
DeJoue(i);
|
||||
return i*-1;
|
||||
}
|
||||
if (Niveau == Niv-1) // 1er coup de l'adversaire
|
||||
// c'est l'adversaire qui gagne, on doit forcément jouer
|
||||
// dans cette colonne. sinon : on perd !
|
||||
// sauf si... col de l'humain = col de l'ordi
|
||||
{
|
||||
c = i;
|
||||
DeJoue(i);
|
||||
return Evalue(i);
|
||||
}
|
||||
if (Niveau == Niv-3) // 2eme coup de l'adversaire
|
||||
// c'est l'adversaire qui gagne, on doit forcément jouer
|
||||
// dans cette colonne. sinon : on perd !
|
||||
// sauf si... col de l'humain = col de l'ordi
|
||||
{
|
||||
c = i;
|
||||
DeJoue(i);
|
||||
return Evalue(i)/2;
|
||||
}
|
||||
}
|
||||
if (Niveau == 1)
|
||||
{
|
||||
T = Evalue(i);
|
||||
if (T >= M)
|
||||
M = T; // MAJ du max de l'adversaire
|
||||
} // fin if Niveau == 0
|
||||
else
|
||||
{
|
||||
T = JoueVirtuel_MinMax(Niveau-1, col, jCo*-1, c);
|
||||
if (Niveau%2 == 0) // noeud ou on maximise
|
||||
{
|
||||
if (racine)
|
||||
{
|
||||
//debug cout << "COL = " << i << ", T = " << T << ", M = " << M << ", C = " << c << " [JOrdinateur = " << jCo << "]" << endl;
|
||||
if (c != -1 && c != i)
|
||||
{
|
||||
col = c;
|
||||
DeJoue(i);
|
||||
return 1;
|
||||
}
|
||||
if (T < M)
|
||||
col = i; // SAV
|
||||
}
|
||||
if (T < M)
|
||||
M = T; // MAJ du MIN de l'adversaire
|
||||
} // fin niveau pair
|
||||
else // noeud ou on minimise
|
||||
{
|
||||
if (T >= M)
|
||||
M = T; // MAJ du MAX de l'adversaire
|
||||
}
|
||||
}
|
||||
DeJoue(i);
|
||||
}
|
||||
}
|
||||
return M;
|
||||
}
|
||||
43
src/Jeu.h
Normal file
43
src/Jeu.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// Jeu.h: interface for the Jeu class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "commun.h"
|
||||
#include <iostream.h>
|
||||
//#include <stdlib.h>
|
||||
|
||||
class Jeu
|
||||
{
|
||||
public:
|
||||
int JO; // Joueur Ordinateur
|
||||
int Niv; // Niveau de l'IA
|
||||
int JCo; // Joueur Courant
|
||||
bool Fini;
|
||||
int CaseCol[9];
|
||||
|
||||
Jeu();
|
||||
virtual ~Jeu();
|
||||
int getJO(){ return JO; }
|
||||
int getJcourant() { return JCo; }
|
||||
int Plateau[9][8][2]; // 0 : qui; 1 : poids
|
||||
void AffichePlateau();
|
||||
void AffichePlateau_Poids();
|
||||
void setJO(int i);
|
||||
void DonneMain();
|
||||
void setFini() {Fini = true;}
|
||||
bool getFini() {return Fini;}
|
||||
bool Gagne(int);
|
||||
bool JoueHumain( int numCol);
|
||||
int JoueOrdi();
|
||||
bool FiniJoueOrdi( int numCol );
|
||||
|
||||
// pour l'IA
|
||||
void Joue(int j, int c);
|
||||
void DeJoue(int c);
|
||||
int Evalue(int);
|
||||
int Evalue(const int& i, const int& j, const int& jo) const;
|
||||
int CalculCoup(int);
|
||||
int JoueVirtuel_MinMax(int Niveau, int&, int, int&, bool=false);
|
||||
};
|
||||
|
||||
|
||||
39
src/Makefile
Normal file
39
src/Makefile
Normal file
@@ -0,0 +1,39 @@
|
||||
#################################################
|
||||
# Makefile pour KNRPuissance4
|
||||
# Reboul Jean-Gael
|
||||
# NADAL Jean-Baptiste
|
||||
#
|
||||
# Octobre 2000
|
||||
#
|
||||
#################################################
|
||||
|
||||
#flags de compilations
|
||||
|
||||
CXX=g++
|
||||
CXXFLAGS= -O7 -DCPU=586 -Wall -I/usr/local/include/SDL/ -D_REENTRANT
|
||||
#LDFLAGS= -Xlinker -s -L. -lSDL
|
||||
LDFLAGS= -Xlinker -s -L/usr/local/lib -lSDL -lSDL_image -lpthread
|
||||
|
||||
OFICHIERS=\
|
||||
main.o plateauview.o csprite.o cpion.o Jeu.o cintro.o
|
||||
|
||||
CFICHIERS=\
|
||||
main.cpp plateauview.cpp csprite.cpp cpion.cpp Jeu.cpp cintro.cpp
|
||||
|
||||
#defintion de la cible all
|
||||
all: clear knrpuissance4
|
||||
|
||||
clear:
|
||||
@ echo; echo -e "on efface tout\n";\
|
||||
/usr/bin/clear;
|
||||
|
||||
clean: Makefile.deps
|
||||
-rm -f *.o *~ knrpuissance4
|
||||
|
||||
knrpuissance4: $(OFICHIERS)
|
||||
$(CXX) $(CFLAGS) -o knrpuissance4 $(LDFLAGS) $(OFICHIERS)
|
||||
|
||||
Makefile.deps:
|
||||
$(CXX) -MM $(CFLAGS) $(CFICHIERS) > Makefile.deps
|
||||
|
||||
include Makefile.deps
|
||||
6
src/Makefile.deps
Normal file
6
src/Makefile.deps
Normal file
@@ -0,0 +1,6 @@
|
||||
main.o: main.cpp
|
||||
plateauview.o: plateauview.cpp plateauview.h
|
||||
csprite.o: csprite.cpp csprite.h
|
||||
cpion.o: cpion.cpp cpion.h
|
||||
Jeu.o: Jeu.cpp Jeu.h
|
||||
cintro.o: cintro.cpp cintro.h
|
||||
119
src/cintro.cpp
Normal file
119
src/cintro.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/***************************************************************************
|
||||
cintro.cpp - description
|
||||
-------------------
|
||||
begin : Sat Nov 18 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "cintro.h"
|
||||
|
||||
#include "csprite.h"
|
||||
|
||||
#include <iostream.h> // pour cout deboug
|
||||
|
||||
// =================================================
|
||||
// Constructeur
|
||||
CIntro::CIntro(SDL_Surface* pecran )
|
||||
{
|
||||
spt_boiteIntro = new CSprite (pecran,50,100,"boite_intro.png");
|
||||
pCurseur = new CSprite (pecran,140,210,"pointeur.png");
|
||||
ecran = pecran;
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Destructeur
|
||||
CIntro::~CIntro()
|
||||
{
|
||||
delete spt_boiteIntro;
|
||||
delete pCurseur;
|
||||
}
|
||||
|
||||
|
||||
// =================================================
|
||||
// Lancement : Permet d'afficher l'intro et de selection
|
||||
// quel joueur commence
|
||||
int CIntro::Lancement()
|
||||
{
|
||||
// Variable locales
|
||||
SDL_Event event;
|
||||
int done;
|
||||
int nResultat = 0;
|
||||
Uint32 couleurfond;
|
||||
// Fin Variables locales
|
||||
|
||||
spt_boiteIntro->show();
|
||||
// pCurseur->show();
|
||||
|
||||
// On recupere la couleur de fond pour les sprites
|
||||
couleurfond = SDL_MapRGB( ecran->format,0xde,0xde,0xde );
|
||||
|
||||
done = 0;
|
||||
while ( !done )
|
||||
{
|
||||
SDL_WaitEvent(&event);
|
||||
|
||||
switch ( event.type )
|
||||
{
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if ( nResultat != 0 )
|
||||
done=1;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (( event.motion.y >212 ) && (event.motion.y < 245 ))
|
||||
{
|
||||
if ( nResultat !=2 )
|
||||
{
|
||||
if ( nResultat == 1 )
|
||||
pCurseur->Hide(couleurfond);
|
||||
|
||||
pCurseur->SetPosY(210);
|
||||
pCurseur->show();
|
||||
SDL_Flip(ecran);
|
||||
nResultat = 2;
|
||||
} // fin if
|
||||
}
|
||||
else if (( event.motion.y >262 ) && (event.motion.y < 295 ))
|
||||
{
|
||||
if ( nResultat !=1 )
|
||||
{
|
||||
if ( nResultat == 2 )
|
||||
pCurseur->Hide(couleurfond);
|
||||
|
||||
pCurseur->SetPosY(265);
|
||||
pCurseur->show();
|
||||
SDL_Flip(ecran);
|
||||
nResultat = 1;
|
||||
} // fin if
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( nResultat !=0 )
|
||||
{
|
||||
pCurseur->Hide(couleurfond);
|
||||
nResultat =0;
|
||||
SDL_Flip(ecran);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
nResultat = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} // fin switch
|
||||
|
||||
} // fin while
|
||||
|
||||
return nResultat;
|
||||
}
|
||||
50
src/cintro.h
Normal file
50
src/cintro.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/***************************************************************************
|
||||
cintro.h - description
|
||||
-------------------
|
||||
begin : Sat Nov 18 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CINTRO_H
|
||||
#define CINTRO_H
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
|
||||
// dépendance
|
||||
class CSprite;
|
||||
|
||||
/**
|
||||
*@author NADAL Jean-Baptiste
|
||||
*/
|
||||
|
||||
class CIntro {
|
||||
public:
|
||||
// =================================================
|
||||
// Constructeur
|
||||
CIntro(SDL_Surface* pecran);
|
||||
// =================================================
|
||||
// Destructeur
|
||||
~CIntro();
|
||||
// =================================================
|
||||
// Lancement : Permet d'afficher l'intro et de selection
|
||||
// quel joueur commence
|
||||
int Lancement();
|
||||
|
||||
private:
|
||||
CSprite* spt_boiteIntro;
|
||||
CSprite* pCurseur;
|
||||
SDL_Surface* ecran;
|
||||
};
|
||||
|
||||
#endif
|
||||
35
src/commun.h
Normal file
35
src/commun.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/********************************************************************************************/
|
||||
/* Jean-Baptiste NADAL, Jean-Gael REBOUL - PROJET PUISSANCE4 - CSII 3A - 2000/2001 */
|
||||
/********************************************************************************************/
|
||||
|
||||
#ifndef COMMUN_H
|
||||
#define COMMUN_H
|
||||
|
||||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define QUI 0
|
||||
#define POIDS 1
|
||||
|
||||
#define INFINI 30000
|
||||
|
||||
#define BORD 0
|
||||
#define VIDE 2
|
||||
#define J1 1
|
||||
#define J2 -1
|
||||
|
||||
|
||||
#define A_CTE 50
|
||||
#define B_CTE 45
|
||||
#define C_CTE 40
|
||||
#define D_CTE 35
|
||||
#define E_CTE 30
|
||||
#define F_CTE 25
|
||||
#define G_CTE 20
|
||||
#define H_CTE 15
|
||||
#define I_CTE 10
|
||||
#define J_CTE 5
|
||||
#define K_CTE 2
|
||||
#define L_CTE 1
|
||||
#endif
|
||||
25
src/config.h
Normal file
25
src/config.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/***************************************************************************
|
||||
config.h - description
|
||||
-------------------
|
||||
begin : Sun Oct 29 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#define VERSION "0.12"
|
||||
|
||||
#define Coef_ALPHA 220
|
||||
|
||||
#endif
|
||||
83
src/cpion.cpp
Normal file
83
src/cpion.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/***************************************************************************
|
||||
cpion.cpp - description
|
||||
-------------------
|
||||
begin : Tue Oct 31 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
//#include <iostream.h>
|
||||
#include "cpion.h"
|
||||
|
||||
// =================================================
|
||||
// Constructeur de la classe
|
||||
CPion::CPion(SDL_Surface *surface,Uint16 posX,Uint16 posY, char* fichier, CSprite* pP)
|
||||
: CSprite (surface,posX,posY, fichier)
|
||||
{
|
||||
pPlateau = pP;
|
||||
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Constructeur de la classe dont on ne passe pas
|
||||
// que le strict minimum
|
||||
CPion::CPion( SDL_Surface *surface, char* fichier, CSprite* pP )
|
||||
: CSprite (surface, fichier)
|
||||
{
|
||||
pPlateau = pP;
|
||||
}
|
||||
|
||||
|
||||
//CPion::CPion(){}
|
||||
|
||||
CPion::~CPion(){
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// cette fonction permet de faire glisser un pion
|
||||
// de sa position actuelle vers sa nouvelle position
|
||||
void CPion::Glisse(int nHauteur)
|
||||
{
|
||||
// -- Variables locales
|
||||
int nHauteurfinale=0;
|
||||
// -- Fin Variables locales
|
||||
|
||||
switch(nHauteur)
|
||||
{
|
||||
case 1: nHauteurfinale=60; break;
|
||||
case 2: nHauteurfinale=126; break;
|
||||
case 3: nHauteurfinale=194; break;
|
||||
case 4: nHauteurfinale=262; break;
|
||||
case 5: nHauteurfinale=330; break;
|
||||
case 6: nHauteurfinale=398; break;
|
||||
}// fin switch
|
||||
|
||||
while ( Pos.y <= nHauteurfinale )
|
||||
{
|
||||
SDL_LockSurface(pSurface);
|
||||
Hide();
|
||||
Pos.y+=4;
|
||||
show();
|
||||
pPlateau->show();
|
||||
SDL_Flip(pSurface);
|
||||
SDL_UnlockSurface(pSurface);
|
||||
} // fin while
|
||||
|
||||
Pos.y = nHauteurfinale;
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette fonction retourne vrai si le pion se trouve en
|
||||
// haut de l'échiquier
|
||||
bool CPion::enHaut()
|
||||
{
|
||||
return ( Pos.y ==0 );
|
||||
}
|
||||
54
src/cpion.h
Normal file
54
src/cpion.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
cpion.h - description
|
||||
-------------------
|
||||
begin : Tue Oct 31 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CPION_H
|
||||
#define CPION_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include "csprite.h"
|
||||
|
||||
/**
|
||||
*@author NADAL Jean-Baptiste
|
||||
*/
|
||||
|
||||
class CPion : public CSprite {
|
||||
public:
|
||||
// =================================================
|
||||
// Constructeur de la classe
|
||||
CPion(SDL_Surface *surface,Uint16 posX,Uint16 posY, char* fichier, CSprite* pP );
|
||||
// =================================================
|
||||
// Constructeur de la classe dont on ne passe pas
|
||||
// que le strict minimum
|
||||
CPion( SDL_Surface *surface, char* fichier, CSprite* pP );
|
||||
// =================================================
|
||||
// Destructeur
|
||||
virtual ~CPion();
|
||||
// =================================================
|
||||
// cette fonction permet de faire glisser un pion
|
||||
// de sa position actuelle vers sa nouvelle position
|
||||
void Glisse(int nHauteur);
|
||||
// =================================================
|
||||
// Cette fonction retourne vrai si le pion se trouve en
|
||||
// haut de l'échiquier
|
||||
bool enHaut();
|
||||
|
||||
private:
|
||||
CSprite* pPlateau;
|
||||
};
|
||||
|
||||
#endif
|
||||
175
src/csprite.cpp
Normal file
175
src/csprite.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/***************************************************************************
|
||||
csprite.cpp - description
|
||||
-------------------
|
||||
begin : Mon Oct 30 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "csprite.h"
|
||||
|
||||
#include <SDL_image.h>
|
||||
|
||||
#include <iostream.h> // pour cout et cerr
|
||||
|
||||
// =================================================
|
||||
// Constructeur de la classe dont on passe
|
||||
// la position de départ
|
||||
CSprite::CSprite( SDL_Surface *surface,Uint16 posX,Uint16 posY, char* fichier )
|
||||
{
|
||||
// On initialise les differents champs de la classe
|
||||
pSurface = surface;
|
||||
Pos.x = posX;
|
||||
Pos.y = posY;
|
||||
Pos.w = 0;
|
||||
Pos.h = 0;
|
||||
pData = NULL;
|
||||
// la couleur de fond sera noire
|
||||
nCouleurFond = SDL_MapRGB(pSurface->format, 0x00, 0x00, 0x00);
|
||||
// puis on charge les donnees du sprite
|
||||
initDonnee(fichier);
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Constructeur de la classe dont on ne passe pas
|
||||
// que le strict minimum
|
||||
CSprite::CSprite( SDL_Surface *surface, char* fichier )
|
||||
{
|
||||
// On initialise les differents champs de la classe
|
||||
pSurface = surface;
|
||||
Pos.x = 0;
|
||||
Pos.y = 0;
|
||||
Pos.w = 0;
|
||||
Pos.h = 0;
|
||||
pData = NULL;
|
||||
// la couleur de fond sera noire
|
||||
nCouleurFond = SDL_MapRGB(pSurface->format, 0x00, 0x00, 0x00);
|
||||
|
||||
// puis on charge les donnees du sprite
|
||||
initDonnee(fichier);
|
||||
}
|
||||
|
||||
|
||||
// =================================================
|
||||
// Destructeur
|
||||
CSprite::~CSprite()
|
||||
{
|
||||
// on supprime les donnée du sprite
|
||||
SDL_FreeSurface(pData);
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette méthode permet de charger le fichier du sprite
|
||||
// et de mettre le premier pixel de l'image comme couleur
|
||||
// de transparance
|
||||
void CSprite::initDonnee(char* szFichier)
|
||||
{
|
||||
// -- Variables locales
|
||||
SDL_Surface *temp;
|
||||
// -- Fin Variables locales
|
||||
|
||||
// On charge l'image
|
||||
pData = IMG_Load(szFichier);
|
||||
// On vérifie que l'image c'est bien chargée
|
||||
if ( pData == NULL )
|
||||
{
|
||||
cerr <<"<ERREUR> : Impossible de chargé "<<szFichier<<" : "<<SDL_GetError()<<endl;
|
||||
return;
|
||||
} // fin if
|
||||
|
||||
// on stocke maintenant la largeur et la hauteur de l'image
|
||||
Pos.w = pData->w;
|
||||
Pos.h = pData->h;
|
||||
|
||||
// on signal que la couleur du premier pixel (0,0) de l'image est la couleur
|
||||
// de transparance du sprite
|
||||
SDL_SetColorKey(pData,(SDL_SRCCOLORKEY|SDL_RLEACCEL) ,*(Uint32 *)pData->pixels);
|
||||
|
||||
// Puis pour des question d'optimisation, on transforme l'image du sprite dans le meme
|
||||
// mode que celui du mode X courant
|
||||
temp = SDL_DisplayFormat(pData);
|
||||
SDL_FreeSurface(pData);
|
||||
if ( temp == NULL )
|
||||
{
|
||||
cerr <<"<ERREUR> Impossible de convertir l'arrière plan: "<<SDL_GetError()<<endl;
|
||||
return;
|
||||
} // fin if
|
||||
|
||||
pData = temp;
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette méthode permet d'afficher le sprite
|
||||
void CSprite::show()
|
||||
{
|
||||
SDL_BlitSurface(pData, NULL, pSurface, &Pos);
|
||||
//SDL_Flip(pSurface);
|
||||
//SDL_UpdateRects(pSurface, 1, &Pos);
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette méthode permet d'afficher le sprite
|
||||
// Avec un coeficient de transparence
|
||||
void CSprite::showA(int val)
|
||||
{
|
||||
SDL_SetAlpha(pData, SDL_SRCALPHA, val);
|
||||
SDL_BlitSurface(pData, NULL, pSurface, &Pos);
|
||||
}
|
||||
|
||||
|
||||
// =================================================
|
||||
// Cette méthode permet de cacher un sprite si la surface a l'arrière plan
|
||||
// est un fond uni
|
||||
void CSprite::Hide()
|
||||
{
|
||||
Uint32 color=0;
|
||||
SDL_FillRect(pSurface, &Pos, color );//nCouleurFond);
|
||||
//SDL_Flip(pSurface);
|
||||
//SDL_UpdateRects(pSurface, 1, &Pos);
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette méthode permet de cacher un sprite
|
||||
// en le remplaçant par la couleur de fond d'écran
|
||||
void CSprite::Hide(Uint32 color)
|
||||
{
|
||||
SDL_FillRect(pSurface, &Pos, color );//nCouleurFond);
|
||||
//SDL_Flip(pSurface);
|
||||
//SDL_UpdateRects(pSurface, 1, &Pos);
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette fonction calcul les nouvelle coordonnée du sprite en fonction de la
|
||||
// case du tableau passé en paramètre
|
||||
void CSprite::SetPosCase(int numCase)
|
||||
{
|
||||
Pos.y=0;
|
||||
switch(numCase)
|
||||
{
|
||||
case 1: Pos.x = 32; break;
|
||||
case 2: Pos.x = 110; break;
|
||||
case 3: Pos.x = 178; break;
|
||||
case 4: Pos.x = 244; break;
|
||||
case 5: Pos.x = 310; break;
|
||||
case 6: Pos.x = 378; break;
|
||||
case 7: Pos.x = 448; break;
|
||||
} // fin switch
|
||||
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette fonction permet de donner une nouvelle valeur pour
|
||||
// la position en y du sprite
|
||||
void CSprite::SetPosY(int val_y)
|
||||
{
|
||||
Pos.y = val_y;
|
||||
}
|
||||
87
src/csprite.h
Normal file
87
src/csprite.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/***************************************************************************
|
||||
csprite.h - description
|
||||
-------------------
|
||||
begin : Mon Oct 30 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CSPRITE_H
|
||||
#define CSPRITE_H
|
||||
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
/**
|
||||
*@author NADAL Jean-Baptiste
|
||||
*/
|
||||
|
||||
class CSprite {
|
||||
public:
|
||||
// =================================================
|
||||
// Constructeur de la classe
|
||||
CSprite(SDL_Surface *surface,Uint16 posX,Uint16 posY, char* fichier);
|
||||
// =================================================
|
||||
// Constructeur de la classe dont on ne passe pas
|
||||
// que le strict minimum
|
||||
CSprite( SDL_Surface *surface, char* fichier );
|
||||
// =================================================
|
||||
// Destructeur
|
||||
virtual ~CSprite();
|
||||
// =================================================
|
||||
// Cette méthode permet d'afficher le sprite
|
||||
void show();
|
||||
// =================================================
|
||||
// Cette méthode permet d'afficher le sprite
|
||||
// Avec un coeficient de transparence
|
||||
void showA(int val);
|
||||
|
||||
// =================================================
|
||||
// Cette méthode permet de cacher un sprite si la surface a l'arrière plan
|
||||
// est un fond uni
|
||||
void Hide();
|
||||
// =================================================
|
||||
// Cette méthode permet de cacher un sprite
|
||||
// en le remplaçant par la couleur de fond d'écran
|
||||
void Hide(Uint32 color);
|
||||
// =================================================
|
||||
// Cette fonction calcul les nouvelle coordonnée du sprite en fonction de la
|
||||
// case du tableau passé en paramètre
|
||||
void SetPosCase(int numCase);
|
||||
// =================================================
|
||||
// Cette fonction permet de donner une nouvelle valeur pour
|
||||
// la position en y du sprite
|
||||
void SetPosY(int val_y);
|
||||
|
||||
|
||||
protected:
|
||||
// =================================================
|
||||
// Variables privée de la classe sprite
|
||||
|
||||
SDL_Surface *pSurface; // pointeur sur la surface sur laquelle dessiner le sprite
|
||||
SDL_Rect Pos; // Rectangle permettant de stouer les informations
|
||||
// du sprite ( posX, posY, largeur hauteur )
|
||||
SDL_Surface *pData; // Donnee du sprite
|
||||
Uint32 nCouleurFond; // Couleur de fond d'un sprite par défaut
|
||||
|
||||
// =================================================
|
||||
// Méthodes privée a la classe sprite
|
||||
|
||||
// =================================================
|
||||
// Cette méthode permet de charger le fichier du sprite
|
||||
// et de mettre le premier pixel de l'image comme couleur
|
||||
// de transparance
|
||||
void initDonnee(char* szFichier);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
33
src/main.cpp
Normal file
33
src/main.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************
|
||||
main.cpp - description
|
||||
-------------------
|
||||
begin : Sun Oct 29 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> // pour EXIT_SUCCESS
|
||||
#include <string.h>
|
||||
|
||||
#include "plateauview.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
CPlateauView* pMonPlateau = new CPlateauView();
|
||||
pMonPlateau->Lancement();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
353
src/plateauview.cpp
Normal file
353
src/plateauview.cpp
Normal file
@@ -0,0 +1,353 @@
|
||||
/***************************************************************************
|
||||
plateau.cpp - description
|
||||
-------------------
|
||||
begin : Sun Oct 29 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
|
||||
#include "plateauview.h"
|
||||
#include "csprite.h"
|
||||
#include "cpion.h"
|
||||
#include "Jeu.h"
|
||||
#include "cintro.h"
|
||||
|
||||
|
||||
// =================================================
|
||||
// Constructeur
|
||||
CPlateauView::CPlateauView()
|
||||
{
|
||||
// -- Variables locales
|
||||
int NivOrdi = 3;
|
||||
int NumJordi=0;
|
||||
// -- Fin Variables locales
|
||||
|
||||
|
||||
// Initialisation de l'interface graphique
|
||||
initSDL();
|
||||
nCaseSelect = 0;
|
||||
// le premier joueur est le joueur Jaune
|
||||
// pPionCourant = spt_Prouge;
|
||||
|
||||
// On initialise le moteur du jeu
|
||||
pMoteur = new Jeu();
|
||||
|
||||
pIntro = new CIntro(ecran);
|
||||
|
||||
NumJordi = pIntro->Lancement();
|
||||
SDL_FillRect(ecran, NULL, 0);
|
||||
spt_Plateau->show();
|
||||
SDL_Flip(ecran);
|
||||
|
||||
cout <<" NumJordi de l'intro vaut :"<< NumJordi<<endl;
|
||||
// si l'utilisateur a demandé a quitter l'application
|
||||
if ( NumJordi == -1 )
|
||||
exit(1);
|
||||
else if ( NumJordi == 1 )
|
||||
{
|
||||
pPionOrdi = spt_Prouge;
|
||||
pPionHumain = spt_Pjaune;
|
||||
|
||||
pb_bVicOrdi = pb_VictoireRouge;
|
||||
pb_bVicHumain = pb_VictoireJaune;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPionOrdi = spt_Pjaune;
|
||||
pPionHumain = spt_Prouge;
|
||||
|
||||
pb_bVicOrdi = pb_VictoireJaune;
|
||||
pb_bVicHumain = pb_VictoireRouge;
|
||||
}
|
||||
|
||||
pMoteur->setJO(NumJordi);
|
||||
|
||||
if (NivOrdi > 0 && NivOrdi < 4)
|
||||
pMoteur->Niv = NivOrdi*2;
|
||||
else
|
||||
pMoteur->Niv = 4;
|
||||
nNbPionenJeu =0;
|
||||
|
||||
bAbouge =false;
|
||||
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Destructeur
|
||||
CPlateauView::~CPlateauView()
|
||||
{
|
||||
// On efface les sprites
|
||||
delete spt_Plateau;
|
||||
delete spt_Prouge;
|
||||
delete spt_Pjaune;
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette fonction permet d'initialiser toutes les couches graphique
|
||||
// et de charger les differents sprites
|
||||
int CPlateauView::initSDL()
|
||||
{
|
||||
// -- Variables locales
|
||||
|
||||
// -- Fin Variables locales
|
||||
|
||||
|
||||
// Initialisation de la couche SDL
|
||||
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
|
||||
{
|
||||
fprintf(stderr, "<ERREUR> Impossible d'initialisé la SDL: %s\n",SDL_GetError());
|
||||
exit(1);
|
||||
} // fin if
|
||||
|
||||
// On creer la fenetre et l'écran dans lequel on va dessiner
|
||||
if ( (ecran=SDL_SetVideoMode(640,480, 16, SDL_SWSURFACE|SDL_DOUBLEBUF|SDL_HWSURFACE)) == NULL ) {
|
||||
fprintf(stderr, "<ERREUR> Impossible de creer un surface 640x480 dans le mode video: %s\n", SDL_GetError());
|
||||
exit(2);
|
||||
} // fin if
|
||||
|
||||
SDL_WM_SetCaption("KNRPuissance4 : v "VERSION" : NADAL-REBOUL -2000", "KNRPuissance4");
|
||||
|
||||
// Chargement du sprite pour le plateau du jeu
|
||||
spt_Plateau = new CSprite(ecran,0,43,"sp_plateau.png" );
|
||||
// Puis on l'affiche
|
||||
spt_Plateau->show();
|
||||
|
||||
// Chargement du sprite pour le poin rouge
|
||||
spt_Prouge = new CPion(ecran,32,0,"sp_pion_rouge.png",spt_Plateau );
|
||||
|
||||
// Chargement du sprite pour le poin jaune
|
||||
spt_Pjaune = new CPion(ecran,32,0,"sp_pion_jaune.png",spt_Plateau );
|
||||
|
||||
// Puis on charge les trois sprite pour la boite final du jeu
|
||||
pb_MatchNul = new CSprite(ecran,50,100,"boite_match_nul.png" );
|
||||
pb_VictoireJaune = new CSprite(ecran,50,100,"boite_victoire_jaune.png" );
|
||||
pb_VictoireRouge = new CSprite(ecran,50,100,"boite_victoire_rouge.png" );
|
||||
|
||||
|
||||
// le sprite dans le coin droit pour a qu'il y a de plus reel
|
||||
pPionRouge = new CSprite(ecran,565,10,"sp_pion_rouge.png" );
|
||||
pPionJaune = new CSprite(ecran,565,10,"sp_pion_jaune.png" );
|
||||
pPionCourant = pPionRouge;
|
||||
|
||||
|
||||
|
||||
// tout est bon on retourn 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// =================================================
|
||||
// Cette fonction contient la boucke infinie du programme.
|
||||
int CPlateauView::Lancement()
|
||||
{
|
||||
// -- Variables locales
|
||||
int nQuitter=0;
|
||||
SDL_Event event;
|
||||
// Fin Variables locales
|
||||
|
||||
pPionCourant->show();
|
||||
SDL_Flip(ecran);
|
||||
|
||||
while ( nQuitter !=2 )
|
||||
{
|
||||
if ( pMoteur->getJcourant() == pMoteur->getJO() )
|
||||
FaitJouerIA();
|
||||
|
||||
SDL_WaitEvent(&event);
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
if ( nQuitter == 1)
|
||||
nQuitter = 2;
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
nQuitter = 2;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if ( nQuitter != 1) {
|
||||
slotMouseMove(event.motion.x );
|
||||
bAbouge =true;
|
||||
}
|
||||
break;
|
||||
case SDL_USEREVENT:
|
||||
if ( nQuitter != 1)
|
||||
{
|
||||
if ( slotMouseButtonDown() )
|
||||
nQuitter=1;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if ( nQuitter != 1)
|
||||
{
|
||||
if (bAbouge)
|
||||
{
|
||||
if ( slotMouseButtonDown() )
|
||||
nQuitter=1;
|
||||
bAbouge =false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} // fin du switch
|
||||
} // fin while ( SDL_PollEvent(&event) )
|
||||
|
||||
// Ajouter ici fonction de dessin
|
||||
// JoueDeplacement();
|
||||
} // fin while ( !bQuitter )
|
||||
|
||||
// le programme est terminé, on quitte en retournat 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// Cette fonction retourne la position dans le tableau
|
||||
// en fonction des coordonnées de la souris passée en paramètres
|
||||
int CPlateauView::PosSouris2Plateau(int x )
|
||||
{
|
||||
// -- Variables locales
|
||||
int nXtemp;
|
||||
int nValret;
|
||||
// -- Fin Variables locales
|
||||
|
||||
nXtemp = (int)(x-50)/5;
|
||||
nXtemp *=5;
|
||||
|
||||
nValret = nXtemp/65;
|
||||
nValret++;
|
||||
|
||||
return nValret;
|
||||
}
|
||||
|
||||
|
||||
//=================================================
|
||||
// Cette fonction est appellée lorsque la souris est en
|
||||
// déplacement
|
||||
void CPlateauView::slotMouseMove(int x)
|
||||
{
|
||||
// On ne deplace le pion que s'il s'agit du coup du joueur ordi.
|
||||
if ( pMoteur->getJcourant() != pMoteur->getJO() )
|
||||
{
|
||||
// on verifie que la souris est bien sur le plateau
|
||||
if (( x >25 ) && ( x < 521 ))
|
||||
{
|
||||
int casetemp;
|
||||
casetemp = PosSouris2Plateau( x );
|
||||
|
||||
if ( nCaseSelect != casetemp )
|
||||
{
|
||||
nCaseSelect = casetemp;
|
||||
SDL_LockSurface(ecran);
|
||||
if ( pPionHumain->enHaut() )
|
||||
pPionHumain->Hide();
|
||||
pPionHumain->SetPosCase(nCaseSelect);
|
||||
pPionHumain->show();
|
||||
spt_Plateau->show();
|
||||
SDL_Flip(ecran);
|
||||
SDL_UnlockSurface(ecran);
|
||||
} // fin if ( nCaseSelect != casetemp )
|
||||
} // fin if ( ( event.motion.x >25 ...
|
||||
else
|
||||
nCaseSelect =0;
|
||||
} // fin if ( pMoteur->getJcourant() != getJO() )
|
||||
}
|
||||
|
||||
//=================================================
|
||||
// Cette fonction est appellé lorsque l'on clique sur un
|
||||
// bouton de la souris
|
||||
// retourne vrai si la partie est terminée
|
||||
bool CPlateauView::slotMouseButtonDown()
|
||||
{
|
||||
// -- Variables locales
|
||||
bool bresultat=false;
|
||||
int colonejouee;
|
||||
bool bQuitter=false;
|
||||
// -- Fin Variables locales
|
||||
|
||||
// si le plateau est plein, on ne joue pas,
|
||||
// il y a match nul
|
||||
if (nNbPionenJeu == 42 )
|
||||
{
|
||||
pb_MatchNul->showA(220);
|
||||
SDL_Flip(ecran);
|
||||
bQuitter = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// si c'est au tour de l'IA de jouer
|
||||
if ( pMoteur->getJcourant() == pMoteur->getJO() )
|
||||
{
|
||||
// On calcul le coup qu'il va jouer
|
||||
colonejouee = pMoteur->JoueOrdi();
|
||||
// On fait glisser le pion de l'ordi
|
||||
pPionOrdi->SetPosCase(colonejouee);
|
||||
pPionOrdi->Glisse(pMoteur->CaseCol[colonejouee]);
|
||||
// On finit de faire jouer l'ordinateur
|
||||
bresultat = pMoteur->FiniJoueOrdi(colonejouee);
|
||||
nNbPionenJeu++;
|
||||
if ( bresultat ) // l'ordi vient de gagner
|
||||
{
|
||||
pb_bVicOrdi->showA(Coef_ALPHA);
|
||||
SDL_Flip(ecran);
|
||||
bQuitter = true;
|
||||
} // fin if ( bresultat )
|
||||
} // fin if a l'ia de jouer
|
||||
else
|
||||
{
|
||||
// On lance l'animation du glissement
|
||||
pPionHumain->Glisse(pMoteur->CaseCol[nCaseSelect]);
|
||||
// On joue le coup dans le moteur du jeu
|
||||
bresultat = pMoteur->JoueHumain(nCaseSelect);
|
||||
nNbPionenJeu++;
|
||||
if ( bresultat ) // le joueur humain vient de gagner
|
||||
{
|
||||
pb_bVicHumain->showA(Coef_ALPHA);
|
||||
SDL_Flip(ecran);
|
||||
bQuitter = true;
|
||||
} // fin if ( bresultat )
|
||||
} // fin else du si c'est à l'IA de jouer
|
||||
ChangePcourant();
|
||||
} // fin else match null
|
||||
|
||||
return bQuitter;
|
||||
}
|
||||
|
||||
//=================================================
|
||||
// Cette fonction envoi un signal pour que l'IA puisse Jouer
|
||||
void CPlateauView::FaitJouerIA(void)
|
||||
{
|
||||
// -- Variables locales
|
||||
SDL_Event event;
|
||||
// -- Fin Variables locales
|
||||
|
||||
event.type = SDL_USEREVENT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
//=================================================
|
||||
// Change le pion courant
|
||||
void CPlateauView::ChangePcourant()
|
||||
{
|
||||
pPionCourant->Hide();
|
||||
if (pPionCourant == pPionRouge)
|
||||
pPionCourant = pPionJaune;
|
||||
else
|
||||
pPionCourant = pPionRouge;
|
||||
pPionCourant->show();
|
||||
SDL_Flip(ecran);
|
||||
}
|
||||
95
src/plateauview.h
Normal file
95
src/plateauview.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/***************************************************************************
|
||||
plateau.h - description
|
||||
-------------------
|
||||
begin : Sun Oct 29 2000
|
||||
copyright : (C) 2000 by NADAL Jean-Baptiste
|
||||
email : jbnadal@ifrance.com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
*@author NADAL Jean-Baptiste
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PLATEAU_H
|
||||
#define PLATEAU_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
// dépendance de la classe
|
||||
class CSprite;
|
||||
class CPion;
|
||||
class Jeu;
|
||||
class CIntro;
|
||||
|
||||
class CPlateauView {
|
||||
public:
|
||||
CPlateauView();
|
||||
~CPlateauView();
|
||||
/** Lancement du plateau */
|
||||
int Lancement();
|
||||
/** initialisation de l'interface graphique */
|
||||
int initSDL();
|
||||
// =================================================
|
||||
// Cette fonction retourne la position dans le tableau
|
||||
// en fonction des coordonnées de la souris passée en paramètres
|
||||
int PosSouris2Plateau(int x);
|
||||
|
||||
|
||||
private:
|
||||
SDL_Surface *ecran; // pointeur sur la surface d'affichage
|
||||
CPion* spt_Prouge; // Objet sprite du pion rouge
|
||||
CPion* spt_Pjaune; // Objet sprite du pion jaune
|
||||
CPion* pPionHumain; // pointeur sur le pion de l'humain
|
||||
CPion* pPionOrdi; // pointeur sur le pion de l'ordi
|
||||
|
||||
|
||||
CSprite* spt_Plateau; // Sprite du plateau
|
||||
Jeu* pMoteur; // pointeur sur le moteur du jeu
|
||||
CIntro* pIntro; // pointeur sur l'Introduction du Jeu
|
||||
CSprite* pb_MatchNul; // boite pour un match nul
|
||||
CSprite* pb_VictoireJaune; // boite pour la victoire des jaunes
|
||||
CSprite* pb_VictoireRouge; // boite pour la victoire des rouges
|
||||
|
||||
CSprite* pb_bVicHumain; // pointeur sur la boite de la victoire de l'humain
|
||||
CSprite* pb_bVicOrdi; // pointeur sur la boite de victoire de l'ordi
|
||||
|
||||
int nCaseSelect; // Nuero de la case séléctionnée
|
||||
int nNbPionenJeu; // Nombre de pions en jeu
|
||||
bool bAbouge; // booleen permettant de savoir le joueur a boug sa souris
|
||||
|
||||
CSprite* pPionRouge; // Pointeur sur le sprite de selection du joueur rouge
|
||||
CSprite* pPionJaune; // Pointeur sur le sprite de selection du joueur jaune
|
||||
CSprite* pPionCourant; // Pointeur sur le sprite de selection du joueur courant
|
||||
|
||||
//=================================================
|
||||
// Fonctions privées
|
||||
|
||||
//=================================================
|
||||
// Cette fonction est appellée lorsque la souris est en
|
||||
// déplacement
|
||||
void slotMouseMove(int x);
|
||||
//=================================================
|
||||
// Cette fonction est appellé lorsque l'on clique sur un
|
||||
// bouton de la souris
|
||||
// retourne vrai si la partie est terminée
|
||||
bool slotMouseButtonDown();
|
||||
//=================================================
|
||||
// Cette fonction envoi un signal pour que l'IA puisse Jouer
|
||||
void FaitJouerIA(void);
|
||||
//=================================================
|
||||
// Change le pion courant
|
||||
void ChangePcourant();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user