|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdlib.h>
#include <Windows.h>
#include<easyx.h>
#include <graphics.h>
#include <conio.h>
#define ROW 10
#define COL 9
#define geziwidth 80//棋盘中一个格子的宽度
#define sxzywidth 80//棋盘上下左右距边界的距离
static int type = RED;// 设置先手后手
static int g = 1; // 记录判断先后手
struct chess
{
int x; //位于窗口的x,y轴坐标
int y;
int id; //棋子名称
int type; //所属类型
int river = 0; //是否过河
};
enum piece
{
SPACE = -1, //表示无棋子
車, 馬, 象, 士, 将, 砲, 卒,
俥, 马, 相, 仕, 帥, 炮, 兵,
BEGIN, END //起子还是落子
};
struct START //鼠标点击坐标
{
int x;
int y;
};
//定义基本数据
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 printfchess() //打印棋子
{
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
enum piece chessid = SPACE;
int chesstype;
if (i <= 4)//打印黑子,赋属性
{
chesstype = BLACK;
if (i == 0)//设置最下面一排
{
if (j <= 4)
{
chessid = blackpiece[j];
}
else
{
chessid = blackpiece[8 - j];
}
}
if (i == 2)//设置炮
{
if (j == 1 || j == 7)
{
chessid = blackpiece[5];
}
}
if (i == 3)// 设置兵
{
if ((j + 1) % 2 == 1)
{
chessid = blackpiece[6];
}
}
}
else
{
chesstype = RED;//打印红子,附属性
if (9 - i == 0)
{
if (j <= 4)
{
chessid = redpiece[j];
}
else
{
chessid = redpiece[8 - j];
}
}
if (9 - i == 2)
{
if (j == 1 || j == 7)
{
chessid = redpiece[5];
}
}
if (9 - i == 3)
{
if ((j + 1) % 2 == 1)
{
chessid = redpiece[6];
}
}
}
map[i][j].river = 0;//赋值各点位属性
map[i][j].id = chessid;
map[i][j].type = chesstype;
map[i][j].x = j *geziwidth + sxzywidth;
map[i][j].y = i * geziwidth + sxzywidth;
}
}
}
void printfboard()
{
initgraph(800, 880);
setbkcolor(RGB(219, 121, 93));
setlinecolor(BLACK);
cleardevice();
//rectangle(80, 80, 720, 800);//内正方形
//rectangle(75, 35, 725, 765);//外正方形
for (int i = 0; i <= 800; i += 80)//绘制横线
line(80, i, 720, i);
for (int i = 80; i <=720; i += 80)//绘制竖线
{
line(i, 80, i, 400);//黑方竖线
line(i, 480, i, 800);//红方竖线
}
line(80, 400, 80, 480);
line(720, 400, 720, 480);
line(320, 80, 480, 240);//画四条线,即两个叉叉
line(320, 240, 480, 80);
line(320, 800, 480, 640);
line(320, 640, 480, 800);
settextcolor(BLACK);
settextstyle(60, 0, _T("楷体"));
outtextxy(180, 410, _T("楚"));
outtextxy(260, 410, _T("河"));
outtextxy(480, 410, _T("汉"));
outtextxy(560, 410, _T("界"));
////下棋方显示
//if (g % 2 == 1)
//{
// settextcolor(RED);
// settextstyle(40, 0, "楷体");
// outtextxy(640, 600, "红方落子");
//}
//if (g % 2 == 0)
//{
// settextcolor(BLACK);
// settextstyle(40, 0, "楷体");
// outtextxy(640, 110, "黑方落子");
//}
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, 50);
fillcircle(map[i][j].x, map[i][j].y, 35);
settextstyle(30, 10, "黑体");
setbkmode(TRANSPARENT);
settextcolor(map[i][j].type);
outtextxy(map[i][j].x , map[i][j].y , chessname[map[i][j].id]);
}
}
}
printfchess();
system("pause");
closegraph();
}
int main()
{
printfboard();
printfchess();
}
|
|