使用C语言和Easyx库
```c
include
int main() {
int step = 50;
initgraph(500, 500);
setbkcolor(YELLOW);
cleardevice();
setlinestyle(PS_SOLID, 2);
setcolor(RGB(0, 0, 0));
int i, j;
for (i = 0; i < 9; i++) {
for (j = 0; j < 10; j++) {
if ((i + j) % 2 == 0) {
line(j * step, i * step, (j + 1) * step, i * step);
line((j + 1) * step, i * step, j * step, (i + 1) * step);
}
}
}
getch();
closegraph();
return 0;
}
```
使用Python的turtle模块
```python
import turtle
def draw_chessboard():
turtle.speed(30)
turtle.penup()
off = True
for y in range(-40, 30 + 1, 10):
for x in range(-40, 30 + 1, 10):
if off:
turtle.goto(x, y)
turtle.pendown()
turtle.begin_fill()
turtle.color("black")
turtle.forward(10)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.end_fill()
turtle.penup()
else:
turtle.goto(x, y)
turtle.pendown()
turtle.forward(10)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.penup()
turtle.hideturtle()
turtle.done()
draw_chessboard()
```
使用C和WinForms
```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
public class Chessboard : Form {
private PictureBox pictureBox;
public Chessboard() {
pictureBox = new PictureBox();
pictureBox.Width = 400;
pictureBox.Height = 400;
pictureBox.BackColor = Color.Tan; // 设置棋盘背景颜色为棕褐色
pictureBox.BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(pictureBox);
for (int i = 0; i < 9; i++) {
// 绘制横线
Line(0, i * 40, 400, i * 40, Color.Black);
// 绘制竖线
Line(i * 40, 0, i * 40, 400, Color.Black);
}
}
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Chessboard());
}
}
```
这些代码示例分别使用C语言、Python和C编程语言,通过不同的图形库和模块绘制象棋棋盘。你可以根据自己的需求和熟悉程度选择合适的编程语言和工具来实现象棋棋盘的绘制。