// Name: // Lab Section: // Primary TA: // Email: // Date: // CS101 Lab 7 // Room.java import java.awt.Color; import cs101.canvas.*; public class Room { private Rect room, nHall, eHall, sHall, wHall; private int row, col; private RoomSet in; private Room north, south, east, west; private CS101Canvas canvas; private int pixs; public Room(int row, int col, int pixs, CS101Canvas canvas) { this.row = row; this.col = col; this.canvas = canvas; this.pixs = pixs; init(); } private Rect install(Rect r, int x, int y, int width, int height, Color c) { if (r != null) canvas.remove(r); r = new Rect(x, y, width, height, c); canvas.add(r); return(r); } public void dropEmptyHalls() { if (north == null) nHall.setColor(Color.white); if (south == null) sHall.setColor(Color.white); if (east == null) eHall.setColor(Color.white); if (west == null) wHall.setColor(Color.white); } public void init() { int x = pixs*col*2; int y = pixs*row*2; nHall = install(nHall, x+pixs/3, y-pixs/2, pixs/3, pixs/2, Color.red); eHall = install(eHall, x+pixs, y+pixs/3, pixs/2, pixs/3, Color.orange); sHall = install(sHall, x+pixs/3, y+pixs, pixs/3, pixs/2, Color.yellow); wHall = install(wHall, x-pixs/2, y+pixs/3, pixs/2, pixs/3, Color.green); room = install(room, x, y, pixs, pixs, Color.black); this.north = null; this.south = null; this.east = null; this.west = null; nowMemberOf(new RoomSet(this)); } public void nowMemberOf(RoomSet set) { this.in = set; room.setColor(set.getColor()); nHall.setColor(set.getColor()); wHall.setColor(set.getColor()); eHall.setColor(set.getColor()); sHall.setColor(set.getColor()); room.setFilled(true); } public String toString() { return ("Room (" + row + "," + col + ")"); } public RoomSet getSet() { return in; } public Room getNorth() { return north; } public Room getSouth() { return south; } public Room getEast () { return east ; } public Room getWest () { return west ; } public Rect getNHall() { return nHall; } public Rect getSHall() { return sHall; } public Rect getEHall() { return eHall; } public Rect getWHall() { return wHall; } public Rect getRoom() { return room; } public void connectNorth(Room r) { north = r; nHall.setFilled(true); } public void connectSouth(Room r) { south = r; sHall.setFilled(true); } public void connectEast (Room r) { east = r; eHall.setFilled(true); } public void connectWest (Room r) { west = r; wHall.setFilled(true); } }