#include<bits/stdc++.h>
#include<iostream>
#include<bitset>
#include<windows.h>
#include <mmsystem.h>
#include<dsound.h>
#pragma comment(lib, "WINMM.LIB")
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
void color(int ForgC, int BackC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
bool b=true,Who=true,Win,sda;//black
string q[]{
"王",//1,7
"后",//2,8
"兵",//3,9
"教",//4,10
"车",//5,11
"马",//6,12
};
int p[8][8]{
5,6,4,1,2,4,6,5,
3,3,3,3,3,3,3,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,
9,9,9,9,9,9,9,9,
11,12,10,8,7,10,12,11,
};
int F(int x){
int f;
if(x<7){
f=0;
}else{
f=15;
}
color(f,4);
switch(x){
case 1:
case 7:
cout<<q[0]<<" ";
break;
case 2:
case 8:
cout<<q[1]<<" ";
break;
case 3:
case 9:
cout<<q[2]<<" ";
break;
case 4:
case 10:
cout<<q[3]<<" ";
break;
case 5:
case 11:
cout<<q[4]<<" ";
break;
case 6:
case 12:
cout<<q[5]<<" ";
break;
default:
cout<<" ";
break;
}
}
void out(void){
cout<<" ■ 1 2 3 4 5 6 7 8 ■ "<<endl;
cout<<"■■■■■■■■■■■■■■■■"<<endl;
for(int i=0;i<8;i++){
cout<<i+1<<" ■";
for(int j=0;j<8;j++){
F(p[i][j]);
color(15,0);
}
cout<<"■"<<endl;
}
cout<<"■■■■■■■■■■■■■■■■"<<endl;
cout<<" ■ ■ "<<endl;
//cout<<" ■ ■ "<<endl;
}
void S(void){
if(Who==true){
Who=false;
}else{
Who=true;
}
}
void Move(int Y,int X,int Y2,int X2){
if(p[X2][Y2]>0){
if(p[X][Y]<7&&p[X2][Y2]<7||p[X][Y]>6&&p[X2][Y2]>6||p[X2][Y2]==0){
cout<<"not ok!";
system("cls");
S();
for(int i=0;i<50000000;i++){
cout<<"";
}
}else{
if(p[X2][Y2]==1||p[X2][Y2]==7){
Win=Who;
}
p[X2][Y2]=0;
swap(p[X][Y],p[X2][Y2]);
}
}else{
swap(p[X][Y],p[X2][Y2]);
}
}
int main()
{
system("mode con cols=40 lines=20");
system("title 国际象棋");
int y1,y2,x1,x2;
while(b){
out();
if(Who==true){
cout<<"黑方";
}else{
cout<<"白方";
}
cout<<"把(输入y,x)处的棋子挪至(输入y2,x2)处"<<endl<<"请输入y,x"<<endl;
cin>>y1>>x1;
cin>>y2>>x2;
system("cls");
Move(x1-1,y1-1,x2-1,y2-1);
S();
}
return 0;
}