Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Piece class
- -----------
- /**
- * Check whether this piece can share its position
- * with another piece.
- *
- * @param piece
- * The other piece to check.
- *
- * @return False if the other piece is not effective.
- * | if (piece == null)
- * | result == false
- */
- public abstract boolean canSharePositionWith(Piece piece);
- Robot class
- --------------
- /**
- * @return False if the other piece is not effective.
- * | if (piece == null)
- * | result == false
- * @return If the other piece is a robot, true if and only if
- * the other piece equals this robot.
- * | else if (piece instanceof Robot)
- * | result == (piece == this)
- * @return True if the other piece is an item.
- * | else if (piece instanceof Item)
- * | result == true
- * @return Otherwise, the call is dispatched to the other piece.
- * | else
- * | result == piece.canSharePositionWith(this)
- */
- @Override
- public boolean canSharePositionWith(Piece piece) {
- if (piece == null)
- return false;
- // Different robots cannot share positions
- if (piece instanceof Robot)
- return (piece == this);
- // Robots can share their position with items
- if (piece instanceof Item)
- return true;
- return piece.canSharePositionWith(this);
- }
- Wall class
- ----
- /**
- * @return True if and only if the other piece equals this wall.
- * | result == (piece == this)
- */
- @Override
- public boolean canSharePositionWith(Piece piece) {
- // Walls cannot share their positions with other pieces
- return (piece == this);
- }
- Item class
- ---------/**
- * @return False if the other piece is not effective.
- * | if (piece == null)
- * | result == false
- * @return True if the other piece is an item.
- * | else if (piece instanceof Item)
- * | result == true
- * @return Otherwise, the call is dispatched to the other piece.
- * | else
- * | result == piece.canSharePositionWith(this)
- */
- @Override
- public boolean canSharePositionWith(Piece piece) {
- if (piece == null)
- return false;
- // Items can share their position with other items
- if (piece instanceof Item)
- return true;
- return piece.canSharePositionWith(this);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement