Accueil > > > PUISSANCE 4 C
PUISSANCE 4 C
Information sur la source
Description
Voici un petit puissance 4 que je dois réaliser pour un projet :) J'aurais bien voulu savoir qu'est ce que vous en pensez et si vous trouvez des choses à améliorer dites le moi :) De plus, je voudrais modifier mon code pour pouvoir déplacer un jeton au dessus de la grille à l'aide des flèches et faire tombé le jeton en appuyant sur entré ou la flèche du bas sauf que je ne sais pas comment faire ... Merci d'avance PS : si j'ai oublié des trucs dans mon post désolé c'est mon premier post
Source
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
-
- void Color(int couleurDuTexte,int couleurDeFond);
- int main()
- {
- /*Declaration des variables et initialisation */
- int Jeu ;
- int i = 0;
- int j = 5;
- char J1[20], J2[20] ;
- char AffP[6][7] ;
- int Puiss[6][7]={{0}};
- int L, Ligne, Colone, Last, C;
- int Victoire, Lastplay;
-
-
-
-
-
- for (L = 0 ; L < 6 ; L++)
- {
- for (C = 0 ; C < 7 ; C++)
- {
- AffP[L][C] = ' ';
- }
- }
-
- Last = 2 ;
- Victoire = 0;
- Lastplay = 2 ;
-
-
-
- printf("Veuillez choisir le jeu de votre choix\n\n");
- printf("1 : Puissance 4 \n2 : Quitter\n\n");
- printf("Faites votre choix : ");
- scanf("%d",&Jeu);
-
- switch (Jeu)
- {
-
- case(1) :
-
-
- /*Saisie des noms des joueurs */
- printf ("Joueur1, Quelle est votre nom : ");
- scanf("%s",J1);
- printf("Joueur2, Quelle est votre nom : ") ;
- scanf("%s",J2);
- /*Attribution des R ou des J */
- printf("\n%s, Vous aurez les R\n\n",J1) ;
- printf("%s, Vous aurez les J\n\n",J2) ;
- do
- {
- /*Affichage du tableau */
- Color(15,0);
- printf(" 0 1 2 3 4 5 6 \n");
- printf("+-------+-------+-------+-------+-------+-------+-------+\n");
-
-
- for (j = 5; j >= 0; j--)
- {
- printf("| | | | | | | |\n");
- for (i = 0; i<=6; i++)
- {
-
-
- if ( AffP[j][i] == 'R')
- {
- Color(15,0);
- printf("|");
- Color(12,0);
- printf(" %c ", AffP[j][i]);
-
- }
- if (AffP[j][i] == 'J')
- {
- Color(15,0);
- printf("|");
- Color(14,0);
- printf(" %c ", AffP[j][i]);
-
- }
- if (AffP[j][i] == ' ')
- {
- Color(15,0);
- printf("|");
- printf(" %c ", AffP[j][i]);
- }
-
- }
- Color(15,0);
- printf("|");
- printf("\n");
- printf("| | | | | | | |\n");
- printf("+-------+-------+-------+-------+-------+-------+-------+\n");
- }
-
-
-
- /*Test permetant de gerer le tour a tour des joueurs*/
- if (Last == 2)
- {
-
- printf("\n%s, Choisissez une colone : ", J1);
- scanf("%d",&Colone);
- /*Differents cas d'invalidité de la colone */
- while (Colone > 6 )
- {
- printf("Votre Colone est invalide veuillez faire un autre choix : ");
- scanf("%d",&Colone);
- }
-
- while ( AffP[5][Colone] == 'R' ||AffP[5][Colone] == 'J' )
- {
- printf ("La colone choisie est complete veuillez effectuer un autre choix : ");
- scanf("%d",&Colone);
- while (Colone > 6 )
- {
- printf("Votre Colone est invalide veuillez faire un autre choix : ");
- scanf("%d",&Colone);
- }
- }
- /*Remplissage du tableau en faisant comme si le jeton tombait*/
- for (L = 0 ; L < 6 ; L++)
- {
- if (Puiss[L][Colone] == 0 )
- {
- Puiss[L][Colone] = 1;
- AffP[L][Colone]= 'R';
- Ligne = L ;
- L = 6 ;
- }
- }
- /*Test pour l'alignement vertical*/
- if (Ligne >= 3)
- {
- if (Puiss[Ligne-1][Colone]== 1 )
- {
- if (Puiss[Ligne-2][Colone]==1)
- {
- if (Puiss[Ligne-3][Colone]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
- /*Tests pour l'alignement horizontal : il y en a 4 car il y a 4 possiblilité de position du pion dans l'alignement*/
- if (Colone <= 3)
- {
- if (Puiss[Ligne][Colone+1]== 1)
- {
- if (Puiss[Ligne][Colone+2]==1)
- {
- if (Puiss[Ligne][Colone+3]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
-
- if (Colone <= 4 && Colone >= 1)
- {
- if (Puiss[Ligne][Colone-1]== 1 )
- {
- if (Puiss[Ligne][Colone+1]==1)
- {
- if (Puiss[Ligne][Colone+2]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
-
- if (Colone <= 5 && Colone >= 2)
- {
- if (Puiss[Ligne][Colone-2]== 1 )
- {
- if (Puiss[Ligne][Colone-1]==1)
- {
- if (Puiss[Ligne][Colone+1]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
-
- if (Colone >= 3)
- {
- if (Puiss[Ligne][Colone -3]== 1 )
- {
- if (Puiss[Ligne][Colone-2]==1)
- {
- if (Puiss[Ligne][Colone -1]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
-
- /*Tests pour la diagonale montante, il y a encore 4 test pour les meme raisons que precedement */
- if (Ligne <= 2 && Colone <= 3)
- {
- if (Puiss[Ligne+1][Colone+1]== 1 )
- {
- if (Puiss[Ligne+2][Colone+2]==1)
- {
- if (Puiss[Ligne+3][Colone+3]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
-
- if (Ligne >= 1 && Ligne <= 3 && Colone <= 4 && Colone >= 1)
- {
- if (Puiss[Ligne-1][Colone-1]== 1 )
- {
- if (Puiss[Ligne+1][Colone+1]==1)
- {
- if (Puiss[Ligne+2][Colone+2]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
-
- if (Ligne >= 2 && Ligne <= 4 && Colone >= 2 && Colone <= 5)
- {
- if (Puiss[Ligne-2][Colone-2]== 1 )
- {
- if (Puiss[Ligne-1][Colone-1]==1)
- {
- if (Puiss[Ligne+1][Colone+1]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
-
- if (Ligne >= 3 && Colone >= 3)
- {
- if (Puiss[Ligne-3][Colone-3]== 1 )
- {
- if (Puiss[Ligne-2][Colone-2]==1)
- {
- if (Puiss[Ligne-1][Colone-1]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
- /*Tests pour la diagonale descendente*/
- if (Ligne >= 3 && Colone <= 3 )
- {
- if (Puiss[Ligne-1][Colone+1]== 1 )
- {
- if (Puiss[Ligne-2][Colone+2]==1)
- {
- if (Puiss[Ligne-3][Colone+3]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
- if (Ligne >= 2 && Ligne <= 4 && Colone <= 4 && Colone >= 1)
- {
- if (Puiss[Ligne-2][Colone+2]== 1 )
- {
- if (Puiss[Ligne+1][Colone-1]==1)
- {
- if (Puiss[Ligne-1][Colone+1]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
- if (Ligne >= 1 && Ligne <= 3 && Colone <= 5 && Colone >= 2)
- {
- if (Puiss[Ligne+1][Colone-1]== 1 )
- {
- if (Puiss[Ligne-1][Colone+1]==1)
- {
- if (Puiss[Ligne+2][Colone-2]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
- if ( Ligne <= 2 && Colone >= 3)
- {
- if (Puiss[Ligne+2][Colone-2]== 1 )
- {
- if (Puiss[Ligne+1][Colone-1]==1)
- {
- if (Puiss[Ligne+3][Colone-3]==1)
- {
- Victoire = 1 ;
- }
- }
- }
- }
- Last = 1 ;
- if (Puiss [5][0] != 0 && Puiss [5][1] != 0 && Puiss [5][2] != 0 && Puiss [5][3] != 0 && Puiss [5][4] != 0 && Puiss [5][5] != 0 && Puiss [5][6] != 0 )
- {
- Victoire = 3 ;
- }
- }
- else
- /*Les commentaires sont les memes que precedement puisque ce qui se produit pour un joueur peu aussi ce produire pour l'autre */
- {
- printf("%s, Choisissez une colone : ", J2);
- scanf("%d",&Colone);
- while (Colone > 6 )
- {
- printf("Votre Colone est invalide veuillez faire un autre choix : ");
- scanf("%d",&Colone);
- }
-
- while ( AffP[5][Colone] == 'R' ||AffP[5][Colone] == 'J' )
- {
- printf("La colone choisie est complete veuillez effectuer un autre choix : ");
- scanf("%d",&Colone);
- while (Colone > 6 )
- {
- printf("Votre Colone est invalide veuillez faire un autre choix : ");
- scanf("%d",&Colone);
- }
- }
-
- for (L = 0 ; L < 6 ; L++)
- {
- if (Puiss[L][Colone] == 0 )
- {
- Puiss[L][Colone] = 2 ;
- AffP[L][Colone] = 'J' ;
- Ligne = L ;
- L = 6 ;
- }
- }
- /*Test pour l'alignement vertical*/
- if (Ligne >= 3)
- {
- if (Puiss[Ligne-1][Colone]== 2 )
- {
- if (Puiss[Ligne-2][Colone]==2)
- {
- if (Puiss[Ligne-3][Colone]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
- /*Tests pour l'alignement horizontal : il y en a 4 car il y a 4 possiblilité de position du pion dans l'alignement*/
- if (Colone <= 3)
- {
- if (Puiss[Ligne][Colone+1]== 2 )
- {
- if (Puiss[Ligne][Colone+2]==2)
- {
- if (Puiss[Ligne][Colone+3]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
-
- if (Colone <= 4 && Colone >= 1)
- {
- if (Puiss[Ligne][Colone-1]== 2 )
- {
- if (Puiss[Ligne][Colone+1]==2)
- {
- if (Puiss[Ligne][Colone+2]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
-
- if (Colone <= 5 && Colone >= 2)
- {
- if (Puiss[Ligne][Colone-2]==2 )
- {
- if (Puiss[Ligne][Colone-1]==2)
- {
- if (Puiss[Ligne][Colone+1]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
-
- if (Colone >= 3)
- {
- if (Puiss[Ligne][Colone -3]== 2 )
- {
- if (Puiss[Ligne][Colone-2]==2)
- {
- if (Puiss[Ligne][Colone -1]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
-
- /*Tests pour la diagonale montante, il y a encore 4 test pour les meme raisons que precedement */
- if (Ligne <= 2 && Colone <= 3)
- {
- if (Puiss[Ligne+1][Colone+1]== 2 )
- {
- if (Puiss[Ligne+2][Colone+2]==2)
- {
- if (Puiss[Ligne+3][Colone+3]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
-
- if (Ligne >= 1 && Ligne <= 3 && Colone <= 4 && Colone >= 1)
- {
- if (Puiss[Ligne-1][Colone-1]== 2 )
- {
- if (Puiss[Ligne+1][Colone+1]==2)
- {
- if (Puiss[Ligne+2][Colone+2]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
-
- if (Ligne >= 2 && Ligne <= 4 && Colone >= 2 && Colone <= 5)
- {
- if (Puiss[Ligne-2][Colone-2]== 2 )
- {
- if (Puiss[Ligne-1][Colone-1]==2)
- {
- if (Puiss[Ligne+1][Colone+1]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
-
- if (Ligne >= 3 && Colone >= 3)
- {
- if (Puiss[Ligne-3][Colone-3]== 2 )
- {
- if (Puiss[Ligne-2][Colone-2]==2)
- {
- if (Puiss[Ligne-1][Colone-1]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
- /*Tests pour la diagonale descendente*/
- if (Ligne >= 3 && Colone <= 3 )
- {
- if (Puiss[Ligne-1][Colone+1]== 2 )
- {
- if (Puiss[Ligne-2][Colone+2]==2)
- {
- if (Puiss[Ligne-3][Colone+3]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
- if (Ligne >= 2 && Ligne <= 4 && Colone <= 4 && Colone >= 1)
- {
- if (Puiss[Ligne-2][Colone+2]== 2 )
- {
- if (Puiss[Ligne+1][Colone-1]==2)
- {
- if (Puiss[Ligne-1][Colone+1]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
- if (Ligne >= 1 && Ligne <= 3 && Colone <= 5 && Colone >= 2)
- {
- if (Puiss[Ligne+1][Colone-1]== 2 )
- {
- if (Puiss[Ligne-1][Colone+1]==2)
- {
- if (Puiss[Ligne+2][Colone-2]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
- if ( Ligne <= 2 && Colone >= 3)
- {
- if (Puiss[Ligne+2][Colone-2]== 2 )
- {
- if (Puiss[Ligne+1][Colone-1]==2)
- {
- if (Puiss[Ligne+3][Colone-3]==2)
- {
- Victoire = 2 ;
- }
- }
- }
- }
- Last = 2 ;
- if (Puiss [5][0] != 0 && Puiss [5][1] != 0 && Puiss [5][2] != 0 && Puiss [5][3] != 0 && Puiss [5][4] != 0 && Puiss [5][5] != 0 && Puiss [5][6] != 0 )
- {
- Victoire = 3 ;
- }
- }
- /*Sortie de la boucle car soit l'un des 2 joueurs a gagné soit le tableau est complet */
- }
-
-
-
-
-
-
- while (Victoire !=1 && Victoire != 2 && Victoire != 3);
- /*Affichage du tableau final*/
- Color(15,0);
- printf(" 0 1 2 3 4 5 6 \n");
- printf("+-------+-------+-------+-------+-------+-------+-------+\n");
-
-
- for (j = 5; j >= 0; j--)
- {
- printf("| | | | | | | |\n");
- for (i = 0; i<=6; i++)
- {
-
-
- if ( AffP[j][i] == 'R')
- {
- Color(15,0);
- printf("|");
- Color(12,0);
- printf(" %c ", AffP[j][i]);
-
- }
- if (AffP[j][i] == 'J')
- {
- Color(15,0);
- printf("|");
- Color(14,0);
- printf(" %c ", AffP[j][i]);
-
- }
- if (AffP[j][i] == ' ')
- {
- Color(15,0);
- printf("|");
- printf(" %c ", AffP[j][i]);
- }
-
- }
- Color(15,0);
-
- printf("|");
- printf("\n");
- printf("| | | | | | | |\n");
- printf("+-------+-------+-------+-------+-------+-------+-------+\n");
- }
-
- /*Tests permetant de conaitre le vaincqueur et de le declarer */
- switch (Victoire)
- {
- case (1) : printf ("\a\a\a\n");
- printf("%s a gagne BRAVO!!!!!\n\n",J1);
- break ;
- case (2): printf ("\a\a\a\n");
- printf("%s a gagne BRAVO!!!!!\n\n",J2);
- break;
- case(3): printf ("Match Nul !!!\n\n");
- break;
- }
- /*Fin du Puissance4*/
- break ;
-
- }
- printf("Pressez Entree pour quitter");
-
-
- return 0;
- }
- void Color(int couleurDuTexte,int couleurDeFond) // fonction d'affichage de couleurs
- {
- HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(H,couleurDeFond*16+couleurDuTexte);
- }
-
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void Color(int couleurDuTexte,int couleurDeFond);
int main()
{
/*Declaration des variables et initialisation */
int Jeu ;
int i = 0;
int j = 5;
char J1[20], J2[20] ;
char AffP[6][7] ;
int Puiss[6][7]={{0}};
int L, Ligne, Colone, Last, C;
int Victoire, Lastplay;
for (L = 0 ; L < 6 ; L++)
{
for (C = 0 ; C < 7 ; C++)
{
AffP[L][C] = ' ';
}
}
Last = 2 ;
Victoire = 0;
Lastplay = 2 ;
printf("Veuillez choisir le jeu de votre choix\n\n");
printf("1 : Puissance 4 \n2 : Quitter\n\n");
printf("Faites votre choix : ");
scanf("%d",&Jeu);
switch (Jeu)
{
case(1) :
/*Saisie des noms des joueurs */
printf ("Joueur1, Quelle est votre nom : ");
scanf("%s",J1);
printf("Joueur2, Quelle est votre nom : ") ;
scanf("%s",J2);
/*Attribution des R ou des J */
printf("\n%s, Vous aurez les R\n\n",J1) ;
printf("%s, Vous aurez les J\n\n",J2) ;
do
{
/*Affichage du tableau */
Color(15,0);
printf(" 0 1 2 3 4 5 6 \n");
printf("+-------+-------+-------+-------+-------+-------+-------+\n");
for (j = 5; j >= 0; j--)
{
printf("| | | | | | | |\n");
for (i = 0; i<=6; i++)
{
if ( AffP[j][i] == 'R')
{
Color(15,0);
printf("|");
Color(12,0);
printf(" %c ", AffP[j][i]);
}
if (AffP[j][i] == 'J')
{
Color(15,0);
printf("|");
Color(14,0);
printf(" %c ", AffP[j][i]);
}
if (AffP[j][i] == ' ')
{
Color(15,0);
printf("|");
printf(" %c ", AffP[j][i]);
}
}
Color(15,0);
printf("|");
printf("\n");
printf("| | | | | | | |\n");
printf("+-------+-------+-------+-------+-------+-------+-------+\n");
}
/*Test permetant de gerer le tour a tour des joueurs*/
if (Last == 2)
{
printf("\n%s, Choisissez une colone : ", J1);
scanf("%d",&Colone);
/*Differents cas d'invalidité de la colone */
while (Colone > 6 )
{
printf("Votre Colone est invalide veuillez faire un autre choix : ");
scanf("%d",&Colone);
}
while ( AffP[5][Colone] == 'R' ||AffP[5][Colone] == 'J' )
{
printf ("La colone choisie est complete veuillez effectuer un autre choix : ");
scanf("%d",&Colone);
while (Colone > 6 )
{
printf("Votre Colone est invalide veuillez faire un autre choix : ");
scanf("%d",&Colone);
}
}
/*Remplissage du tableau en faisant comme si le jeton tombait*/
for (L = 0 ; L < 6 ; L++)
{
if (Puiss[L][Colone] == 0 )
{
Puiss[L][Colone] = 1;
AffP[L][Colone]= 'R';
Ligne = L ;
L = 6 ;
}
}
/*Test pour l'alignement vertical*/
if (Ligne >= 3)
{
if (Puiss[Ligne-1][Colone]== 1 )
{
if (Puiss[Ligne-2][Colone]==1)
{
if (Puiss[Ligne-3][Colone]==1)
{
Victoire = 1 ;
}
}
}
}
/*Tests pour l'alignement horizontal : il y en a 4 car il y a 4 possiblilité de position du pion dans l'alignement*/
if (Colone <= 3)
{
if (Puiss[Ligne][Colone+1]== 1)
{
if (Puiss[Ligne][Colone+2]==1)
{
if (Puiss[Ligne][Colone+3]==1)
{
Victoire = 1 ;
}
}
}
}
if (Colone <= 4 && Colone >= 1)
{
if (Puiss[Ligne][Colone-1]== 1 )
{
if (Puiss[Ligne][Colone+1]==1)
{
if (Puiss[Ligne][Colone+2]==1)
{
Victoire = 1 ;
}
}
}
}
if (Colone <= 5 && Colone >= 2)
{
if (Puiss[Ligne][Colone-2]== 1 )
{
if (Puiss[Ligne][Colone-1]==1)
{
if (Puiss[Ligne][Colone+1]==1)
{
Victoire = 1 ;
}
}
}
}
if (Colone >= 3)
{
if (Puiss[Ligne][Colone -3]== 1 )
{
if (Puiss[Ligne][Colone-2]==1)
{
if (Puiss[Ligne][Colone -1]==1)
{
Victoire = 1 ;
}
}
}
}
/*Tests pour la diagonale montante, il y a encore 4 test pour les meme raisons que precedement */
if (Ligne <= 2 && Colone <= 3)
{
if (Puiss[Ligne+1][Colone+1]== 1 )
{
if (Puiss[Ligne+2][Colone+2]==1)
{
if (Puiss[Ligne+3][Colone+3]==1)
{
Victoire = 1 ;
}
}
}
}
if (Ligne >= 1 && Ligne <= 3 && Colone <= 4 && Colone >= 1)
{
if (Puiss[Ligne-1][Colone-1]== 1 )
{
if (Puiss[Ligne+1][Colone+1]==1)
{
if (Puiss[Ligne+2][Colone+2]==1)
{
Victoire = 1 ;
}
}
}
}
if (Ligne >= 2 && Ligne <= 4 && Colone >= 2 && Colone <= 5)
{
if (Puiss[Ligne-2][Colone-2]== 1 )
{
if (Puiss[Ligne-1][Colone-1]==1)
{
if (Puiss[Ligne+1][Colone+1]==1)
{
Victoire = 1 ;
}
}
}
}
if (Ligne >= 3 && Colone >= 3)
{
if (Puiss[Ligne-3][Colone-3]== 1 )
{
if (Puiss[Ligne-2][Colone-2]==1)
{
if (Puiss[Ligne-1][Colone-1]==1)
{
Victoire = 1 ;
}
}
}
}
/*Tests pour la diagonale descendente*/
if (Ligne >= 3 && Colone <= 3 )
{
if (Puiss[Ligne-1][Colone+1]== 1 )
{
if (Puiss[Ligne-2][Colone+2]==1)
{
if (Puiss[Ligne-3][Colone+3]==1)
{
Victoire = 1 ;
}
}
}
}
if (Ligne >= 2 && Ligne <= 4 && Colone <= 4 && Colone >= 1)
{
if (Puiss[Ligne-2][Colone+2]== 1 )
{
if (Puiss[Ligne+1][Colone-1]==1)
{
if (Puiss[Ligne-1][Colone+1]==1)
{
Victoire = 1 ;
}
}
}
}
if (Ligne >= 1 && Ligne <= 3 && Colone <= 5 && Colone >= 2)
{
if (Puiss[Ligne+1][Colone-1]== 1 )
{
if (Puiss[Ligne-1][Colone+1]==1)
{
if (Puiss[Ligne+2][Colone-2]==1)
{
Victoire = 1 ;
}
}
}
}
if ( Ligne <= 2 && Colone >= 3)
{
if (Puiss[Ligne+2][Colone-2]== 1 )
{
if (Puiss[Ligne+1][Colone-1]==1)
{
if (Puiss[Ligne+3][Colone-3]==1)
{
Victoire = 1 ;
}
}
}
}
Last = 1 ;
if (Puiss [5][0] != 0 && Puiss [5][1] != 0 && Puiss [5][2] != 0 && Puiss [5][3] != 0 && Puiss [5][4] != 0 && Puiss [5][5] != 0 && Puiss [5][6] != 0 )
{
Victoire = 3 ;
}
}
else
/*Les commentaires sont les memes que precedement puisque ce qui se produit pour un joueur peu aussi ce produire pour l'autre */
{
printf("%s, Choisissez une colone : ", J2);
scanf("%d",&Colone);
while (Colone > 6 )
{
printf("Votre Colone est invalide veuillez faire un autre choix : ");
scanf("%d",&Colone);
}
while ( AffP[5][Colone] == 'R' ||AffP[5][Colone] == 'J' )
{
printf("La colone choisie est complete veuillez effectuer un autre choix : ");
scanf("%d",&Colone);
while (Colone > 6 )
{
printf("Votre Colone est invalide veuillez faire un autre choix : ");
scanf("%d",&Colone);
}
}
for (L = 0 ; L < 6 ; L++)
{
if (Puiss[L][Colone] == 0 )
{
Puiss[L][Colone] = 2 ;
AffP[L][Colone] = 'J' ;
Ligne = L ;
L = 6 ;
}
}
/*Test pour l'alignement vertical*/
if (Ligne >= 3)
{
if (Puiss[Ligne-1][Colone]== 2 )
{
if (Puiss[Ligne-2][Colone]==2)
{
if (Puiss[Ligne-3][Colone]==2)
{
Victoire = 2 ;
}
}
}
}
/*Tests pour l'alignement horizontal : il y en a 4 car il y a 4 possiblilité de position du pion dans l'alignement*/
if (Colone <= 3)
{
if (Puiss[Ligne][Colone+1]== 2 )
{
if (Puiss[Ligne][Colone+2]==2)
{
if (Puiss[Ligne][Colone+3]==2)
{
Victoire = 2 ;
}
}
}
}
if (Colone <= 4 && Colone >= 1)
{
if (Puiss[Ligne][Colone-1]== 2 )
{
if (Puiss[Ligne][Colone+1]==2)
{
if (Puiss[Ligne][Colone+2]==2)
{
Victoire = 2 ;
}
}
}
}
if (Colone <= 5 && Colone >= 2)
{
if (Puiss[Ligne][Colone-2]==2 )
{
if (Puiss[Ligne][Colone-1]==2)
{
if (Puiss[Ligne][Colone+1]==2)
{
Victoire = 2 ;
}
}
}
}
if (Colone >= 3)
{
if (Puiss[Ligne][Colone -3]== 2 )
{
if (Puiss[Ligne][Colone-2]==2)
{
if (Puiss[Ligne][Colone -1]==2)
{
Victoire = 2 ;
}
}
}
}
/*Tests pour la diagonale montante, il y a encore 4 test pour les meme raisons que precedement */
if (Ligne <= 2 && Colone <= 3)
{
if (Puiss[Ligne+1][Colone+1]== 2 )
{
if (Puiss[Ligne+2][Colone+2]==2)
{
if (Puiss[Ligne+3][Colone+3]==2)
{
Victoire = 2 ;
}
}
}
}
if (Ligne >= 1 && Ligne <= 3 && Colone <= 4 && Colone >= 1)
{
if (Puiss[Ligne-1][Colone-1]== 2 )
{
if (Puiss[Ligne+1][Colone+1]==2)
{
if (Puiss[Ligne+2][Colone+2]==2)
{
Victoire = 2 ;
}
}
}
}
if (Ligne >= 2 && Ligne <= 4 && Colone >= 2 && Colone <= 5)
{
if (Puiss[Ligne-2][Colone-2]== 2 )
{
if (Puiss[Ligne-1][Colone-1]==2)
{
if (Puiss[Ligne+1][Colone+1]==2)
{
Victoire = 2 ;
}
}
}
}
if (Ligne >= 3 && Colone >= 3)
{
if (Puiss[Ligne-3][Colone-3]== 2 )
{
if (Puiss[Ligne-2][Colone-2]==2)
{
if (Puiss[Ligne-1][Colone-1]==2)
{
Victoire = 2 ;
}
}
}
}
/*Tests pour la diagonale descendente*/
if (Ligne >= 3 && Colone <= 3 )
{
if (Puiss[Ligne-1][Colone+1]== 2 )
{
if (Puiss[Ligne-2][Colone+2]==2)
{
if (Puiss[Ligne-3][Colone+3]==2)
{
Victoire = 2 ;
}
}
}
}
if (Ligne >= 2 && Ligne <= 4 && Colone <= 4 && Colone >= 1)
{
if (Puiss[Ligne-2][Colone+2]== 2 )
{
if (Puiss[Ligne+1][Colone-1]==2)
{
if (Puiss[Ligne-1][Colone+1]==2)
{
Victoire = 2 ;
}
}
}
}
if (Ligne >= 1 && Ligne <= 3 && Colone <= 5 && Colone >= 2)
{
if (Puiss[Ligne+1][Colone-1]== 2 )
{
if (Puiss[Ligne-1][Colone+1]==2)
{
if (Puiss[Ligne+2][Colone-2]==2)
{
Victoire = 2 ;
}
}
}
}
if ( Ligne <= 2 && Colone >= 3)
{
if (Puiss[Ligne+2][Colone-2]== 2 )
{
if (Puiss[Ligne+1][Colone-1]==2)
{
if (Puiss[Ligne+3][Colone-3]==2)
{
Victoire = 2 ;
}
}
}
}
Last = 2 ;
if (Puiss [5][0] != 0 && Puiss [5][1] != 0 && Puiss [5][2] != 0 && Puiss [5][3] != 0 && Puiss [5][4] != 0 && Puiss [5][5] != 0 && Puiss [5][6] != 0 )
{
Victoire = 3 ;
}
}
/*Sortie de la boucle car soit l'un des 2 joueurs a gagné soit le tableau est complet */
}
while (Victoire !=1 && Victoire != 2 && Victoire != 3);
/*Affichage du tableau final*/
Color(15,0);
printf(" 0 1 2 3 4 5 6 \n");
printf("+-------+-------+-------+-------+-------+-------+-------+\n");
for (j = 5; j >= 0; j--)
{
printf("| | | | | | | |\n");
for (i = 0; i<=6; i++)
{
if ( AffP[j][i] == 'R')
{
Color(15,0);
printf("|");
Color(12,0);
printf(" %c ", AffP[j][i]);
}
if (AffP[j][i] == 'J')
{
Color(15,0);
printf("|");
Color(14,0);
printf(" %c ", AffP[j][i]);
}
if (AffP[j][i] == ' ')
{
Color(15,0);
printf("|");
printf(" %c ", AffP[j][i]);
}
}
Color(15,0);
printf("|");
printf("\n");
printf("| | | | | | | |\n");
printf("+-------+-------+-------+-------+-------+-------+-------+\n");
}
/*Tests permetant de conaitre le vaincqueur et de le declarer */
switch (Victoire)
{
case (1) : printf ("\a\a\a\n");
printf("%s a gagne BRAVO!!!!!\n\n",J1);
break ;
case (2): printf ("\a\a\a\n");
printf("%s a gagne BRAVO!!!!!\n\n",J2);
break;
case(3): printf ("Match Nul !!!\n\n");
break;
}
/*Fin du Puissance4*/
break ;
}
printf("Pressez Entree pour quitter");
return 0;
}
void Color(int couleurDuTexte,int couleurDeFond) // fonction d'affichage de couleurs
{
HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(H,couleurDeFond*16+couleurDuTexte);
}
Historique
- 22 mai 2010 17:23:51 :
- petite erreur dans le code
- 24 mai 2010 12:22:44 :
- apparemment le .cbp ne marchait pas donc voici seulement le fichier .c il faut juste créer un projet en mode console puis ajouter le fichier et c'est bon
- 24 mai 2010 12:22:46 :
- apparemment le .cbp ne marchait pas donc voici seulement le fichier .c il faut juste créer un projet en mode console puis ajouter le fichier et c'est bon
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|