为这段五子棋代码添加注释void drawchess() { num = 1; for_(i, 0, 14) { for_(j, 0, 14) { if (chess(i, j) == 1) { num++; int x = X0 + j * step; int y = Y0 + i * step; setfillcolor(BLACK); setlinecolor(BLACK); fillcircle(x, y, r0); settextcolor(WHITE); char s[20]; sprintf(s, "%d", nums(i, j)); settextstyle(30, 0, _T("Consolas")); if (nums(i, j) < 10) outtextxy(x - 7, y - 15, s); else outtextxy(x - 15, y - 15, s); } else if (chess(i, j) == 2) { num++; int x = X0 + j * step; int y = Y0 + i * step; setfillcolor(WHITE); setlinecolor(BLACK); fillcircle(x, y, r0); settextcolor(BLACK); char s[20]; sprintf(s, "%d", nums(i, j)); settextstyle(30, 0, _T("Consolas")); if (nums(i, j) < 10) outtextxy(x - 7, y - 15, s); else outtextxy(x - 15, y - 15, s); } } } }
时间: 2024-04-27 20:23:31 浏览: 89
//该函数用于绘制五子棋子
void drawchess() {
//初始化num为1
num = 1;
//遍历棋盘
for_(i, 0, 14) {
for_(j, 0, 14) {
//如果该位置有黑棋
if (chess(i, j) == 1) {
//num+1
num++;
//获取该位置棋子的坐标
int x = X0 + j * step;
int y = Y0 + i * step;
//设置填充颜色和线条颜色为黑色
setfillcolor(BLACK);
setlinecolor(BLACK);
//绘制黑棋
fillcircle(x, y, r0);
//设置文字颜色为白色
settextcolor(WHITE);
//将该位置的数字转换为字符串
char s[20];
sprintf(s, "%d", nums(i, j));
//设置文字样式为30号Consolas字体
settextstyle(30, 0, _T("Consolas"));
//如果数字小于10,则将文字位置调整一下
if (nums(i, j) < 10)
outtextxy(x - 7, y - 15, s);
else
outtextxy(x - 15, y - 15, s);
}
//如果该位置有白棋
else if (chess(i, j) == 2) {
//num+1
num++;
//获取该位置棋子的坐标
int x = X0 + j * step;
int y = Y0 + i * step;
//设置填充颜色为白色,线条颜色为黑色
setfillcolor(WHITE);
setlinecolor(BLACK);
//绘制白棋
fillcircle(x, y, r0);
//设置文字颜色为黑色
settextcolor(BLACK);
//将该位置的数字转换为字符串
char s[20];
sprintf(s, "%d", nums(i, j));
//设置文字样式为30号Consolas字体
settextstyle(30, 0, _T("Consolas"));
//如果数字小于10,则将文字位置调整一下
if (nums(i, j) < 10)
outtextxy(x - 7, y - 15, s);
else
outtextxy(x - 15, y - 15, s);
}
}
}
}
注释已经添加到代码中,对代码进行了解释,方便其他人更好地理解代码。
阅读全文
相关推荐










