rogue
Class DungeonGame

java.lang.Object
  extended by rogue.DungeonGame

public class DungeonGame
extends java.lang.Object

The main class.
Its main() function creates a DungeonGame object, gets it to load its data and starts it running.
Most of the functions are private. The (private) run function controls the game with a loop having the form:

     forever
        sleep a bit
        execute any user command (moving the Player avatar)
        let all the Monsters have a move
        update display
        check for termination conditions (Player dead?, all collectables consumed?)
 
You will have to modify the (private) loadItems() function so that it has code to read the definitions of any Monsters that you add to the data file.
The public functions provide access to information that you would want when writing behavioural code for your Monster subclasses.


Constructor Summary
DungeonGame()
          Constructor
 
Method Summary
 boolean clearLineOfSight(Pt p1, Pt p2, int max, Pt[] path)
          Utility function likely to be useful from Monster code that your write.
 Collectable collectableAt(Pt p)
          Checks whether there is a collectable item at given location
 Player human()
          Access function - returns reference to Player object.
static void main(java.lang.String[] args)
          Main line - create object, initialize it (read data file, create display etc), let game run.
 Map map()
          Access function, returns reference to Map object.
 Monster monsterAt(Pt p)
          Checks whether there is a monster at given location
 void removeCollectable(Collectable c)
          Invoked from Player code, informs DungeonGame object that a Collectable has been consumed.
 void removeMonster(Monster m)
          Used in Player code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DungeonGame

public DungeonGame()
Constructor

Method Detail

main

public static void main(java.lang.String[] args)
Main line - create object, initialize it (read data file, create display etc), let game run.

Parameters:
args - Command line arguments - there should be one: the name of a text data file defining the map.

map

public Map map()
Access function, returns reference to Map object.
A monster might want to access the map to plot a route that it was to follow, or performs some similar task.

Returns:
Reference to Map object

human

public Player human()
Access function - returns reference to Player object.
Monster might want a reference to the Player; it can ask Player object for its position (method inheritted from DungeonItem); it can tell Player that it has been hit.

Returns:
Reference to Player object

removeMonster

public void removeMonster(Monster m)
Used in Player code.
If player kills monster, it has to inform dungeon game object that the monster should be removed from collection of inhabitants.
Not likely to be used from inside your Monster code.

Parameters:
m - Reference to (deceased) Monster

removeCollectable

public void removeCollectable(Collectable c)
Invoked from Player code, informs DungeonGame object that a Collectable has been consumed.
Probably not used from your Monster code (unless your Monster also collects Collectables).
You would have to modify supplied framework if you simply wanted Monsters to move collectables around (possibly add a move method to Collectable class).

Parameters:
c - Collectable being removed from game.

collectableAt

public Collectable collectableAt(Pt p)
Checks whether there is a collectable item at given location

Parameters:
p - Point where wish to check
Returns:
Reference to collectable (or null)

monsterAt

public Monster monsterAt(Pt p)
Checks whether there is a monster at given location

Parameters:
p - Point of interest
Returns:
Reference to Monster or null

clearLineOfSight

public boolean clearLineOfSight(Pt p1,
                                Pt p2,
                                int max,
                                Pt[] path)
Utility function likely to be useful from Monster code that your write.
It is used to determine whether there is a "clear line of sight" between two points (typically monster's location and player's location).
The arithmetic is a bit tedious (have to determine grid points that would lie under "line of sight") and is hidden in private auxiliary functions (if you look at source you will see functions like clearSemiVertical).
The max parameter depends on visual accuity range of Monster - maybe 5 square, maybe 10.
The path parameter is for an array of Pt objects; this array must be allocated by the caller (size at least max). The caller creates the array, but not any Pt objects. The function fills in the array with the points along the path.
Use:
    Monster relying on vision to detect Player;
    Calls clearLineOfSight
    If result is false, Monster cannot see Player; should continue with normal routine
    If result is true, Monster can see player; Monster can possibly fire a projectile
    down specified path, or monster can advance along path toward player.
 

Parameters:
p1 - Monster location
p2 - Player location
max - Max sight range
path - Allocated array of Pt object reference variables (of sufficient size to hold all points along path); on return this will be filled in with actual Pt objects.
Returns:
boolean true => clear line of sight exists and is described in path array; false implies no line of sight (contents of path are undefined)