次のコードを考えると:
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();
}
}
...
}
各 2 つのセルの間に Door/Wall としてセパレーターを使用して、 maze を描画する必要があります。メソッド drawMaze() で、最初に頂点とエッジ (頂点=部屋、エッジ=ドア/壁) を持つグラフ G=(V,E) を作成してから、それを使用します。
while ループで、エッジの数だけループを実行し、2 つの部屋 (x、y 平面内) の座標を取得するたびに、コネクタ (壁/ドア) を使用して 1 番目の部屋を印刷したいただし、最初の部屋が他の部屋に印刷されるたびに (および残りのエッジについても)。
どうすれば修正できますか?
よろしく、ロン