AlenDjavo
Messages postés3Date d'inscriptionjeudi 29 mars 2012StatutMembreDernière intervention12 mai 2012
-
3 avril 2012 à 23:46
cptpingu
Messages postés3837Date d'inscriptiondimanche 12 décembre 2004StatutModérateurDernière intervention28 mars 2023
-
4 avril 2012 à 10:36
salut tout le monde je suis bloque dans mon pussance 4
je n`arive pas a afficher mon tableu quelquen peux me aider svp
dsl pour le fautes.
#include
using namespace std;
#define LONGUEUR 7
#define HAUTEUR 7
#define VIDE '_'
void Puissance4();
void AfficherGrid(char grid[LONGUEUR][HAUTEUR]);
char DemanderEntree();
bool PlacerJeton(char joueur, int x,int y ,char grid[LONGUEUR][HAUTEUR] );
int DeterminerLinge(int colonne ,char grid[LONGUEUR][HAUTEUR]);
char VerifierVictoire(int x, int y);
//bool VerifierLinge();
//bool VerifierColonne();
//bool VerifierDiagonale();
int CharToInt(char c);
cptpingu
Messages postés3837Date d'inscriptiondimanche 12 décembre 2004StatutModérateurDernière intervention28 mars 2023123 4 avril 2012 à 01:03
Bonjour.
Met ton code dans "des balises des codes", si tu veux de l'aide.
int main()
{
// C'est mieux non ?
}
________________________________________________________________________
Historique de mes créations, et quelques articles:
[ http://0217021.free.fr/portfoliohttp://0217021.free.fr/portfolio]
Merci d'utiliser Réponse acceptée si un post répond à votre question
cptpingu
Messages postés3837Date d'inscriptiondimanche 12 décembre 2004StatutModérateurDernière intervention28 mars 2023123 4 avril 2012 à 10:36
Quelques remarques:
- Indente ton code ! La prochaine fois, je ne t'aiderais pas, si tu n'aligne pas ton code correctement !
- Évite la commande system, tu perds en portabilité pour une fonctionnalité très limité...
- Évite les "using namespace", voir: http://0217021.free.fr/portfolio/axel.berardino/articles/bon-usage-using-namespace - Pas besoin de déclarer toutes tes méthodes en haut, il suffit de les écrire du bas vers le haut.
- Évite les "define". Pour déclarer des constantes, on utilise plutôt des "static const".
Ce qui ne va pas dans ton code:
- On a l'impression que tu ne comprends pas ce que tu fais ! Il y a plein d'endroit où tu met toutes les cases à 0 alors qu'il ne faut pas.
- Ta grille ne s'affiche jamais, car tu n'as jamais intialisé celle-ci au début de ton programme ! Donc forcément, il n'y a jamais de case vide disponible. (J'ai ajouté une méthode initGrid qui le fait).
Je t'ai fait une correction, mais je ne t'ai bien évidemment pas tout corrigé. J'ai surtout mis au propre ton code, et j'ai corrigé ton erreur d'initialisation. Pour toutes les autres erreurs, je te laisse le soin de réfléchir et de les corriger par toi même.
#include
static const int LONGUEUR = 7;
static const int HAUTEUR = 7;
static const char VIDE = '_';
void AfficherGrid(char grid[LONGUEUR][HAUTEUR])
{
std::cout << " A B C D E F G " << std::endl;
for (int i = 0; i < LONGUEUR; ++i)
{
std::cout << i + 1 << '.';
for (int j = 0; j < HAUTEUR; ++j)
std::cout << '|' << grid[i][j];
std::cout << '|'<< std::endl;
}
}
char DemanderEntree()
{
char choix;
do
{
std::cout << "Entre un valeure entre A et G :";
std::cin >> choix;
}
while (choix < 'A' || choix > 'G');
return choix;
}
bool PlacerJeton(char joueur, int x, int y, char grid[LONGUEUR][HAUTEUR])
{
if (grid[x][y] != VIDE)
return false;
// FIXME Ajouter le placement de jeton.
// ? pourquoi remettre tout à 0 ?
// for (x = 0; x < 7; ++x)
// for (y = 0; y < 7; ++y)
// grid[LONGUEUR][HAUTEUR] = 0/*'_'*/;
return true;
}
int DeterminerLinge(int colonne, char grid[LONGUEUR][HAUTEUR])
{
for (int i = HAUTEUR - 1; i >= 0; --i)
if (grid[colonne][i] == VIDE)
return i;
return -1;
}
char VerifierVictoire(int x, int y)
{
return '_';
}
int CharToInt(char c)
{
return c-'A';
}
void initGrid(char grid[LONGUEUR][HAUTEUR])
{
for (int x = 0; x < 7; ++x)
for (int y = 0; y < 7; ++y)
grid[x][y] = VIDE;
}
void Puissance4()
{
const char joueur1 ='X';
const char joueur2 ='O';
bool rejouer = true;
bool gameOver = false;
int nbTour=0;
char grid[LONGUEUR][HAUTEUR];
while (rejouer)
{
initGrid(grid);
while (!gameOver)
{
char joueurCourant (nbTour % 2 0) ? joueur1 : joueur2;
int x;
int y;
do
{
x = CharToInt(DemanderEntree());
y = DeterminerLinge(x, grid);
std::cout << y << std::endl;
}
while (y == -1);
PlacerJeton(joueurCourant, x , y, grid);
AfficherGrid(grid);
char winner = VerifierVictoire(x, y);
gameOver (winner joueur1
|| winner == joueur2
|| nbTour == LONGUEUR * HAUTEUR);
nbTour++;
}
}
}
int main()
{
Puissance4();
return 0;
}
@buno: Haha, j'ai pensé à la même chose que toi ;p
________________________________________________________________________
Historique de mes créations, et quelques articles:
[ http://0217021.free.fr/portfoliohttp://0217021.free.fr/portfolio]
Merci d'utiliser Réponse acceptée si un post répond à votre question