diff --git a/src/GUI/game/Controller.java b/src/GUI/game/Controller.java index 8f0e7a242f59364a7f8e5a26cacb581209240e73..c35d7455a48927c9b79d195d1774041733e75f8e 100644 --- a/src/GUI/game/Controller.java +++ b/src/GUI/game/Controller.java @@ -13,15 +13,33 @@ package GUI.game; */ public class Controller { - private View view; + public View view; private Model model; - public Controller(Model model, View view) + private Boolean isStopButtonPressed = false; + + Controller() + { + + } + public void registerView(View view) + { + this.view = view; + } + public void registerModel(Model model) { - this.view = view; - this.model = model; + this.model = model; + } + public int getButtonState() + { + if( isStopButtonPressed ) + return 1; + return -1; - view.draw(); + } + public void resetButtonState() + { + this.isStopButtonPressed = false; } diff --git a/src/GUI/game/Game.java b/src/GUI/game/Game.java index 89654579b401fc236b2e8c9d121ab36b8f86cb5e..3daddc66357665a66db4bca2ceb9e846ed0433c5 100644 --- a/src/GUI/game/Game.java +++ b/src/GUI/game/Game.java @@ -10,8 +10,17 @@ package GUI.game; * * @author Kovax */ -public class Game { - View view = new View(); - Model model = new Model(); - Controller game = new Controller(model,view); +public class Game +{ + public Controller controller; + + public Game() + { + Model gameModel = new Model(); + Controller game = new Controller(); + View gameView = new View(game,gameModel); + + this.controller = game; + } + } diff --git a/src/GUI/game/View.java b/src/GUI/game/View.java index ba6901579e7eb432ca1c926d2ca8b007981d437e..e364aa0457b1100a65ece4ac8ffd2b131e15b4d3 100644 --- a/src/GUI/game/View.java +++ b/src/GUI/game/View.java @@ -6,6 +6,7 @@ package GUI.game; +import GUI.Window.Window; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; @@ -15,7 +16,11 @@ import javax.swing.JPanel; * * @author Kovax */ -public class View extends JPanel { +public class View extends Window +{ + private Controller controller; + private Model model; + private JButton[][] squares; private JFrame frame; @@ -26,6 +31,12 @@ public class View extends JPanel { squares = new JButton[6][6]; } + + View(Controller game, Model gameModel) + { + this.model = gameModel; + this.controller = game; + } public void draw() { this.build(); diff --git a/src/GUI/menu/Controller.java b/src/GUI/menu/Controller.java index 7378b00726b247b1e3b305633b9e03bfbc52bf46..9137f76e9e97b2feb175012e4c1de542cb864006 100644 --- a/src/GUI/menu/Controller.java +++ b/src/GUI/menu/Controller.java @@ -6,7 +6,6 @@ package GUI.menu; -import GUI.window.GUIMSG; /** * @@ -16,7 +15,7 @@ public class Controller { private Boolean isNewGameButtonPressed = false; - private View view; + public View view; private Model model; @@ -39,9 +38,16 @@ public class Controller isNewGameButtonPressed = true; //throw new GUIMSG("kakispite"); } - public Boolean getButtonState() + public void resetButtonState() { - return isNewGameButtonPressed; + this.isNewGameButtonPressed = false; + } + public int getButtonState() + { + if( isNewGameButtonPressed ) + return 1; + return -1; + } diff --git a/src/GUI/menu/View.java b/src/GUI/menu/View.java index 573a26afc1ea2a9c36ebbe0e2422f0d0d4817876..81567f1e2d729f5362e67a9b3b97e6a9310fe9b9 100644 --- a/src/GUI/menu/View.java +++ b/src/GUI/menu/View.java @@ -167,6 +167,7 @@ public class View extends Window private void newGameBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newGameBTNActionPerformed controller.newGameButtonPressed(); + }//GEN-LAST:event_newGameBTNActionPerformed private void settingsBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsBTNActionPerformed diff --git a/src/GUI/window/GUIMSG.java b/src/GUI/window/GUIMSG.java deleted file mode 100644 index 320d1f339568df4dc63a98e2354825636b7e42ad..0000000000000000000000000000000000000000 --- a/src/GUI/window/GUIMSG.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package GUI.window; - -/** - * - * @author Kovax - */ -public class GUIMSG extends Throwable -{ - String msg_str; - int msg_int; - - - public GUIMSG() - { - - msg_str = null; - msg_int = 0; - - } - - public GUIMSG(String test) { - this.msg_str = test; - } - - public void setMsg(String msg_str) - { - this.msg_str = msg_str; - } - public void setMsg(int msg_int) - { - this.msg_int = msg_int; - } - @Override - public String toString() - { - if( msg_str != null ) - return msg_str; - else - return Integer.toString(msg_int); - } - - public Integer toInteger() - { - return msg_int; - } -} diff --git a/src/GUI/window/Window.java b/src/GUI/window/Window.java index 86a440c9c933020318763e58ea8b190df0fd4ca3..9cf2ea0c06b2c07665cac74a70e3de18bb819468 100644 --- a/src/GUI/window/Window.java +++ b/src/GUI/window/Window.java @@ -47,6 +47,9 @@ public class Window extends JPanel { public void setWindosWidth (int windowWidth ) { this.windowWidth = windowWidth; } public void setWindowName ( String windowName ) { this.windowName = windowName; } - + public void close() + { + this.frame.dispose(); + } } diff --git a/src/GUI/window/WindowChangedAction.java b/src/GUI/window/WindowChangedAction.java new file mode 100644 index 0000000000000000000000000000000000000000..281488194c46362423245ecd55a6a85944328b1d --- /dev/null +++ b/src/GUI/window/WindowChangedAction.java @@ -0,0 +1,24 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package GUI.window; + +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; + +/** + * + * @author Kovax + */ +public class WindowChangedAction extends AbstractAction +{ + + @Override + public void actionPerformed(ActionEvent e) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/src/Program/Game.java b/src/Program/Game.java index b314c6b1a08bc5c05a883be596afa1a2ebf7ca66..298392c94be9eca510d31aea3ffb933948169cf8 100644 --- a/src/Program/Game.java +++ b/src/Program/Game.java @@ -15,45 +15,85 @@ import GUI.menu.Menu; public class Game { Menu menu; - Thread BTNListener; + GUI.game.Game game; - public Game() - { - Menu menu = new Menu(); - this.menu = menu; - - System.out.println(menuWaitForButton()); + private int window; + + public Game() + { + this.window = 0; + + while( true ) + { + this.windowManager(); + } + } + public void windowManager() + { + while( true ) + { + switch(this.window) + { + case 0: this.window = this.menuWindow(); + break; + case 1: this.window = this.gameWindow(); + break; } - - public int menuWaitForButton() + } + } + public int gameWindow() + { + this.game = new GUI.game.Game(); + + while( true ) + { + if( this.game.controller.getButtonState() != -1 ) + { + int state = this.game.controller.getButtonState(); + this.game.controller.resetButtonState(); + this.game.controller.view.close(); + this.window = state; + return state; + } + try + { + Thread.sleep(100); + } + catch(InterruptedException ex ) + { + + } + } + + } + public int menuWindow() + { + Menu menu = new Menu(); + this.menu = menu; + + synchronized(menu) + { + while( true ) { - - synchronized(menu) - { - while( true ) - { - if( this.menu.controller.getButtonState() ) - { - System.out.println("asdasdsadsasaddas"); - return 1; - } - try - { - Thread.sleep(100); - } - catch(InterruptedException ex ) - { - - } - - - } - - } - - + if( this.menu.controller.getButtonState() != -1 ) + { + int state = this.menu.controller.getButtonState(); + this.menu.controller.resetButtonState(); + this.menu.controller.view.close(); + this.window = state; + return state; + } + try + { + Thread.sleep(100); + } + catch(InterruptedException ex ) + { + + } } - - - } \ No newline at end of file + } + } + +} \ No newline at end of file diff --git a/src/Program/Program.java b/src/Program/Program.java index 3ecac79824f7457549aa30038a5db8f4b16857e4..d35d20409904796b8abb2f3a79a214b7a2f4fb85 100644 --- a/src/Program/Program.java +++ b/src/Program/Program.java @@ -11,7 +11,6 @@ import GUI.menu.Controller; import GUI.menu.Menu; import GUI.menu.Model; import GUI.menu.View; -import GUI.window.GUIMSG; import java.util.ArrayList; /**