int ROWS = 10, COLUMNS = 10, bombCap = 15, spacesRemaining;
float panelX, panelY, panelSize;
ArrayList < Block > panel = new ArrayList();
panelX = 5, panelY = 50+panelX, panelSize = width-panelX*2;
for (int jter = panelY; jter < panelY+panelSize; jter += panelSize / ROWS)
for (int iter = panelX; iter < panelX+panelSize; iter += panelSize / ROWS)
panel.add(new Block(iter, jter, panelSize / ROWS, panel.size()));
for (Block thisBlock: panel)
for (int iter = 0; iter < bombCap; iter++) {
for (Block thisBlock: panel)
thisBlock.selfAssignState();
spacesRemaining = (ROWS * COLUMNS) - bombCap;
Block thisBlock = panel.get((int) random(panel.size()));
if (thisBlock.state == -1)
for (Block thisBlock: panel)
if (thisBlock.state == -1)
thisBlock.revealed = true;
for (Block thisBlock: panel)
if (thisBlock.touchingMouse()) {
if (mouseButton == LEFT && !thisBlock.flagged) {
if (!thisBlock.revealed) {
thisBlock.revealed = true;
if (thisBlock.state == -1)
if (thisBlock.state == 0)
thisBlock.revealAround();
if (mouseButton == RIGHT) {
thisBlock.flagged = !thisBlock.flagged;
if (spacesRemaining <= 0) {
for (Block thisBlock: panel) {
thisBlock.revealed = false;
thisBlock.revealed = true;
bool revealed = false, flagged = false;
Block(float x, float y, float s, float i) {
if (mouseX > xPos && mouseY > yPos && mouseX < xPos + size && mouseY < yPos + size)
rect(xPos, yPos, size, size);
rect(xPos + 10, yPos + 10, size - 20, size - 20);
line(xPos + 10, yPos + 10, xPos + size - 10, yPos + size - 10);
line(xPos + size - 10, yPos + 10, xPos + 10, yPos + size - 10);
rect(xPos, yPos, size, size);
textAlign(CENTER, CENTER);
ellipse(xPos + size / 2, yPos + size / 2, size - 10, size - 10);
text("1", xPos + size / 2, yPos + size / 2);
text("2", xPos + size / 2, yPos + size / 2);
text("3", xPos + size / 2, yPos + size / 2);
text("4", xPos + size / 2, yPos + size / 2);
text("5", xPos + size / 2, yPos + size / 2);
text("6", xPos + size / 2, yPos + size / 2);
text("7", xPos + size / 2, yPos + size / 2);
text("8", xPos + size / 2, yPos + size / 2);
text(ID, xPos + size / 2, yPos + size / 2);
for (int jter = ID - ROWS; jter <= ID + ROWS; jter += ROWS) {
for (int iter = 0; iter <= 1; iter++) {
Block thisBlock = panel.get(jter + iter);
if (thisBlock != null && thisBlock.state == -1)
} else if (ID % COLUMNS == COLUMNS - 1) {
for (int iter = -1; iter <= 0; iter++) {
Block thisBlock = panel.get(jter + iter);
if (thisBlock != null && thisBlock.state == -1)
for (int iter = -1; iter <= 1; iter++) {
Block thisBlock = panel.get(jter + iter);
if (thisBlock != null && thisBlock.state == -1)
for (int jter = ID - ROWS; jter <= ID + ROWS; jter += ROWS) {
for (int iter = 0; iter <= 1; iter++) {
Block thisBlock = panel.get(jter + iter);
if (thisBlock != null && !thisBlock.revealed) {
thisBlock.revealed = true;
if (thisBlock.state == 0)
thisBlock.revealAround();
} else if (ID % COLUMNS == COLUMNS - 1) {
for (int iter = -1; iter <= 0; iter++) {
Block thisBlock = panel.get(jter + iter);
if (thisBlock != null && !thisBlock.revealed) {
thisBlock.revealed = true;
if (thisBlock.state == 0)
thisBlock.revealAround();
for (int iter = -1; iter <= 1; iter++) {
Block thisBlock = panel.get(jter + iter);
if (thisBlock != null && !thisBlock.revealed) {
thisBlock.revealed = true;
if (thisBlock.state == 0)
thisBlock.revealAround();