我猜这是一个图形类型的问题。节点是房间,边是连接房间的线。您可以引入另一个类(例如 Connection 类)来描述节点如何连接到边。例如,您的大厅连接到卧室,不一定使用直线。Graphics.DrawBezier 允许您绘制曲线,但需要一个点数组。这就是 Connection 类的用武之地。一些代码可能会有所帮助......
class Room
{
public Room(String name, Point location);
public void Draw(Graphics g);
}
class Connection
{
public void Add(Point ptConnection);
public void Add(Point[] ptConnection);
// Draw will draw a straight line if only two points or will draw a bezier curve
public void Draw(Graphics g);
}
class House // basically a graph
{
public void Add(Room room);
public void AddRoomConnection(Room r1, Room r2, Connection connector);
// draw, draw each room, then draw connections.
public void Draw(Graphics g);
}
void Main()
{
House myHouse = new House();
Room hall = new Room("Hall", new Point(120,10);
Room bedroom1 = new Room("Bedroom1", Point(0, 80));
Connection cnHallBedroom = new Connection();
cn.Add(new Point()); // add two points to draw a line, 3 or more points to draw a curve.
myHouse.AddRoomConnection(hall, bedroom1, cnHallBedroom);
}
这是基本方法,可能不是最好的,但可以作为起点。