#include
#include
#include
#include
#include
HANDLE handle_in;
HANDLE handle_out;
CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体
void DisplayMousePosition(COORD pos)
{
COORD dis = { 0, 24 }; //在第24行显示鼠标位置
WORD att = FOREGROUND_GREEN | FOREGROUND_INTENSITY; //文本属性
GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
printf("X = %3d, Y = %3d", (int)pos.X, (int)pos.Y);
FillConsoleOutputAttribute(handle_out, att, 16, dis, NULL); //填充文本属性
return;
}
void gotoxy(int x, int y)
{
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); //定义一个结构体pos,x,y就是构成的成员
}
void member()
{
int i, j;
setcolor(YELLOW);
for (i = 120; i <= 360; i += 30)
for (j = 120; j <= 240; j += 30)
{
line(i, 120, i, 240);
line(120, j, 360, j);
}
for (i = 120; i <= 360; i += 30)
for (j = 270; j <= 390; j += 30)
{
line(i, 270, i, 390);
line(120, j, 360, j);
}
line(120, 120, 120, 360);
line(120, 120, 360, 120);
line(105, 105, 105, 405);
line(105, 105, 375, 105);
line(105, 405, 375, 405);
line(375, 105, 375, 405);
line(360, 120, 360, 390);
line(210, 120, 270, 180);
line(270, 120, 210, 180);
line(210, 390, 270, 330);
line(270, 390, 210, 330);
for (int i = 120; i <= 360; i += 30)
{
setcolor(RED);
circle(i, 120, 13);
setcolor(GREEN);
circle(i, 390, 13);
}
setcolor(RED);
char a[] = { "车" };
outtextxy(120 - 6, 120 - 8, _T("车"));
outtextxy(150 - 6, 120 - 8, _T("马"));
outtextxy(180 - 6, 120 - 8, _T("相"));
outtextxy(210 - 6, 120 - 8, _T("士"));
outtextxy(240 - 6, 120 - 8, _T("将"));
outtextxy(270 - 6, 120 - 8, _T("士"));
outtextxy(300 - 6, 120 - 8, _T("相"));
outtextxy(330 - 6, 120 - 8, _T("马"));
outtextxy(360 - 6, 120 - 8, _T("车"));
setcolor(GREEN);
outtextxy(120 - 6, 390 - 8, _T("車"));
outtextxy(150 - 6, 390 - 8, _T("马"));
outtextxy(180 - 6, 390 - 8, _T("象"));
outtextxy(210 - 6, 390 - 8, _T("仕"));
outtextxy(240 - 6, 390 - 8, _T("帅"));
outtextxy(270 - 6, 390 - 8, _T("仕"));
outtextxy(300 - 6, 390 - 8, _T("象"));
outtextxy(330 - 6, 390 - 8, _T("马"));
outtextxy(360 - 6, 390 - 8, _T("車"));
for (int i = 150; i <= 360; i += 180)
{
setcolor(RED);
circle(i, 180, 13);
outtextxy(i - 6, 180 - 8, _T("炮"));
setcolor(GREEN);
circle(i, 330, 13);
outtextxy(i - 6, 330 - 8, _T("炮"));
}
for (int i = 120; i <= 360; i += 60)
{
setcolor(RED);
circle(i, 210, 13);
outtextxy(i - 6, 210 - 8, _T("卒"));
setcolor(GREEN);
circle(i, 300, 13);
outtextxy(i - 6, 300 - 8, _T("兵"));
}
setcolor(RED);
outtextxy(135, 245, _T("楚河"));
outtextxy(315, 245, _T("汉界"));
}
void main()
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "d:\\tc3\\bgi");
cleardevice();
member();
setcolor(YELLOW);
outtextxy(460, 110, _T("中 国 象 棋"));
outtextxy(400, 150, _T(" 红方 绿方 "));
handle_in = GetStdHandle(STD_INPUT_HANDLE); //获得标准输入设备句柄
handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
INPUT_RECORD mouserec; //定义输入事件结构体
DWORD res; //用于存储读取记录
COORD pos; //用于存储鼠标当前位置
COORD size = { 80, 25 }; //窗口缓冲区大小
GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息
SetConsoleScreenBufferSize(handle_out, size); //设置窗口缓冲区大小
while (1)
{
ReadConsoleInput(handle_in, &mouserec, 1, &res); //读取输入事件
if (mouserec.EventType == MOUSE_EVENT) //如果当前为鼠标事件
{ //单击鼠标左键,输出字符A
if (mouserec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
pos = mouserec.Event.MouseEvent.dwMousePosition; //获得当前鼠标位置
gotoxy(0, 0); //在第25行显示鼠标位置
//DisplayMousePosition(pos); //显示鼠标位置
gotoxy(pos.X, pos.Y);
putchar('A');
}
//单击鼠标右键,输出字符B
if (mouserec.Event.MouseEvent.dwButtonState == RIGHTMOST_BUTTON_PRESSED)
{
pos = mouserec.Event.MouseEvent.dwMousePosition; //获得当前鼠标位置
gotoxy(0, 0); //在第25行显示鼠标位置
//DisplayMousePosition(pos); //显示鼠标位置
gotoxy(pos.X, pos.Y);
putchar('B');
}
//双击退出
if (mouserec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK)
{
break;
}
}
}
CloseHandle(handle_out);
CloseHandle(handle_in);
system("pause");
}