setup()
setup() runs once when the sketch starts. It configures the canvas and initializes the game board to a fresh state, ready for the first click.
function setup() {
createCanvas(mapSize, mapSize + footerHeight);
textAlign(CENTER, CENTER);
initGrid();
}
Line-by-line explanation (3 lines)
createCanvas(mapSize, mapSize + footerHeight);- Creates a square canvas (300×330 by default) that holds the game grid plus a footer for the timer and restart button
textAlign(CENTER, CENTER);- Aligns all text to its center point, making numbers and flags appear centered in cells
initGrid();- Calls initGrid() to populate the grid array and reset all game state variables