<color yellow = color (255, 217, 0); color red = color (255, 0, 0); color black = color (0, 0, 0); int winner = 0; int rows = 6; int cols = 7; int[][] gridChecker = new int[cols][rows]; boolean gameOn = true; boolean locked = false; boolean isRed = true; void draw () { smooth(); background (yellow); for (int i = 0; i < 7; i++) { for (int j = 0; j < 6; j++) { a[i][j].render(); a[i][j].mouseOver(); } } stroke (20); line (100, 0, 100, 600); line (200, 0, 200, 600); line (300, 0, 300, 600); line (400, 0, 400, 600); line (500, 0, 500, 600); line (600, 0, 600, 600); line (0, 100, 700, 100); line (0, 200, 700, 200); line (0, 300, 700, 300); line (0, 400, 700, 400); line (0, 500, 700, 500); } { if (checkWin() == true) { gameOn = false; PFont font = loadFont("IskoolaPota-48.vlw"); textFont(font, 80); if (winner == 4) { shadowtext("Red Wins!", width/4, height/2, 3); } else if(winner == 8) { shadowtext("Black Wins!", width/3.5, height/2, 3); } shadowtext("Click to play again", width/5.5, height*.3, 1); } } void shadowtext (String s, float x, float y, int o) { fill(100,100); text(s, x+o, y+o); fill(58,12,247); text(s, x, y); } void mousePressed() { if (gameOn == false) { gameOn = true; setup(); } } boolean checkWin() { int counter; //horizontal for (int i=0; i < rows; i++) { for (int j=0; j < cols-3; j++) { int tCheck = (gridChecker[j][i]) + (gridChecker[j+1][i]) + (gridChecker[j+2][i]) + (gridChecker[j+3][i]); if (tCheck == 8 || tCheck == 4) { winner = tCheck; return true; } } } //vertical for (int i=0; i < rows-3; i++) { for (int j=0; j < cols; j++) { int tCheck = (gridChecker[j][i]) + (gridChecker[j][i+1]) + (gridChecker[j][i+2]) + (gridChecker[j][i+3]); if (tCheck == 8 || tCheck == 4) { winner = tCheck; return true; } } } //diagonals for (int i=0; i < rows-3; i++) { for (int j=0; j < cols-3; j++) { int tCheck = (gridChecker[j][i]) + (gridChecker[j+1][i+1]) + (gridChecker[j+2][i+2]) + (gridChecker[j+3][i+3]); if (tCheck == 8 || tCheck == 4) { winner = tCheck; return true; } } } for (int i =0; i < rows-3; i++) { for (int j=0; j < cols-3; j++) { int tCheck = (gridChecker[j][i]) + (gridChecker[j+1][i+1]) + (gridChecker[j+2][i+2]) + (gridChecker[j+3][i+3]); if (tCheck == 8 || tCheck == 4) { winner = tCheck; return true; } } } for (int i=0; i < rows-3; i++) { for (int j=3; j < cols; j++) { int tCheck = (gridChecker[j][i]) + (gridChecker[j-1][i+1]) + (gridChecker[j-2][i+2]) + (gridChecker[j-3][i+3]); if (tCheck == 8 || tCheck == 4) { winner = tCheck; return true; } } } return false; } void mouseClicked() { for (int i = 0; i < 7; i++) { for (int j = 0; j < 6; j++) { if (a[i][j].isFilled == false) { if (mouseX > a[i][j].x - a[i][j].diameter / 2 && mouseX < a[i][j].x + a[i][j].diameter / 2 && mouseY > a[i][j].y - a[i][j].diameter / 2 && mouseY < a[i][j].y + a[i][j].diameter / 2) { a[i][j].fillColor = (isRed ? red : black); a[i][j].isFilled = true; gridChecker[i][j] = (isRed ? red : black); isRed = !isRed; } } } } } >