1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| #include <stdio.h>
#include <stdlib.h>
#define DIM 5
struct joueur {
char nom[25];
char marque;
};
typedef struct joueur s_joueur;
struct cellule {
int permutation;//si=1 : piège
char joueur;//si=a : cellule libre
};
typedef struct cellule s_cellule ;
void Affichage_grille (s_cellule grille[DIM][DIM],s_joueur tab_j[]);
void Pose_pion (s_joueur tab_j[],s_cellule grille[DIM][DIM]);
int main()
{
char a;
s_joueur tab_j[2];
s_cellule grille[DIM][DIM]=
{{{0,a},{0,a},{0,a},{0,a},{1,a}},
{{0,a},{0,a},{0,a},{0,a},{0,a}},
{{0,a},{0,a},{1,a},{0,a},{0,a}},
{{0,a},{0,a},{0,a},{0,a},{0,a}},
{{1,a},{0,a},{0,a},{0,a},{0,a}}};
printf("BIENVENUE SUR LE MORPION PIEGE\n\nLE PREMIER QUI ALIGNE 3 PIONS HORIZONTALEMENT OU VERTICALEMENT A GAGNE !!!\n\nATTENTION : Certaines cases transformeront le pion joue en pion adverse. \n");
printf("Entrez le nom du joueur 1 : ");
scanf("%s",tab_j[0].nom);
printf("Entrez la marque du joueur 1 : ");
scanf("%s",&tab_j[0].marque);
printf("Entrez le nom du joueur 2 : ");
scanf("%s",tab_j[1].nom);
printf("Entrez la marque du joueur 2 : ");
scanf("%s",&tab_j[1].marque);
Affichage_grille (grille,tab_j);
Pose_pion (tab_j,grille);
return 0;
}
void Affichage_grille (s_cellule grille[DIM][DIM],s_joueur tab_j[])
{
int i,j;
char a;
for(i=0;i<DIM;i++)
{ printf("\n");
for(j=0;j<DIM;j++)
{if(grille[i][j].joueur==a)
{printf("_%c_|",tab_j[grille[i][j].joueur].marque);
}
}
}
}
void Pose_pion (s_joueur tab_j[],s_cellule grille[DIM][DIM])
{
int ligne, colonne;
int i,j,k;
printf ("\nC'est a %s de jouer.\n", tab_j[k].nom);
printf ("Entrer la ligne : ");
scanf("%d",&ligne);
printf("Entrer la colonne : ");
scanf("%d",&colonne);
grille[ligne][colonne].joueur=tab_j[k].marque;
Affichage_grille (grille,tab_j);
} |
Partager