纯手打,肝了4个小时,请各位大佬帮忙看一看!!!
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int n,x,y,xx1[30],yy1[30];
int a[27][27]={};
int b[27][27]={1};
void pd(int i,int j,int k,int l);
void co(int x,int y);
bool pdsl(int a);
bool pdh(int c);
bool pds(int c);
bool pdzx(int c);
bool pdyx(int c);
void costr(string c);
int main()
{
system("color B");
char q[100]={"Welcome the gobang simulator!"};
for(int i=0;i<29;i++){
cout<<q[i];
Sleep(50);
}
cout<<'\n';
char qq[200]={"Now,you will answer some qustion."};
for(int i=0;i<33;i++){
cout<<qq[i];
Sleep(50);
}
cout<<'\n';
char p=MessageBox(NULL,"Do you want to do this?","Game prompt",MB_YESNO);
if(p==IDNO){
string quququ="Sorry, you don't have the authority to do this.";
costr(quququ);
}
int iii=0;
string question[5]={"1.Wrter luogu name is Zouwenhan,luogu number is 1123435.Please add him luogu.","2.Writr is very lazy to code typing.Can you help him?","3.You must admit,the author is very handsome,humorous,and understanding.","4.Just to emphasize,this is not an advertisement or narcissism,it is just a proper promotion."};
while(p!=IDNO&&iii<4){
string rt=question[iii];
costr(rt);
p=MessageBox(NULL,"Yes or no?","Question",MB_YESNO);
iii++;
}
if(p==IDNO){
string quququ="Sorry, you don't have the authority to do this.";
costr(quququ);
Sleep(5000);
return 0;
}
system("cls");
costr("Now,you have arrived at the real the gobang simulator!");
costr("I'll teach you how to operate it.");
costr("Press the W key and move up one grid.");
costr("Press the S key and move down one grid.");
costr("Press the A key and move one space to the left.");
costr("Press the D key and move one space to the right.");
costr("Press the spacebar to play chess here.");
costr("Press the P key to undo the previous step.");
costr("Attention, it must be capitalized!");
Sleep(7000);
system("cls");
costr("Now,you study the rule.");
costr("You can cin the board size now.");
cout<<"Size:";
cin>>n;
while(n<5||n>25){
cout<<"This size is wrong,please cin again.\n";
Sleep(1900);
system("cls");
cout<<"Please cin the board size:";
cin>>n;
}
system("cls");
x=1;y=1;
int i=1;
co(x,y);
while(true){
if(GetAsyncKeyState('W')){
system("cls");
if(x>1){
x--;
}
co(x,y);
Sleep(30);
}
else if(GetAsyncKeyState('S')){
system("cls");
if(x<n){
x++;
}
co(x,y);
Sleep(30);
}
else if(GetAsyncKeyState('A')){
system("cls");
if(y>1){
y--;
}
co(x,y);
Sleep(30);
}
else if(GetAsyncKeyState('D')){
system("cls");
if(y<n){
y++;
}
co(x,y);
Sleep(30);
}
else if(GetAsyncKeyState(VK_SPACE)){
if(a[x][y]){
continue;
}
system("cls");
if(i%2){
a[x][y]=1;
xx1[i]=x;
yy1[i]=y;
}
else{
a[x][y]=2;
xx1[i]=x;
yy1[i]=y;
}
i++;
co(x,y);
if(i%2&&pdsl(1)){
cout<<'\n'<<"Blacks are win."<<'\n';
Sleep(3000);
break;
}
if(i%2==0&&pdsl(2)){
cout<<'\n'<<"Whites are win."<<'\n';
Sleep(3000);
break;
}
if(i==n*n&&pdsl(2)&&pdsl(1)){
cout<<'\n'<<"It is draw."<<'\n';
Sleep(3000);
break;
}
Sleep(30);
continue;
}
else if(GetAsyncKeyState(VK_ESCAPE)){
char a=MessageBox(NULL,"Do you want to stop this game?","Game prompt",MB_YESNO);
if(a==IDYES){
break;
}
}
else if(GetAsyncKeyState('P')){
system("cls");
if(a[x][y]==0){
co(x,y);
Sleep(30);
continue;
}
if(x!=xx1[i-1]||y!=yy1[i-1]){
co(x,y);
Sleep(30);
continue;
}
i--;
a[x][y]=0;
co(x,y);
Sleep(30);
}
Sleep(10);
}
return -1;
}
void pd(int i,int j,int k,int l){
if(l==1){
if(k==0){
if(a[i][j]==0){
cout<<' '<<"."<<" ";
}
else if(a[i][j]==1){
cout<<' '<<"B"<<" ";
}
else{
cout<<' '<<"W" <<" ";
}
}
else{
if(a[i][j]==0){
cout<<'>'<<"."<<"< ";
}
else if(a[i][j]==1){
cout<<'>'<<"B"<<"< ";
}
else{
cout<<'>'<<"W"<<"< ";
}
}
}
else{
if(k==0){
if(a[i][j]==0){
cout<<' '<<"."<<' ';
}
else if(a[i][j]==1){
cout<<' '<<"B"<<' ';
}
else{
cout<<' '<<"W" <<' ';
}
}
else{
if(a[i][j]==0){
cout<<'>'<<"."<<'<';
}
else if(a[i][j]==1){
cout<<'>'<<"B"<<'<';
}
else{
cout<<'>'<<"W" <<'<';
}
}
}
}
void co(int x,int y)
{
if(n>9){
for(int i=0;i<=n;i++){
if(i==0){
cout<<" ";
for(int j=1;j<=n;j++){
if(j>9){
cout<<j<<" ";
}
else{
cout<<j<<" ";
}
}
cout<<'\n';
continue;
}
for(int j=0;j<=n;j++){
if(j==0&&i<10){
cout<<i<<" ";
}
else if(j==0&&i>9){
cout<<i<<" ";
}
else if(i==x&&j==y){
pd(i,j,1,1);
}
else{
pd(i,j,0,1);
}
}
cout<<'\n';
}
}
else{
for(int i=0;i<=n;i++){
if(i==0){
cout<<" ";
for(int j=1;j<=n;j++){
cout<<j<<" ";
}
cout<<'\n';
continue;
}
for(int j=0;j<=n;j++){
if(j==0){
cout<<i<<' ';
}
else if(i==x&&j==y){
pd(i,j,1,0);
}
else{
pd(i,j,0,0);
}
}
cout<<'\n';
}
}
}
bool pdsl(int a){
if(pdh(a)||pds(a)||pdzx(a)||pdyx(a)){
return 1;
}
return 0;
}
bool pdh(int c){
int sum=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
b[i][j]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]==c){
b[i][j]=b[i][j-1]+1;
}
else{
b[i][j]=0;
}
sum=max(sum,b[i][j]);
}
}
if(sum>=5){
return 1;
}
else{
return 0;
}
}
bool pds(int c){
int sum=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
b[i][j]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]==c){
b[i][j]=b[i-1][j]+1;
}
else{
b[i][j]=0;
}
sum=max(sum,b[i][j]);
}
}
if(sum>=5){
return 1;
}
else{
return 0;
}
}
bool pdzx(int c){
int sum=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
b[i][j]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]==c){
b[i][j]=b[i-1][j-1]+1;
}
else{
b[i][j]=0;
}
sum=max(sum,b[i][j]);
}
}
if(sum>=5){
return 1;
}
else{
return 0;
}
}
bool pdyx(int c){
int sum=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
b[i][j]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]==c){
b[i][j]=b[i-1][j+1]+1;
}
else{
b[i][j]=0;
}
sum=max(sum,b[i][j]);
}
}
if(sum>=5){
return 1;
}
else{
return 0;
}
}
void costr(string c){
for(int i=0;i<c.length();i++){
cout<<c[i];
Sleep(50);
}
cout<<'\n';
}