begin process at 2012 05 27 17:59:45
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > PUISSANCE 4 C

PUISSANCE 4 C


 Information sur la source

Note :
Aucune note
Catégorie :Jeux Classé sous :Puissance 4, jeux C, grille tableau, mini projet, mini jeux Niveau :Débutant Date de création :22/05/2010 Date de mise à jour :24/05/2010 12:22:46 Vu / téléchargé :3 484 / 136

Auteur : Simon73

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 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);
}



 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 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

Source avec Zip Source avec une capture JEU DES CARTES par eapaceinfo
PROGRAMME DE JEU DE MPT par KerizGarmm
Source avec Zip Source avec une capture JEUX SERPENT par antho974
Source avec Zip Source avec une capture PENDU EN SDL par Damsou91
Source avec Zip STATE MACHINE MODIFICATION MATH BUCKHAM par billybones79

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture JEU PUISSANCE 4 EN C AVEC GTK par msaidara
Source avec Zip PUISSANCE 4 EN SDL, AVEC SAUVEGARDE , JOUEUR VS JOUEUR OU IA... par diablosephiroth
Source avec Zip Source avec une capture Source .NET (Dotnet) PUISSANCE 4 par XelectroX
Source avec Zip Source avec une capture PUISSANCE 4 C++ par Fituza

Commentaires et avis

Commentaire de bonhommecrea le 24/05/2010 11:56:45

euh comment on fait pour le lancer ?

Commentaire de Simon73 le 24/05/2010 12:25:40

dsl il y avait un bug dans le .cbp il faut créer un nouveau projet console application et tu ajoute puissance.c dedans et normalement ca marche en tous cas ca marche chez moi ^^

Commentaire de Simon73 le 25/05/2010 22:44:26

Personne ne peut m'aider ? :'(

Commentaire de kml404 le 30/05/2010 03:28:04

salut tous le monde vous me faites pour l'aide c'est quoi? comment tu as su fait de chose? dites moi quels modèles de Viual Studio dans les installées? c'est l'application console Win32? ou project Win32? apres dans assistant application Win32 suivant. quelles paramétres d'application?

Merci pour l'avance si comme nous aussi faire pour l'aide!

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,390 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales