用户:
萌新大佬查看:32 回复:8 评论:32 创建时间:2021-07-19T17:23:01
这个五子棋怎么错的??!!
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
int qp[19][19]={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
void printc(const char* s, int color){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color | BACKGROUND_INTENSITY | 48);
printf(s);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
bool h_(int who,int x,int y){
bool is_h;
for(int i=x-3;i<=x;i++){
is_h=true;
for(int j=0;j<4;j++){
if(qp[y][i+j]!=who)is_h=false;
}
if(is_h&&(qp[y][i-1]==0&&qp[y][i+4]==0||qp[y][i-1]==who||qp[y][i+4]==who))return is_h;
}
return is_h;
}
bool s_(int who,int x,int y){
bool is_s;
for(int i=y-3;i<=y;i++){
is_s=true;
for(int j=0;j<4;j++){
if(qp[i+j][x]!=who)is_s=false;
}
if(is_s&&((qp[i-1][x]==0&&qp[i+4][x]==0)||qp[i-1][x]==who||qp[i+4][x]==who))return is_s;
}
return is_s;
}
bool x_1(int who,int x,int y){
bool is_x1;
for(int i=0;i<4;i++){
is_x1=true;
for(int j=0;j<4;j++){
if(qp[y-i+j][x-i+j]!=who)is_x1=false;
}
if(is_x1&&((qp[y-i-1][x-i-1]==0&&qp[y-i+4][x-i+4]==0)||(qp[y-i-1][x-i-1]==who&&qp[y-i+4][x-i+4]==who)))return is_x1;
}
return is_x1;
}
bool x_2(int who,int x,int y){
bool is_x2;
for(int i=0;i<4;i++){
is_x2=true;
for(int j=0;j<4;j++){
if(qp[y-i+j][x+i-j]!=who)is_x2=false;
}
if(is_x2&&(qp[y-i+1][x+i-1]==0&&qp[y-i-4][x+i+4]==0||qp[y-i+1][x+i-1]==who||qp[y-i-4][x+i+4]==who))return is_x2;
}
return is_x2;
}
void gotoxy(int x, int y) {
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = 2*x;pos.Y = y;
SetConsoleCursorPosition(hOut, pos);
}
void print(int x,int y){
if(qp[y][x]==1)printc("●",0);
else if(qp[y][x]==2)printc("●",7);
else if(qp[y][x]==3||qp[y][x]==4)printc("●",4);
else if(y==0&&x==0)printc("┌ ",0);
else if(y==0&&x==18)printc("┐ ",0);
else if(y==0)printc("┬ ",0);
else if(y==18&&x==0)printc("└ ",0);
else if(y==18&&x==18)printc("┘ ",0);
else if(y==18)printc("┴ ",0);
else if(x==0)printc("├ ",0);
else if(x==18)printc("┤ ",0);
else if(y==9&&x==9||y==2&&x==2||y==2&&x==15||y==15&&x==2||y==15&&x==15||y==2&&x==9||y==15&&x==9||y==9&&x==2||y==9&&x==15)printc("喵 ",0);
}
int main(){
int x=9,y=9,o=0,h=0;
string z[3]={"黑","白"};
system("cls");
for(int i=0;i<19;i++){
for(int j=0;j<19;j++){
print(j,i);
}
cout<<endl;
}
while(1){
char a;
a=_getch();
if(a=='w'||a==72){
if(y!=0){
qp[y][x]=o;
gotoxy(x,y);
print(x,y);
y--;
o=qp[y][x];
qp[y][x]=h%2+3;
gotoxy(x,y);
print(x,y);
}
else{
gotoxy(0,19);
printf("wrong step\n");
system("pause");
gotoxy(0,19);
cout<<" \n \n ";
}
}
else if(a=='s'||a==80){
if(y!=18){
qp[y][x]=o;
gotoxy(x,y);
print(x,y);
y++;
o=qp[y][x];
qp[y][x]=h%2+3;
gotoxy(x,y);
print(x,y);
}
else{
gotoxy(0,19);
printf("wrong step\n");
system("pause");
gotoxy(0,19);
cout<<" \n \n ";
}
}
else if(a=='a'||a==75){
if(x!=0){
qp[y][x]=o;
gotoxy(x,y);
print(x,y);
x--;
o=qp[y][x];
qp[y][x]=h%2+3;
gotoxy(x,y);
print(x,y);
}
else{
gotoxy(0,19);
printf("wrong step\n");
system("pause");
gotoxy(0,19);
cout<<" \n \n ";
}
}
else if(a=='d'||a==77){
if(x!=18){
qp[y][x]=o;
gotoxy(x,y);
print(x,y);
x++;
o=qp[y][x];
qp[y][x]=h%2+3;
gotoxy(x,y);
print(x,y);
}
else{
gotoxy(0,19);
printf("wrong step\n");
system("pause");
gotoxy(0,19);
cout<<" \n \n ";
}
}
else if(a==' '){
if(o==0){
qp[y][x]=o=h%2+1;
gotoxy(x,y);
print(x,y);
if(h_(h%2+1,x,y)||s_(h%2+1,x,y)||x_1(h%2+1,x,y)||x_2(h%2+1,x,y)){
system("cls");
printf("%s子玩家赢了!!\n",z[h%2].c_str());
system("pause");
exit(1);
}
h++;
}
else {
gotoxy(0,19);
printf("wrong step\n");
Sleep(1000);
gotoxy(0,19);
cout<<" \n \n ";
}
}
}
return 0;
}
醉醉白凰编译项目变更...
--------
- 项目文件名: C:\Users\小毛人\Desktop\项目1.dev
- 编译器名: TDM-GCC 4.9.2 喵-bit Release
生成 makefile...
--------
- 文件名: C:\Users\小毛人\Desktop\Makefile.win
正在处理makefile...
--------
- makefile处理器: C:\Program Files (x86)\Dev-Cpp\MinGW喵\bin\mingw32-make.exe
- 命令: mingw32-make.exe -f "C:\Users\小毛人\Desktop\Makefile.win" all
mingw32-make.exe: Nothing to be done for 'all'.
编译结果...
--------
- 错误: 0
- 警告: 0
- 输出文件名: C:\Users\小毛人\Desktop\项目1.exe
- 输出大小: 1.84323310852051 MiB
- 编译时间: 0.13s
点赞0
评论
CaTional其实我很好奇啊,也不是杠啊就什么的。你用了万能表头,还要conio.h和cstdio.h干嘛呢?都用了.h的表头,还using什么std啊?那个数组也是一言难尽。还有部分if...else的可以用其他比如switch...case代替啊。纯属萌新观点啊,我也不是特别懂啊,也就是略懂略懂而已。
点赞0
评论