//**********************************************************************************//
// Project Name : Cross Game
//
// Prepared By : ASHUTOSH SINGH
//
//
//********************************************************************************//
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
struct play
{
char a[20],b[20];
};
void main()
{
clrscr();
cout<<"\n\t\t******WELCOME******\n";
cout<<"\n\n\tThis game is meant especially for you.";
cout<<"\n\n\tThe rules are extremely simple.";
cout<<"\n\n\tThis game is played turn wise.";
cout<<"\n\n\tTwo players are required.";
cout<<"\n\n\tThey requiresd to enter no of row and column"<<"number
as\n";
cout<<"\n\tasked.";
cout<<"\n\n\tThe player who manages to make a triplet in any\n";
cout<<"\n\tways to wins the game.";
cout<<"\n\n\tSo go ahead and have fun.\n";
cout<<"\n\n\tPress any key to continue.......";
getch();
char a[3][3],x;
start:
clrscr();
for(int y=0;y<3;y++)
{
for(int z=0;z<3;z++)
{
a[y][z]=' ';
}
}
cout<<"\n\t col 1 col 2 col 3";
cout<<"\n\t";
cout<<"\n\nRow 1 "<<a[0][0]<<" | "<<a[0][1]<<" |
";
cout<<a[0][2];
cout<<"\n\t ----------------------------";
cout<<"\n\nRow 2 "<<a[1][0]<<" | "<<a[1][1]<<" |
";
cout<<a[1][2];
cout<<"\n\t -----------------------------";
cout<<"\n\nRow 3 "<<a[2][0]<<" | "<<a[2][1]<<" |
";
cout<<a[2][2];
int i,player,r,c,j,s;
play players;
cout<<"\n\n\tEnter the name of palyer 1:";
gets(players.a);
cout<<"\n\tEnter the name of palyer 2:";
gets(players.b);
for(i=1;i<10;i++)
{
if(i%2==1)
{
player=1;
x=0;
}
else
{
player=2;
x='X';
}
entry:
{
if(player==1)
{
cout<<"\n\n\t"<<players.a<<" Enter the "<<" row
no.";
cin>>r;
while((r<1)||(r>3))
{
cout<<"\n\n\tInvalid location! Try again.";
cin>>r;
}
cout<<"\n\n\t"<<players.a<<" Enter the column no.";
cin>>c;
while((c<1)||(c>3))
{
cout<<"\n\tInvalid location! Try again.";
cin>>c;
}
if(a[r-1][c-1]==' ')
a[r-1][c-1]='O';
else
{
cout<<"\n\n\tThe space is occupide! Try
again.";
goto entry;
}
}
if(player==2)
{
cout<<"\n\n\t"<<players.b<<" Enter the row no.";
cin>>r;
while((r<1)||(r>3))
{
cout<<"\n\n\tInvalid location! Try again.";
cin>>r;
}
cout<<"\n\n\t"<<players.b<<" Enter the column no.";
cin>>c;
while((c<1)||(c>3))
{
cout<<"\n\tInvalid location! Try again.";
cin>>c;
}
if(a[r-1][c-1]==' ')
a[r-1][c-1]='X';
else
{
cout<<"\n\n\tThe space is occupide! Try again.";
goto entry;
}
}
}
clrscr();
cout<<"\n\t col 1 col 2 col 3";
cout<<"\n\t";
cout<<"\n\nRow 1 "<<a[0][0]<<" | "<<a[0][1]<<" |
";
cout<<a[0][2];
cout<<"\n\t -----------------------------";
cout<<"\n\nRow 2 "<<a[1][0]<<" | "<<a[1][1]<<" |
";
cout<<a[1][2];
cout<<"\n\t -----------------------------";
cout<<"\n\nRow 3 "<<a[2][0]<<" | "<<a[2][1]<<" |
";
cout<<a[2][2];
for(j=0;j<3;j++)
{
if(((a[j][0]==a[j][1])&&(a[j][0]==a[j][2])&&(a[j][0]!=' '))||
((a[0][j]==a[1][j])&&(a[0][j]==a[2][j])&&(a[0][j]!=' '))||
((a[0][0]==a[1][1])&&(a[0][0]==a[2][2])&&(a[0][0]!=' ')))
{
if(x=='O')
{
cout<<"\n\n\t"<<players.b<<" Wins the game.";
goto end;
}
if(x=='X')
{
cout<<"\n\n\t"<<players.a<<" Wins the game.";
goto end;
}
}
}
}
cout<<"\n\n\t The game is tied !!!!!!!!!";
end:
char choice;
cout<<"\n\n\tDo you want to play again(Y/N)";
cin>>choice;
if((choice=='Y')||(choice=='Y'))
goto start;
}
No comments:
Post a Comment