最近想玩一玩五子棋,就自己做了一个
现在只能玩双人的。。。
上代码:
#ifndef SOMETHING_H
#define SOMETHING_H
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
void ycgb() {
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = FALSE;
cursor.dwSize = sizeof(cursor);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
return ;
}
#endif
using namespace std;
int s[20][20]= {0};
int a,b,c;
void show() {
memset(s,0,sizeof s);
cout<<"先行再列!"<<endl;
cout<<" 0 1 2 3 4 5 6 7 8 9 10"<<endl;
for(int y=0; y<=9; y++)
cout<<y<<" - - - - - - - - - - -"<<endl;
cout<<"10"<<" - - - - - - - - - - -"<<endl;
}
int main() {
system("mode con cols=31 lines=15");
ycgb();
show();
while(1) {
cout<<"1P:";
cin>>a;
cout<<"1P:";
cin>>b;
if(s[a][b]!=0) {
do {
cout<<"已存在,请重新输入:"<<endl;
system("cls");
cout<<"先行再列!"<<endl;
cout<<" 0 1 2 3 4 5 6 7 8 9 10"<<endl;
for(int i=0; i<10; i++) {
cout<<i<<" ";
for(int j=0; j<11; j++) {
if(s[i][j]==0) cout<<"- ";
else cout<<s[i][j]<<" ";
}
cout<<endl;
}
cout<<"10 ";
for(int j=0; j<11; j++) {
if(s[10][j]==0) cout<<"- ";
else cout<<s[10][j]<<" ";
}
cout<<endl;
cout<<"2P:";
cin>>a;
cout<<"2P:";
cin>>b;
} while(s[a][b]!=0);
}
s[a][b]=1;
system("cls");
cout<<"先行再列!"<<endl;
cout<<" 0 1 2 3 4 5 6 7 8 9 10"<<endl;
for(int i=0; i<10; i++) {
cout<<i<<" ";
for(int j=0; j<11; j++) {
if(s[i][j]==0) cout<<"- ";
else cout<<s[i][j]<<" ";
}
cout<<endl;
}
cout<<"10 ";
for(int j=0; j<11; j++) {
if(s[10][j]==0) cout<<"- ";
else cout<<s[10][j]<<" ";
}
cout<<endl;
if(s[a][b]==1&&s[a-1][b+1]==1&&s[a-2][b+2]==1&&s[a-3][b+3]==1&&s[a-4][b+4]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a+1][b-1]==1&&s[a-1][b+1]==1&&s[a-2][b+2]==1&&s[a-3][b+3]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a+1][b-1]==1&&s[a+2][b-2]==1&&s[a-1][b+1]==1&&s[a-2][b+2]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a+1][b-1]==1&&s[a+2][b-2]==1&&s[a+3][b-3]==1&&s[a-1][b+1]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a+1][b-1]==1&&s[a+2][b-2]==1&&s[a+3][b-3]==1&&s[a+4][b-4]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a+1][b+1]==1&&s[a+2][b+2]==1&&s[a+3][b+3]==1&&s[a+4][b+4]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b-1]==1&&s[a+1][b+1]==1&&s[a+2][b+2]==1&&s[a+3][b+3]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b-1]==1&&s[a-2][b-2]==1&&s[a+1][b+1]==1&&s[a+2][b+2]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b-1]==1&&s[a-2][b-2]==1&&s[a-3][b-3]==1&&s[a+1][b+1]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b-1]==1&&s[a-2][b-2]==1&&s[a-3][b-3]==1&&s[a-4][b-4]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a+1][b]==1&&s[a+2][b]==1&&s[a+3][b]==1&&s[a+4][b]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b]==1&&s[a+1][b]==1&&s[a+2][b]==1&&s[a+3][b]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b]==1&&s[a-2][b]==1&&s[a+1][b]==1&&s[a+2][b]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b]==1&&s[a-2][b]==1&&s[a-3][b]==1&&s[a+1][b]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a-1][b]==1&&s[a-2][b]==1&&s[a-3][b]==1&&s[a-4][b]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a][b+1]==1&&s[a][b+2]==1&&s[a][b+3]==1&&s[a][b+4]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a][b-1]==1&&s[a][b+1]==1&&s[a][b+2]==1&&s[a][b+3]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a][b-1]==1&&s[a][b-2]==1&&s[a][b+1]==1&&s[a][b+2]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a][b-1]==1&&s[a][b-2]==1&&s[a][b-3]==1&&s[a][b+1]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==1&&s[a][b-1]==1&&s[a][b-2]==1&&s[a][b-3]==1&&s[a][b-4]==1) {
cout<<"1Pwin"<<endl;
system("pause");
return 0;
}
cout<<"2P:";
cin>>a;
cout<<"2P:";
cin>>b;
if(s[a][b]!=0) {
do {
cout<<"已存在,请重新输入:"<<endl;
system("cls");
cout<<"先行再列!"<<endl;
cout<<" 0 1 2 3 4 5 6 7 8 9 10"<<endl;
for(int i=0; i<10; i++) {
cout<<i<<" ";
for(int j=0; j<11; j++) {
if(s[i][j]==0) cout<<"- ";
else cout<<s[i][j]<<" ";
}
cout<<endl;
}
cout<<"10 ";
for(int j=0; j<11; j++) {
if(s[10][j]==0) cout<<"- ";
else cout<<s[10][j]<<" ";
}
cout<<endl;
cout<<"2P:";
cin>>a;
cout<<"2P:";
cin>>b;
} while(s[a][b]!=0);
}
s[a][b]=2;
system("cls");
cout<<"先行再列!"<<endl;
cout<<" 0 1 2 3 4 5 6 7 8 9 10"<<endl;
for(int i=0; i<10; i++) {
cout<<i<<" ";
for(int j=0; j<11; j++) {
if(s[i][j]==0) cout<<"- ";
else cout<<s[i][j]<<" ";
}
cout<<endl;
}
cout<<"10 ";
for(int j=0; j<11; j++) {
if(s[10][j]==0) cout<<"- ";
else cout<<s[10][j]<<" ";
}
cout<<endl;
if(s[a][b]==2&&s[a-1][b+1]==2&&s[a-2][b+2]==2&&s[a-3][b+3]==2&&s[a-4][b+4]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a+1][b-1]==2&&s[a-1][b+1]==2&&s[a-2][b+2]==2&&s[a-3][b+3]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a+1][b-1]==2&&s[a+2][b-2]==2&&s[a-1][b+1]==2&&s[a-2][b+2]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a+1][b-1]==2&&s[a+2][b-2]==2&&s[a+3][b-3]==2&&s[a-1][b+1]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a+1][b-1]==2&&s[a+2][b-2]==2&&s[a+3][b-3]==2&&s[a+4][b-4]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a+1][b+1]==2&&s[a+2][b+2]==2&&s[a+3][b+3]==2&&s[a+4][b+4]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b-1]==2&&s[a+1][b+1]==2&&s[a+2][b+2]==2&&s[a+3][b+3]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b-1]==2&&s[a-2][b-2]==2&&s[a+1][b+1]==2&&s[a+2][b+2]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b-1]==2&&s[a-2][b-2]==2&&s[a-3][b-3]==2&&s[a+1][b+1]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b-1]==2&&s[a-2][b-2]==2&&s[a-3][b-3]==2&&s[a-4][b-4]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a+1][b]==2&&s[a+2][b]==2&&s[a+3][b]==2&&s[a+4][b]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b]==2&&s[a+1][b]==2&&s[a+2][b]==2&&s[a+3][b]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b]==2&&s[a-2][b]==2&&s[a+1][b]==2&&s[a+2][b]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b]==2&&s[a-2][b]==2&&s[a-3][b]==2&&s[a+1][b]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a-1][b]==2&&s[a-2][b]==2&&s[a-3][b]==2&&s[a-4][b]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a][b+1]==2&&s[a][b+2]==2&&s[a][b+3]==2&&s[a][b+4]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a][b-1]==2&&s[a][b+1]==2&&s[a][b+2]==2&&s[a][b+3]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a][b-1]==2&&s[a][b-2]==2&&s[a][b+1]==2&&s[a][b+2]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a][b-1]==2&&s[a][b-2]==2&&s[a][b-3]==2&&s[a][b+1]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
if(s[a][b]==2&&s[a][b-1]==2&&s[a][b-2]==2&&s[a][b-3]==2&&s[a][b-4]==2) {
cout<<"2Pwin"<<endl;
system("pause");
return 0;
}
}
system("pause");
return 0;
}
谢谢观看,好玩就来个赞和收藏吧!