#include<iostream>
using namespace std;
void init(char a[20][20]);
void draw(char b[20][20]);
int test(char c[20][20],char);
int check(int,int);
int main()
{
char d[20][20];
int i,j;
for(i=0;i<20;i++)
for(j=0;j<20;j++)
{
d[i][j]='|';
cout<<"-";
cout<<d[i][j];
}
for(int x=0;x<900;)
{
int i,j;
if(x%2==0)
{
cout<<endl<<"請A方走:";
cin>>i>>j;
if(check(i,j))
{
cout<<endl<<"輸入不合法,請重新輸入:";
cin>>i>>j;
}
if(d[i][j]=='X'||d[i][j]=='O')
{
cout<<"此處已有子,請重新輸入:";
cin>>i>>j;
}
d[i][j]='X';
draw(d);
if(test(d,'X'))
{
char replay;
cout<<endl<<"A方勝,是否再來一局?N/Y";
cin>>replay;
if((replay=='y')||(replay=='Y'))
main();
else
cout<<endl<<"游戲結束";
}
x+=1;
}
else
{
cout<<endl<<"請B方走:";
cin>>i>>j;
if(check(i,j))
{
cout<<endl<<"輸入不合法,請重新輸入:";
cin>>i>>j;
}
if(d[i][j]=='X'||d[i][j]=='O')
{
cout<<"此處已有子,請重新輸入:";
cin>>i>>j;
}
d[i][j]='O';
draw(d);
if(test(d,'O'))
{
char replay;
cout<<endl<<"A方勝,是否再來一局?N/Y";
cin>>replay;
if((replay=='y')||(replay=='Y'))
main();
else
cout<<endl<<"游戲結束";
}
x+=1;
}
}
return 0;
}
void draw(char b[20][20])
{
for(int i=0;i<20;i++)
for(int j=0;j<20;j++)
{
cout<<"-";
cout<<b[i][j];
}
}
int check(int x,int y)
{
if(x<0||x>20||y<0||y>20)
return 1;
else
return 0;
}
int test(char c[20][20],char z)
{
int i,j;
for(i=0;i<15;i++)
for(j=0;j<15;j++)
if((z==c[i][j]&&z==c[i+1][j+1]&&z==c[i+2][j+2]&&z==c[i+3][j+3]&&z==c[i+4][j+4])||
(z==c[i][j]&&z==c[i+1][j]&&z==c[i+2][j]&&z==c[i+3][j]&&z==c[i+4][j])||
(z==c[i][j]&&z==c[i][j+1]&&z==c[i][j+2]&&z==c[i][j+3]&&z==c[i][j+4]))
return 1;
else
return 0;
}
uj5u.com熱心網友回復:
有什么問題?uj5u.com熱心網友回復:
無法判斷輸贏啊!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/151625.html
標籤:基礎類
上一篇:C++builder 2009 要用什么控制元件能直接粘貼進復制的excel格式資料?
下一篇:BCB6不能打開
