给定以下代码:
private void drawMaze(PaintEvent e)
{
Graph maze = new Graph();
maze.generateMaze(25);
int i = 0;
int level = 25;
e.gc.setAntialias(SWT.ON);
e.gc.setBackground(new Color(e.display, 150, 150, 150));
e.gc.setLineWidth(12);
while (i < level)
{
Connector connector = maze.getEdgeConnectorByIndex(i);
if (connector instanceof Door)
{
Room room1 = ((Door)connector).getFirstRoom();
Room room2 = ((Door)connector).getSecondRoom();
int x = room1.getXcoordinate()+10;
int y = room1.getYcoordinate()+10;
System.out.println(x);
System.out.println(y);
e.gc.fillRectangle(x,y,100,79);
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLUE));
e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_GREEN));
e.gc.drawLine(x,y, 280+100,20);
}
i++;
}
}
类 BasicShapes
public class BasicShapes {
private Shell shell;
public BasicShapes(Display display) {
shell = new Shell(display);
shell.addPaintListener(new ExmaplePaingListener());
shell.setText("Basic shapes");
shell.setSize(1000, 700);
shell.setLocation(50, 50);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
private class ExmaplePaingListener implements PaintListener {
public void paintControl(PaintEvent e) {
// drawRectangles(e);
drawMaze(e);
e.gc.dispose();
}
}
...
}
我需要画迷宫,每两个单元格之间有分隔符作为门/墙。在方法 drawMaze() 中,我首先创建一个带有顶点和边(vertices=rooms,edges=Door/Wall)的图 G=(V,E),然后我想使用它。
在while循环中,我按边数运行循环,每次我得到两个房间的坐标(在x,y平面上),我想用连接器(墙/门)打印第一个房间与另一个房间,但每次第一个房间都印在另一个房间上(以及其余的边缘)。
我该如何解决?
问候,罗恩