就是easyx有动态画面的时候鼠标交互失效了,想知道怎么解决
Outlook函数是个动态计时器,把它注释掉的时候鼠标交互可用,未注释鼠标交互失效,悬赏,金额不满意可另谈,求解决
以下是源码
#include <stdio.h>
#include <tchar.h>
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
#include<easyx.h>
#define INTERVAL 50 //前面的间隔
#define CHESS_GRID_SIZE 70 //格子宽度
#define ROW 10
#define COL 9
int O = 1, step = 0;
enum PIECES//枚举棋子
{
車, 馬, 象, 士, 将, 砲, 卒,
俥, 马, 相, 仕, 帥, 炮, 兵,
SPACE, BEGIN, END, NONE
};
//红黑方棋子、
int blackChess[] = { 車, 馬, 象, 士, 将, 砲, 卒 };
int redChess[] = { 俥, 马, 相, 仕, 帥, 炮, 兵 };
const char* chessName[] = { "車", "馬", "象", "士", "将", "砲", "卒", "俥", "马", "相", "仕", "帥", "炮", "兵" };
struct Chess//棋子属性
{
int x;
int y;
int id;//哪个棋子
int type;//是哪一方的棋子 红,黑?
bool river;//判断小兵是否过了河
};
struct Chess map[ROW][COL];//结构体数组,用来保存每一个点的信息
POINT begin = { -1, -1 }, end = { -1, -1 };//保存前后两次点击的数组下标
int state = BEGIN;
void visualize() {
for (int i = 0; i < 10; i++)
{
printf("\n");
for (int j = 0; j < 9; j++) {
printf(" %d", map[i][j].type);
}
}
}
//初始化游戏数据
void GameInit()
{
for (int i = 0; i < ROW; i++)
{
for (int k = 0; k < COL; k++)
{
int chessname = SPACE;
int mcolor = WHITE;
//黑棋
if (i <= 4)
{
//初始化第一行的棋子,
if (i == 0)
{
mcolor = BLACK;
if (k <= 4)
{
chessname = blackChess[k];
}
else
{
chessname = blackChess[8 - k];
}
}
//设置炮
if (i == 2 && (k == 1 || k == 7))
{
chessname = blackChess[5];
mcolor = BLACK;
}
//设置小兵
if (i == 3 && k % 2 == 0)
{
chessname = blackChess[6];
mcolor = BLACK;
}
}
//紅棋
else
{
//初始化第一行的棋子,
if (i == 9)
{
mcolor = RED;
if (k <= 4)
{
chessname = redChess[k];
}
else
{
chessname = redChess[8 - k];
}
}
//设置炮
if (i == 7 && (k == 1 || k == 7))
{
chessname = redChess[5];
mcolor = RED;
}
//设置小兵
if (i == 6 && k % 2 == 0)
{
chessname = redChess[6];
mcolor = RED;
}
}
map[i][k].id = chessname;
map[i][k].river = false;
map[i][k].type = mcolor;
map[i][k].x = k * CHESS_GRID_SIZE + INTERVAL;
map[i][k].y = i * CHESS_GRID_SIZE + INTERVAL;
}
}
visualize();
}
void Outlook() {
settextstyle(50, 0, "Consolas");//时间显示文字的样式
settextcolor(BLACK);
char t[100];//计时器部分
int minutes = 9, seconds = 59;//初始化,参数即为开始倒计时的时间
while (minutes != 0 || seconds != 0) {//倒计时逻辑
if (seconds == 0) {
minutes--; seconds = 59;
}
else seconds--;
Sleep(1000);//1秒
setbkcolor(RGB(252, 215, 162)); // 设置刷新小矩形背景颜色
setfillstyle(SOLID_FILL, RGB(252, 215, 162)); // 设置填充样式
bar(650, 340, 800, 410); // 用背景颜色清除时间文本区域,达到使得时间文本区域透明的效果
sprintf_s(t, "%02d:%02d", minutes, seconds);//打印时间文字的函数
outtextxy(650, 340, t);//打印时间文字的函数
FlushBatchDraw();
while (minutes == 4 && seconds >= 59) //五分钟后弹出弹窗
{
HWND hand = GetHWnd(); // 获取图形窗口的句柄
int ResultMB = MessageBox(hand, "随机天罚降临!!!", "温馨提示", MB_OKCANCEL);
// 点击不同按钮之后的不同操作,省略了取消按钮
if (IDOK == ResultMB) {
//printf("弹窗点击了确认");可以不加
}
break;
}
}
}
//游戏的绘制函数
void GameDraw()
{
//设置背景颜色 red black
setbkcolor(RGB(252, 215, 162));
IMAGE Pic1;
IMAGE Pic2;
loadimage(&Pic1, "wj1.png");//背景图片设置
loadimage(&Pic2, "wj2.png");
cleardevice();
settextcolor(BLACK);
settextstyle(35, 0, "微软雅黑", 0, 0, 500, false, false, false);
outtextxy(670, 160, "玩家一");
settextcolor(BLACK);
settextstyle(35, 0, "微软雅黑", 0, 0, 500, false, false, false);
outtextxy(670, 555, "玩家二");
putimage(680, 80, &Pic1);
putimage(680, 600, &Pic2);
//绘制棋盘
setlinecolor(BLACK);
setlinestyle(PS_SOLID, 2);
for (int i = 0; i < 10; i++)
{
//画横线
line(INTERVAL, i * CHESS_GRID_SIZE + INTERVAL, 8 * CHESS_GRID_SIZE + INTERVAL, i * CHESS_GRID_SIZE + INTERVAL);
//画竖线
if (i < 9)
{
line(i * CHESS_GRID_SIZE + INTERVAL, INTERVAL, i * CHESS_GRID_SIZE + INTERVAL, 9 * CHESS_GRID_SIZE + INTERVAL);
}
}
rectangle(INTERVAL - 5, INTERVAL - 5, 8 * CHESS_GRID_SIZE + INTERVAL + 5, 5 + 9 * CHESS_GRID_SIZE + INTERVAL);
//楚河汉界显示
setfillcolor(RGB(252, 215, 162));
fillrectangle(INTERVAL, 4 * CHESS_GRID_SIZE + INTERVAL, 8 * CHESS_GRID_SIZE + INTERVAL, 5 * CHESS_GRID_SIZE + INTERVAL);
//显示文字
char river[21] = "楚河 汉界";
settextstyle(50, 0, _T("楷体"));
settextcolor(BLACK);
setbkmode(TRANSPARENT);
outtextxy(INTERVAL + 100, 4 * CHESS_GRID_SIZE + INTERVAL + 10, river);
outtextxy(INTERVAL + 100, 4 * CHESS_GRID_SIZE + INTERVAL + 10, river);
//画九宫格
//画上面
line(3 * CHESS_GRID_SIZE + INTERVAL, INTERVAL, 5 * CHESS_GRID_SIZE + INTERVAL, 2 * CHESS_GRID_SIZE + INTERVAL);
line(3 * CHESS_GRID_SIZE + INTERVAL, 2 * CHESS_GRID_SIZE + INTERVAL, 5 * CHESS_GRID_SIZE + INTERVAL, INTERVAL);
//画下面
line(3 * CHESS_GRID_SIZE + INTERVAL, 7 * CHESS_GRID_SIZE + INTERVAL, 5 * CHESS_GRID_SIZE + INTERVAL, 9 * CHESS_GRID_SIZE + INTERVAL);
line(3 * CHESS_GRID_SIZE + INTERVAL, 9 * CHESS_GRID_SIZE + INTERVAL, 5 * CHESS_GRID_SIZE + INTERVAL, 7 * CHESS_GRID_SIZE + INTERVAL);
//画棋子
settextstyle(30, 0, _T("楷体"));
for (int i = 0; i < ROW; i++)
{
for (int k = 0; k < COL; k++)
{
if (map[i][k].id != SPACE)
{
setlinecolor(map[i][k].type);
fillcircle(map[i][k].x, map[i][k].y, 30);
fillcircle(map[i][k].x, map[i][k].y, 25);
settextcolor(map[i][k].type);
outtextxy(map[i][k].x - 10, map[i][k].y - 10, chessName[map[i][k].id]);
}
}
}
Outlook();
}
void chessMove() {
bool canmove = 0;
int j = 0;
printf("begin.x=%d\nbegin.y=%d\nend.x=%d\nend.y=%d\n", begin.x, begin.y, end.x, end.y);
if (!(begin.x == end.x && begin.y == end.y)
&& end.x != -1 && end.y != -1
&& map[begin.x][begin.y].id != SPACE
&& map[begin.x][begin.y].type != map[end.x][end.y].type) {
printf("CAN");
switch (map[begin.x][begin.y].id)
{
case 車:
case 俥:
if (begin.x == end.x) {
j = 1;
if (end.y > begin.y) {
printf("canmove");
for (int i = begin.y + 1; i < end.y; i++) {
printf("i=%d\nmap[][]=%d\n", i, map[begin.x][i].id);
if (map[begin.x][i].id != SPACE) { j = 0; printf("stop\n"); }
}
}
else if (end.y < begin.y) {
for (int i = end.y + 1; i < begin.y; i++) {
if (map[begin.x][i].id != SPACE) j = 0;
}
}
}
else if (end.y == begin.y) {
j = 1;
if (begin.x < end.x) {
for (int i = begin.x + 1; i < end.x; i++) {
if (map[i][end.y].id != SPACE) j = 0;
}
}
else if (begin.x > end.x) {
for (int i = end.x + 1; i < begin.x; i++) {
if (map[i][end.y].id != SPACE) j = 0;
}
}
}
canmove += j;
break;
case 馬:
case 马:
if (end.y - begin.y == 2 && map[begin.x][begin.y + 1].type == WHITE && abs(end.x - begin.x) == 1)canmove = 1;
else if (end.y - begin.y == -2 && map[begin.x][begin.y - 1].id == SPACE && abs(end.x - begin.x) == 1)canmove = 1;
else if (end.x - begin.x == -2 && map[begin.x - 1][begin.y].id == SPACE && abs(end.y - begin.y) == 1)canmove = 1;
else if (end.x - begin.x == 2 && map[begin.x + 1][begin.y].id == SPACE && abs(end.y - begin.y) == 1)canmove = 1;
break;
case 象:
case 相:
if ((begin.x < 5 && end.x < 5) || (begin.x > 4 && end.x > 4)) {
if (end.y - begin.y == 2 && map[begin.x + 1][begin.y + 1].type == WHITE && end.x - begin.x == 2)canmove = 1;
else if (end.y - begin.y == -2 && map[begin.x + 1][begin.y - 1].type == WHITE && end.x - begin.x == 2)canmove = 1;
else if (end.y - begin.y == 2 && map[begin.x - 1][begin.y + 1].type == WHITE && end.x - begin.x == -2)canmove = 1;
else if (end.y - begin.y == -2 && map[begin.x - 1][begin.y - 1].type == WHITE && end.x - begin.x == -2)canmove = 1;
}
break;
case 士:
case 仕:
if ((begin.x < 3 && end.x < 3) || (begin.x > 6 && end.x > 6))
if (end.y > 2 && end.y < 6) {
if (abs(end.y - begin.y) == 1 && abs(end.x - begin.x) == 1)canmove = 1;
}
break;
case 将:
case 帥:
if ((begin.x < 3 && end.x < 3) || (begin.x > 6 && end.x > 6))
if (end.y > 2 && end.y < 6) {
if (abs(end.y - begin.y) + abs(end.x - begin.x) == 1)canmove = 1;
}
break;
case 砲:
case 炮:
if (begin.x == end.x) {
j = 1;
if (end.y > begin.y) {
printf("canmove");
for (int i = begin.y + 1; i < end.y; i++) {
if (map[begin.x][i].id != SPACE) { j--; }
}
if (map[begin.x][end.y].type == WHITE) j--;
}
else if (end.y < begin.y) {
for (int i = end.y + 1; i < begin.y; i++) {
if (map[begin.x][i].id != SPACE) j--;
}
if (map[end.x][end.y].type == WHITE) j--;
}
}
else if (end.y == begin.y) {
j = 1;
if (begin.x < end.x) {
for (int i = begin.x + 1; i < end.x; i++) {
if (map[i][end.y].id != SPACE) j--;
}
if (map[end.x][end.y].type == WHITE) j--;
}
else if (begin.x > end.x) {
for (int i = end.x + 1; i < begin.x; i++) {
if (map[i][end.y].id != SPACE) j--;
}
if (map[end.x][end.y].type == WHITE) j--;
}
}
if (j == 0) canmove = 1;
break;
case 卒:
case 兵:
if (map[begin.x][begin.y].type == BLACK && end.x - begin.x >= 0) {
if (end.x - begin.x == 1 && end.y == begin.y) canmove = 1;
else if (begin.x > 4 && begin.x == end.x && abs(begin.y - end.y) == 1) canmove = 1;
}
else if (map[begin.x][begin.y].type == RED && end.x - begin.x <= 0) {
if (end.x - begin.x == -1 && end.y == begin.y) canmove = 1;
else if (begin.x < 5 && begin.x == end.x && abs(begin.y - end.y) == 1) canmove = 1;
}
break;
}
if (canmove) {
if (map[end.x][end.y].id == 将 || map[end.x][end.y].id == 帥) O = 0;
map[end.x][end.y].id = map[begin.x][begin.y].id;
map[end.x][end.y].type = map[begin.x][begin.y].type;
map[begin.x][begin.y].id = SPACE;
map[begin.x][begin.y].type = WHITE;
}
step += canmove;
printf("step=%d", step);
}
}
void MouseControl()
{
if (MouseHit())
{
MOUSEMSG msg = GetMouseMsg();
if (msg.uMsg == WM_LBUTTONDOWN)
{
//获取鼠标点击的数组的下标
map[-1][-1].type = WHITE;
int row = (msg.y - INTERVAL + CHESS_GRID_SIZE / 2) / CHESS_GRID_SIZE;
int col = (msg.x - INTERVAL + CHESS_GRID_SIZE / 2) / CHESS_GRID_SIZE;
if ((step % 4 == 0 && map[row][col].type == RED || step % 4 == 2 && map[row][col].type == BLACK))
{
state = END;
begin.x = row;
begin.y = col;
step++;
}
else if ((step % 4 == 1 || step % 4 == 3))
{
state = BEGIN;
end.x = row;
end.y = col;
chessMove();
}
printf("%d,%d %d\n", row, col, state);
}
}
}
int main()
{
//创建一个图形窗口
initgraph(800, 800, SHOWCONSOLE);
GameInit();
BeginBatchDraw();
while (O)
{ MouseControl();
GameDraw();
FlushBatchDraw();
}printf("GAME OVER");
return 0;
}