java.lang.Object | +--java.awt.Component | +--java.awt.Canvas | +--RobotRoom
Represents a room in which Science of Computing robots can move. A room consists of a tiled floor and walls. The floor tiles can be colored. Within the room, tiles provide a coordinate system for describing the positions of robots, walls, etc. The coordinate system's origin is the upper left corner of the room, with horizontal coordinates increasing to the right and vertical coordinates increasing down. Coordinates start at 0, i.e., the left-most side of the room is horizontal coordinate 0, and the top side is row 0. Every room has walls around its edges (so that robots can't fall out of the room), and a room may have other walls (or fragments of wall) in its interior.
Field Summary |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
RobotRoom()
Initialize a robot's room with default size and contents. |
|
RobotRoom(java.lang.String description)
Initialize a robot's room from its description. |
Method Summary | |
void |
addRobot(Robot robot,
int col,
int row)
Put a robot in a room. |
protected java.awt.Color |
getColor(int col,
int row)
Find out what color a tile within a room has. |
int |
getRoomHeight()
Get a room's height. |
int |
getRoomWidth()
Get a room's width. |
protected boolean |
isObstructed(int col,
int row)
Find out whether a tile within a room is obstructed. |
protected void |
moveRobot(int oldCol,
int oldRow,
int newCol,
int newRow)
Move a robot from one tile to another. |
void |
paint(java.awt.Graphics context)
Redisplay a robot room. |
protected void |
setColor(int col,
int row,
java.awt.Color newColor)
Change the color of a tile in a room. |
Methods inherited from class java.awt.Canvas |
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public RobotRoom()
RobotRoom room = new RobotRoom();
public RobotRoom(java.lang.String description)
RobotRoom room = new RobotRoom( "5 5 2 1 Y" );
description
- The description of the room. This is a string that
must start with two integers, the room's width and height, in tiles.
The string may then contain any number of tile specifications, which
consist of column and row coordinates (integers) followed by a color
or wall designator (R, G, B, Y, or K for red, green, blue, yellow, and
black, or * for a wall). All elements of the specification should be
separated by white space. For example
9 5 4 2 * 3 2 r
specifies a 9-tile wide by 5-tile high room whose middle tile is
a wall, the tile to its left is red. The outer-most rows and columns of
the room always contain walls, and any tiles not defined by the description
are white.Method Detail |
public void addRobot(Robot robot, int col, int row)
room.addRobot( someRobot, 3, 5 );
robot
- The robot that is being put in this room.col
- The horizontal coordinate (tile column) at which to
place this robot.row
- The vertical coordinate (tile row) at which to place
this robot.protected java.awt.Color getColor(int col, int row)
col
- The horizontal coordinate (i.e., tile column) of the tile.row
- The vertical coordinate (i.e.,tile row) of the tile.
public int getRoomHeight()
int h = room.getRoomHeight();
public int getRoomWidth()
int w = room.getRoomWidth();
protected boolean isObstructed(int col, int row)
col
- The horizontal coordinate (tile column) of the tile.row
- The vertical coordinate (tile row) of the tile.
protected void moveRobot(int oldCol, int oldRow, int newCol, int newRow)
oldCol
- The horizontal coordinate (tile column) of the tile the
robot is moving from.oldRow
- The vertical coordinate (tile row) of the tile the robot
is moving from.newCol
- The horizontal coordinate of the tile the robot is moving to.newRow
- The vertical coordinate of the tile the robot is moving to.public void paint(java.awt.Graphics context)
paint
in class java.awt.Canvas
context
- The graphics context in which to draw the room.protected void setColor(int col, int row, java.awt.Color newColor)
col
- The horizontal coordinate (i.e., tile column) of the tile
to change.row
- The vertical coordinate (i.e., tile row) of the tile
to change.newColor
- The color to make the tile.