I need to create a maze in Java where each time (i.e. every time I run the program ) a different maze would be made .
The program consists of 3 levels : beginner (25 rooms) , advanced (40 rooms) and expert (60 rooms) , with players (up to 20 players) and treasures , where each player must get at least one treasure .
I’ve made the logic side of the maze , meaning , I’ve written the maze algorithm where
each time the program randomly get a dot in the (x,y) plane and adds it to a graph – G=(V,E) – where the vertices are the rooms , and the edges are connectors (Door/Wall) .
Now my problem , is that I need to represent the maze using GUI , so I’ve attached the SWT from the Eclipse’s site to my program , but I do not know how to use the GUI to describe the maze/graph .
At first, I want to present to the user the maze before that game begins , meaning is , after creating the maze , before the players hit the road .
Can you please give me a hint where or how to start ?
the relevant classes are :
public class Room {
private ArrayList<Connector> connectors;
private int x; // x coordinate of the room
private int y; // y coordinate of the room
// constructor
Room(int xCoordinate,int yCoordinate)
{
//this.connectors = new HashMap<String,Connector>();
this.connectors = new ArrayList<Connector>();
this.x = xCoordinate;
this.y = yCoordinate;
}
Room()
{
this.x = 0;
this.y = 0;
}
public void addConnector(Connector connector)
{
this.connectors.add(connector);
}
/* Getters and Setters */
public int getXcoordinate()
{
return this.x;
}
public int getYcoordinate()
{
return this.y;
}
public void setXcoordinate(int newX)
{
this.x = newX;
}
public void setYcoordinate(int newY)
{
this.y = newY;
}
}
package model;
public class Door extends Connector {
// holds private Room[] rooms = new Room[2];
Door(Room room1,Room room2)
{
super(room1,room2);
}
public Room getNextRoom(Room room)
{
if(this.rooms[0].equals(room))
{
return this.rooms[1];
}
return this.rooms[0];
}
}
public abstract class Connector {
protected Room[] rooms = new Room[2];
public abstract Room getNextRoom(Room room);
public Connector(Room room1,Room room2) // building a new connector that connects between two rooms s
{
rooms[0] = room1;
rooms[1] = room2;
}
public Room getFirstRoom()
{
return this.rooms[0];
}
public Room getSecondRoom()
{
return this.rooms[1];
}
}
Regards,Ron
Take a look at http://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html . You can draw lines, points, or any other geometry that you would need.