// class Floor.java //:Assignment 4: //:Student Name: Duo Zhou //:Studnet Number: 722452 /**FileName: Floor.java * Date: July, 27, 2000 * Purpose: Learn how to use JFrame, JPanel, Synchronized method, creating * multithread, the basic idea of creating GUI * Name of Files: This assignment include Building.java, ConnectedWall.java, * Elevator.java, ElevatorFrame.java, ElevatorPanel.java, * Floor.java, MailDeliveryApp.java, MailPiece.java, * Position.java, Robot.java * Brief Discription: Nothing is changed from the original sample file. */ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import java.lang.*; public class Floor { public static final int MAX_ROWS=33; // specify maximum floor dimensions public static final int MAX_COLS=37; public static final int MAX_ROOMS = 27; public static final int MAX_WALLS = 2; public static final int UPPER_LEFT_ROW = 24; // elevator ULCorner public static final int UPPER_LEFT_COL = 30; public static final int LOWER_RIGHT_ROW = 28; // elevator LRCorner public static final int LOWER_RIGHT_COL = 36; public static final int INSIDE_ELEVATOR_ROW = 26; // position inside elevator public static final int INSIDE_ELEVATOR_COL = 34; public static final Position INSIDE_ELEVATOR_POS = new Position(INSIDE_ELEVATOR_ROW, INSIDE_ELEVATOR_COL); public static final int INFRONT_ELEVATOR_ROW = 26; // position inside elevator public static final int INFRONT_ELEVATOR_COL = 29; public static final Position INFRONT_ELEVATOR_POS = new Position(INFRONT_ELEVATOR_ROW, INFRONT_ELEVATOR_COL); public static final int MAIL_START_ROW = 24; public static final int MAIL_START_COL = 29; public static final Position MAIL_START = new Position(MAIL_START_ROW,MAIL_START_COL); // this array holds the floorLayout as specified in the assignment write-up public char[][] floorLayout = new char[Floor.MAX_ROWS][Floor.MAX_COLS]; // this array holds the set of connected walls, containing the starting and stopping // positions for each connected wall objects on this floor. public ConnectedWall[] connectedWalls = new ConnectedWall[Floor.MAX_WALLS]; // this array holds the directory giving position for each mailBoxNum // The index is used as the associated MailBox number public Position[] directory = new Position[Floor.MAX_ROOMS]; //*** //**************************************************************** Floor(char[][] floorLayout ){ this.floorLayout = floorLayout; }// end of Floor() constructor Floor( char[][] floorLayout, Position[] directory){ this.floorLayout = floorLayout; this.directory = directory; } // end of Floor() constructor ////////////////////////////////////////////////////// // This method returns the position of mailBoxNumber public Position getMBoxPos(int mailBoxNumber){ return directory[mailBoxNumber]; }// end of getMBoxPos() ////////////////////////////////////////////////////// // This method returns the character stored in a given tile position char getTile(Position pos){ if(pos.row >= 0 && pos.row <= MAX_ROWS && pos.col >= 0 && pos.col <= MAX_COLS ) { return floorLayout[pos.row][pos.col]; } else{ System.out.println("Floor:getTile(): Invalid coordinates received"); return '\0'; } } // end of getTile() ////////////////////////////////////////////////////// // This method assigns a character to the tile at a given position void setTile(Position pos, char tileSymbol){ if(pos.row >= 0 && pos.row <= MAX_ROWS && pos.col >= 0 && pos.col <= MAX_COLS ) { floorLayout[pos.row][pos.col] = tileSymbol ; //printLayout(); } else{ System.out.println("Floor:setTile(): Invalid coordinates received"); } //new Floor(m_parent); } // end of setTile() ////////////////////////////////////////////////////// // This method prints the floor layout for this floor void printLayout(){ System.out.print("\n"); for(int i=0; i < floorLayout.length; i++){ for(int j=0; j< floorLayout[i].length; j++){ System.out.print(floorLayout[i][j]); } //if(i == floorLayout.length/2) // pause(3.0); System.out.print("\n"); } //pause(3.0); }// end of printLayout() ////////////////////////////////////////////////////// // This method determines if a tile is part of wall boolean isWall(Position pos){ if(floorLayout[pos.row][pos.col] == '-' || floorLayout[pos.row][pos.col] == '+' || floorLayout[pos.row][pos.col] == '|' || floorLayout[pos.row][pos.col] == 'M' || // check for MailPieces floorLayout[pos.row][pos.col] == 'H' || // check for Humans floorLayout[pos.row][pos.col] == '*' ) return true; else return false; }// end of isWall() ////////////////////////////////////////////////////// // This method determines if a tile is a MailBox boolean isMailBox(Position pos){ if(floorLayout[pos.row][pos.col] == '*') return true; else return false; } // end of isMailBox() ////////////////////////////////////////////////////// // This method determines if a tile is a Human boolean isHuman(Position pos){ if(floorLayout[pos.row][pos.col] == 'H') return true; else return false; } // end of isHuman() ////////////////////////////////////////////////////// // This method determines if a coordinate is inside the elevator area boolean inElevator(Position pos){ if( pos.row > UPPER_LEFT_ROW && pos.row < LOWER_RIGHT_ROW && pos.col > UPPER_LEFT_COL && pos.col < LOWER_RIGHT_COL ) return true; else return false; }// end of inElevator() method //////////////////////////////////////////////////// // This method determines if a coordinate is one of the wall start/stop positions boolean isStartStop(Position pos){ for(int i=0 ; i-->