Complete code
#include <graphics.h>
#include <conio.h>//用到getch()函数
#define SIDE 30//棋框边长
#define X_LEFT 120//棋框左边界
#define X_RIGHT 360//棋框右边界
#define Y_BOTTOM 360//棋框下边界
#define Y_TOP 120//棋框上边界
void main()
{
int y = 0,x=0;//记录起点位置
int new_x=0,new_y=0;//记录终点位置
initgraph(480, 480);// 初始化绘图窗口
setbkcolor(YELLOW);// 设置背景色为黄色
cleardevice();// 用背景色清空屏幕
//x和y的增量要为奇数
for(y=Y_TOP;y<Y_BOTTOM;y+=SIDE)//画完一行再画一行
{
for(x=X_LEFT;x<X_RIGHT;x+=SIDE)//8个格子-一行一行来画
{
if((x/10+y/10)%2==0)//判断什么时候输出白格子
{
new_x=x+SIDE;
new_y=y+SIDE;
setcolor(BLACK);//设置矩形边框颜色
setfillcolor(WHITE);//设置矩形填充颜色
fillrectangle(x, y, new_x, new_y);//填充矩阵
}
else//输出黑格子
{
new_x=x+SIDE;
new_y=y+SIDE;
setcolor(BLACK);
setfillcolor(BLACK);
fillrectangle(x, y, new_x, new_y);
}
}
}
//按任意键退出
getch();
closegraph();
}
Easyx official website URL: https://easyx.cn/
is currently Xiaobai, only as a learning record, if there is any error, or improvement, please advise. Thank you!