public class Labyrinth
extends java.lang.Object
Top-left coordinate is (0,0).
invariant: numberOfLines >= 1 && numberOfColumns >= 1
invariant: board != null
This class follows DbC(tm) methodology. Where possible, contracts are implement with JML and native's Java assert.
| Modifier and Type | Field and Description |
|---|---|
GBoard |
board
Maze's GBoard object.
|
int |
numberOfColumns
Maze's number of columns.
|
int |
numberOfLines
Maze's number of lines.
|
| Constructor and Description |
|---|
Labyrinth(java.lang.String filename)
Creates a labyrinth from a file.
|
Labyrinth(java.lang.String[] maze)
Creates a labyrinth from an array of Strings.
|
Labyrinth(java.lang.String[] maze,
char[] roadSymbols)
Creates a labyrinth from an array of Strings, using external road symbols.
|
Labyrinth(java.lang.String[] maze,
char[] roadSymbols,
int gelemCellsSize)
Creates a labyrinth from an array of Strings, using external road symbols.
|
Labyrinth(java.lang.String[] maze,
char[] roadSymbols,
int gelemCellsSize,
boolean outsideIsRoad)
Creates a labyrinth from an array of Strings, using external road symbols.
|
Labyrinth(java.lang.String[] maze,
int gelemCellsSize)
Creates a labyrinth from an array of Strings.
|
Labyrinth(java.lang.String filename,
char[] roadSymbols)
Creates a labyrinth from a file, using external road symbols.
|
Labyrinth(java.lang.String filename,
char[] roadSymbols,
int gelemCellsSize)
Creates a labyrinth from a file, using external road symbols.
|
Labyrinth(java.lang.String filename,
char[] roadSymbols,
int gelemCellsSize,
boolean outsideIsRoad)
Creates a labyrinth from a file, using external road symbols.
|
Labyrinth(java.lang.String filename,
int gelemCellsSize)
Creates a labyrinth from a file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attachGelemToRoadSymbol(char roadSymbol,
Gelem gelem)
Attach a gelem to a road symbol.
|
void |
attachGelemToWallSymbol(char wallSymbol,
Gelem gelem)
Attach a gelem to a wall symbol.
|
void |
detachGelemToRoadSymbol(char roadSymbol,
Gelem gelem)
Detach a gelem to a road symbol.
|
void |
detachGelemToWallSymbol(char wallSymbol,
Gelem gelem)
Detach a gelem to a wall symbol.
|
Gelem |
gelemAttachedToRoadSymbol(char roadSymbol)
Get Gelem attached to road symbol.
|
Gelem |
gelemAttachedToWallSymbol(char wallSymbol)
Get Gelem attached to wall symbol.
|
boolean |
isOutside(int line,
int column)
Is
(line,column) a position outside the maze? |
boolean |
isRoad(int line,
int column)
Is
(line,column) a road position? |
boolean |
isRoadSymbol(char c)
Is character
c a road symbol? |
boolean |
isRoadSymbolAttachToGelem(char roadSymbol)
Is road symbol attached to a gelem?.
|
boolean |
isWall(int line,
int column)
Is
(line,column) a wall position? |
boolean |
isWallSymbol(char c)
Is character
c a wall symbol? |
boolean |
isWallSymbolAttachToGelem(char wallSymbol)
Is wall symbol attached to a gelem?.
|
static int |
numberOfLayers()
Number of layers used when creating the GBoard (default value is 2).
|
void |
putRoadSymbol(int line,
int column,
char roadSymbol)
Defines the road symbol at position
(line,column). |
void |
putWallSymbol(int line,
int column,
char wallSymbol)
Defines the wall symbol at position
(line,column). |
char |
roadSymbol(int line,
int column)
Get the road symbol at position
(line,column). |
Position[] |
roadSymbolPositions(char roadSymbol)
Get all the external road symbol's positions at the maze.
|
static void |
setNumberOfLayers(int numberOfLayers)
Define the number of layers to be used when creating the GBoard.
|
static void |
setWindowName(java.lang.String windowName)
Define the name used when creating the GBoard.
|
Position[] |
symbolPositions(char symbol)
Get all the symbol's positions at the maze (applies both to wall and road symbols including space).
|
static boolean |
validMapFile(java.lang.String filename)
Checks if a file path is valid
|
boolean |
validPosition(int line,
int column)
Is
(line,column) a position inside the rectangle defined by the maze? |
char |
wallSymbol(int line,
int column)
Get the wall symbol at position
(line,column). |
static java.lang.String |
windowName()
Nome of window used when creating the GBoard (default value is Labyrinth).
|
public final int numberOfLines
public final int numberOfColumns
public final GBoard board
public Labyrinth(java.lang.String filename)
requires: validMapFile(filename)
filename - path to the filepublic Labyrinth(java.lang.String filename,
char[] roadSymbols)
requires: validMapFile(filename)
filename - path to the fileroadSymbols - array of extra character road symbolspublic Labyrinth(java.lang.String filename,
int gelemCellsSize)
requires: validMapFile(filename)
requires: gelemCellsSize > 0
filename - path to the filegelemCellsSize - width and height of each gelem in GBoardpublic Labyrinth(java.lang.String filename,
char[] roadSymbols,
int gelemCellsSize)
requires: validMapFile(filename)
requires: gelemCellsSize > 0
filename - path to the fileroadSymbols - array of extra character road symbolsgelemCellsSize - width and height of each gelem in GBoardpublic Labyrinth(java.lang.String filename,
char[] roadSymbols,
int gelemCellsSize,
boolean outsideIsRoad)
requires: validMapFile(filename)
requires: gelemCellsSize > 0
filename - path to the fileroadSymbols - array of extra character road symbolsgelemCellsSize - width and height of each gelem in GBoardoutsideIsRoad - if true outside within rectangle limits is considered road (otherwise it is neither road nor wall)public Labyrinth(java.lang.String[] maze)
requires: maze != null && maze.length > 0
maze - arraypublic Labyrinth(java.lang.String[] maze,
char[] roadSymbols)
requires: maze != null && maze.length > 0
maze - arrayroadSymbols - array of extra character road symbolspublic Labyrinth(java.lang.String[] maze,
int gelemCellsSize)
requires: maze != null && maze.length > 0
requires: gelemCellsSize > 0
maze - arraygelemCellsSize - width and height of each gelem in GBoardpublic Labyrinth(java.lang.String[] maze,
char[] roadSymbols,
int gelemCellsSize)
requires: maze != null && maze.length > 0
requires: gelemCellsSize > 0
maze - arrayroadSymbols - array of extra character road symbolsgelemCellsSize - width and height of each gelem in GBoardpublic Labyrinth(java.lang.String[] maze,
char[] roadSymbols,
int gelemCellsSize,
boolean outsideIsRoad)
requires: maze != null && maze.length > 0
requires: gelemCellsSize > 0
maze - arrayroadSymbols - array of extra character road symbolsgelemCellsSize - width and height of each gelem in GBoardoutsideIsRoad - if true outside within rectangle limits is considered road (otherwise it is neither road nor wall)public static int numberOfLayers()
public static void setNumberOfLayers(int numberOfLayers)
requires: numberOfLayers >= 1
numberOfLayers - the number of layerspublic static boolean validMapFile(java.lang.String filename)
filename - file pathboolean true if the path is valid, otherwise it returns falsepublic static java.lang.String windowName()
public static void setWindowName(java.lang.String windowName)
requires: windowName != null
windowName - namepublic boolean validPosition(int line,
int column)
(line,column) a position inside the rectangle defined by the maze?line - line numbercolumn - column numberboolean true if position is valid, otherwise it returns falsepublic boolean isOutside(int line,
int column)
(line,column) a position outside the maze?
requires: validPosition(line, column)
line - line numbercolumn - column numberboolean true if it is an outside position, otherwise it returns falsepublic boolean isRoadSymbol(char c)
c a road symbol?c - character symbolboolean true if is a road symbol, otherwise it returns false (meaning that it is a wall symbol)public boolean isWallSymbol(char c)
c a wall symbol?c - character symbolboolean true if is a wall symbol, otherwise it returns false (meaning that it is a road symbol)public boolean isRoad(int line,
int column)
(line,column) a road position?
requires: validPosition(line, column)
line - line numbercolumn - column numberboolean true if it is a road position, otherwise it returns falsepublic boolean isWall(int line,
int column)
(line,column) a wall position?
requires: validPosition(line, column)
line - line numbercolumn - column numberboolean true if it is a wall position, otherwise it returns falsepublic char roadSymbol(int line,
int column)
(line,column).
requires: isRoad(line, column)
line - line numbercolumn - column numberchar road symbolpublic char wallSymbol(int line,
int column)
(line,column).
requires: isWall(line, column)
line - line numbercolumn - column numberchar wall symbolpublic Position[] roadSymbolPositions(char roadSymbol)
requires: isRoadSymbol(roadSymbol) && roadSymbol != ' '
ensures: \result != null
roadSymbol - character road symbolPosition[] array of positionspublic Position[] symbolPositions(char symbol)
ensures: \result != null
symbol - character symbolPosition[] array of positionspublic void putRoadSymbol(int line,
int column,
char roadSymbol)
(line,column).
requires: isRoad(line, column)
requires: isRoadSymbol(roadSymbol)
ensures: isRoad(line, column)
ensures: roadSymbol(line, column) == roadSymbol
line - line numbercolumn - column numberroadSymbol - character road symbolpublic void putWallSymbol(int line,
int column,
char wallSymbol)
(line,column).
requires: isWall(line, column)
requires: isWallSymbol(wallSymbol)
ensures: isWall(line, column)
ensures: wallSymbol(line, column) == wallSymbol
line - line numbercolumn - column numberwallSymbol - character wall symbolpublic boolean isRoadSymbolAttachToGelem(char roadSymbol)
requires: isRoadSymbol(roadSymbol)
roadSymbol - character road symbolboolean true if is attached, otherwise it returns falsepublic Gelem gelemAttachedToRoadSymbol(char roadSymbol)
requires: isRoadSymbol(roadSymbol)
requires: isRoadSymbolAttachToGelem(roadSymbol)
roadSymbol - character road symbolGelem gelem's objectpublic void attachGelemToRoadSymbol(char roadSymbol,
Gelem gelem)
requires: isRoadSymbol(roadSymbol)
requires: gelem != null
requires: !isRoadSymbolAttachToGelem(roadSymbol)
ensures: isRoadSymbolAttachToGelem(roadSymbol)
roadSymbol - character road symbolgelem - gelem objectpublic void detachGelemToRoadSymbol(char roadSymbol,
Gelem gelem)
requires: isRoadSymbol(roadSymbol)
requires: isRoadSymbolAttachToGelem(roadSymbol)
ensures: !isRoadSymbolAttachToGelem(roadSymbol)
roadSymbol - character road symbolgelem - the gelem's objectpublic boolean isWallSymbolAttachToGelem(char wallSymbol)
requires: isWallSymbol(wallSymbol)
wallSymbol - character wall symbolboolean true if is attached, otherwise it returns falsepublic Gelem gelemAttachedToWallSymbol(char wallSymbol)
requires: isWallSymbol(wallSymbol)
requires: isWallSymbolAttachToGelem(wallSymbol)
wallSymbol - character wall symbolGelem gelem's objectpublic void attachGelemToWallSymbol(char wallSymbol,
Gelem gelem)
requires: isWallSymbol(wallSymbol)
requires: gelem != null
requires: !isWallSymbolAttachToGelem(wallSymbol)
ensures: isWallSymbolAttachToGelem(wallSymbol)
wallSymbol - character wall symbolgelem - gelem objectpublic void detachGelemToWallSymbol(char wallSymbol,
Gelem gelem)
requires: isWallSymbol(wallSymbol)
requires: isWallSymbolAttachToGelem(wallSymbol)
ensures: !isWallSymbolAttachToGelem(wallSymbol)
wallSymbol - character wall symbolgelem - the gelem's object