下棋的时候如果已经设计了循环,获得要被移动的棋子和要移到的位置就进行移动并且机器也同时移动位置,这时候应该怎么写一些按钮如存档,返回等等,应该加在什么位置才能不影响棋局的对局并且能够发挥效用呢。
下方的代码可以让我获取鼠标的坐标,那么请问按钮的判断应该加在什么地方才能保证不影响对局并且任何时候都有效呢
void singleplayer_mouse() {
start_x = 0;
start_y = 0;
end_x = 0;
end_y = 0;
judge = 0;
HWND hwnd = GetHWnd();
MOUSEMSG point;
MOUSEMSG n;
while (1) {
while (MouseHit()) {
if (judge == 2) break;//这个时候point.x与j对应
if (judge == 0) {
point = GetMouseMsg();
if (point.uMsg == WM_LBUTTONDOWN) {
/*GetCursorPos(&point);
ScreenToClient(hwnd, &point);*/
for (int i = 1; i <= 7; i++) {
for (int j = 1; j <= 7; j++) {
if (point.x >= j * Unitlength
&& point.x < (j + 1) * Unitlength
&& point.y >= i * Unitlength
&& point.y <= (i + 1) * Unitlength
&& Recordlocation[i - 1][j - 1] == Playercolor
&& can_move(i - 1, j - 1)) {
start_x = i - 1;
start_y = j - 1;
draw_circle(start_x, start_y);
judge = 1;
break;
}
}
if (judge == 1) break;
}
}
}
else if (judge == 1) {
point = GetMouseMsg();
if (point.uMsg == WM_LBUTTONDOWN) {
/*GetCursorPos(&point);
ScreenToClient(hwnd, &point);*/
for (int i = 1; i <= 7; i++) {
for (int j = 1; j <= 7; j++) {
if (point.x > j * Unitlength
&& point.x <(j + 1) * Unitlength
&& point.y > i * Unitlength
&& point.y < (i + 1) * Unitlength
&& Recordlocation[i - 1][j - 1] == Empty
&& can_move(i - 1, j - 1)
&& inside(start_x, start_y, i - 1, j - 1)) {
end_x = i - 1;
end_y = j - 1;
judge = 2;
ifget = true;
break;
}
}
if (judge == 2) break;
}
}
}
}
if (ifget) break;
}
}