// TicTacToe.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
char map[9] = {'0','1','2','3','4','5','6','7','8',};
void sortp1(int p[]);
void sortp2(int p[]);
void display(int, int);
void display(int, int);
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int p1[5];
int p2[5];
int map[9];
int t=0;
cout<< "0" << " | " << "1" << " | " << "2" <<endl;
cout<< "========="<<endl;
cout<< "3" << " | " << "4" << " | " << "5" <<endl;
cout<< "========="<<endl;
cout<< "6" << " | " << "7" << " | " << "8" <<endl;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2,p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1,p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2, p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2,p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2,p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
//for(int j=0; j<5; j++)
//{
// cout<<p1[j] << "\n";
//}
//for(int j=0; j<4; j++)
//{
// cout<<p2[j] << "\n";
//}
sortp1(p1);
sortp2(p2);
if( p1[0] == 0 && p1[1] == 1 && p1[2] == 2 || p1[0] == 3 && p1[1] == 4 && p1[2] == 5 || p1[0] ==6 && p1[1] == 7 && p1[2] ==8
||p1[0] ==0 && p1[1] ==3 && p1[2] ==6 || p1[0] ==1 && p1[1] ==4 && p1[2] ==7 || p1[0] ==2 && p1[3] ==5 && p1[6] ==8
|| p1[0] == 0 && p1[1] ==4 && p1[2] == 8 || p1[0] == 2 && p1[1] == 4 && p1[2] == 6)
{
cout << "Congratulations Player 1 , You Win!";
}
else
if( p2[0] == 0 && p2[1] == 1 && p2[2] == 2 || p2[0] == 3 && p2[1] ==4 && p2[2] == 5 || p2[0] == 6 && p2[1] == 7 && p2[2] == 8
||p2[0] ==0 && p2[1] ==3 && p2[2] ==6 || p2[0] ==1 && p2[1] ==4 && p2[2] ==7 || p2[0] ==2 && p2[3] ==5 && p2[6] ==8
|| p2[0] == 0 && p2[1] ==4 && p2[2] == 8 || p2[0] == 2 && p2[1] ==4 && p2[2] == 6)
{
cout << "Congratulations Player 2 , You Win!";
}
else
cout << "It's a draw";
getch();
return 0;
}
void sortp1(int p[])
{
for(int i=0; i<3;i--)
{
for(int i=0; i<4;i++)
{
int temp;
if(p[i] >p[i+1])
{
temp = p[i];
p[i]=p[i+1];
p[i+1]=temp;
}
}
}
/*for(int j=0; j<5; j++)
{
cout<<p[j] << "\n";
}*/
}
void sortp2(int p[])
{
int temp;
for(int i=0; i<2;i--)
{
for(int i=0; i<3;i++)
{
if(p[i] >p[i+1])
{
temp = p[i];
p[i]=p[i+1];
p[i+1]=temp;
}
}
}
/*for(int j=0; j<4; j++)
{
cout<<p[j] << "\n";
}*/
}
void display(int a, int p)
{
if(a ==1)
{
map[p]='X';
}
if(a == 2)
{
map[p] = 'O';
}
cout<< map[0] << " | " << map[1] << " | " << map[2] <<endl;
cout<< "========="<<endl;
cout<< map[3] << " | " <<map[4] << " | " << map[5] <<endl;
cout<< "========="<<endl;
cout<< map[6] << " | " <<map[7] << " | " << map[8] <<endl;
}
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
char map[9] = {'0','1','2','3','4','5','6','7','8',};
void sortp1(int p[]);
void sortp2(int p[]);
void display(int, int);
void display(int, int);
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int p1[5];
int p2[5];
int map[9];
int t=0;
cout<< "0" << " | " << "1" << " | " << "2" <<endl;
cout<< "========="<<endl;
cout<< "3" << " | " << "4" << " | " << "5" <<endl;
cout<< "========="<<endl;
cout<< "6" << " | " << "7" << " | " << "8" <<endl;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2,p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1,p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2, p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2,p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
cout<< "\nTurn: Player 2=>";
cin>> p2[t];
display(2,p2[t]);
t++;
cout<< "\nTurn: Player 1=>";
cin>> p1[t];
display(1, p1[t]);
//for(int j=0; j<5; j++)
//{
// cout<<p1[j] << "\n";
//}
//for(int j=0; j<4; j++)
//{
// cout<<p2[j] << "\n";
//}
sortp1(p1);
sortp2(p2);
if( p1[0] == 0 && p1[1] == 1 && p1[2] == 2 || p1[0] == 3 && p1[1] == 4 && p1[2] == 5 || p1[0] ==6 && p1[1] == 7 && p1[2] ==8
||p1[0] ==0 && p1[1] ==3 && p1[2] ==6 || p1[0] ==1 && p1[1] ==4 && p1[2] ==7 || p1[0] ==2 && p1[3] ==5 && p1[6] ==8
|| p1[0] == 0 && p1[1] ==4 && p1[2] == 8 || p1[0] == 2 && p1[1] == 4 && p1[2] == 6)
{
cout << "Congratulations Player 1 , You Win!";
}
else
if( p2[0] == 0 && p2[1] == 1 && p2[2] == 2 || p2[0] == 3 && p2[1] ==4 && p2[2] == 5 || p2[0] == 6 && p2[1] == 7 && p2[2] == 8
||p2[0] ==0 && p2[1] ==3 && p2[2] ==6 || p2[0] ==1 && p2[1] ==4 && p2[2] ==7 || p2[0] ==2 && p2[3] ==5 && p2[6] ==8
|| p2[0] == 0 && p2[1] ==4 && p2[2] == 8 || p2[0] == 2 && p2[1] ==4 && p2[2] == 6)
{
cout << "Congratulations Player 2 , You Win!";
}
else
cout << "It's a draw";
getch();
return 0;
}
void sortp1(int p[])
{
for(int i=0; i<3;i--)
{
for(int i=0; i<4;i++)
{
int temp;
if(p[i] >p[i+1])
{
temp = p[i];
p[i]=p[i+1];
p[i+1]=temp;
}
}
}
/*for(int j=0; j<5; j++)
{
cout<<p[j] << "\n";
}*/
}
void sortp2(int p[])
{
int temp;
for(int i=0; i<2;i--)
{
for(int i=0; i<3;i++)
{
if(p[i] >p[i+1])
{
temp = p[i];
p[i]=p[i+1];
p[i+1]=temp;
}
}
}
/*for(int j=0; j<4; j++)
{
cout<<p[j] << "\n";
}*/
}
void display(int a, int p)
{
if(a ==1)
{
map[p]='X';
}
if(a == 2)
{
map[p] = 'O';
}
cout<< map[0] << " | " << map[1] << " | " << map[2] <<endl;
cout<< "========="<<endl;
cout<< map[3] << " | " <<map[4] << " | " << map[5] <<endl;
cout<< "========="<<endl;
cout<< map[6] << " | " <<map[7] << " | " << map[8] <<endl;
}
No comments:
Post a Comment