UML Class Diagrams
for Sample Robots Design

BoardPiece

-x:int
-y:int
+BoardPiece(int,int)
+getX():int
+getY():int
+toString():String
+manhattanDistance(BoardPiece,BoardPiece):int

Player
extends BoardPiece

 
+Player(int,int)
+move(int,int):void
+teleport(int,int):void
+toString():String
 

Explosion
extends BoardPiece

 
+Explosion(int,int)
+toString():String

BasicRobot
extends BoardPiece

 
+BasicRobot(int,int)
+move(Player):void
+toString():String
 

FastRobot
extends BoardPiece

 
+FastRobot(int,int)
+move(Player):void
+toString():String

Board

-rows:int
-cols:int
-board:BoardPiece[][]
+Board(int,int)
+getRows():int
+getCols():int
+getPiece(int,int):BoardPiece
+addPiece(BoardPiece):void
+isOnBoard(int,int):boolean
+toString():String

Game
implements KeyBoardListener, WindowPainter

-gameBoard:Board
-player:Player
-boardWindow:Window
+Game(Board)
+setWindow(Window):void

Note that methods that are given in an interface must be implemented in a class implementing that interface; however, methods that are given in the UML diagram for the interface are not repeated in the UML class diagram for the implementing class.  In particular, because Game implements the KeyBoardListener interface, the Game class will have a takeKey(char) method and because Game implements the WindowPainter interface, the Game class will have a repaint() method.  The UML class diagram for Game (above) does not list takeKey(char) or repaint(); those methods are listed in the UML diagrams for the appropriate interfaces.

GameIO

 
+saveToFile(Board,String):void
+loadFromFile(String):Board>
+loadRandom():Board>
+getIntFromUser(Scanner):int
 

GameApp

 
+main(String[]):void