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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
////////////////////////// menu()////////////////////
void menu(){
printf("\n*************************************\n");
printf("* *\n");
printf("* TIC TAC *\n");
printf("* *\n");
printf("*************************************\n");
printf("* *\n");
printf("* 1:jouer *\n");
printf("* 2:regle du jeu *\n");
printf("* 3:quitter *\n");
printf("* *\n");
printf("*************************************\n");
}
///////////////////////// jouer/////////////////////////
int jouer(){
printf("_________________________________________________");
char t[9]={'1','2','3','4','5','6','7','8','9'};
int nbr,nbr2, f;
char lettre;
char nom1[100] ="A";
char nom2[100] ="B";
printf("\n\nbienvenue, veuillez entrer le nom du joueur 1(O): ");
scanf("%s",&nom1);
printf("\nveuillez entrer le nom du joueur 2 (X): ");
scanf("%s",&nom2);
do{
f=0;
system("cls");
printf("\n -------------");
printf(" \n | %c | %c | %c |",t[0],t[1],t[2]);
printf(" \n -------------\n | %c | %c | %c | \n -------------\n | %c | %c | %c | \n -------------",t[3],t[4],t[5],t[6],t[7],t[8]);
if((t[0]=='X' || t[0]=='O') && (t[1]=='X' || t[1]=='O') && (t[2]=='X' || t[2]=='O') && (t[3]=='X' || t[3]=='O') && (t[4]=='X' || t[4]=='O') && (t[5]=='X' || t[5]=='O') && (t[6]=='X' || t[6]=='O') && (t[7]=='X' || t[7]=='O') && (t[8]=='X' || t[8]=='O'))
{
if((t[0]=='X' && t[1]=='X' && t[2]=='X' )|| (t[3]=='X' && t[4]=='X' && t[5]=='X' ) || (t[6]=='X' && t[7]=='X' && t[8]=='X' )||
(t[0]=='X' && t[3]=='X' && t[6]=='X' )|| (t[1]=='X' && t[4]=='X' && t[7]=='X' ) || (t[2]=='X' && t[5]=='X' && t[8]=='X' )||
(t[0]=='X' && t[4]=='X' && t[8]=='X' )|| (t[2]=='X' && t[4]=='X' && t[6]=='X' ))
printf("\n Mr.%s est gagnant",nom1);
else
if((t[0]=='O' && t[1]=='O' && t[2]=='O' )|| (t[3]=='O' && t[4]=='O' && t[5]=='O' ) || (t[6]=='O' && t[7]=='O' && t[8]=='O' )||
(t[0]=='O' && t[3]=='O' && t[6]=='O' )|| (t[1]=='O' && t[4]=='O' && t[7]=='O' ) || (t[2]=='O' && t[5]=='O' && t[8]=='O' )||
(t[0]=='O' && t[4]=='O' && t[8]=='O' )|| (t[2]=='O' && t[4]=='O' && t[6]=='O' ))
printf("\n Mr.%s est gagnant",nom2);
else printf("\n Parrie perdu");
menu();
break;}
printf("\nveuillez choisir une case (X) Mr(%s):",nom1);
scanf("%d",&nbr);
if(nbr==1 || nbr==2||nbr==3||nbr==4||nbr==5||nbr==6||nbr==7||nbr==8||nbr==9)
{
if(t[nbr-1]!='X' && t[nbr-1]!='O')
t[nbr-1]='X';
else if(t[nbr-1]=='X' || t[nbr-1]=='O') {printf("\ncase non vide\n");}}//}
system("cls");
printf("\n -------------");
printf(" \n | %c | %c | %c |",t[0],t[1],t[2]);
printf(" \n -------------\n | %c | %c | %c | \n -------------\n | %c | %c | %c | \n -------------",t[3],t[4],t[5],t[6],t[7],t[8]);
printf("\nveuillez choisir une case (O) Mr(%s):",nom2);
scanf("%d",&nbr2);
if(nbr2==1 || nbr2==2||nbr2==3||nbr2==4||nbr2==5||nbr2==6||nbr2==7||nbr2==8||nbr2==9)
{
if(t[nbr2-1]!='O'&& t[nbr2-1]!='X')
t[nbr2-1]='O';
else if(t[nbr2-1]=='X' || t[nbr2-1]=='O') {printf("\ncase non vide\n");}}
}while(f!=1);}
////////////////////////////// MAIN///////////////
main()
{
int choix,fin=1,somme,sous,a=1,b=2;
menu();
while(fin){
printf("\nquel est votre choix :");
scanf("%d",&choix);
system("cls");
switch(choix){
case 1: {jouer();break; }
case 2: {printf("\n\n_________________________________________________________________________\nregle du jeu de tic tac toe:");
printf("\n\nLe Tic-Tac-Toe est une variante simplifiee du morpion\n \nqui se joue sur des damiers 3x3.");
printf("\n\nLes joueurs doivent placer chacun a leur tour sur le damier le symbole\n\nqui leur est attribue : O ou X. Le gagnant est celui qui arrive a aligner");
printf("\n\ntrois symboles identiques, horizontalement, verticalement ou en diagonale.\n\n___________________________________________________________________________\n");
menu();
break;}
case 3: {exit(-1);break;}
default: {printf("ce choix n'existe pas !");}}
}
getch();
} |
Partager