|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpt.ua.gboard.games.Labyrinth
public class Labyrinth
GBoard's based maze module.
Top-left coordinate is (0,0)
.
Point objects are used with the following meaning:
- y: line position;
- x: column position;
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.
Field Summary | |
---|---|
GBoard |
board
Maze's GBoard object. |
int |
numberOfColumns
Maze's number of columns. |
int |
numberOfLines
Maze's number of lines. |
Constructor Summary | |
---|---|
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,
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,
int gelemCellsSize)
Creates a labyrinth from a file. |
Method Summary | |
---|---|
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) . |
java.awt.Point[] |
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. |
java.awt.Point[] |
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). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final int numberOfLines
public final int numberOfColumns
public final GBoard board
Constructor Detail |
---|
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[] 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 GBoardMethod Detail |
---|
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 path
boolean
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 number
boolean
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 number
boolean
true if it is an outside position, otherwise it returns falsepublic boolean isRoadSymbol(char c)
c
a road symbol?
c
- character symbol
boolean
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 symbol
boolean
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 number
boolean
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 number
boolean
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 number
char
road symbolpublic char wallSymbol(int line, int column)
(line,column)
.
requires: isWall(line, column)
line
- line numbercolumn
- column number
char
wall symbolpublic java.awt.Point[] roadSymbolPositions(char roadSymbol)
requires: isRoadSymbol(roadSymbol) && roadSymbol != ' '
ensures: \result != null
roadSymbol
- character road symbol
Point[]
array of positionspublic java.awt.Point[] symbolPositions(char symbol)
ensures: \result != null
symbol
- character symbol
Point[]
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 symbol
boolean
true if is attached, otherwise it returns falsepublic Gelem gelemAttachedToRoadSymbol(char roadSymbol)
requires: isRoadSymbol(roadSymbol)
requires: isRoadSymbolAttachToGelem(roadSymbol)
roadSymbol
- character road symbol
Gelem
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 symbolpublic boolean isWallSymbolAttachToGelem(char wallSymbol)
requires: isWallSymbol(wallSymbol)
wallSymbol
- character wall symbol
boolean
true if is attached, otherwise it returns falsepublic Gelem gelemAttachedToWallSymbol(char wallSymbol)
requires: isWallSymbol(wallSymbol)
requires: isWallSymbolAttachToGelem(wallSymbol)
wallSymbol
- character wall symbol
Gelem
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 symbol
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |