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
| // Affichage d'un puissance 4.
// g++ -Wall -Wextra -O puissan.cpp -o puissan
#include<iostream>
using namespace std;
int const lignes = 6;
int const colonnes = 7;
char tab[6][7];
void pion(int choix, char c){
int i = lignes;
bool place=false;
while(place!=true){
if (i==-1 || choix < 0 || choix > 6){
cout << "entrez un autre numero\n";
cin >> choix;
i = lignes;
}
if (tab[choix][i]!=' ')
i--;
else{
tab[choix][i]=c;
place=true;
}
}
}
void initgrille(){
int i,j;
for(i=0;i<lignes;i++){
for(j=0;j<colonnes;j++){
tab[j][i]=' ';
}
}
}
void affich(){
cout << "_______________\n";
for(int i=0; i < lignes;i++){
cout << "|";
for(int j=0; j < colonnes;j++){
cout << tab [j][i] << "|";
}
cout << "\n_______________\n";
}
cout << " 0 1 2 3 4 5 6 \n";
}
bool gagner(char c){
for(int i=0; i < lignes;i++){
for(int j=0; j < colonnes;j++){
if (i < 3){
if (tab[j][i]== c && tab[j][i+1]== c
&& tab[j][i+2]== c && tab[j][i+3]== c)
return true;
}
if (j < 4){
if (tab[j][i]== c && tab[j+1][i]== c
&& tab[j+2][i]== c && tab[j+3][i]== c)
return true;
}
if (j < 4 && i < 3){
if (tab[j][i]== c && tab[j+1][i+1]== c
&& tab[j+2][i+2]== c && tab[j+3][i+3]== c)
return true;
}
if (j < 4 && i > 2){
if (tab[j][i]== c && tab[j+1][i-1]== c
&& tab[j+2][i-2]== c && tab[j+3][i-3]== c)
return true;
}
}
}
}
int main(){
//initialiser le tableau
//afficher le tableau
//vérifier la place du pion
//verifier si on gagne
int i;
int j;
int joueurs;
bool gagne = false;
int choix;
int joueur=1;
initgrille();
cout << "le nombre de joueurs\n";
cin >> joueurs;
while(gagne != true){
i=0;
j=0;
if (joueur==1){
affich();
cin >> choix;
pion(choix, 'X');
//gagner(gagne);
joueur++;
}
if (joueur==2){
affich();
cin >> choix;
pion(choix, 'O');
//gagner(gagne);
joueur--;
}
}
if (joueur==1)
cout << "le joueur 2 gagne\n";
if (joueur==2)
cout << "le joueur 1 gagne\n";
} |
Partager