Methods
calculateInsideArea()
A method to calculate all of the boxes that are currently inside the
filled area. This needs to be explicitly calculated separetely to
the filling algorithm because if there are boxes which are adjacent
to the fill area with the correct color this fill algorithm will
ignore them to prevent visiting unecessary boxes.
colourAt(xPos, yPos) → {Integer}
Finds the colour of the tile at the given position in pixels.
Parameters:
| Name | Type | Description |
|---|---|---|
xPos |
Integer | The x position in pixels |
yPos |
Integer | The y position in pixels |
Returns:
Number representing the colour of the tile.
- Type
- Integer
draw()
Method that draws the grid in the given position at the given dimensions
drawLineDown(xPos, yPos)
Method that draws a line below the given box coordinates
Parameters:
| Name | Type | Description |
|---|---|---|
xPos |
Float | x pixel coordinate of the top left of the box |
yPos |
Float | y pixel coordinate of the top left of the box |
drawLineLeft(xPos, yPos)
Method that draws a line to the left of the given box coordinates
Parameters:
| Name | Type | Description |
|---|---|---|
xPos |
Float | x pixel coordinate of the top left of the box |
yPos |
Float | y pixel coordinate of the top left of the box |
drawLineRight(xPos, yPos)
Method that draws a line to the right of the given box coordinates
Parameters:
| Name | Type | Description |
|---|---|---|
xPos |
Float | x pixel coordinate of the top left of the box |
yPos |
Float | y pixel coordinate of the top left of the box |
drawLineUp(xPos, yPos)
Method that draws a line above the given box coordinates
Parameters:
| Name | Type | Description |
|---|---|---|
xPos |
Float | x pixel coordinate of the top left of the box |
yPos |
Float | y pixel coordinate of the top left of the box |
drawOutline()
Method that draws a boundary line around all of the boxes within the
filled area
fill(selectedColour) → {Integer}
Implements the flood fill algorithm
Parameters:
| Name | Type | Description |
|---|---|---|
selectedColour |
Integer | Number representing the selected colour |
Returns:
Integer indicating the success condition of the
function. The only error condition resulting in
-1 occurs when the selected colour is equal to the
colour of the top left tile (this.grid[0][0]). All
other condition result in success and return 0.
- Type
- Integer
getNeighbours(gridIndex) → {Array}
Finds the Manhattan neighbours of a given tile in the grid
Parameters:
| Name | Type | Description |
|---|---|---|
gridIndex |
Array | The grid index values in an array. The first value of each index is the row index and the second value is the column index. |
Returns:
The index values of all the neighbours as a 2D array
- Type
- Array
isBoxInsideArea(row, col)
Check if a box is inside the filled area
Parameters:
| Name | Type | Description |
|---|---|---|
row |
Integer | the row of the box |
col |
Integer | the col of the box |
notBeenNeighbour(tileIndex) → {boolean}
Determines if the given tile is already a neighbour encountered in the
previous steps of the flood fill algorithm. This is done my comparing
the given index to an array of indices of previously traversed tiles in
the grid. This array is updated as each tile is encountered as a
neighbour to an explored tile and is reset to [] every time the
mouse is pressed at the beginning of this.fill.
Parameters:
| Name | Type | Description |
|---|---|---|
tileIndex |
Array | The tile index with the first value being the row index and the second value being the column index |
Returns:
{ description_of_the_return_value }
- Type
- boolean
notBeenVisited(tileIndex) → {boolean}
Determines if the given tile has been previously visited during the flood
fill algorithm. This is done my comparing the given index to an array
of indices of previously traversed tiles in the grid. This array is
updated as each tile is "explored" and is reset to [] every time the
mouse is pressed at the beginning of this.fill.
Parameters:
| Name | Type | Description |
|---|---|---|
tileIndex |
Array | The tile index with the first value being the row index and the second value being the column index |
Returns:
{ description_of_the_return_value }
- Type
- boolean
randomiseGrid()
Method that randomly selects colours for each tile in the grid
tileHasColour(tileIndex) → {boolean}
Determines if the given tile is the colour of any of the values in the
wanted colour list stored in the object. This wanted colour list is
determined when the mouse is clicked and is given by the colour value of
the tile at the cursor location as well as the colour value of the tile
at the top left position (this.grid[0][0]).
Parameters:
| Name | Type | Description |
|---|---|---|
tileIndex |
Array | The tile index with the first value being the row index and the second value being the column index |
Returns:
true when the given tile is one of the colours in
the this.wantedColours array.
- Type
- boolean
toggleShowGrid()
Toggle the state of the show internal lines flag
toggleShowNumbers()
Toggle the internal state of the show numbers flag
toggleShowOutline()
Toggle the state of the show external outline flag
winState() → {boolean}
Determines if all of the grid has the same colour.
Returns:
true when the whole grid is the same colour
- Type
- boolean