From c2286409849aa72bb97a5f3e0c2ea7a7e030b672 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?D=C3=A1niel?= <Dániel@kovax-pc>
Date: Wed, 20 Nov 2013 12:49:35 +0100
Subject: [PATCH] =?UTF-8?q?Menu=20rendszer=20optimaliz=C3=A1lva,=20process?=
 =?UTF-8?q?zorhaszn=C3=A1lat=20optimaliz=C3=A1lva.=20Sz=C3=A1lak=20kezel?=
 =?UTF-8?q?=C3=A9se=20jav=C3=ADtva.=20J=C3=A1t=C3=A9k=20bugok=20jav=C3=ADt?=
 =?UTF-8?q?va.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Még bug:
- Ha mindent megjelöl, akkor is nyer
---
 src/GUI/game/Controller.java          | 30 ++++++++++---------
 src/GUI/game/EndOfGamePopUp.java      | 12 ++++----
 src/GUI/game/Game.java                | 39 +++++++++++++++++--------
 src/GUI/game/Model.java               |  4 ++-
 src/GUI/game/RecursiveNullFinder.java |  1 -
 src/GUI/game/View.java                | 12 ++++----
 src/GUI/menu/Controller.java          | 32 +++++++++++---------
 src/GUI/menu/Menu.java                | 14 +++++++--
 src/Program/Game.java                 | 42 +++++++++++++++------------
 9 files changed, 111 insertions(+), 75 deletions(-)

diff --git a/src/GUI/game/Controller.java b/src/GUI/game/Controller.java
index 5d9dd18..9bb7627 100644
--- a/src/GUI/game/Controller.java
+++ b/src/GUI/game/Controller.java
@@ -16,13 +16,13 @@ import java.awt.Color;
  */
 public class Controller
 {
-    public View view;
-    public Model model;
+    public View     view;
+    public Model    model;
     public Settings settings;
-    public Game game;
+    public Game     game;
     
     //Mutatók külső threadekre
-    public StopWatch stopWatch;
+    public StopWatch    stopWatch;
     public ScoreCounter scoreCounter;
     
     //ha igaz, a játék leáll
@@ -35,18 +35,18 @@ public class Controller
    }
     
     /* setterek */
-    public void setStopButtonPressed(Boolean is) { this.isStopButtonPressed = is; }
-    public void setView(View view) { this.view = view; }
-    public void setModel(Model model) { this.model = model; }
-    public void setGame(Game game){ this.game = game; }
+   // public void setStopButtonPressed(Boolean is)    { this.isStopButtonPressed = is; }
+    public void setView(View view)                  { this.view = view; }
+    public void setModel(Model model)               { this.model = model; }
+    public void setGame(Game game)                  { this.game = game; }
     /* getterek */
-    public int getButtonState() { if( isStopButtonPressed ) return 1; return -1; }
+    public int getButtonState()                     { if( isStopButtonPressed ) return 1; return -1; }
     
     /* Gomb lenyomasok */
     private int[] buttonPosStringToIntArr(String buttonName)
     {
         String[] splitted =  buttonName.split(":");
-        int[] pos = new int[2];
+        int[] pos   = new int[2];
         pos[0] = Integer.parseInt(splitted[0]);
         pos[1] = Integer.parseInt(splitted[1]);
         
@@ -84,10 +84,10 @@ public class Controller
     {
         //stopper leallitasa
         this.stopWatch.stopTimer();
-        this.stopWatch = null;
+     //   this.stopWatch = null;
         
         this.scoreCounter.stopCounter();
-        this.scoreCounter = null;
+     //   this.scoreCounter = null;
         
         this.model.isGameOver = true;
         
@@ -99,6 +99,7 @@ public class Controller
     /* Eventek */
     public void timeLeft()
     {
+        model.timeLeft++;
         view.timeLeft();
     }
     //public void newGame()
@@ -122,13 +123,14 @@ public class Controller
      */
     void endOfGameNewGameButtonPressed() 
     {
-        this.view = null;
-        this.model = null;
+        this.view.close();
         this.game.newGame();
     }
 
     void endOfGameNewNoMoreGameButtonPressed() 
     {
+        this.game.stopGame();
+        this.view.close();
         this.isStopButtonPressed = true;
     }
 
diff --git a/src/GUI/game/EndOfGamePopUp.java b/src/GUI/game/EndOfGamePopUp.java
index d2d2e04..85ac03c 100644
--- a/src/GUI/game/EndOfGamePopUp.java
+++ b/src/GUI/game/EndOfGamePopUp.java
@@ -22,13 +22,13 @@ public class EndOfGamePopUp
     {
         this.controller = controller;
         this.endScore = this.controller.model.getScore();
-        
+        int n = 0;
         if( this.controller.model.isWinner )
         {
             this.controller.showMines(Color.green);
             
             Object[] options = {"Yes","No","Quit"};
-            int n = JOptionPane.showOptionDialog(frame,"Your score: " + this.endScore +  "\n Would you like to start a new game?","Winner!",
+            n = JOptionPane.showOptionDialog(frame,"Your score: " + this.endScore +  "\n Would you like to start a new game?","Winner!",
             JOptionPane.YES_NO_CANCEL_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             null,
@@ -39,9 +39,9 @@ public class EndOfGamePopUp
         {
             this.controller.showMines(Color.red);
 
-           
-            int n = this.popUpWindow("Would you like to start a new game?");
-
+        
+            n = this.popUpWindow("Would you like to start a new game?");
+        }
 
             if( n == 0 )
             {
@@ -55,7 +55,7 @@ public class EndOfGamePopUp
             {
                 this.controller.endOfGameExitGameButtonPressed();
             }
-        }
+        
     }
     private int popUpWindow(String msg)
     {
diff --git a/src/GUI/game/Game.java b/src/GUI/game/Game.java
index 5fb2674..56999af 100644
--- a/src/GUI/game/Game.java
+++ b/src/GUI/game/Game.java
@@ -6,7 +6,7 @@
 
 package GUI.game;
 
-import Program.Program;
+
 import Program.Settings;
 
 
@@ -19,19 +19,29 @@ public class Game
 {
     public Controller controller;
     public Settings settings;
+    public Program.Game game;
     
-    public Game(Settings settings)
+    public Game(Program.Settings settings, Program.Game game)
     {
         this.settings = settings;
-        this.startGUI();
+        this.startGUI(null,null,null);
+        this.game = game;
     }
  
-    public synchronized void startGUI()
+    public synchronized void startGUI(Controller controller, Model model, View view)
     {
-        Controller game    = new Controller(this.settings);
+        Controller game = controller;
+        if( game == null )
+            game    = new Controller(this.settings);
+        
+        Model gameModel = model ;
+        if( gameModel == null )
+            gameModel    = new Model(game);
+        
+        View gameView = view;
+        if( gameView == null )
+            gameView      = new View(game,gameModel);
         
-        Model gameModel    = new Model(game);
-        View gameView      = new View(game,gameModel);
         game.setModel(gameModel);
         game.setView(gameView);
         game.setGame(this);
@@ -43,12 +53,17 @@ public class Game
     }
     public void newGame()
     {
-        this.controller.view.closeWindow();
-        this.controller.model = null;
+     //   this.controller.view.closeWindow();
+      //  this.controller.model = null;
         
-        this.controller.view = null;
-        this.controller = null;
-        this.startGUI();
+      //  this.controller.view = null;
+      //  this.controller = null;
+        this.startGUI(null,null,null);
         
     }
+    
+    public void stopGame()
+    {
+        this.game.windowManager(0);
+    }
 }
diff --git a/src/GUI/game/Model.java b/src/GUI/game/Model.java
index e8b9335..4c6b134 100644
--- a/src/GUI/game/Model.java
+++ b/src/GUI/game/Model.java
@@ -148,6 +148,7 @@ public class Model
         if( isGameOver )
             return;
         
+        System.out.println(pos[0] + ":" + pos[1]);
         //EndOfGamePopUp popup;
         if( this.isMined(pos[0], pos[1]))
         {
@@ -158,12 +159,13 @@ public class Model
                     if( isMined(i, j))
                     {
                         squares[i][j].setText("*");
-                        this.controller.gameOver();
+                        this.isGameOver = true;
                     }                   
                 }
             }
             if( isGameOver )
             {
+                this.controller.gameOver();
                 //popup = new EndOfGamePopUp(this.controller);
                 return;
             }
diff --git a/src/GUI/game/RecursiveNullFinder.java b/src/GUI/game/RecursiveNullFinder.java
index 3f72974..4ee1190 100644
--- a/src/GUI/game/RecursiveNullFinder.java
+++ b/src/GUI/game/RecursiveNullFinder.java
@@ -62,7 +62,6 @@ public class RecursiveNullFinder extends Thread
                     this.nulls = nullsAround;
                     
                     this.depth++;
-                    System.out.println(this.depth);
                     ArrayList<int[]> newNulls = this.getNullFieldAround();
                     
                     
diff --git a/src/GUI/game/View.java b/src/GUI/game/View.java
index ab9e612..5fe8e26 100644
--- a/src/GUI/game/View.java
+++ b/src/GUI/game/View.java
@@ -46,8 +46,8 @@ public class View extends Window
     }
     public void timeLeft()
     {
-        this.timeLeft++;
-        this.timeLeftLabel.setText(Integer.toString(this.timeLeft));
+      //  this.timeLeft++;
+        this.timeLeftLabel.setText(Integer.toString(this.model.timeLeft));
     }
     public void flagChanged(int i)
     {
@@ -167,10 +167,10 @@ public class View extends Window
         
         this.setCenter();
     }
-    public void closeWindow()
-    {
-        this.frame.dispose();
-    }
+ //   public void closeWindow()
+  //  {
+  //      this.frame.dispose();
+  //  }
 
     void scoreChanged() {
         this.scoreLabel.setText("Score:" + this.model.score);
diff --git a/src/GUI/menu/Controller.java b/src/GUI/menu/Controller.java
index 9137f76..3967ba0 100644
--- a/src/GUI/menu/Controller.java
+++ b/src/GUI/menu/Controller.java
@@ -13,17 +13,19 @@ package GUI.menu;
  */
 public class Controller 
 {
-    private Boolean isNewGameButtonPressed = false;
+   // private Boolean isNewGameButtonPressed = false;
     
     public View view;
     private Model model;
+    private Menu menu;
 
     
-    public Controller()
+    public Controller(Menu menu)
     {
+        this.menu = menu;
         this.view   = null;
         this.model  = null;
-        this.isNewGameButtonPressed = false;
+  //      this.isNewGameButtonPressed = false;
     }
     public void registerView(View view)
     {
@@ -35,20 +37,22 @@ public class Controller
     }
     protected void newGameButtonPressed()
     {
-        isNewGameButtonPressed = true;
+        this.view.close();
+        this.menu.startNewGameButtonPressed();
+        //isNewGameButtonPressed = true;
         //throw new GUIMSG("kakispite");
     }
-    public void resetButtonState()
-    {
-        this.isNewGameButtonPressed = false;
-    }
-    public int getButtonState()
-    {
-        if( isNewGameButtonPressed )
-            return 1;
-        return -1;
+  //  public void resetButtonState()
+   // {
+    //    this.isNewGameButtonPressed = false;
+    //}
+    //public int getButtonState()
+    //{
+    //    if( isNewGameButtonPressed )
+    ///        return 1;
+    //    return -1;
         
-    }
+   // }
     
     
     
diff --git a/src/GUI/menu/Menu.java b/src/GUI/menu/Menu.java
index 1c9b0e5..9265853 100644
--- a/src/GUI/menu/Menu.java
+++ b/src/GUI/menu/Menu.java
@@ -15,15 +15,17 @@ package GUI.menu;
 public class Menu  
 {
     public Controller controller;
+    public Program.Game game;
     
-    public Menu()
+    public Menu(Program.Game game)
     {
+        this.game = game;
         this.startGUI();
     }
  
     public synchronized void startGUI()
     {
-        GUI.menu.Controller menu    = new GUI.menu.Controller();
+        GUI.menu.Controller menu    = new GUI.menu.Controller(this);
         
         GUI.menu.Model menuModel    = new GUI.menu.Model();
         GUI.menu.View menuView      = new GUI.menu.View(menu,menuModel);
@@ -32,4 +34,12 @@ public class Menu
         
         this.controller = menu;
     }
+
+    void startNewGameButtonPressed() 
+    {
+        
+        this.game.windowManager(1);
+    }
+
+   
 }
diff --git a/src/Program/Game.java b/src/Program/Game.java
index 0f450b2..eee8525 100644
--- a/src/Program/Game.java
+++ b/src/Program/Game.java
@@ -24,29 +24,28 @@ public class Game
     {
         this.window = 0;
         this.settings = settings;
-
-        while( true )
-        {
-            this.windowManager();
-        }
+        this.windowManager(0);
+        //while( true )
+        //{
+         //   this.windowManager();
+       // }
     }
-    public void windowManager()
+    public void windowManager(int window)
     {
-        while( true )
+        switch(window)
         {
-            switch(this.window)
-            {
-                case 0: this.window = this.menuWindow();
-                        break;
-                case 1: this.window = this.gameWindow();
-                        break;
-            }
+            case 0: this.menuWindow();
+                    break;
+            case 1: this.gameWindow();
+                    break;
         }
     }
-    public int gameWindow()
+   
+    public void gameWindow()
     {
-        this.game = new GUI.game.Game(this.settings);
-        
+        this.game = new GUI.game.Game(this.settings,this);
+    }
+        /*
         while( true )
         {
             if( this.game.controller.getButtonState() != -1 )
@@ -66,13 +65,17 @@ public class Game
 
                 }
         }
+      
+        
         
     }
-    public int menuWindow()   
+*/
+    public void menuWindow()   
     {
-        Menu menu = new Menu();
+        Menu menu = new Menu(this);
         this.menu =  menu;
         
+        /*
         synchronized(menu)
         {
             while( true )
@@ -95,6 +98,7 @@ public class Game
                 }
             }
         }
+        * */
     }
                  
 }
\ No newline at end of file
-- 
GitLab