gecco.client
Class Map

java.lang.Object
  |
  +--gecco.client.Map

public class Map
extends Object

This class represents the map of a game. The map should be given an Image and a map size. The map has a coordinate system of its own, where the upper left corner is (0,0), and every pixel is an automaton. The coordinates are then given as integer numbers.

Every point of the map can be set as either visible or invisible. When a point is invisible it is painted darker. To make a point invisible, call invisiblizePoint(). To make a point visible, or to change the state of som point (automaton), call method updatePoint.

When the map is painted, a certain visible area of the map is painted. The currently visible area is specified with a left upper point (in the map's coordinates), and the size (in pixels) of the visible area. The resoultion is also affectable, by setting the size of the pixels (i.e. a number 1, 2, 3 indicating how many screen pixels the side of every map pixel should occupy).

Author:
Andreas Enblom

Field Summary
(package private)  BufferedImage map
          Description of the Field
(package private)  Dimension size
          Description of the Field
(package private)  int squareSize
          Description of the Field
(package private)  boolean[][] visibilities
          Description of the Field
(package private)  Dimension visibleAreaSize
          Description of the Field
(package private)  Point visibleAreaUpperLeft
          Description of the Field
 
Constructor Summary
Map(Dimension size)
          Initilizes a new map.
 
Method Summary
 void clear()
          Clears the map.
 Dimension getSize()
          Gets the Size attribute of the Map object
 void invisibilizePoint(Point p)
          Makes the given point invisibile by making it darker.
 void loadMap(Image map)
          Loads the given image as map.
 void paint(Graphics g)
          Paints the map on the givewn graphics, with the currently set visible area and resolution.
 void setVisibleArea(Point upperLeft, int squareSize, Dimension size)
          Set the currently visible area of the map.
 void updatePoint(Point p, int color)
          Updates the given point of the map to the new color.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

size

Dimension size
Description of the Field

visibleAreaUpperLeft

Point visibleAreaUpperLeft
Description of the Field

squareSize

int squareSize
Description of the Field

visibleAreaSize

Dimension visibleAreaSize
Description of the Field

map

BufferedImage map
Description of the Field

visibilities

boolean[][] visibilities
Description of the Field
Constructor Detail

Map

public Map(Dimension size)
Initilizes a new map.
Parameters:
size - The size of the map.
Method Detail

setVisibleArea

public void setVisibleArea(Point upperLeft,
                           int squareSize,
                           Dimension size)
Set the currently visible area of the map. Remember that the map has (0,0) as its upper left corner.
Parameters:
upperLeft - The upper left corner of the currently visible area. Relative to the map's coordinate system, with (0,0) in the upper left corner.
squareSize - The size of every square (automaton) in pixels on the screen when the map is painted.
size - The size (in squares, not actual screen size) of the currently visible area of the map.

getSize

public Dimension getSize()
Gets the Size attribute of the Map object
Returns:
The Size value

clear

public void clear()
Clears the map.

loadMap

public void loadMap(Image map)
Loads the given image as map. The map is set as invisible.
Parameters:
map - Description of Parameter

invisibilizePoint

public void invisibilizePoint(Point p)
Makes the given point invisibile by making it darker. If the point is already set as invisible, nothing is done.
Parameters:
p - Description of Parameter

updatePoint

public void updatePoint(Point p,
                        int color)
Updates the given point of the map to the new color. This marks the point as visible.
Parameters:
p - The point of the map to update, remember that the map has (0,0) as its upper left corner.
color - The color of the point, given as an int as described in java.awt.Color.

paint

public void paint(Graphics g)
Paints the map on the givewn graphics, with the currently set visible area and resolution.
Parameters:
g - Description of Parameter