Class games.Battle.client.ClientApplet.ClientBoardComponent
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class games.Battle.client.ClientApplet.ClientBoardComponent

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----games.Battle.client.ClientApplet.ClientBoardComponent

public class ClientBoardComponent
extends Canvas
The ClientBoardComponent is the awt component derivation responsible for a) maintaining and refreshing an offscreen game animation bitmap and b) collecting events from the user and sending Commands to the server on behalf of the player. The methods setPlayer() and setOutputStream() must be called after contructing a ClientBoardCompent.

Constructor Index

 o ClientBoardComponent(ClientBoard)
Construct a ClientBoardComponent with the given ClientBoard.

Method Index

 o getColFromBoardCoord(int)
Given a "world" x-coordinate, return which column this occurs in
 o getOffScreenImage()
Return a reference to the offscreen image being maintained by this ClientBoardComponent.
 o getRowFromBoardCoord(int)
Given a "world" y-coordate, return which row this occurs in
 o getXPosFromBoardCoord(int)
Given a "world" x-coordinate, return an x-coordinate in cell space for the cell the mouse is currently located inside
 o getYPosFromBoardCoord(int)
Given a "world" y-coordinate, return an y-coordinate in cell space for the cell the mouse is currently located inside
 o handleEvent(Event)
Handle game action events generated by a user playing the game.
 o paint(Graphics)
We use the paint method to see if an offscreen bitmap image has been created yet, and if not, to create one.
 o preferredSize()
Return the preferred size for this component
 o setLook(ClientLook)
We allow a reference to the look for this game board to be stored here so that we can force it to update with the "!" command.
 o setOutputStream(OutputStream)
Commands generated by user input events are sent to this output stream, presumably a connection to the server.
 o setPlayer(int)
Setting the player id for this component allows the component to process events from the user with some degree of intelligence.
 o update(Graphics)
We overload the update method to do nothing, as the regular update cycles generated from the connection to the server will regularly update.

Constructors

 o ClientBoardComponent
  public ClientBoardComponent(ClientBoard b)
Construct a ClientBoardComponent with the given ClientBoard. We keep a reference to the board we are playing on in order to give the clients some intelligence with respect to the Commands they will be sending to the server.
Parameters:
b - the client board defining the current battle field
See Also:
ClientBoard

Methods

 o setLook
  public void setLook(ClientLook lk)
We allow a reference to the look for this game board to be stored here so that we can force it to update with the "!" command. This is an undocumented emergency procedure for forcing the client to update its terrain.
Parameters:
lk - the ClientLook reference to update
See Also:
ClientLook
 o setPlayer
  public void setPlayer(int p)
Setting the player id for this component allows the component to process events from the user with some degree of intelligence. For example, events not occuring in a cell owned by this id are thrown away. This method must be called after constructing a ClientBoardComponent.
Parameters:
p - the id of the player this ClientBoardComponent represents
 o setOutputStream
  public void setOutputStream(OutputStream os)
Commands generated by user input events are sent to this output stream, presumably a connection to the server.
Parameters:
os - the output stream to send commands to
 o update
  public void update(Graphics g)
We overload the update method to do nothing, as the regular update cycles generated from the connection to the server will regularly update.
Overrides:
update in class Component
 o paint
  public void paint(Graphics g)
We use the paint method to see if an offscreen bitmap image has been created yet, and if not, to create one.
Parameters:
g - unused
Overrides:
paint in class Canvas
 o getOffScreenImage
  public Image getOffScreenImage()
Return a reference to the offscreen image being maintained by this ClientBoardComponent.
 o preferredSize
  public Dimension preferredSize()
Return the preferred size for this component
Overrides:
preferredSize in class Component
 o getRowFromBoardCoord
  public int getRowFromBoardCoord(int y)
Given a "world" y-coordate, return which row this occurs in
Parameters:
y - the y coordinate in board space
 o getColFromBoardCoord
  public int getColFromBoardCoord(int x)
Given a "world" x-coordinate, return which column this occurs in
Parameters:
x - the x coordinate in board space
 o getXPosFromBoardCoord
  public int getXPosFromBoardCoord(int x)
Given a "world" x-coordinate, return an x-coordinate in cell space for the cell the mouse is currently located inside
 o getYPosFromBoardCoord
  public int getYPosFromBoardCoord(int y)
Given a "world" y-coordinate, return an y-coordinate in cell space for the cell the mouse is currently located inside
 o handleEvent
  public boolean handleEvent(Event ev)
Handle game action events generated by a user playing the game. When valid events are processed, a Command is created and dumped to the server via out output stream.
Parameters:
ev - the event to process
Overrides:
handleEvent in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index