client.brickblock.fwimpl
Class BBBoard

java.lang.Object
  extended by GameCanvas
      extended by client.framework.views.GameView
          extended by client.brickblock.fwimpl.BBBoard

public class BBBoard
extends GameView

This class is the implementation of the abstract class GameView. It is responsible for displaying the game board with all its objects. When a player is pushed (or moves himself) into the trap, he receives -1 points. Power up objects are used; if a player picks up one such, he receives a temporary bonus by getting bigger, faster or stronger.

Author:
Eivind Sorteberg, Martin Jarrett

Field Summary
 
Fields inherited from class client.framework.views.GameView
background, boardHeight, boardWidth, layerManager, model
 
Constructor Summary
BBBoard(AbstractGame model)
          Constructor.
 
Method Summary
 void addObject(Sprite object)
          Adds an object to the board.
protected  void clean()
          Empties all the class' object lists.
 Image createBackgroundImage()
          Creates a background image that covers the entire game board.
 java.lang.Object detectObjectCollision(AbstractPlayer player, int[] movement)
          Called whenever the local player moves, to check whether the move causes a collision with one of the game objects.
 Powerup findPowerup(java.lang.String name, int posX, int posY)
          Removes a PowerUp object from the board at the specified position.
 void handleObjectCollision(java.lang.Object collidesWith, int[] movement)
          Called if a collision is detected with a game object (PowerUp or Trap).
protected  void handlePlayerCollision(AbstractPlayer collidesWith, int[] movement)
          Called if a collision is detected with another player.
 void handleSelfPushed(int[] movement)
          Method that is called whenever the server has notified that the local player has been pushed.
 void removePowerup(Powerup powerup)
          Removes the specified PowerUp object from the game board.
protected  void specialCheck()
          Called continously the game from the check() method in GameView.
 
Methods inherited from class client.framework.views.GameView
check, checkInput, commandAction, detectPlayerCollision, detectWallCollision, drawBoard, fireBoardChanged, getSize, initPlayers, isRunning, notifyAboutPlayerAdded, removePlayer, startGame, stopGame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BBBoard

public BBBoard(AbstractGame model)
Constructor. Calls the super constructor, and decides when the first power up object should be placed on the game board.

Parameters:
model - The game's underlying model.
Method Detail

addObject

public void addObject(Sprite object)
Adds an object to the board.

Parameters:
object - The object added to the board.

findPowerup

public Powerup findPowerup(java.lang.String name,
                           int posX,
                           int posY)
Removes a PowerUp object from the board at the specified position. This method is called when a power up times out, or when it is picked up by one of the remote players.

Parameters:
name - The name of the power up to remove.
posX - The x-position of the power up.
posY - The y-position of the power up.
Returns:
The power up containing the specified attributes

createBackgroundImage

public Image createBackgroundImage()
Creates a background image that covers the entire game board.

Specified by:
createBackgroundImage in class GameView
Returns:
The background image.

handlePlayerCollision

protected void handlePlayerCollision(AbstractPlayer collidesWith,
                                     int[] movement)
Called if a collision is detected with another player. Detects whether the local player is strong enough to push the other player. If he is as strong as, or stronger than the other player, he pushes the other player with with his own movement speed. After the other player has been pushed, all participants are notified.

Specified by:
handlePlayerCollision in class GameView
Parameters:
collidesWith - The player with whom a collision is detected.
movement - The move that leads to the collision.
See Also:
GameView.detectPlayerCollision(client.framework.models.AbstractPlayer, int[]), GameView.check()

handleObjectCollision

public void handleObjectCollision(java.lang.Object collidesWith,
                                  int[] movement)
Called if a collision is detected with a game object (PowerUp or Trap). If such a collision is detected, the server is notified.

Specified by:
handleObjectCollision in class GameView
Parameters:
collidesWith - The object with which the player collides.
movement - The move that leads to the collision.
See Also:
GameView.detectObjectCollision(client.framework.models.AbstractPlayer, int[]), GameView.check()

specialCheck

protected void specialCheck()
Called continously the game from the check() method in GameView. In this implementation, nothing is performed in this method, as all necessary client checks are performed in the default check() method.

Specified by:
specialCheck in class GameView
See Also:
GameView.check()

detectObjectCollision

public java.lang.Object detectObjectCollision(AbstractPlayer player,
                                              int[] movement)
Called whenever the local player moves, to check whether the move causes a collision with one of the game objects. If so, the handleObjectCollision() method is called, and appropriate actions are taken. If no collision is detected, the method returns null.

Specified by:
detectObjectCollision in class GameView
Parameters:
player - The player trying to move
movement - The movement to take place.
Returns:
The object with which the player collides.
See Also:
handleObjectCollision(Object, int[]), GameView.check()

clean

protected void clean()
Empties all the class' object lists. Used when a game is over, to ensure that no objects are transferred to the next game.

Specified by:
clean in class GameView

removePowerup

public void removePowerup(Powerup powerup)
Removes the specified PowerUp object from the game board. The object is removed from both the displayed screen, as well as the list of game objects.

Parameters:
powerup - The power up to remove.

handleSelfPushed

public void handleSelfPushed(int[] movement)
Method that is called whenever the server has notified that the local player has been pushed. Checks if the push results in the user colliding with a game object (i.e. trap or power up). If so, the server needs to be notified of this event. If not, the player is simply moved.

Parameters:
movement - The movement with which the local player has been pushed.
See Also:
BrickBlock.fireForcePushed(String[])