예제 #1
0
파일: Control.java 프로젝트: t498homas/src
 // method to load and start a saved game, called by the "Ladda spel" button"
 private void runSavedGame() {
   if (!mGameInAction) // can only be done if no game is active
   {
     abortGame();
     Game game = mLoader.loadGame("savedgames"); // set the folder where the game is to be stored
     if (game != null) {
       mGUI.getBoard().setButtons(game.getButtons());
       mGUI.getTimePanel()
           .getDisplay()
           .setTime(game.getHours(), game.getMinutes(), game.getSeconds());
       mSolved = false;
       mGUI.getBoard().boardUpdate();
       extractLockedValues(); // important only to read buttons from original game
       try {
         mSolver.run(mCurrentValues);
       } catch (Exception ex) {
         // No need to do anything, game is already checked
       }
       getSolution();
       extractValuesFromBoard(); // now get all values to get current board
       mGUI.getTimePanel().start();
       mGameInAction = true;
       mLoader.nullGame();
     }
   }
 }
예제 #2
0
파일: Control.java 프로젝트: t498homas/src
 // save a new unplayed game called by "Lägg till nytt spel button"
 private void saveNewGame() {
   if (!mGameInAction) // can only be done if no game is active
   {
     extractValuesFromBoard();
     if (mSolver.checkNewGame(mCurrentValues)) {
       mGUI.getBoard().lockShowingNumbers(); // set button showing number to locked
       String newName =
           JOptionPane.showInputDialog(
               "Vad vill du döpa spelet till?"); // get name of the game from user
       if (!"".equals(newName)
           && newName != null) // dont do anything unless user names game or if press cancel
       { // save the game
         mSaver.saveGame(
             "newgames/",
             newName,
             new Game(
                 mGUI.getBoard().getButtons(),
                 mGUI.getTimePanel().getHours(),
                 mGUI.getTimePanel().getMinutes(),
                 mGUI.getTimePanel().getSeconds()));
         clearBoard(); // clear the board
       } else if (newName.equals("")) {
         JOptionPane.showMessageDialog(
             null, "Du måste namnge det nya spelet!", "Namnge spelet!", JOptionPane.PLAIN_MESSAGE);
       }
     } else {
       JOptionPane.showMessageDialog(
           null,
           "Du har försökt spara ett olösligt sudoku!",
           "HOPPSAN!!!",
           JOptionPane.PLAIN_MESSAGE);
     }
   }
 }
예제 #3
0
파일: Control.java 프로젝트: t498homas/src
 // gets current values from  locked buttons, other value set to zero
 private void extractLockedValues() {
   for (int i = 0; i < 9; i++) {
     for (int j = 0; j < 9; j++) {
       if (mGUI.getBoard().getButton(i, j).isLocked()) {
         mCurrentValues[i][j] = mGUI.getBoard().getButton(i, j).getValue();
       } else {
         mCurrentValues[i][j] = 0;
       }
     }
   }
 }
예제 #4
0
파일: Control.java 프로젝트: t498homas/src
 // helpmethod to solveGame()
 // used bwhen solution is to be shown to user
 private void updateBoardButton() {
   for (int i = 0; i < 9; i++) {
     for (int j = 0; j < 9; j++) {
       mGUI.getBoard().getButton(i, j).setValueAndUpdate(mCurrentValues[i][j]);
     }
   }
 }
예제 #5
0
파일: Control.java 프로젝트: t498homas/src
 // gets current values from buttons
 private void extractValuesFromBoard() {
   for (int i = 0; i < 9; i++) {
     for (int j = 0; j < 9; j++) {
       mCurrentValues[i][j] = mGUI.getBoard().getButton(i, j).getValue();
     }
   }
 }
예제 #6
0
파일: Control.java 프로젝트: t498homas/src
 // method to save a game in action, time stops when the ok to save is pressed, called by "Spara
 // spel" button
 private void saveGame() {
   if (mGameInAction) // can only be done if there is a game to save
   {
     String savedname =
         JOptionPane.showInputDialog(
             "<html>Vad vill du döpa spelet till?<br>Tomt fält ger datum och tid som namn</html>"); // get the name from user
     if (savedname != null) // if user dont press cancel
     {
       // save the game in folder savedgames
       mSaver.saveGame(
           "savedgames/",
           savedname,
           new Game(
               mGUI.getBoard().getButtons(),
               mGUI.getTimePanel().getHours(),
               mGUI.getTimePanel().getMinutes(),
               mGUI.getTimePanel().getSeconds()));
       // stop clock and reset game
       mGUI.getTimePanel().stop();
       mGameInAction = false;
       clearBoard();
       mGUI.getTimePanel().reset();
     }
   }
 }
예제 #7
0
파일: Control.java 프로젝트: t498homas/src
 // start a new game, called by "Nytt spel"" button
 private void runNewGame() {
   if (!mGameInAction) // can only be done if no game is active
   {
     mGUI.getTimePanel().stop();
     mGUI.getTimePanel().reset();
     clearBoard(); // just to be sure nothing remains
     Game game = mLoader.loadGame("newgames"); // set the folder from where new game is retrieved
     if (game != null) {
       mGUI.getBoard().setButtons(game.getButtons()); // set the buttons
       startGame();
       mLoader.nullGame();
     }
   }
 }
예제 #8
0
파일: Control.java 프로젝트: t498homas/src
 // starts the game
 private void startGame() {
   mSolved = false;
   mGameInAction = true;
   mGUI.getBoard().boardUpdate();
   extractValuesFromBoard(); // update mCurrentValues
   try {
     mSolver.run(mCurrentValues);
   } catch (Exception ex) {
     // Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex);
   }
   getSolution(); // update mSolutionValues
   extractLockedValues(); // update mCurrentValues
   mGUI.getTimePanel().start();
 }
예제 #9
0
파일: Control.java 프로젝트: t498homas/src
 // method to get the solution, called by the "Läs in och lös" button
 private void solveGame() {
   if (!mGameInAction) // can only be done if no game is active, no cheating!
   {
     mGUI.getBoard().lockShowingNumbers();
     extractValuesFromBoard();
     try {
       mSolver.run(mCurrentValues);
     } catch (Exception ex) {
       String info = ex.getMessage();
       JOptionPane.showMessageDialog(null, info, "HOPPSAN!!!", JOptionPane.PLAIN_MESSAGE);
     }
     updateBoardButton();
   }
 }
예제 #10
0
파일: Control.java 프로젝트: t498homas/src
 // resets all unlocked buttos during a game, called by "Börja om" button
 private void restartGame() {
   mGUI.getBoard().resetUnlockedButtons();
 }
예제 #11
0
파일: Control.java 프로젝트: t498homas/src
 // method to set all button to unlocked and value to zero
 // and resets mCurrentValues to zero
 private void clearBoard() {
   if (!mGameInAction) // can only be done if no game is active
   {
     mGUI.getBoard().resetAllButtons();
   }
 }