import { GridGame } from './GridGame';
var gg = new GridGame(5, 5);
gg.onClick(function click(x, y) {
gg.toggleButton(x,y);
});
This will create a table with 5 rows and 5 columns.
If you click on a tile it will change color and looks slightly.
Just like a toggle button.
td {
width: 80px;
height: 80px;
border:5px outset orange;
background-color: orange;
}
td.off {
background-color: darkorange;
border-style: inset;
}
Get back your custom information class instance that can contains things like counter or kind.
Set the HTML style sheet class for a tile (td).
Toggle the HTML style sheet class for a tile (td).
Convenience function.
Simply calls toggleClass(x,y,"off").
Used in many of the demos.
Call callback on mouse click. Passes x,y coordinate of tile clicked.
As well as the mouse button that was clicked.
Convenience function.
Returns true if x or y are out of bounds (this helps some demos work better)
Returns true if the classList contains "off".
Returns an array of 8 or 9 tuples with the x,y coordinates of a tile and its surrounding neighbours.
It starts top left and ends bottom right.
Why does it return x,y coordinates and not simply the tile itself ?
Because a tile is not guaranteed to have the x,y coordinates.
So this way it is guaranteed that the caller has acceess to both.
calls getTD(x,y).style.visibility = "hidden";
calls getAllNeighboursTD(x,y,includeThyself).forEach((td) => td.style.visibility = "hidden")
setHidden(x: number, y: number, trueOrFalse: boolean)
calls getTD( x,y ).style.backgroundColor = trueOrFalse ? "white" : null
calls getTD( x,y ).style.backgroundColor = "white".
The idea here is to make the tile disappear on a white page.
calls getTD( x,y ).style.backgroundColor = null.
The idea here is to make the tile use the style from the style class definition and usually reappear.
isHidden(x,y)
return this.getTD(x, y).style.backgroundColor == "white";
Note: Working on the Minesweeper demo made me realize that this method might not be named well...
Sets:
- td.style.backgroundColor = backgroundColor;
- td.style.borderStyle = borderStyle;
- td.innerHTML = text;
Can be used to show a hidden tile secret (like in Minesweeper).
Sets td.innerHTML = text
Pass in an array of number tuples, which are used as x,y coordinates to call setText in a loop.
return td.innerHTML
Randomizes the tile class instances using Fishers-Yates
returns an integer number between min and max. BOTH LIMITS ARE INCLUSIVE.
A nice array equals method I found on Stackoverflow.
GridGame contains the following leaky abstraction methods:
Get access to the underlying HTML element.
Returns an array of 8 or 9 HTMLElements containing a td and its surrounding neighbours. It starts top left and ends bottom right.
Call the callback for each tile td. Passes in x,y,td.
Add some text to the HTML document.
Usefull for quick debugging.
visually reveal a tile
only set the text of a tile, useful for markings
shuffle the custom information tiles so that their final location is random