Class Map

java.lang.Object
  extended by Map

public class Map
extends java.lang.Object

This class creates a map of locations which represents the game board for Oregon Trail


Field Summary
private  double depotDensity
          The density of the number of Depots on the map
private  double forestDensity
          The density of the number of forests on the map.
private  Location[][] map
          The 2d array of locations in the map, indexed by row-col coordinates.
private  double mountainDensity
          The density of the number of mountains on the map.
 
Constructor Summary
Map()
          Default constructor.
Map(int height, int width)
          This constructor initializes a 2D map of null Location references using the values specified by height and width as row and column dimensions, if they are positive.
Map(int height, int width, double theDepotDensity, double theForestDensity, double theMountainDensity)
          This specific constructor initializes the 2D map using the given height and width parameters, if positive, as the row and column dimensions.
 
Method Summary
 double getDepotDensity()
          Returns the value of the private data member depotDensity
 double getForestDensity()
          Returns the value of the private data member forestDensity
 Location getLocationAt(int row, int col)
          Returns the location at the coordinates specified by row and col.
 Location[][] getMap()
          Returns the 2-D private data member map
 double getMountainDensity()
          Returns the value of the private data member mountainDensity.
 int getNumCols()
          Returns the number of columns on the map.
 int getNumRows()
          Returns the number of rows on the Map.
 void populate()
          This method takes care of populating the map.
 void setDepotDensity(double theDepotDensity)
          Sets the depotDensity property to the value passed.
 void setForestDensity(double theForestDensity)
          Sets the forestDensity property to the value passed.
 void setLocationAt(int row, int col, Location loc)
          Sets the map location at the coordinates specified by row and col (if valid) to the passed Location, loc.
 void setMap(Location[][] map)
          Sets the private 2-D map array to the 2-D map that is passed as a parameter.
 void setMountainDensity(double theMountainDensity)
          Sets the mountainDensity property to the parameter value passed.
 void setPriceFactors()
          Sets the price factors for each Depot that exists on the map.
 void setVisibility(int row, int col, int visibility)
          Sets the isVisited flag to true for all the locations within visibility distance from the location specified by row and col.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private Location[][] map
The 2d array of locations in the map, indexed by row-col coordinates.


depotDensity

private double depotDensity
The density of the number of Depots on the map


forestDensity

private double forestDensity
The density of the number of forests on the map.


mountainDensity

private double mountainDensity
The density of the number of mountains on the map.

Constructor Detail

Map

public Map()
Default constructor. Creates a 2d array of null Location references using the Game.BOARD_HEIGHT and Game.BOARD_WIDTH as dimensions. After the constructor is executed, the map will contain BOARD_HEIGHT by BOARD_WIDTH null Location references.


Map

public Map(int height,
           int width)
This constructor initializes a 2D map of null Location references using the values specified by height and width as row and column dimensions, if they are positive. If height is 0 or negative, the row dimension is set to 1. If width is 0 or negative, the column dimension is set to 1.

Parameters:
height - The height of the map
width - The width of the map

Map

public Map(int height,
           int width,
           double theDepotDensity,
           double theForestDensity,
           double theMountainDensity)
This specific constructor initializes the 2D map using the given height and width parameters, if positive, as the row and column dimensions. There will be height x width null Location references. (See the 2-parameter specific constructor.) The remaining parameters are used to set the other private data member values by calling the appropriate mutator methods.

Parameters:
height - The height of the map
width - The width of the map
theDepotDensity - The density value for Depots. Must be greater than 0.0.
theForestDensity - The density value for Forests. Must be greater than 0.0.
theMountainDensity - The density value for Mountains. Must be greater than 0.0.
Method Detail

getDepotDensity

public double getDepotDensity()
Returns the value of the private data member depotDensity

Returns:
Returns the depotDensity.

setDepotDensity

public void setDepotDensity(double theDepotDensity)
Sets the depotDensity property to the value passed. If the value passed is negative, then the density is set to Game.DEPOT_CHANCE.

Parameters:
theDepotDensity - The depotDensity to set.

getForestDensity

public double getForestDensity()
Returns the value of the private data member forestDensity

Returns:
Returns the forestDensity.

setForestDensity

public void setForestDensity(double theForestDensity)
Sets the forestDensity property to the value passed. If the value passed is negative, then the density is set to Game.DENSITY_FOREST.

Parameters:
theForestDensity - The forestDensity to set.

getMap

public Location[][] getMap()
Returns the 2-D private data member map

Returns:
Returns the map.

setMap

public void setMap(Location[][] map)
Sets the private 2-D map array to the 2-D map that is passed as a parameter.

Parameters:
map - The map to set.

getMountainDensity

public double getMountainDensity()
Returns the value of the private data member mountainDensity.

Returns:
Returns the mountainDensity.

setMountainDensity

public void setMountainDensity(double theMountainDensity)
Sets the mountainDensity property to the parameter value passed. If the parameter value passed is negative, then the density is set to Game.DENSITY_MOUNTAIN.

Parameters:
theMountainDensity - The mountainDensity to set.

getNumCols

public int getNumCols()
Returns the number of columns on the map. The columns correspond to the second dimension of the 2-D map. Since the map is a 2-D array, this method returns the value of the length attribute of map's second dimension.

Returns:
The width (number of columns) of the Map

getNumRows

public int getNumRows()
Returns the number of rows on the Map. The rows correspond to the first dimension of the 2-D map. Since the map is a 2-D array, this method returns the value of the length attribute of the map's first dimension.

Returns:
The height (number of rows) of the Map

setLocationAt

public void setLocationAt(int row,
                          int col,
                          Location loc)
Sets the map location at the coordinates specified by row and col (if valid) to the passed Location, loc. Row and col may not be negative values, nor may they be larger than the Map's dimensions. If invalid row or col values are given, an error message is printed and loc is not assigned to any Location in the 2-D map.

Parameters:
row - The row of the location in the map
col - The column of the location in the map
loc - The location to set

getLocationAt

public Location getLocationAt(int row,
                              int col)
Returns the location at the coordinates specified by row and col. if an invalid row or column index is given, null is returned. Invalid index values are negative or larger than the corresponding dimension of the map.

Parameters:
row - The row of the location in the map
col - The column of the location in the map
Returns:
the location at the position (i,j)

setVisibility

public void setVisibility(int row,
                          int col,
                          int visibility)
Sets the isVisited flag to true for all the locations within visibility distance from the location specified by row and col. This method examines every map coordinate and calculates the row distance and the column distance. If both row distance AND column distance are less than or equal to the value of the visibility value, then that Location's isVisited data member is set to true using the corresponding Location mutator.

Parameters:
row - The row position
col - The column position
visibility - The number of squares of visibility that can be seen beyond those that have been visited.

populate

public void populate()
This method takes care of populating the map. This consists of several tasks: 1) Create new locations for each map coordinate 2) Create a Depot at the Location at the default Game starting coordinates The starting row is the largest possible row index on the map The starting column is the largest possible column index on the map 3) Set the initial visibility from the Game starting coordinates, using the default visibility using the setVisibility() method. 4) Set the price factors for each Location on the map using the setPriceFactors() method.


setPriceFactors

public void setPriceFactors()
Sets the price factors for each Depot that exists on the map. This method examines every Location on the map. If a Depot exists at the Location being examined, set the Depot's price factor based on its distance from the starting position using the equation: 1 + (distance/Game.PRICE_FACTOR_MODIFIER)