۳-۳-۱۳۸۶, ۰۸:۵۰ عصر
سلام
این بازی رو ممکنه تو بازی های لینوکس دیده باشین
من که خودم عاشقشم
این بازی رو ممکنه تو بازی های لینوکس دیده باشین
من که خودم عاشقشم
کد:
//www.codecorona.com
//written by soheil setayeshi
#include<iostream>
#include<conio.h>
using namespace std;
class ataxx
{
public:
ataxx();
int move(int,int,int,int,char);
int checkwin(char);
void winner();
void display();
void play();
int checkend();
private:
char map[7][7];
int white;
int black;
int state;
};
//**********************************
ataxx ::ataxx()
{
for (int i=0;i<7;i++)
for (int j=0;j<7;j++)
map[i][j]=' ';
map[0][0]=map[6][6]=2;
map[0][6]=map[6][0]=1;
white=0;
black=0;
state=1;
}
//**********************************
int ataxx::checkend()
{
return !state;
}
//**********************************
int ataxx::move(int p1i,int p1j,int p2i,int p2j,char ch)
{
int i,j,k,l;
if ( map[p2i][p2j] != ' ')
return 0;
for (i=p1i-2;i<=p1i+2;i++)
for (j=p1j-2;j<=p1j+2;j++)
if ( i==p2i && j==p2j )
{
map[i][j]=ch;
if ( i-p1i==2 || i-p1i==-2 || j-p1j==2 || j-p1j==-2 )
map[p1i][p1j]=' ';
//
for (k=i-1;k<=i+1;k++)
for (l=j-1;l<=j+1;l++)
if ( map[k][l] != ch && map[k][l] !=' ' && k>-1 && k<7 && l>-1 && l<7 )
map[k][l]=ch;
//
return 1;
}
return 0;
}
//**********************************
int ataxx::checkwin(char ch)
{
int i,j,k,l,counter=0;
for (i=0;i<7;i++)
for (j=0;j<7;j++)
if (map[i][j]==' ')
counter++;
if (!counter) return 1;
for (i=0;i<7;i++)
for (j=0;j<7;j++)
if (map[i][j]==ch)
for (k=i-2;k<=i+2;k++)
for (l=j-2;l<=j+2;l++)
if (map[k][l]==' ')
return 0;
return 1;
}
//**********************************
void ataxx::winner()
{
int i,j,k,w=1;
char ch;
system("cls");
display();
system("pause");
for (i=0;i<white;i++)
map[0][i]=2;
for (j=i;j<black+white;j++)
map[0][j]=1;
for (k=j;k<49;k++)
map[0][k]='x';
for (i=0;i<7;i++)
{
for (j=0;j<7;j++)
cout<<map[i][j]<<' ';
cout<<endl;
}
if (white>black)
cout<<"White is: "<<white<<endl;
cout<<"black is: "<<black<<endl;
cout<<"So winner is: ";
if (white > black) cout<<" WHITE \n";
else cout<<" Black \n";
system("pause");
cout<<"The game is over\nFor restart press R\nFor exit press E\n";
while(w)
{
ch=getch();
if (ch=='e' || ch=='E')
{
state=0;
w=0;
}
else if (ch=='r' || ch=='R')
{
state=1;
w=0;
}
else
cout<<'\a';
}
}
//**********************************
void ataxx::display()
{
int i,j;
white=black=0;
cout<<" ";
for (i=0;i<7;i++)
cout<<i+1<<" ";
cout<<"\n\n";
for (i=0;i<7;i++)
{
cout<<i+1<<" ";
for (j=0;j<7;j++)
{
cout<<'('<<map[i][j]<<") ";
if (map[i][j]==2)
white++;
else if (map[i][j]==1)
black++;
}
cout<<"\n\n";
}
cout<<"White: "<<white<<"\tBlack: "<<black<<endl;
}
//**********************************
void ataxx::play()
{
int p1i,p1j,p2i,p2j,f,t;
char ch=2;
while(1)
{
system("cls");
display();
f=t=1;
while(f)
{
if (ch==2)
cout<<"Player white:\n";
else
cout<<"Player black:\n";
cout<<"From X:";
cin>>p1i;
p1i--;
if (p1i<0 || p1i>6)
{
cout<<'\a';
system("cls");
display();
continue;
}
else
{
cout<<"From Y:";
cin>>p1j;
p1j--;
if (p1j<0 || p1j>6)
{
cout<<'\a';
system("cls");
display();
continue;
}
}
if ( map[p1i][p1j] != ch)
{
cout<<'\a';
system("cls");
display();
continue;
}
f=0;
}
while(t)
{
if (ch==2)
cout<<"Player white:\n";
else
cout<<"player black:\n";
cout<<"TO X:";
cin>>p2i;
p2i--;
if (p2i<0 || p2i>6)
{
cout<<'\a';
system("cls");
display();
continue;
}
else
{
cout<<"TO Y:";
cin>>p2j;
p2j--;
if (p2j<0 || p2j>6)
{
cout<<'\a';
system("cls");
display();
continue;
}
}
t=0;
}
if ( move(p1i,p1j,p2i,p2j,ch))
{
ch=(ch==2)?1:2;
if ( checkwin(ch))
{
winner();
return;
}
}
else
cout<<'\a';
}
}
//**********************************
int main()
{
while(1)
{
ataxx game;
game.play();
if (game.checkend())
return 0;
}
}
//**********************************