import java.awt.*; import java.util.*; /**

A class for demonstrating the independence of Spider objects from Room objects. Conventionally, a single Room is inhabited by one or more Spiders. In this program a single Spider ("itzy") wanders from Room to Room, in a Frame comprised of more than one Rooms. The rooms are laid out "railroad style" inside the Frame: equal-sized rectangles in a single row, left-to-right.

Itzy starts out in the center of the leftmost Room with a snapshot of itself, and roams until it runs into a wall. Another snapshot is taken at this point, and then itzy gets relocated to the center of the next Room, with a darker silk color. At this point the process repeats, until itzy runs into the wall of the last Room.

Click on the "close button" (marked X) in the top right corner of the spider's window, to terminate the application. @see Spider @see Room @see AppFrame @author Java translation by Istvan Mohos, 1996 */ public class ThreeRoomFlat { static final int MAXROOMS = 3; public static void main(String[] args) { Room[] flat = new Room[MAXROOMS]; // reserve array space for (int i = 0; i < MAXROOMS; i++) { flat[i] = new Room(); // create the Room objects } new AppFrame("Three-Room Flat", flat, 600, 200); Room currentRoom; // reference to one of three rooms Spider itzy = new Spider(); // create a spider Random numGen = new Random( ); // set up random number generator for (int i = 0; i < MAXROOMS; i++) { currentRoom = flat[i]; currentRoom.jumpToMiddle(itzy); currentRoom.showMe(itzy); // show the spider at the center itzy.setSilk(itzy.getSilk().darker()); while(!currentRoom.isAtWall(itzy)) { itzy.turnRight(); currentRoom.veer(itzy, numGen.nextInt() % 32 , numGen.nextInt() % 16); } // end of while-loop // Show the spider at the wall before sending it into the next room currentRoom.showMe(itzy); } // end of for-loop } // end definition of main method } // end definition of class ThreeRoomFlat;