- // Jeu de TIC-TAC-TOE ,
- // Auteur : Amokrane Chentir
- // Date : 4/07/2003
-
- #include <iostream>
- #include <cstdlib>
- #include <econio.h>
-
-
- using std::cin;
- using std::cout;
- using std::endl;
-
- void affiche(const int [][3]);
- void verifie(int[][3],int);
- void jeu();
-
- int a=0;
-
- int main()
- {
-
- jeu();
-
- return 0;
- }
-
- void jeu()
- {
- t:
- a=0;
- int tictactoe[3][3]={ {0},{0} ,{0} };
- int ligneCourante;
- int colonneCourante;
-
- clrscr();
- cout<<"Bienvenu(e)s dans mon jeu de TIC-TAC-TOE 2 joueurs ...."<<endl<<endl;
- cout<<"A vous de jouer !"<<endl<<endl<<endl<<endl;
-
- while(1)
- {
- cout<<endl;
- affiche(tictactoe);
- verifie(tictactoe,2);
- if(a==3)
- goto t;
-
- cout<<endl<<endl;
- textbackground(RED);
- cout<<"--------"<<endl;
- cout<<"Joueur 1"<<endl;
- cout<<"--------"<<endl;
- do
- {
- textbackground(YELLOW);
- cout<<"Quelle est la ligne ou vous voulez placer votre \202toile ?"<<endl<<endl;
- cin>>ligneCourante;
- cout<<"Quelle est la colonne ou vous voulez placer votre colonne ?"<<endl<<endl;
- cin>>colonneCourante;
- }while(tictactoe[ligneCourante-1][colonneCourante-1]!=0);
-
- tictactoe[ligneCourante-1][colonneCourante-1]=1;
- cout<<endl;
- affiche(tictactoe);
- verifie(tictactoe,1);
- if(a==3)
- goto t;
-
-
-
- cout<<endl<<endl;
- textbackground(GREEN);
- cout<<"---------"<<endl;
- cout<<"Joueur 2 "<<endl;
- cout<<"---------"<<endl;
-
- do
- {
- cout<<endl;
- textbackground(WHITE);
- cout<<"Quelle est la ligne ou vous voulez placer votre \202toile ?"<<endl<<endl;
- cin>>ligneCourante;
- cout<<endl<<"Quelle est la colonne ou vous voulez placer votre colonne ?"<<endl<<endl;
- cin>>colonneCourante;
- }while(tictactoe[ligneCourante-1][colonneCourante-1]!=0);
-
- tictactoe[ligneCourante-1][colonneCourante-1]=2;
-
-
- }
- }
-
-
- void affiche(const int wTic[][3])
- {
-
-
- for(int i=0;i<3;i++){
-
- for(int j=0;j<3;j++){
-
- if(wTic[i][j]==0)
- cout<<"0"<<" ";
-
- else if(wTic[i][j]==1)
- cout<<"*"<<" ";
-
- else if(wTic[i][j]==2)
- cout<<"#"<<" ";
-
- }
- cout<<endl;
-
-
- }
- }
-
- void verifie(int tab[][3],int v)
- {
- char reponse;
-
- if( (tab[0][0]==v) && (tab[0][1]==v) && (tab[0][2]==v) ){
- cout<<endl<<endl;
- printf("Le joueur %d a gagn\202 !",v);
- cout<<endl<<"Voulez vous rejouer ?"<<endl;
- cin>>reponse;
- if(reponse=='y' || reponse=='Y')
- a=3;
-
- else
- exit(0);
- }
-
- else if( (tab[1][0]==v) && (tab[1][1]==v) && (tab[1][2]==v) ){
- cout<<endl<<endl;
- printf("Le joueur %d a gagn\202 !",v);
- cout<<endl<<"Voulez vous rejouer ?"<<endl;
- cin>>reponse;
- if(reponse=='y' || reponse=='Y')
- a=3;
- else
- exit(0);
- }
-
- else if( (tab[2][0]==v) && (tab[2][1]==v) && (tab[2][2]==v) ){
- cout<<endl<<endl;
- printf("Le joueur %d a gagn\202 !",v);
- cout<<endl<<"Voulez vous rejouer ?"<<endl;
- cin>>reponse;
- if(reponse=='y' || reponse=='Y')
- a=3;
-
- else
- exit(0);
- }
-
- else if( (tab[0][0]==v) && (tab[1][0]==v) && (tab[2][0]==v) ){
- cout<<endl<<endl;
- printf("Le joueur %d a gagn\202 !",v);
- cout<<endl<<"Voulez vous rejouer ?"<<endl;
- cin>>reponse;
- if(reponse=='y' || reponse=='Y')
- a=3;
-
- else
- exit(0);
- }
-
- else if( (tab[0][1]==v) && (tab[1][1]==v) && (tab[1][2]==v) ){
- cout<<endl<<endl;
- printf("Le joueur %d a gagn\202 !",v);
- cout<<endl<<"Voulez vous rejouer ?"<<endl;
- cin>>reponse;
- if(reponse=='y' || reponse=='Y')
- a=3;
-
- else
- exit(0);
- }
-
- else if( (tab[0][2]==v) && (tab[1][2]==v) && (tab[2][2]==v) ){
- cout<<endl<<endl;
- printf("Le joueur %d a gagn\202 !",v);
- cout<<endl<<"Voulez vous rejouer ?"<<endl;
- cin>>reponse;
- if(reponse=='y' || reponse=='Y')
- a=3;
-
- else
- exit(0);
- }
-
- else if( (tab[0][0]==v) && (tab[1][1]==v) && (tab[2][2]==v) ){
- cout<<endl<<endl;
- printf("Le joueur %d a gagn\202 !",v);
- cout<<endl<<"Voulez vous rejouer ?"<<endl;
- cin>>reponse;
- if(reponse=='y' || reponse=='Y')
- a=3;
-
- else
- exit(0);
- }
-
-
- }
// Jeu de TIC-TAC-TOE ,
// Auteur : Amokrane Chentir
// Date : 4/07/2003
#include <iostream>
#include <cstdlib>
#include <econio.h>
using std::cin;
using std::cout;
using std::endl;
void affiche(const int [][3]);
void verifie(int[][3],int);
void jeu();
int a=0;
int main()
{
jeu();
return 0;
}
void jeu()
{
t:
a=0;
int tictactoe[3][3]={ {0},{0} ,{0} };
int ligneCourante;
int colonneCourante;
clrscr();
cout<<"Bienvenu(e)s dans mon jeu de TIC-TAC-TOE 2 joueurs ...."<<endl<<endl;
cout<<"A vous de jouer !"<<endl<<endl<<endl<<endl;
while(1)
{
cout<<endl;
affiche(tictactoe);
verifie(tictactoe,2);
if(a==3)
goto t;
cout<<endl<<endl;
textbackground(RED);
cout<<"--------"<<endl;
cout<<"Joueur 1"<<endl;
cout<<"--------"<<endl;
do
{
textbackground(YELLOW);
cout<<"Quelle est la ligne ou vous voulez placer votre \202toile ?"<<endl<<endl;
cin>>ligneCourante;
cout<<"Quelle est la colonne ou vous voulez placer votre colonne ?"<<endl<<endl;
cin>>colonneCourante;
}while(tictactoe[ligneCourante-1][colonneCourante-1]!=0);
tictactoe[ligneCourante-1][colonneCourante-1]=1;
cout<<endl;
affiche(tictactoe);
verifie(tictactoe,1);
if(a==3)
goto t;
cout<<endl<<endl;
textbackground(GREEN);
cout<<"---------"<<endl;
cout<<"Joueur 2 "<<endl;
cout<<"---------"<<endl;
do
{
cout<<endl;
textbackground(WHITE);
cout<<"Quelle est la ligne ou vous voulez placer votre \202toile ?"<<endl<<endl;
cin>>ligneCourante;
cout<<endl<<"Quelle est la colonne ou vous voulez placer votre colonne ?"<<endl<<endl;
cin>>colonneCourante;
}while(tictactoe[ligneCourante-1][colonneCourante-1]!=0);
tictactoe[ligneCourante-1][colonneCourante-1]=2;
}
}
void affiche(const int wTic[][3])
{
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(wTic[i][j]==0)
cout<<"0"<<" ";
else if(wTic[i][j]==1)
cout<<"*"<<" ";
else if(wTic[i][j]==2)
cout<<"#"<<" ";
}
cout<<endl;
}
}
void verifie(int tab[][3],int v)
{
char reponse;
if( (tab[0][0]==v) && (tab[0][1]==v) && (tab[0][2]==v) ){
cout<<endl<<endl;
printf("Le joueur %d a gagn\202 !",v);
cout<<endl<<"Voulez vous rejouer ?"<<endl;
cin>>reponse;
if(reponse=='y' || reponse=='Y')
a=3;
else
exit(0);
}
else if( (tab[1][0]==v) && (tab[1][1]==v) && (tab[1][2]==v) ){
cout<<endl<<endl;
printf("Le joueur %d a gagn\202 !",v);
cout<<endl<<"Voulez vous rejouer ?"<<endl;
cin>>reponse;
if(reponse=='y' || reponse=='Y')
a=3;
else
exit(0);
}
else if( (tab[2][0]==v) && (tab[2][1]==v) && (tab[2][2]==v) ){
cout<<endl<<endl;
printf("Le joueur %d a gagn\202 !",v);
cout<<endl<<"Voulez vous rejouer ?"<<endl;
cin>>reponse;
if(reponse=='y' || reponse=='Y')
a=3;
else
exit(0);
}
else if( (tab[0][0]==v) && (tab[1][0]==v) && (tab[2][0]==v) ){
cout<<endl<<endl;
printf("Le joueur %d a gagn\202 !",v);
cout<<endl<<"Voulez vous rejouer ?"<<endl;
cin>>reponse;
if(reponse=='y' || reponse=='Y')
a=3;
else
exit(0);
}
else if( (tab[0][1]==v) && (tab[1][1]==v) && (tab[1][2]==v) ){
cout<<endl<<endl;
printf("Le joueur %d a gagn\202 !",v);
cout<<endl<<"Voulez vous rejouer ?"<<endl;
cin>>reponse;
if(reponse=='y' || reponse=='Y')
a=3;
else
exit(0);
}
else if( (tab[0][2]==v) && (tab[1][2]==v) && (tab[2][2]==v) ){
cout<<endl<<endl;
printf("Le joueur %d a gagn\202 !",v);
cout<<endl<<"Voulez vous rejouer ?"<<endl;
cin>>reponse;
if(reponse=='y' || reponse=='Y')
a=3;
else
exit(0);
}
else if( (tab[0][0]==v) && (tab[1][1]==v) && (tab[2][2]==v) ){
cout<<endl<<endl;
printf("Le joueur %d a gagn\202 !",v);
cout<<endl<<"Voulez vous rejouer ?"<<endl;
cin>>reponse;
if(reponse=='y' || reponse=='Y')
a=3;
else
exit(0);
}
}