|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<easyx.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#define ROW 10
#define COL 9
#define sxzywidth 80 //棋盘前后左右距离bianjie间隔
#define geziwidth 80 //格子大小
static int type = RED;//设置先手后手,象棋中红方为先手
static int g = 1; //记录判断先后手
struct chess
{
int x;
int y;
int id;
int type;
int river = 0;
};
struct START
{
int x;
int y;
};
enum piece
{
SPACE = -1,//判断某点处是否有棋子
車, 馬, 象, 士, 将, 砲, 卒,
俥, 马, 相, 仕, 帥, 炮, 兵,
BEGIN, END
};
struct chess map[ROW][COL];
struct START begin = { -1, -1 };
struct START end = { -1, -1 };
int start = BEGIN;
enum piece blackpiece[] = { 車, 馬, 象, 士, 将, 砲, 卒 };
enum piece redpiece[] = { 俥, 马, 相, 仕, 帥, 炮, 兵 };
const char* chessname[] = { "車", "馬", "象", "士", "将", "砲", "卒", "俥", "马", "相", "仕", "帥", "炮", "兵" };
void printfboard() //打印棋盘
{
setbkcolor(RGB(219, 121, 93)); //设置背景
cleardevice();
setlinecolor(BLACK);
setlinestyle(PS_SOLID, 2); //设置线形
for (int i = 0; i < 10; i++) //划线
{
line(sxzywidth, i * geziwidth + sxzywidth, 8 * geziwidth + sxzywidth, i * geziwidth + sxzywidth);
if (i < 9)
{
line(i * geziwidth + sxzywidth, sxzywidth, i * geziwidth + sxzywidth, 9 * geziwidth + sxzywidth);
}
}
//绘制矩形框
rectangle(sxzywidth - 5, sxzywidth - 5, 8 * geziwidth + sxzywidth + 5, 9 * geziwidth + sxzywidth + 5);
//将楚河汉界的线条覆盖掉
setfillcolor(RGB(219, 121, 93));
fillrectangle(sxzywidth, 4 * geziwidth + sxzywidth, 8 * geziwidth + sxzywidth, 5 * geziwidth + sxzywidth);
// 打印楚河汉界
settextcolor(BLACK);
settextstyle(60, 0, _T("楷体"));
outtextxy(180, 410, _T("楚"));
outtextxy(260, 410, _T("河"));
outtextxy(480, 410, _T("汉"));
outtextxy(560, 410, _T("界"));
//上面的叉叉
line(3 * geziwidth + sxzywidth, sxzywidth, 5 * geziwidth + sxzywidth, 2 * geziwidth + sxzywidth);
line(3 * geziwidth + sxzywidth, 2 * geziwidth + sxzywidth, 5 * geziwidth + sxzywidth, sxzywidth);
//下面的叉叉
line(3 * geziwidth + sxzywidth, 7 * geziwidth + sxzywidth, 5 * geziwidth + sxzywidth, 9 * geziwidth + sxzywidth);
line(3 * geziwidth + sxzywidth, 9 * geziwidth + sxzywidth, 5 * geziwidth + sxzywidth, 7 * geziwidth + sxzywidth);
//下棋方显示
if (g % 2 == 1)
{
settextcolor(RED);
settextstyle(40, 0, "楷体" );
outtextxy(740, 350, "红");
outtextxy(740, 390, "方");
outtextxy(740, 430, "落");
outtextxy(740, 470, "子");
}
if (g % 2 == 0)
{
settextcolor(BLACK);
settextstyle(40, 0, "楷体");
settextstyle(40, 0, "楷体");
outtextxy(740, 350, "黑");
outtextxy(740, 390, "方");
outtextxy(740, 430, "落");
outtextxy(740, 470, "子");
}
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
if (map[i][j].id != SPACE)
{
fillcircle(map[i][j].x, map[i][j].y, 38);
fillcircle(map[i][j].x, map[i][j].y, 33);
settextstyle(40, 34, "隶书");
setbkmode(TRANSPARENT);
settextcolor(map[i][j].type);
outtextxy(map[i][j].x - 35, map[i][j].y - 20, chessname[map[i][j].id]);
}
}
}
} |
|