hello i am creating a tictictoe game , however i cannot get the program to check if the player has won or not . and produce a you have won message
#include<iostream>
#include"110ct.h"
using namespace std;
class TICTACTOE
{
CursorController*crs;
ColourController*cl;
int xplayer ;
int oplayer;
colour Cs;
public:
void Board();// will display the main part of the game
void score();// this will keep the score
void win();
void HumanTCT();//this will determine human input
void ComputerTCT();//this will alllow the computer to be player 2
void SetPositon(int x, int y);// co-ordinate position
void setColour(ColourController*colour){cl = colour;}
void setColourCL(colour c){Cs = c;}
void setPtr(CursorController *c1, ColourController *c2){crs=c1; cl=c2;}
};
void TICTACTOE::HumanTCT()
{
char Map[10] = {'o','1','2','3','4','5','6','7','8','9'};
char x = 'x';
char o = 'o';
char mone = '1';
char mtwo = '2';
char mthree = '3';
char mfour = '4';
char mfive = '5';
char msix = '6';
char mseven = '7';
char meight = '8';
char mnine = '9';
int counter = 0;
int xplayer = 1;
int oplayer = 1;
while ( xplayer = 1) {
counter = counter + 1;
cout << "player one"<<xplayer<<" Enter the co-ordinate on the board please ?";
cin >> mone;
if ( mone == '1') {
Map[1] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mone == '2') {
Map[2] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mone == '3') {
Map[3] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}
else if ( mone == '4') {
Map[4] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mone == '5') {
Map[5] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mone == '6') {
Map[6] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mone == '7') {
Map[7] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mone == '8') {
Map[8] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mone == '9') {
Map[9] = 'x';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}
else{
cout<< " you have entered something wrong , try again " << endl;
}
cout << "computer"<<oplayer<<" Enter the co-ordinate on the board please ?";
cin >> mtwo;
if ( mtwo == '1') {
Map[1] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mtwo == '2') {
Map[2] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mtwo == '3') {
Map[3] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}
else if ( mtwo == '4') {
Map[4] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mtwo == '5') {
Map[5] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mtwo == '6') {
Map[6] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mtwo == '7') {
Map[7] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mtwo == '8') {
Map[8] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}else if ( mtwo == '9') {
Map[9] = 'o';
system("cls");
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}
else{
cout<< " you have entered something wrong , try again " << endl;
}
for( int i = 0 ; i < 3 ; i++)
{
if(Map[1] == 'x' && Map[2] == 'x' && Map[3] == 'x' || Map[1] == 'x' && Map[4] == 'x' && Map[7] == 'x' )
{
system("cls");
cout<< endl;
cout << "PLAYER 1 WINS YEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH "<< endl;
system("cls");
system("PAUSE");
char Map[10] = {'o','1','2','3','4','5','6','7','8','9'};
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}
}
}
}
void TICTACTOE::win()
{
char Map[9] = {'1','2','3','4','5','6','7','8','9'};
char x = 'x';
char o = 'o';
int counter = 0;
for( int i = 0 ; i < 3 ; i++)
{
if(Map[1] == 'x' && Map[2] == 'x' && Map[3] == 'x' || Map[1] == 'x' && Map[4] == 'x' && Map[7] == 'x' )
{
system("cls");
cout<< endl;
cout << "PLAYER 1 WINS YEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH "<< endl;
system("cls");
system("PAUSE");
char Map[9] = {'1','2','3','4','5','6','7','8','9'};
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}
}
}
void TICTACTOE::Board ()
{
char Map[10] = {'o','1','2','3','4','5','6','7','8','9'};
cout << " user must choose a number on the board to play \n";
cout << " | | \n";
cout << " " << Map[1] << " | " << Map[2] << " | " << Map[3] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[4] << " | " << Map[5] << " | " << Map[6] << endl;
cout << " _____|_____|_____\n";
cout << " | | \n";
cout << " " << Map[7] << " | " << Map[8] << " | " <<Map[9] << endl;
cout << " | | \n\n";
}
int main()
{
cout << "\nWelcome To The Awesome Game Of\n\t MEGA Tic Tac Toe\n\n";
cout << "Player 1 uses X and Player 2(computer) uses O" << endl << endl;
TICTACTOE T;
T.Board();
T.HumanTCT();
T.win();
qin.get();
return 0;
}