// knotmosaic.java compile javac -cp . knotmosaic.java // execute java -cp . knotmosaic // reads knotmosaic.dat writes knotmosaicw.dat // show knotmosaic1.dat 2.dat 3.dat 4.dat import java.io.*; import java.util.*; import java.text.*; import java.awt.*; import java.awt.event.*; public class knotmosaic extends Frame { int win_w = 600; int win_h = 660; int win_x = 160; int win_y = 180; int win_cx = 20; int win_cy = win_y-40; int n = 10; // grid cells int step = 40; int grid[][] = new int[n][n]; // has chip number int tgrid[][] = new int[n][n]; // has color Graphics gg; Boolean scontinue = false; Boolean sgrid = true; Boolean debug = false; int count = 0; // count int score = 0; // score int scolor = 1; // red default 0 white Color lcolor[] = {Color.white, Color.red, Color.green, Color.blue, Color.yellow, Color.pink, Color.black}; int chipselected = -1; String filename = "knotmosaic.dat"; int amiss = 0; public knotmosaic() { System.out.println("knotmosaic.java running"); setTitle("knotmosaic"); setSize(win_w,win_h); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); for(int i=0; i6) scolor=1; gg.setColor(lcolor[scolor]); gg.fillRect(240, 125, 10, 10); } // end mcolor void mnogrid() { if(debug) System.out.println("menu no grid"); sgrid = false; draw_grid(gg); } // end mnogrid void mdogrid() { if(debug) System.out.println("menu show grid"); sgrid = true; draw_grid(gg); } // end mdogrid void mpoint(int x, int y) { int xl = win_x+step*n; int yl = win_y+step*n; if(debug) System.out.println("menu point x="+x+", y="+y); if(x>xl || y>yl) return; x = x - win_x; y = y - win_y; if(x<0 || y<0) return; x = x/step; y = y/step; if(grid[x][y]==scolor) { grid[x][y] = 0; // delete second click } else { grid[x][y] = scolor; // change color OK } } // end mpoint void mcheck() // check chip conections { int topc[] = {2, 4, 5, 6, 7, 9, 10}; int leftc[] = {1, 3, 5, 6, 8, 9, 10}; int rigtc[] = {1, 2, 5, 6, 9, 8, 10}; int botc[] = {1, 3, 5, 6, 7, 9, 10}; int chip = 0; int top = 0; int left = 0; int rigt = 0; int bot = 0; int miss = 0; int group = 0; // 1 needs topc, leftc // 2 needs leftc, botc // 3 needs topc, rigtc // 4 needs rigtc, botc // 5, 6, 7, 8 needs all four if(debug) System.out.println("menu check connections"); amiss = 0; for(int i=0; i 10) continue; group = chip; if(chip == 5 || chip == 6 || chip == 9 || chip == 10) group = 5; if(debug) System.out.println("mcheck group ="+group+", i="+i+", j="+j); top = 5; // default OK if(j != 0) top = grid[i][j-1]; // grid[i][j-1] = 9; // if missing // tgrid[i][j-1] = 6; // miss++; left = 5; if(i != 0) left = grid[i-1][j]; rigt = 5; if(i