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
|
#include <iostream>
#include <stdlib.h>
using namespace std;
char l[10] = {'0','1','2','3','4','5','6','7','8','9'}; // table
int vic(); //victory
void table(); // table
void pc(); // playing with pc
void cil(); // 2 players
int N=0 ,i=1, d, player=1;
int main()
{
int g;
cout << "Who will play-chose 1 if player vs pc, chose 2 if 2 players: ";
cin >> g;
if (g==1) // if pc
{
pc(); // i havent writen this jet
}
else // players
{
do
{
cil();
N++;
system("CLS");
vic();
}
while (N!=9 || i==d );
}
}
void pc()
{
cout <<"still working on it ";
}
void cil()
{
int z;
if (player==1)
{
cout << "player 1 move: ";
cin >>z;
l[z]= 'X';
player++;
table();
}
else
{
cout << "player 2 move: ";
cin >>z;
l[z]='O';
player--;
table();
}
}
int vic()
{
int d;
if ( l[1] == l[2] && l[2] == l[3])
return d=1;
else if ( l[4] == l[5] && l[5] == l[6])
return d=1;
else if (l[7] == l[8] && l[8] == l[9])
return d=1;
else if (l[1] == l[4] && l[4] == l[7])
return d=1;
else if (l[2] == l[5] && l[5] == l[8])
return d=1;
else if (l[3] == l[6] && l[6] == l[9])
return d=1;
else if (l[1] == l[5] && l[5] == l[9])
return d=1;
else if (l[3] == l[5] && l[5] == l[7])
return d=1;
else return d=0;
}
void table()
{
cout << "\n Tic Tac Toe\n\n";
cout << "player 1 (X) - player 2 (O)" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << l[1] << " | " << l[2] << " | " << l[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << l[4] << " | " << l[5] << " | " << l[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << l[7] << " | " << l[8] << " | " << l[9] << endl;
cout << " | | " << endl << endl;
}
|