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.
-
ClientBoardComponent(ClientBoard)
- Construct a ClientBoardComponent with the given ClientBoard.
-
getColFromBoardCoord(int)
- Given a "world" x-coordinate, return which column this occurs in
-
getOffScreenImage()
- Return a reference to the offscreen image being maintained by
this ClientBoardComponent.
-
getRowFromBoardCoord(int)
- Given a "world" y-coordate, return which row this occurs in
-
getXPosFromBoardCoord(int)
- Given a "world" x-coordinate, return an x-coordinate in cell
space for the cell the mouse is currently located inside
-
getYPosFromBoardCoord(int)
- Given a "world" y-coordinate, return an y-coordinate in cell
space for the cell the mouse is currently located inside
-
handleEvent(Event)
- Handle game action events generated by a user playing the game.
-
paint(Graphics)
- We use the paint method to see if an offscreen bitmap image
has been created yet, and if not, to create one.
-
preferredSize()
- Return the preferred size for this component
-
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.
-
setOutputStream(OutputStream)
- Commands generated by user input events are sent to this output
stream, presumably a connection to the server.
-
setPlayer(int)
- Setting the player id for this component allows the component
to process events from the user with some degree of intelligence.
-
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.
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
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
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
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
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
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
getOffScreenImage
public Image getOffScreenImage()
- Return a reference to the offscreen image being maintained by
this ClientBoardComponent.
preferredSize
public Dimension preferredSize()
- Return the preferred size for this component
- Overrides:
- preferredSize in class Component
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
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
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
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
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