In this case study we require to model a map of some arbitrary rectangular area. This map should be accessible by (x,y) coordinates with the bottom left of the map considered to be at (0,0). Each coordinate position is modelled by a tile representing a square area of the overall physical area of the map. The only measurement units used in the map are tile position coordinates, the actual physical size of each tile, and hence of the map, being irrelevant to the model. thus the resolution of the map is determined by the size of the area that each tile represents and the number of tiles making up the map.
For example, a room may be modelled by a 10x5 grid of tiles each representing a square metre; or by a 1,000x500 grid of tiles each representing a square centimetre. Similarly, a map might model a garden, town, country, or continent with the number and size of tiles determining the resolution of the model. The physical tile size and hence resolution of a map is determined by the client of the map model; the map model itself is only concerned with tiles and the units of coordinates are in terms of tiles only.
Each tile indicates the type of terrain at its position in the map, the entire tile area is considered to be made up of that terrain type. The term "terrain" may be used to cover such types as ...
we call this the terrain context of the map. A client application should be able to create different maps modelling different areas but within one specific terrain context. However, since code reuse is a central aspect of good software engineering, it is expected that the map model is easily modifiable to cope with different terrain contexts for other applications. For example, an application might be written to find a path through different maps in an outdoor context with grass, water, etc.; this application should require only minimal changes to be able to find a path through a computer room with chairs, tables, etc.
In using the map model, a client application should be able to ...
As the case study progresses, aspects of the above requirements will be presented and diffferent approaches discussed. However at this stage we will introduce a very basic model in the simplest terrain context.
Consider the simplest terrain context where the terrain type is either passable or impassable. This can be modelled by tile values of true or false. Thus the overall map can be modelled by a 2-D array of boolean values.
Note that we must be watchful of the different interpretations of the dimensions of the 2D array as opposed to that of the map coordinates. The former sees these as rows and columns but the latter sees the first index being the x coordinate, i.e. the column number, with the second being the row. It doesn't really matter as long as a consistent interpretation is used throughout your application.
To start work on this case study let us first just get back into Java by creating a program that defines a simple map and then exercises it, we will not concern ourselves with the overall model requirements at this stage.
For this program, map a space where all we are interested in is whether or not the tiles are passable or not.