미로와 GUI가있는 내 모험이 계속되고 현재 어떤 그래프도 볼 수 있습니다 G=(V,E)
Vertices가 방이고 가장자리는 커넥터 (문 또는 벽)입니다. , 그러나 직사각형의 크기가 너무 작아서 나는 그것을 확대하려고 시도했지만 직사각형은 서로 위에 하나씩 나아 간다.미로의 GUI를 확대하려고 시도 할 때 사각형이 겹치다
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);
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_DARK_GREEN));
while (i < level) {
Connector connector = maze.getEdgeConnectorByIndex(i);
if (connector instanceof Door) {
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_DARK_GREEN));
Room room1 = ((Door)connector).getFirstRoom();
Room room2 = ((Door)connector).getSecondRoom();
int x = room1.getXcoordinate()+10;
int y = room1.getYcoordinate()+10;
int x1 = room2.getXcoordinate()+10;
int y1 = room2.getYcoordinate()+10;
e.gc.fillRectangle(x*30,y*30,20,20);
e.gc.fillRectangle(x1*30,y1*30,20,20);
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLUE));
Room r1 = new Room(30*x,30*y);
Room r2 = new Room(30*x1,30*y1);
Coordinate c = this.checkWhereConnectorLocated(r1,r2);
if (c.getSign() == DIAGONAL)
e.gc.fillRectangle(c.getXCoordinate(),c.getYCoordinate(),10,20);
else
e.gc.fillRectangle(c.getXCoordinate(),c.getYCoordinate(),20,10);
}
if (connector instanceof Wall) {
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_DARK_GREEN));
Room room1 = ((Wall)connector).getFirstRoom();
Room room2 = ((Wall)connector).getSecondRoom();
int x = room1.getXcoordinate()+10;
int y = room1.getYcoordinate()+10;
int x1 = room2.getXcoordinate()+10;
int y1 = room2.getYcoordinate()+10;
e.gc.fillRectangle(x*30,y*30,20,20);
e.gc.fillRectangle(x1*30,y1*30,20,20);
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_DARK_RED));
Room r1 = new Room(30*x,30*y);
Room r2 = new Room(30*x1,30*y1);
Coordinate c = this.checkWhereConnectorLocated(r1,r2);
if (c.getSign() == DIAGONAL)
e.gc.fillRectangle(c.getXCoordinate(),c.getYCoordinate(),10,20);
else
e.gc.fillRectangle(c.getXCoordinate(),c.getYCoordinate(),20,10);
}
i++;
}
}
// void org.eclipse.swt.graphics.GC.fillRectangle(int x, int y, int width, int
// height)
private Coordinate checkWhereConnectorLocated(Room room1,Room room2) {
int x = 0; int y = 0;
Coordinate coordinate ;
if (room1.getXcoordinate() == room2.getXcoordinate()) {
// same X coordinate
if (room1.getYcoordinate() > room2.getYcoordinate()) {
// ROOM1 is located above ROOM2 - same X different Y
x = room1.getXcoordinate();
y = room1.getYcoordinate()-10;
coordinate = new Coordinate(x,y);
}
else {
// ROOM2 is located above ROOM1
x = room1.getXcoordinate();
y = room2.getYcoordinate()-10;
coordinate = new Coordinate(x,y);
}
coordinate.setSign(HORIZONTAL);
return coordinate;
}
else if (room1.getYcoordinate() == room2.getYcoordinate()) {
// else maybe same Y coordinate - the X is changing
if (room1.getXcoordinate() > room2.getXcoordinate()) {
// ROOM1 is on the right of ROOM2 l
x = room1.getXcoordinate() - 10;
y = room2.getYcoordinate(); // same Y so there is no difference
// whom Y's we choose
coordinate = new Coordinate(x,y);
}
else {
// ROOM2 is on the right of ROOM1
x = room2.getXcoordinate() - 10;
y = room2.getYcoordinate(); // same Y so there is no difference
// whom Y's we choose
coordinate = new Coordinate(x,y);
}
coordinate.setSign(DIAGONAL);
return coordinate;
}
coordinate = new Coordinate(0,0);
return coordinate;
}
출력 :
다음 코드를 감안할 때녹색 사각형이 rooms
과 red
및 blue
있는 connectors
이다. 보시다시피, 직사각형이 너무 작아서 "60"과 같은 크기가 필요합니다. 그러나 fillRectangle
및 x,x1,y,y1
에 대한 올바른 조합의 값을 찾을 수없는 것 같습니다. 여기서 직사각형은 서로 겹치지 않습니다.
누군가이 문제를 해결할 수있는 방법을 설명해 주시겠습니까?
당신이 숙제 우리는 당신이 해결하려고하는 것입니다
BasicShapes
클래스 생성자의 시작 부분에 간다 ..? ;] – Sorceror이것은 실제로 내 숙제이지만, 나는 그들을 풀어달라고하지 않았다. 여기서 볼 수 있듯이, 나는 지난 며칠간 작업해온 코드를 게시했다. 그 코드, 그러나 내가 당신에게 내가 잘못한 것을 진단하도록 도와달라고 부탁했다. 그것을 해결하지 않기 위해, 나는 당신의 도움에 감사 할 것이다. – ron
그것은 불쾌한 의미가 없었습니다.] 선생님 (저는 또한 University에서 가르칩니다)으로서, 열심히하는 부분이 있어도 문제를 해결하고 해결하려고 노력한 것을 기쁘게 생각합니다. – Sorceror