rogue
Class Map

java.lang.Object
  extended by rogue.Map

public class Map
extends java.lang.Object

Instance of class Map holds the data that represent the "dungeon" and the current locations of movable items ("treasures", "player", and "monsters") that are in the dungeon. It provides a few utility functions e.g. accessible() that will get called from code implementing the behaviours of various monster classes.


Field Summary
static int kMAPGRIDSIZE
          Size of one square of dungeon (pixel dimension)
 
Constructor Summary
Map(int width, int height)
          Constructor, creates two arrays representing dungeon and contents.
 
Method Summary
 boolean accessible(int x, int y)
          Checks that square is open-space
 void clear(int x, int y)
          Removes any entry from "overlay" grid
 int elementAt(int h, int v)
          Identifies whether square is open or wall.
 int height()
          Return height of map
 void paint(java.awt.Graphics g, java.awt.Canvas drawer)
          Redraws Map in MyCanvas.
 void read(java.io.BufferedReader input)
          Reads dungeon layout.
 void set(int x, int y, int sym)
          Sets overlay grid to contain identifier of particular icon to be displayed (if several moveable items are on same spot, the display will show only the one that called "set()" last; it is possible for there to be a Collectable item and several Monsters on the same square, only one shown)
 boolean validPoint(int x, int y)
          Checks whether x,y coordinate is located within map and is not a wall square.
 int width()
          Returns width of map
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kMAPGRIDSIZE

public static int kMAPGRIDSIZE
Size of one square of dungeon (pixel dimension)

Constructor Detail

Map

public Map(int width,
           int height)
Constructor, creates two arrays representing dungeon and contents. The baseContentGrid basically defines the physical arrangement of walls in the dungeon. The overlay grid defines current positions of moveable items.

Parameters:
width - Width of map
height - Height of map
Method Detail

read

public void read(java.io.BufferedReader input)
Reads dungeon layout. This should be a series of lines, one line for each row of map grid. The line should have spaces and non-space characters (#) indicating open areas and walls.

Parameters:
input - BufferedReader connected to dungeon definition file.

validPoint

public boolean validPoint(int x,
                          int y)
Checks whether x,y coordinate is located within map and is not a wall square.

Parameters:
x - x coordinate of point being tested
y - y coordinate of point being tested
Returns:
boolean indicating whether point is valid

accessible

public boolean accessible(int x,
                          int y)
Checks that square is open-space

Parameters:
x - x coordinate of square of interest
y - y coordinate of square of interest
Returns:
boolean - true if square not "wall"

clear

public void clear(int x,
                  int y)
Removes any entry from "overlay" grid

Parameters:
x - X coordinate of point
y - Y coordinate of point

set

public void set(int x,
                int y,
                int sym)
Sets overlay grid to contain identifier of particular icon to be displayed (if several moveable items are on same spot, the display will show only the one that called "set()" last; it is possible for there to be a Collectable item and several Monsters on the same square, only one shown)

Parameters:
x - X coordinate of square
y - Y coordinate of square
sym - Integer id of image to be shown in overlay

paint

public void paint(java.awt.Graphics g,
                  java.awt.Canvas drawer)
Redraws Map in MyCanvas. MyCanvas class uses double buffering so display is OK; for each square in map either leave blank, or draw wall image, or draw overlay image

Parameters:
g - Graphics object (associated with offscreen buffer)
drawer - Component reference needed as ImageObserver when drawing an Image

width

public int width()
Returns width of map

Returns:
integer width

height

public int height()
Return height of map

Returns:
integer height

elementAt

public int elementAt(int h,
                     int v)
Identifies whether square is open or wall.

Parameters:
h - Horizontal coordinate
v - Vertical coordinate
Returns:
boolean indicating whether space or wall