Beispiel #1
0
 private void sinchronizeGrids() {
   for (int i = 0; i < 9; i++) {
     for (int j = 0; j < 9; j++) {
       sGrid.fields[i][j].setEditable(true);
       sGrid.fields[i][j].setInitVal(
           gg.getGrid().getField(i, j), gg.getGrid().isFieldDefault(i, j));
     }
   }
 }
Beispiel #2
0
  public void update(Observable arg0, Object arg1) {
    try {
      FieldVals fv = (FieldVals) arg1;
      gg.getGrid().setField(fv.getY(), fv.getX(), fv.getVal());
      boolean b = gg.getGrid().isGridSolved();
      // -----------------------------------------------------------------------------------

      // boolean b = true;
      /*
       * if(b) { sGrid.repaint(); doSolved(); }
       */

      // -----------------------------------------------------------------------------------
    } catch (ClassCastException ex) {
      ex.printStackTrace();
    }
  }
Beispiel #3
0
 private void doSolve() {
   try {
     gg.solve();
     sinchronizeGrids();
     setGridToFinished();
     sGrid.repaint();
   } catch (NullPointerException e) {
     e.printStackTrace();
     JOptionPane.showMessageDialog(
         this, "Sudoku seems to be solved.", "Solved", JOptionPane.INFORMATION_MESSAGE);
   }
 }
Beispiel #4
0
 private void doLoad() {
   if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
     try {
       SerGrid sg = LoadSaver.load(fc.getSelectedFile().getAbsolutePath());
       sGrid.setSerGrid(sg, gg.getGrid());
     } catch (Exception e) {
       e.printStackTrace();
       JOptionPane.showMessageDialog(
           this, "Sudoku game have not been saved!", "Error", JOptionPane.ERROR_MESSAGE);
     }
   }
   sGrid.repaint();
 }
Beispiel #5
0
 private void doClear() {
   gg.getGrid().clearNoDefaultFields();
   sinchronizeGrids();
   sGrid.repaint();
 }
Beispiel #6
0
 // -------------------------------------------------------------------------------------------------
 private boolean checkIfSolved() {
   // boolean b = gg.isGridValidGG();
   boolean b = gg.getGrid().isGridSolved();
   return b;
 }
Beispiel #7
0
 private void doCreate() {
   gg.getGrid().resetGrid();
   sinchronizeGrids();
   sGrid.repaint();
 }
Beispiel #8
0
  public void listenSocket() {
    // Create socket connection
    ObjectInputStream ois = null;
    ObjectOutputStream oos = null;
    Date date = null;
    int[][] gridd = new int[9][9];
    boolean[][] fieldsDefault = new boolean[9][9];

    try {
      socket = new Socket("localhost", 12340);
      System.out.println(
          "Connected to"
              + socket.getInetAddress()
              + " on port "
              + socket.getPort()
              + "from port "
              + socket.getLocalPort()
              + " of "
              + socket.getLocalAddress());

      oos = new ObjectOutputStream(socket.getOutputStream());
      ois = new ObjectInputStream(socket.getInputStream());
      // read an object from the server
      // System.out.println("Before reading the object");
      // date = (Date) ois.readObject();

      System.out.println("Before reading the object");

      gridd = (int[][]) ois.readObject();
      fieldsDefault = (boolean[][]) ois.readObject();
      System.out.println("After reading the object");

      for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
          System.out.println(gridd[i][j] + " |");
        }
        System.out.println("\n");
      }
      for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
          System.out.println("**************************" + fieldsDefault[i][j] + " |");
        }
        System.out.println("\n");
      }

      gg.getGrid().resetGrid();
      gg.getGrid().setFieldss(gridd);
      // System.out.print("The date is: " + date);
      System.out.println("Blah Blah");

      //	oos.close();
      //	ois.close();
    } catch (Exception e) {
      System.out.println(e);
    }

    // ----------------------------------------------------------------------------------------------------------------
    try {
      out = new PrintWriter(socket.getOutputStream(), true);

      in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    } catch (UnknownHostException e) {
      System.out.println("Unknown host: kq6py.eng");
      System.exit(1);
    } catch (IOException e) {
      System.out.println("No I/O" + e);
      System.exit(1);
    }

    int i = -1;
    while (i == -1) {
      try {
        String line = in.readLine();
        /*System.out.println("Line is  :  "+ line);
        System.out
        .println("Connected to" + socket.getInetAddress()
        		+ " on port " + socket.getPort() + "from port "
        		+ socket.getLocalPort() + " of "
        		+ socket.getLocalAddress());
        		*/
        // if (line.length() > 0)
        if (line != null) {
          System.out.println("Someone else won!!!");
          doOtherPersonWon();
          i = 0;
        }

      } catch (IOException e) {
        System.out.println("Read failed");
        System.exit(1);
      }
    }
  }