int iSelect = -1; int jSelect = -1; int highlight = 0; int[][] savedGame = new int[0][0]; PFont myFont; sBox[][] myBox; void setup() { size(400,400); myFont = loadFont("arial.vlw"); textFont(myFont,11); myBox = new sBox[9][9]; for(int i=0;i < 9;i++) for(int j=0; j<9; j++) myBox[i][j] = new sBox(i,j); } void draw() { fill(255); strokeWeight(1); for(int i=0;i<9;i++) for(int j=0;j<9;j++) { rect(20+j*40,20+i*40,40,40); } strokeWeight(3); noFill(); rect(20,20,360,360); line(140,20,140,380); line(260,20,260,380); line(20,140,380,140); line(20,260,380,260); if (iSelect !=-1) { //highlight box stroke(#00FF00); //fill(#0000FF); if(highlight == 1) rect(20,20+iSelect*40,360,40); else if(highlight==2) rect(20+jSelect*40,20,40,360); else if(highlight == 3) rect(int(jSelect/3.0)*120+20,int(iSelect/3.0)*120+20,120,120); noFill(); //selector box stroke(#FF0000); rect(20+jSelect*40,20+iSelect*40,40,40); stroke(0); } for(int i=0;i < 9;i++) for(int j=0; j<9; j++) myBox[i][j].display(); } void mouseReleased() { if(mouseX > 20 && mouseX < 380 && mouseY > 20 && mouseY < 380) { jSelect = floor((mouseX-20.0)/40.0); iSelect = floor((mouseY-20.0)/40.0); } else { jSelect = -1; iSelect = -1; } //println("Row: " + iSelect + " - Col: " + jSelect); } void keyPressed() { //INPUT NUMBER TO SELECTED BOX int numPress = int(str(key)); if (iSelect != -1 && numPress < 10 && numPress > 0 && myBox[iSelect][jSelect].num ==-1) { myBox[iSelect][jSelect].num = numPress; killOthers(iSelect,jSelect,numPress); } //MISTAKE DELETER if(key == 'd' && myBox[iSelect][jSelect].num != -1) { myBox[iSelect][jSelect].num = -1; for(int i=0; i<9; i++) for (int j=0; j<9; j++) if (myBox[i][j].num == -1) for (int x=0; x<9;x++) myBox[i][j].numPossible[x] = true; for(int i=0; i<9; i++) for (int j=0; j<9; j++) if (myBox[i][j].num != -1) killOthers(i,j,myBox[i][j].num); /* for(int i=0; i<9; i++) { myBox[iSelect][jSelect].numPossible[i] = true; if (myBox[iSelect][i].num == -1) myBox[iSelect][i].numPossible[myBox[iSelect][jSelect].num-1] = true; if (myBox[i][jSelect].num == -1) myBox[i][jSelect].numPossible[myBox[iSelect][jSelect].num-1] = true; } // same 3x3 box int iBase = iSelect - iSelect%3; int jBase = jSelect - jSelect%3; for(int i=0;i<3;i++) for(int j=0;j<3;j++) if (myBox[iBase+i][jBase + j].num == -1) myBox[iBase+i][jBase + j].numPossible[myBox[iSelect][jSelect].num-1] = true; myBox[iSelect][jSelect].num = -1; */ } //MOVE SELECTOR BOX if (key==CODED && iSelect != -1) { if (keyCode == UP && iSelect > 0) iSelect--; else if (keyCode == DOWN && iSelect < 8) iSelect++; else if (keyCode == LEFT && jSelect > 0) jSelect--; else if (keyCode == RIGHT && jSelect < 8) jSelect++; } if (key == 'n') { myBox = new sBox[9][9]; for(int i=0;i < 9;i++) for(int j=0; j<9; j++) myBox[i][j] = new sBox(i,j); } else if (key == 'h') { if (highlight == 3) highlight = 0; else highlight++; } //SAVE else if (key == 's') { savedGame = new int[9][9]; for(int i=0;i<9;i++) for(int j=0;j<9;j++) savedGame[i][j] = myBox[i][j].num; } else if (key == 'r') { if(savedGame.length !=0) { for(int i=0; i<9; i++) for (int j=0; j<9; j++) for (int x=0; x<9;x++) { myBox[i][j].numPossible[x] = true; myBox[i][j].num = -1; } for(int i=0; i<9; i++) for (int j=0; j<9; j++) if (savedGame[i][j] != -1) { myBox[i][j].num = savedGame[i][j]; killOthers(i,j,myBox[i][j].num); } } } }