使用Java GUI的迷宫绘图 - 矩形一个接一个地打印

时间:2012-01-23 03:57:43

标签: java eclipse graph swt maze

给出以下代码:

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++;
    }

}

class 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()中,我首先创建一个图G =(V,E),顶点和顶点。边(顶点=房间,边=门/墙),然后我想使用它。

它是while循环,我按边数运行循环,每次都得到 两个房间的坐标(在x,y平面)我想打印第一个房间,连接器(墙/门)与另一个房间,但每次第一个房间打印在另一个房间(和其余的边缘也是。)

我该如何解决?

的问候,罗恩

0 个答案:

没有答案
相关问题