各位哥哥姐姐叔叔阿姨爷爷奶奶们,给我个赞吧!
我是一名四升五小学生,第二个是我用暑假的时间编的代码,却出现了问题,请大家帮我纠正下,感谢大家!
1
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<windows.h>
#include<cmath>
using namespace std;
class Chessboard;
class Chess
{
private:
int Id;
public:
Chess(int x) :Id(x) {}
int Get() //取ID
{
return Id;
}
virtual bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy) = 0;//判断走步合理性
virtual ~Chess() {}
};
class Chessboard
{
private:
Chess *c[10][11]; //棋盘:X为横(9),Y为纵(10),从1开始记
char Chessword[15][4] = { "兵","炮","车","马","相","仕","帅"," ","将","士","象","馬","車","砲","卒" };
public:
static int Player; //上半区为1,下半区为-1
static bool End; //判断是否结束
Chessboard();
Chess *Get(int x, int y);//返回指定点的指针
int Getid(int x, int y);//返回指定点处棋子ID的指针
bool Move(int startx, int starty, int endx, int endy); //移动
void Init(); //初始化棋子
void Show(); //打印
void Play(); //开始游戏
~Chessboard();
};
class General :public Chess//将、帅类,ID为-1和1
{
public:
General(int i) :Chess((i == 0 ? -1 : 1)) {}
bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
{
int TempX = startx - endx;
int TempY = starty - endy;
int S_Id = ch.Getid(startx, starty);
int E_Id = ch.Getid(endx, endy);
if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 1) && (endx >= 4 && endx <= 6) && (endy >= 1 && endy <= 3 || endy >= 8 && endy <= 10))
{
return true;
}
return false;
}
~General()
{
Chessboard::End = false;
}
};
class BodyGuard :public Chess//士、仕类,ID为-2和2
{
public:
BodyGuard(int i) :Chess((i == 0 ? -2 : 2)) {}
bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
{
int TempX = startx - endx;
int TempY = starty - endy;
int S_Id = ch.Getid(startx, starty);
int E_Id = ch.Getid(endx, endy);
if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 2) && (endx >= 4 && endx <= 6) && (endy >= 1 && endy <= 3 || endy >= 8 && endy <= 10))
{
return true;
}
return false;
}
};
class Chancellor :public Chess//象、相类,ID为-3和3
{
public:
Chancellor(int i) :Chess((i == 0 ? -3 : 3)) {}
bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
{
int TempX = startx - endx;
int TempY = starty - endy;
int S_Id = ch.Getid(startx, starty);
int E_Id = ch.Getid(endx, endy);
if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 8) && (endx % 2 != 0 && endx >= 1 && endy <= 9) && ((starty - 1) / 5 == (endy - 1) / 5) && !ch.Get(startx + (TempX / 2), starty + (TempY / 2)))
{
return true;
}
return false;
}
};
class Horse :public Chess//馬、马类,ID为-4和4
{
public:
Horse(int i) :Chess((i == 0 ? -4 : 4)) {}
bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
{
int TempX = startx - endx;
int TempY = starty - endy;
int S_Id = ch.Getid(startx, starty);
int E_Id = ch.Getid(endx, endy);
if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 5) && !ch.Get(startx + (TempX / 2), starty + (TempY / 2)))
{
return true;
}
return false;
}
};
class Chariot :public Chess//車、车类,ID为-5和5
{
public:
Chariot(int i) :Chess((i == 0 ? -5 : 5)) {}
bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
{
int TempX = startx - endx;
int TempY = starty - endy;
int S_Id = ch.Getid(startx, starty);
int E_Id = ch.Getid(endx, endy);
if ((S_Id*E_Id <= 0) && (!(TempX&&TempY)) && (TempX + TempY))
{
if (TempX)
{
int Sign = (TempX > 0 ? -1 : 1);
for (int i = 1; i < fabs(TempX); i++)
{
if (ch.Get(startx + Sign * i, starty))
{
return false;
}
}
}
else
{
int Sign = (TempY > 0 ? -1 : 1);
for (int i = 1; i < fabs(TempY); i++)
{
if (ch.Get(startx, starty + Sign * i))
{
return false;
}
}
}
return true;
}
return false;
}
};
class Cannon :public Chess//砲、炮类,ID为-6和6
{
public:
Cannon(int i) :Chess((i == 0 ? -6 : 6)) {}
bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
{
int TempX = startx - endx;
int TempY = starty - endy;
int S_Id = ch.Getid(startx, starty);
int E_Id = ch.Getid(endx, endy);
if ((S_Id*E_Id <= 0) && (!(TempX&&TempY)) && (TempX + TempY))
{
int Tmp = 0;
if (TempX)
{
int Sign = (TempX > 0 ? -1 : 1);
for (int i = 1; i < fabs(TempX); i++)
{
if (ch.Get(startx + Sign * i, starty))
{
Tmp++;
}
}
}
else
{
int Sign = (TempY > 0 ? -1 : 1);
for (int i = 1; i < fabs(TempY); i++)
{
if (ch.Get(startx, starty + Sign * i))
{
Tmp++;
}
}
}
if (E_Id)
{
if (Tmp == 1)
{
return true;
}
}
else
{
if (!Tmp)
{
return true;
}
}
}
return false;
}
};
class Soldier :public Chess//卒、兵类,ID为-7和7
{
public:
Soldier(int i) :Chess((i == 0 ? -7 : 7)) {}
bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
{
int TempX = startx - endx;
int TempY = starty - endy;
int S_Id = ch.Getid(startx, starty);
int E_Id = ch.Getid(endx, endy);
if ((S_Id*E_Id <= 0) && (S_Id*TempY <= 0))
{
if (fabs(TempY) == 1 && TempX == 0)
{
return true;
}
if (fabs(TempX) == 1 && TempY == 0)
{
if (((starty - 1) / 5 == 0 && S_Id < 0) || ((starty - 1) / 5 == 1 && S_Id > 0))
{
return true;
}
}
}
return false;
}
};
int Chessboard::Player = -1;
bool Chessboard::End = true;
inline Chessboard::Chessboard()
{
memset(c, NULL, sizeof(c));
}
inline Chess * Chessboard::Get(int x, int y)
{
return c[x][y];
}
int Chessboard::Getid(int x, int y)
{
if (c[x][y] != NULL)
{
return c[x][y]->Get();
}
return NULL;
}
bool Chessboard::Move(int startx, int starty, int endx, int endy)
{
if (startx >= 1 && startx <= 9 && starty >= 1 && starty <= 10 && endx >= 1 && endx <= 9 && endy >= 1 && endy <= 10 && Getid(startx, starty) && Getid(startx, starty)*Player > 0 && c[startx][starty]->Judgement(*this, startx, starty, endx, endy))
{
if (c[endx][endy] != NULL)
{
delete c[endx][endy]; //吃子
}
c[endx][endy] = c[startx][starty];
c[startx][starty] = NULL;
Player *= -1; //更换玩家操作
return true;
}
else
{
cout << "走法错误,请重新输入:" << endl;
return false;
}
}
void Chessboard::Init()
{
c[1][1] = new Chariot(1);
c[9][1] = new Chariot(1);
c[2][1] = new Horse(1);
c[8][1] = new Horse(1);
c[3][1] = new Chancellor(1);
c[7][1] = new Chancellor(1);
c[4][1] = new BodyGuard(1);
c[6][1] = new BodyGuard(1);
c[5][1] = new General(1);
c[2][3] = new Cannon(1);
c[8][3] = new Cannon(1);
c[1][4] = new Soldier(1);
c[3][4] = new Soldier(1);
c[5][4] = new Soldier(1);
c[7][4] = new Soldier(1);
c[9][4] = new Soldier(1);
c[1][10] = new Chariot(0);
c[9][10] = new Chariot(0);
c[2][10] = new Horse(0);
c[8][10] = new Horse(0);
c[3][10] = new Chancellor(0);
c[7][10] = new Chancellor(0);
c[4][10] = new BodyGuard(0);
c[6][10] = new BodyGuard(0);
c[5][10] = new General(0);
c[2][8] = new Cannon(0);
c[8][8] = new Cannon(0);
c[1][7] = new Soldier(0);
c[3][7] = new Soldier(0);
c[5][7] = new Soldier(0);
c[7][7] = new Soldier(0);
c[9][7] = new Soldier(0);
}
void Chessboard::Show()
{
cout << endl;
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, 0xF0);
cout << " P2 一 二 三 四 五 六 七 八 九" << endl << endl;
char num[11][4] = { "零","一","二","三","四","五","六","七","八","九" ,"十" };
for (int i = 1; i < 11; i++)
{
if (i == 6)
{
SetConsoleTextAttribute(handle, 0xF0);
cout << " ————楚河 汉界————" << endl << endl;
}
SetConsoleTextAttribute(handle, 0xF0);
cout << " " << num[i] << " ";
for (int j = 1; j < 10; j++)
{
if (c[j][i] != NULL)
{
if (c[j][i]->Get() > 0)
{
SetConsoleTextAttribute(handle, 0xF2);
cout << Chessword[c[j][i]->Get() + 7] << " ";
}
else
{
SetConsoleTextAttribute(handle, 0xFC);
cout << Chessword[c[j][i]->Get() + 7] << " ";
}
}
else if ((i == 2 && j == 5) || (i == 9 && j == 5))
{
SetConsoleTextAttribute(handle, 0xF0);
cout << "米" << " ";
}
else
{
SetConsoleTextAttribute(handle, 0xF0);
cout << "十" << " ";
}
}
cout << endl << endl;
}
SetConsoleTextAttribute(handle, 0xF0);
cout << " P1 一 二 三 四 五 六 七 八 九" << endl << endl;
}
void Chessboard::Play()
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, 0xFC);
system("cls");
this->Init();
this->Show();
do
{
int startx, starty, aimx, aimy, iflag;
int sid, aid;
iflag = 0;
do
{
sid = aid = 0;
if ((Chessboard::Player == 1 ? 2 : 1) == 1)
{
SetConsoleTextAttribute(handle, 0xFC);
}
else
{
SetConsoleTextAttribute(handle, 0xF2);
}
cout << "请P" << (Chessboard::Player == 1 ? 2 : 1) << "输入起始棋子位置与目标位置的坐标:" << endl;
cin >> startx >> starty >> aimx >> aimy;
} while (!this->Move(startx, starty, aimx, aimy));
system("cls");
this->Show();
for (int i = 4; i < 7; i++)
{
for (int j = 1; j < 11; j++)
{
if (c[i][j] != NULL)
{
if ((int)fabs(c[i][j]->Get()) == 1)
{
iflag++;
}
else if (iflag != 0 && iflag != 2)
{
if ((int)fabs(c[i][j]->Get()) != 1)
{
iflag--;
}
}
}
}
}
if (iflag == 2)
{
Player *= -1;
Chessboard::End = false;
}
} while (Chessboard::End);
if ((Chessboard::Player == 1 ? 1 : 2) == 1)
{
SetConsoleTextAttribute(handle, 0xFC);
}
else
{
SetConsoleTextAttribute(handle, 0xF2);
}
cout << "结束,赢家是Player" << (Chessboard::Player == 1 ? 1 : 2) << endl;
}
Chessboard::~Chessboard()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 11; j++)
{
if (c[i][j] != NULL)
{
delete c[i][j];
c[i][j] = NULL;
}
}
}
}
using namespace std;
int main()
{
Chessboard C;
C.Play();
system("pause");
}
2(没编完)
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //用来检测按键的点击事件
using namespace std;
char qipan[11][9][3] = {
{"╔","╦","╦","╦","╦","╦","╦","╦","╗"},//0
{"├","┼","┼","┼","╳","┼","┼","┼","┤"},//1
{"├","╬","┼","┼","┼","┼","┼","╬","┤"},//2
{"╠","┼","╬","┼","╬","┼","╬","┼","╣"},//3
{"├","┴","┴","┴","┴","┴","┴","┴","┤"},//4
{"│","楚","河"," "," "," ","汉","界","│"},//5
{"├","┬","┬","┬","┬","┬","┬","┬","┤"},//6
{"╠","┬","╬","┼","╬","┼","╬","┼","╣"},//7
{"├","╬","┼","┼","┼","┼","┼","╬","┤"},//8
{"├","┼","┼","┼","╳","┼","┼","┼","┤"},//9
{"╚","╩","╩","╩","╩","╩","╩","╩","╝"}//10
//0 1 2 3 4 5 6 7 8
};
int hongfangsiwangqizishuliang = 0;
int heifangsiwangqizishuliang = 0;
struct qizi
{
string name;
int q[2][2];
};
qizi hong[5] = {{"车",10,0,10,8},{"马",10,1,10,7},{"相",10,2,10,6},{"仕",10,3,10,5},{"炮",8,1,8,7}};
qizi hei[5] = {{"車",0,0,0,8}, {"馬",0,1,0,7}, {"象",0,2,0,6}, {"士",0,3,0,5}, {"砲",2,1,2,7}};
struct zu_bin
{
string name;
int q[5][2];
};
int weizhi(int x){
if(0 <= x && x <= 15) return 0;
if(15 <= x && x <= 30) return 1;
if(30 <= x && x <= 45) return 2;
if(45 <= x && x <= 60) return 3;
if(60 <= x && x <= 75) return 4;
// if(75 <= x && x <= 90) return 5;
if(90 <= x && x <= 105) return 6;
if(105 <= x && x <= 120)return 7;
if(120 <= x && x <= 135)return 8;
if(135 <= x && x <= 150)return 9;
if(150 <= x && x <= 165)return 10;
else return 100;
}
zu_bin hongbin = {"兵",7,0,7,2,7,4,7,6,7,8};
zu_bin heizu = {"卒",3,0,3,2,3,4,3,6,3,8};
struct shuai
{
string name;
int x;
int y;
};
shuai Hong = {"帅",10,4};
shuai Hei = {"将",0,4};
string SiFoyouhongfangqizi(int x,int y){
if(x > 10 && y > 8)return 0;
bool z = true;
for(int i = 0; i < 5; i++){
for(int j = 0; j < 2; j++){
if(hong[i].q[j][0] == x && hong[i].q[j][1] == y){z = false;return hong[i].name;}
}
if(hongbin.q[i][0] == x && hongbin.q[i][1] == y){z = false;return hongbin.name;}
}
if(Hong.x == x && Hong.y == y && z){z = false;return Hong.name;}
return " ";
}
string SiFoyouheifangqizi(int x,int y){
if(x > 10 && y > 8)return 0;
bool z = true;
for(int i = 0; i < 5; i++){
for(int j = 0; j < 2; j++){
if(hei[i].q[j][0] == x && hei[i].q[j][1] == y){z = false;return hei[i].name;}
}
if(heizu.q[i][0] == x && heizu.q[i][1] == y){z = false;return heizu.name;}
}
if(Hong.x == x && Hong.y == y && z){z = false;return Hong.name;}
return " ";
}
bool SiFouyouqizi(int x,int y){
if(SiFoyouheifangqizi(x,y) != " " || SiFoyouhongfangqizi(x,y) != " ")return true;
else return false;
}
bool good(string name,int x,int y,int X,int Y,int f){
if(name == "车" ||name == "車"){
}
return true;
}
void color(int x)
{
switch(x)
{
case 1:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED );break;//红//抄
case 2:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );break;//灰//抄
case 3:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN|FOREGROUND_BLUE |FOREGROUND_RED);break;//白//抄
// case 4:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE );break;//蓝//抄
// case 5:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN);break;//绿//抄
// case 6:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_BLUE );break;//粉//抄
// case 7:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_GREEN);break;//黄//抄
// case 8:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_GREEN);break;//青//抄
// default:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN|FOREGROUND_BLUE |FOREGROUND_RED);break;//白//抄
}
}
int yanse;
void printqizi(int i,int j){
for(int o = 0; o < 5; o++){
for(int x = 0; x < 2; x++){
if(hong[o].q[x][0] == i && hong[o].q[x][1] == j){color(1);cout << hong[o].name;color(yanse);yanse = 1;return ;}
if(hei[o].q[x][0] == i && hei[o].q[x][1] == j){color(2);cout << hei[o].name;color(yanse);yanse = 2;return ;}
}
}
for(int o = 0; o < 5; o++){
if(hongbin.q[o][0] == i && hongbin.q[o][1] == j){color(1);cout << hongbin.name;color(yanse);yanse = 1;return ;}
if(heizu.q[o][0] == i && heizu.q[o][1] == j){color(2);cout << heizu.name;color(yanse);yanse = 2;return ;}
}
if(Hong.x == i && Hong.y == j){color(1);cout << Hong.name;color(yanse);yanse = 1;return ;}
else if(Hei.x == i && Hei.y == j){color(2);cout << Hei.name;color(yanse);yanse = 2;return ;}
else if(i < 11 && j < 9){color(3);cout << qipan[i][j];color(yanse);yanse = 3;return ;}
else if(10 < j && j < 20){color(3);cout << " ";color(yanse);yanse = 3;return ;}
else {color(3);yanse = 3;}
color(3);
return ;
}
void printqipan(void){
system("color f0");
for(int i = 0; i < 11; i++){
for(int j = 0; j < 14; j++){
printqizi(i,j);
if(i == 0 && j == 11)cout << "红方死亡棋子:";
if(i == 6 && j == 11)cout << "黑方死亡棋子:";
}
cout << endl;
}
cout << "\n";
}
int main()
{
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin, &mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
HWND gameh = FindWindow(NULL,"test");//抄
HWND pinmu = GetForegroundWindow();//抄
RECT r;//抄
GetWindowRect(gameh,&r);//抄
POINT pmzs;//抄
pmzs.x = r.left;//抄
pmzs.y = r.right;//抄
POINT pmsb1;//屏幕鼠标1
POINT pmsb2;//屏幕鼠标2
int a = MessageBox(NULL, "\n\t欢迎来到象棋游戏!\t\n", "象棋游戏游戏开始提示", MB_YESNO);//抄
Sleep(1000);
if(a != 6)return 0;//抄
while(1){
system("cls");
printqipan();
cout << "红方选择移动棋子起点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb1);//抄
pmsb1.x = weizhi(pmsb1.x);
pmsb1.y = weizhi(pmsb1.y);
break;
}
}
}
if(SiFoyouhongfangqizi(pmzs.x,pmzs.y) == " "){
while(1){
cout << "您选择的位置不正确,请重新选择\n";
system("pause");
system("cls");
printqipan();
cout << "红方选择移动棋子起点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb1);//抄
pmsb1.x = weizhi(pmsb1.x);
pmsb1.y = weizhi(pmsb1.y);
break;
}
}
if(SiFoyouhongfangqizi(pmsb1.x,pmsb1.y) != " ")break;
}
}
system("cls");
printqipan();
cout << "红方选择移动棋子终点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb2);//抄
pmsb2.x = weizhi(pmsb2.x);
pmsb2.y = weizhi(pmsb2.y);
break;
}
}
if(SiFoyouhongfangqizi(pmsb2.x,pmsb2.y) != " ")
while(1){
cout << "您选择的位置不正确,请重新选择\n";
system("pause");
system("cls");
printqipan();
cout << "红方选择移动棋子终点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb2);//抄
pmsb2.x = weizhi(pmsb2.x);
pmsb2.y = weizhi(pmsb2.y);
break;
}
}
if(SiFoyouhongfangqizi(pmsb2.x,pmsb2.y) == " "){
string yy = SiFoyouhongfangqizi(pmsb1.x,pmsb1.y);
if(good(yy,pmsb1.x,pmsb1.y,pmsb2.x,pmsb2.y,0))
{
break;
}
else continue;
}
}
for(int i = 0; i < 5; i++){
for(int j = 0; j < 2; j++){
if(hong[i].q[j][0] == pmsb1.x && hong[i].q[j][1] == pmsb1.y){
hong[i].q[j][0] = pmsb2.x;
hong[i].q[j][1] = pmsb2.y;
}
}
if(hongbin.q[i][0] == pmsb1.x && hongbin.q[i][1] == pmsb1.y){
hongbin.q[i][0] = pmsb2.x;
hongbin.q[i][1] = pmsb2.y;
}
}
if(Hong.x == pmsb1.x && Hong.y == pmsb1.y){
Hong.x = pmsb2.x;
Hong.y = pmsb2.y;
}
for(int i = 0; i < 5; i++){
for(int j = 0; j < 2; j++){
if(hei[i].q[j][0] == pmsb2.x && hei[i].q[j][1] == pmsb2.y){
hei[i].q[j][0] = heifangsiwangqizishuliang / 4 + 7;
hei[i].q[j][1] = heifangsiwangqizishuliang % 4 + 20;
heifangsiwangqizishuliang++;
}
}
if(heizu.q[i][0] == pmsb2.x && heizu.q[i][1] == pmsb2.y){
heizu.q[i][0] = heifangsiwangqizishuliang / 4 + 7;
heizu.q[i][1] = heifangsiwangqizishuliang % 4 + 11;
heifangsiwangqizishuliang++;
}
}
if(Hei.x == pmsb2.x && Hei.y == pmsb2.y){
Hei.x = heifangsiwangqizishuliang / 4 + 7;
Hei.y = heifangsiwangqizishuliang % 4 + 11;
heifangsiwangqizishuliang++;
return 0;
}
system("cls");
printqipan();
cout << "黑方选择移动棋子起点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb1);//抄
pmsb1.x = weizhi(pmsb1.x);
pmsb1.y = weizhi(pmsb1.y);
break;
}
}
if(SiFoyouheifangqizi(pmsb1.x,pmsb1.y) == " "){
while(1){
cout << "您选择的位置不正确,请重新选择\n";
system("pause");
system("cls");
printqipan();
cout << "黑方选择移动棋子起点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb1);//抄
pmsb1.x = weizhi(pmsb1.x);
pmsb1.y = weizhi(pmsb1.y);
break;
}
}
if(SiFoyouheifangqizi(pmsb1.x,pmsb1.y) != " ")break;
}
}
system("cls");
printqipan();
cout << "黑方选择移动棋子终点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb2);//抄
pmsb2.x = weizhi(pmsb2.x);
pmsb2.y = weizhi(pmsb2.y);
break;
}
}
if(SiFoyouheifangqizi(pmsb2.x,pmsb2.y) != " ")
while(1){
cout << "您选择的位置不正确,请重新选择\n";
system("pause");
system("cls");
printqipan();
cout << "黑方选择移动棋子终点\n";
while(1){
if(KEY_DOWN(VK_LBUTTON))
{
GetCursorPos(&pmsb2);//抄
pmsb2.x = weizhi(pmsb2.x);
pmsb2.y = weizhi(pmsb2.y);
break;
}
}
if(SiFoyouheifangqizi(pmsb2.x,pmsb2.y) == " "){
string yy = SiFoyouheifangqizi(pmsb1.x,pmsb1.y);
if(good(yy,pmsb1.x,pmsb1.y,pmsb2.x,pmsb2.y,1))
{
break;
}
else continue;
}
}
for(int i = 0; i < 5; i++){
for(int j = 0; j < 2; j++){
if(hei[i].q[j][0] == pmsb1.x && hei[i].q[j][1] == pmsb1.y){
hei[i].q[j][0] = pmsb2.x;
hei[i].q[j][1] = pmsb2.y;
}
}
if(heizu.q[i][0] == pmsb1.x && heizu.q[i][1] == pmsb1.y){
heizu.q[i][0] = pmsb2.x;
heizu.q[i][1] = pmsb2.y;
}
}
if(Hei.x == pmsb1.x && Hei.y == pmsb1.y){
Hei.x = pmsb2.x;
Hei.y = pmsb2.y;
}
for(int i = 0; i < 5; i++){
for(int j = 0; j < 2; j++){
if(hong[i].q[j][0] == pmsb2.x && hong[i].q[j][1] == pmsb2.y){
hong[i].q[j][0] = hongfangsiwangqizishuliang / 4 + 1;
hong[i].q[j][1] = hongfangsiwangqizishuliang % 4 + 11;
hongfangsiwangqizishuliang++;
}
}
if(hongbin.q[i][0] == pmsb2.x && hongbin.q[i][1] == pmsb2.y){
hongbin.q[i][0] = hongfangsiwangqizishuliang / 4 + 1;
hongbin.q[i][1] = hongfangsiwangqizishuliang % 4 + 11;
hongfangsiwangqizishuliang++;
}
}
if(Hong.x == pmsb2.x && Hong.y == pmsb2.y){
Hong.x = hongfangsiwangqizishuliang / 4 + 1;
Hong.y = hongfangsiwangqizishuliang % 4 + 11;
hongfangsiwangqizishuliang++;
return 0;
}
}
return 0;
}