From 1eea3fe97ad38b357acfc97031407592ec1e7c89 Mon Sep 17 00:00:00 2001 From: kovax <kovacsdanielhun@gmail.com> Date: Wed, 4 Dec 2013 15:55:47 +0100 Subject: [PATCH] =?UTF-8?q?Refactoring=202,=20kommentel=C3=A9s,=20sz=C3=A9?= =?UTF-8?q?p=C3=ADtget=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Program/Game.java | 89 ++--- src/Program/Player.java | 122 +++--- src/Program/Settings.java | 363 ++++++++++-------- .../GUI/game/ButtonActionListener.java | 52 ++- .../mindesweeper/GUI/game/Controller.java | 74 +++- .../mindesweeper/GUI/game/EndOfGamePopUp.java | 48 ++- .../szoftlab3/mindesweeper/GUI/game/Game.java | 29 +- .../mindesweeper/GUI/game/Model.java | 87 ++++- .../GUI/game/RecursiveNullFinder.java | 29 +- .../mindesweeper/GUI/game/ScoreCounter.java | 27 +- .../mindesweeper/GUI/game/StopWatch.java | 24 +- .../szoftlab3/mindesweeper/GUI/game/View.java | 60 +-- .../mindesweeper/GUI/menu/Controller.java | 35 +- .../szoftlab3/mindesweeper/GUI/menu/Menu.java | 19 +- .../mindesweeper/GUI/menu/Model.java | 10 +- .../szoftlab3/mindesweeper/GUI/menu/View.form | 10 +- .../szoftlab3/mindesweeper/GUI/menu/View.java | 26 +- .../mindesweeper/GUI/settings/Controller.java | 43 ++- .../mindesweeper/GUI/settings/Model.java | 39 +- .../mindesweeper/GUI/settings/Settings.java | 19 +- .../GUI/settings/SettingsViewPanel.form | 3 + .../GUI/settings/SettingsViewPanel.java | 31 +- .../mindesweeper/GUI/window/Window.java | 34 +- 23 files changed, 754 insertions(+), 519 deletions(-) diff --git a/src/Program/Game.java b/src/Program/Game.java index fc2b948..bd1da6c 100644 --- a/src/Program/Game.java +++ b/src/Program/Game.java @@ -14,26 +14,30 @@ import hu.bme.szoftlab3.mindesweeper.GUI.menu.Menu; */ public class Game { - Menu menu; - hu.bme.szoftlab3.mindesweeper.GUI.game.Game game; - public Settings settings; - hu.bme.szoftlab3.mindesweeper.GUI.settings.Settings settingsWindow; + public Menu menu; + public hu.bme.szoftlab3.mindesweeper.GUI.game.Game game; + public Settings settings; + public hu.bme.szoftlab3.mindesweeper.GUI.settings.Settings settingsWindow; private int window; - + /** + * + * + * @param settings + */ public Game(Settings settings) { - this.window = 0; this.settings = settings; this.settings.game = this; this.settings.load(); this.windowManager(0); - //while( true ) - //{ - // this.windowManager(); - // } } + /** + * Modulkezelo, a megfelelo modult tolti be + * + * @param window + */ public void windowManager(int window) { switch(window) @@ -46,68 +50,27 @@ public class Game break; } } - + /** + * A jatek modult inditja el (peldanyositja) + * + */ public void gameWindow() { this.game = new hu.bme.szoftlab3.mindesweeper.GUI.game.Game(this.settings,this); - // this.game = new GUI.game.Game(this.settings, this); - } - /* - while( true ) - { - if( this.game.controller.getButtonState() != -1 ) - { - int state = this.game.controller.getButtonState(); - this.game.controller.setStopButtonPressed(Boolean.FALSE); - this.game.controller.view.close(); - this.window = 0; - return 0; - } - try - { - Thread.sleep(100); - } - catch(InterruptedException ex ) - { - - } - } - - - } -*/ + /** + * A menu modult inditja el + * + */ public void menuWindow() { Menu menu = new Menu(this); this.menu = menu; - - /* - synchronized(menu) - { - while( true ) - { - 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 ) - { - - } - } - } - * */ } - + /** + * A beallitasok modult inditja el + * + */ private void settingsWindow() { hu.bme.szoftlab3.mindesweeper.GUI.settings.Settings settings = new hu.bme.szoftlab3.mindesweeper.GUI.settings.Settings(this); this.settingsWindow = settings; diff --git a/src/Program/Player.java b/src/Program/Player.java index 20b0f53..ad8f34f 100644 --- a/src/Program/Player.java +++ b/src/Program/Player.java @@ -1,53 +1,69 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package Program; - -import java.io.Serializable; -import java.util.Comparator; -import javax.swing.table.AbstractTableModel; - -/** - * - * @author Dániel - */ -public class Player implements Serializable, Comparable<Player> -{ - public String name; - public int maxScore; - public int date; - - public Player() - { - this.name = null; - this.maxScore = 0; - this.date = 0; - } - public Player(String name,int maxScore, int date) - { - this.name = name; - this.maxScore = maxScore; - this.date = date; - } - - @Override - public int compareTo(Player t) { - if( t.maxScore < this.maxScore ) - return 0; - else - return 1; - } - - - public class ComparePlayerByScore implements Comparator<Player> - { - - @Override - public int compare(Player t, Player t1) { - if( t.maxScore < t1.maxScore ) - return 0; - return 1; - } - } -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Program; + +import java.io.Serializable; +import java.util.Comparator; + +/** + * + * @author Dániel + */ +public class Player implements Serializable, Comparable<Player> +{ + public String name; + public int maxScore; + public int date; + /** + * Konstruktor + * + */ + public Player() + { + this.name = null; + this.maxScore = 0; + this.date = 0; + } + /** + * Konstruktor + * + * @param name + * @param maxScore + * @param date + */ + public Player(String name,int maxScore, int date) + { + this.name = name; + this.maxScore = maxScore; + this.date = date; + } + /** + * Komparátor + * + * @param t + * @return + */ + @Override + public int compareTo(Player t) { + if( t.maxScore < this.maxScore ) + return 0; + else + return 1; + } + /** + * Score alapján komparál + * + */ + public class ComparePlayerByScore implements Comparator<Player> + { + + @Override + public int compare(Player t, Player t1) { + if( t.maxScore < t1.maxScore ) + return 0; + return 1; + } + } +} diff --git a/src/Program/Settings.java b/src/Program/Settings.java index 0a69139..98104ce 100644 --- a/src/Program/Settings.java +++ b/src/Program/Settings.java @@ -1,165 +1,198 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package Program; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import javax.swing.table.AbstractTableModel; - -/** - * - * @author Dániel - */ -public class Settings extends AbstractTableModel implements Serializable -{ - public Player actualPlayer; - public int size; - //public String playerName; - public int diff; - public int windowWidth; - public int windowHeight; - public int[] availableDiff; - public transient Game game; - public String saveFileName; - public ArrayList<Player> players; - - public void setActualPlayer(Player actualPlayer) - { - this.actualPlayer = actualPlayer; - } - public Settings(Settings progSettings) - { - this.size = progSettings.size; - // this.playerName = progSettings.playerName; - this.diff = progSettings.diff; - this.windowWidth = progSettings.windowHeight; - this.windowHeight = progSettings.windowWidth; - this.availableDiff = progSettings.availableDiff; - this.game = progSettings.game; - this.saveFileName = "settings2.dat"; - this.players = progSettings.players; - this.actualPlayer = progSettings.actualPlayer; - } - public void setGame(Game game) - { - this.game = game; - - } - public Settings(int size,String playerName, int level,int windowWidth, int windowHeight ) - { - this.size = size; - // this.playerName = playerName; - this.diff = level; - this.windowHeight = windowHeight; - this.windowWidth = windowWidth; - - this.availableDiff = new int[4]; - this.availableDiff[0] =0; //% - this.availableDiff[1] =20; - this.availableDiff[2] =30; - this.availableDiff[3] =40; - this.players = new ArrayList<>(); - this.actualPlayer = new Player(playerName,0, (int) (System.currentTimeMillis() / 1000L)); - this.saveFileName = "settings2.dat"; - } - - - public void postLoadPatch() - { - Player player = new Player(); - player.date = this.actualPlayer.date; - player.maxScore = this.actualPlayer.maxScore; - player.name = this.actualPlayer.name; - - this.actualPlayer = player; - } - - public void setBoardSize(int newSize) { - this.size = newSize; - } - - public void setDiff(int i) { - this.diff = i; - } - public void save() - { - try - { - FileOutputStream fileOut = new FileOutputStream(this.saveFileName); - ObjectOutputStream out = new ObjectOutputStream(fileOut); - out.writeObject(this); - out.close(); - fileOut.close(); - } - catch(IOException i) - { - i.printStackTrace(); - } - } - public void load() - { - Settings e = null; - try - { - FileInputStream fileIn = new FileInputStream(this.saveFileName); - ObjectInputStream in = new ObjectInputStream(fileIn); - e = (Settings) in.readObject(); - in.close(); - fileIn.close(); - - this.postLoadPatch(); - } - catch(IOException i) - { - System.out.println(i.getMessage()); - return; - } - catch(ClassNotFoundException c) - { - return; - } - this.game.settings = e; - } - public ArrayList<Player> getTopPlayer(int num) - { - ArrayList<Player> temp = new ArrayList<>(); - for( int i =0;i<this.players.size();i++) - { - temp.add(this.players.get(i)); - } - Collections.sort(temp); - return temp; - } - - @Override - public int getRowCount() - { - return this.players.size(); - } - - @Override - public int getColumnCount() { - return 2; - } - - @Override - public Object getValueAt(int i, int i1) { - if( i1 == 1 ) - { - return players.get(i).maxScore; - } - else if( i1 == 0 ) - { - return players.get(i).name; - } - return 0; - } -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Program; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import javax.swing.table.AbstractTableModel; + +/** + * + * @author Dániel + */ +public class Settings extends AbstractTableModel implements Serializable +{ + public Player actualPlayer; + public int size; + public int diff; + public int windowWidth; + public int windowHeight; + public int[] availableDiff; + public transient Game game; + public String saveFileName; + public ArrayList<Player> players; + + public void setActualPlayer(Player actualPlayer) { this.actualPlayer = actualPlayer; } + public void setGame(Game game) { this.game = game; } + public void setDiff(int i) { this.diff = i; } + public void setBoardSize(int newSize) { this.size = newSize; } + /** + * + * + * @param progSettings + */ + public Settings(Settings progSettings) + { + this.size = progSettings.size; + // this.playerName = progSettings.playerName; + this.diff = progSettings.diff; + this.windowWidth = progSettings.windowHeight; + this.windowHeight = progSettings.windowWidth; + this.availableDiff = progSettings.availableDiff; + this.game = progSettings.game; + this.saveFileName = "settings2.dat"; + this.players = progSettings.players; + this.actualPlayer = progSettings.actualPlayer; + } + /** + * + * + * @param size + * @param playerName + * @param level + * @param windowWidth + * @param windowHeight + */ + public Settings(int size,String playerName, int level,int windowWidth, int windowHeight ) + { + this.size = size; + // this.playerName = playerName; + this.diff = level; + this.windowHeight = windowHeight; + this.windowWidth = windowWidth; + + this.availableDiff = new int[4]; + this.availableDiff[0] =0; //% + this.availableDiff[1] =20; + this.availableDiff[2] =30; + this.availableDiff[3] =40; + this.players = new ArrayList<>(); + this.actualPlayer = new Player(playerName,0, (int) (System.currentTimeMillis() / 1000L)); + this.saveFileName = "settings2.dat"; + } + + /** + * A beállítások betöltése után ezt le kell futtatni, + * hogy ne legyen hibás adat betöltve + * (az előző playert nem jól töltötte be) + * + */ + public void postLoadPatch() + { + Player player = new Player(); + player.date = this.actualPlayer.date; + player.maxScore = this.actualPlayer.maxScore; + player.name = this.actualPlayer.name; + + this.actualPlayer = player; + } + /** + * Beállítások fájlba mentése + * + */ + public void save() + { + try + { + FileOutputStream fileOut = new FileOutputStream(this.saveFileName); + ObjectOutputStream out = new ObjectOutputStream(fileOut); + out.writeObject(this); + out.close(); + fileOut.close(); + } + catch(IOException i) + { + i.printStackTrace(); + } + } + /** + * Beállítások betöltése fájlból + * + */ + public void load() + { + Settings e = null; + try + { + FileInputStream fileIn = new FileInputStream(this.saveFileName); + ObjectInputStream in = new ObjectInputStream(fileIn); + e = (Settings) in.readObject(); + in.close(); + fileIn.close(); + + this.postLoadPatch(); + } + catch(IOException i) + { + System.out.println(i.getMessage()); + return; + } + catch(ClassNotFoundException c) + { + return; + } + this.game.settings = e; + } + /** + * TopPlayerek listáját visszaadja + * + * @param num + * @return + */ + public ArrayList<Player> getTopPlayer(int num) + { + ArrayList<Player> temp = new ArrayList<>(); + for( int i =0;i<this.players.size();i++) + { + temp.add(this.players.get(i)); + } + Collections.sort(temp); + return temp; + } + /** + * A táblázatba tölthetőség miatt szükséges függvény + * + * @return + */ + @Override + public int getRowCount() + { + return this.players.size(); + } + /** + * A táblázatba tölthetőség miatt szükséges függvény + * + * @return + */ + @Override + public int getColumnCount() { + return 2; + } + /** + * A táblázatba tölthetőség miatt szükséges függvény + * + * @param i + * @param i1 + * @return + */ + @Override + public Object getValueAt(int i, int i1) { + if( i1 == 1 ) + { + return players.get(i).maxScore; + } + else if( i1 == 0 ) + { + return players.get(i).name; + } + return 0; + } +} diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ButtonActionListener.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ButtonActionListener.java index f7ab5ca..0c39bf2 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ButtonActionListener.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ButtonActionListener.java @@ -16,19 +16,32 @@ import javax.swing.SwingUtilities; public class ButtonActionListener implements MouseListener { Controller controller; - + /** + * Konstruktor + * + * @param controller + */ public ButtonActionListener(Controller controller) { this.controller = controller; } - - + /** + * MousListener eseményvezérlő + * + * @param me + */ @Override public void mouseClicked(MouseEvent me) { } - + /** + * MousListener eseményvezérlő + * Ha lenyomta a gombot, ez fut le, és a gombnak meglfelelő + * függvényt hivja meg a kontrolleren + * + * @param me + */ @Override public void mousePressed(MouseEvent me) { @@ -55,19 +68,34 @@ public class ButtonActionListener implements MouseListener } } - + /** + * MousListener eseményvezérlő (nem használt) + * + * @param me + */ @Override - public void mouseReleased(MouseEvent me) { + public void mouseReleased(MouseEvent me) + { + } - + /** + * MousListener eseményvezérlő (nem használt) + * + * @param me + */ @Override - public void mouseEntered(MouseEvent me) { - - + public void mouseEntered(MouseEvent me) + { + } - + /** + * MousListener eseményvezérlő (nem használt) + * + * @param me + */ @Override - public void mouseExited(MouseEvent me) { + public void mouseExited(MouseEvent me) + { } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Controller.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Controller.java index a9b6b01..9bb4c55 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Controller.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Controller.java @@ -6,7 +6,6 @@ package hu.bme.szoftlab3.mindesweeper.GUI.game; -import Program.Settings; import java.awt.Color; @@ -18,7 +17,6 @@ public class Controller { public View view; public Model model; - // public Settings settings; public Game game; //Mutatók külső threadekre @@ -27,23 +25,30 @@ public class Controller //ha igaz, a játék leáll private Boolean isStopButtonPressed; - + /** + * + * + * @param game + */ public Controller(Game game) { - // this.settings = settings; this.game = game; this.isStopButtonPressed = false; } /* 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; } /* getterek */ public int getButtonState() { if( isStopButtonPressed ) return 1; return -1; } - /* Gomb lenyomasok */ + /** + * A gomb nevéből visszaadja a pozícióját. + * + * @param buttonName + * @return + */ private int[] buttonPosStringToIntArr(String buttonName) { String[] splitted = buttonName.split(":"); @@ -53,12 +58,21 @@ public class Controller return pos; } - + /** + * Bal oldali gomb megnyomva + * + * @param button + */ public void gameLeftButtonPressed(String button) { int[]pos = this.buttonPosStringToIntArr(button); model.calculateButtonStyle(pos); } + /** + * Jobb oldali gomb megnyomva + * + * @param button + */ public void gameRightButtonPressed(String button) { int[] pos = this.buttonPosStringToIntArr(button); @@ -66,6 +80,10 @@ public class Controller } /* Jatek vezerlesek */ + /** + * Játék indítása + * + */ public void gameStart() { if( this.model != null && this.view != null ) @@ -81,13 +99,15 @@ public class Controller } } + /** + * Játék leállítása + * + */ public void gameOver() { //stopper leallitasa this.stopWatch.stopTimer(); - // this.stopWatch = null; - this.scoreCounter.stopCounter(); - // this.scoreCounter = null; + this.scoreCounter.stopCounter(); this.model.isGameOver = true; /* @@ -98,21 +118,28 @@ public class Controller } /* Eventek */ + /** + * + * Eltelt 1 mp + */ public void timeLeft() { model.timeLeft++; view.timeLeft(); } - //public void newGame() - //{ - // this.game.newGame(); - //} - + /** + * Az összes akna megmutatása a megfelelő színnel + * + * @param color + */ void showMines(Color color) { this.model.showAllMines(color); } - + /** + * Pont változás + * @param score + */ void scoreChanged(int score) { this.model.score = score; @@ -122,22 +149,31 @@ public class Controller /* Játék végi popup ablak kezelése */ + /** + * Játék végén a pop-up ablak előhozása és lekezelése + * Akar még játszani + */ void endOfGameNewGameButtonPressed() { this.view.close(); this.game.newGame(); } - + /** + * Nem akar többet játszani + */ void endOfGameNewNoMoreGameButtonPressed() { this.game.stopGame(); this.view.close(); this.isStopButtonPressed = true; } - + /** + * Kilépés gomb + */ void endOfGameExitGameButtonPressed() { - + /* csunyam egoldás..*/ + System.exit(0); } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/EndOfGamePopUp.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/EndOfGamePopUp.java index f905ae2..a006d31 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/EndOfGamePopUp.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/EndOfGamePopUp.java @@ -14,10 +14,16 @@ import javax.swing.JOptionPane; */ public class EndOfGamePopUp { - public int endScore; - private JFrame frame = new JFrame(); - private Controller controller; + public int endScore; + private JFrame frame = new JFrame(); + private Controller controller; + /** + * Feldobja az ablakot, és a felhasználó választhat, a válasznak megfelelő + * függvényét hívja meg a kontrollernek. + * + * @param controller + */ public EndOfGamePopUp(Controller controller) { this.controller = controller; @@ -38,24 +44,28 @@ public class EndOfGamePopUp else { this.controller.showMines(Color.red); - - n = this.popUpWindow("Would you like to start a new game?"); } - if( n == 0 ) - { - this.controller.endOfGameNewGameButtonPressed(); - } - else if( n == 1 ) - { - this.controller.endOfGameNewNoMoreGameButtonPressed(); - } - else if( n == 2 ) - { - this.controller.endOfGameExitGameButtonPressed(); - } + + if( n == 0 ) + { + this.controller.endOfGameNewGameButtonPressed(); + } + else if( n == 1 ) + { + this.controller.endOfGameNewNoMoreGameButtonPressed(); + } + else if( n == 2 ) + { + this.controller.endOfGameExitGameButtonPressed(); + } } + /** + * Az ismétlődés elkerülése végett csak + * @param msg + * @return + */ private int popUpWindow(String msg) { Object[] options = {"Yes","No","Quit"}; @@ -67,7 +77,5 @@ public class EndOfGamePopUp options[2]); return n; - } - - + } } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Game.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Game.java index f4e7823..90b6f9b 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Game.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Game.java @@ -18,17 +18,23 @@ import Program.Settings; public class Game { public Controller controller; - // public Settings settings; public Program.Game game; - + /** + * Konstruktor game átvétele, GUI elindíása + * @param settings + * @param game + */ public Game(Program.Settings settings, Program.Game game) { - // this.settings = settings; this.game = game; this.startGUI(null,null,null); - } - + /** + * MVC-inicializálása, szükséges objektumok példányosítása + * @param controller + * @param model + * @param view + */ public synchronized void startGUI(Controller controller, Model model, View view) { Controller game = controller; @@ -54,17 +60,16 @@ public class Game this.controller = game; } + /** + * Új játék esetén minden null, ezért újat csinálunk mindenből + */ public void newGame() { - // this.controller.view.closeWindow(); - // this.controller.model = null; - - // this.controller.view = null; - // this.controller = null; this.startGUI(null,null,null); - } - + /** + * Jelzés a modulevezérlőnek, hogy végeztünk. + */ public void stopGame() { this.game.windowManager(0); diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Model.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Model.java index ad73543..f9a9106 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Model.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/Model.java @@ -30,14 +30,14 @@ public class Model public Boolean isWinner; public int score; - + /** + * + * @param controller + */ public Model(Controller controller) { this.timeLeft = 0; this.controller = controller; - // squares = new JButton[controller.settings.size][controller.settings.size]; - - // int mines = 0; isGameOver = false; isWinner = false; } @@ -48,10 +48,13 @@ public class Model * 678 */ - public int getTimeLeft(){ return this.timeLeft; } - public int getMines() { return this.mines; } - public int getScore() { return this.score; } - + public int getTimeLeft() { return this.timeLeft; } + public int getMines() { return this.mines; } + public int getScore() { return this.score; } + /** + * A még nem felfedett mezoket mutatja meg + * @return + */ public int getUncoveredFields() { int uncovered = 0; @@ -67,6 +70,11 @@ public class Model } return uncovered; } + /** + * Megkeresi a szomszédokat + * @param pos + * @return + */ public String[] getNeighbours(int[] pos) { int actX = (pos[0]); @@ -102,6 +110,11 @@ public class Model } + /** + * Megnézi, hogy vége van-e a játéknak + * és , hogy nyert-e a user + * @return + */ private Boolean isGameOverAndWinner() { Boolean isWinner = true ; @@ -128,6 +141,10 @@ public class Model } return isWinner; } + /** + * Játékos hozzáadása a toplistához + * Ha benne van már, akkor a pontok frissítése, ha nincs akkor hozzáadás + */ public void addPlayerToList() { if( controller.game.game.settings.players.contains(controller.game.game.settings.actualPlayer)) @@ -141,8 +158,7 @@ public class Model controller.game.game.settings.players.remove(player); controller.game.game.settings.actualPlayer.maxScore = this.score; controller.game.game.settings.players.add(this.controller.game.game.settings.actualPlayer); - } - + } } } } @@ -155,12 +171,22 @@ public class Model controller.game.game.settings.save(); } + /** + * Visszzaadja, hogy az adott mező jelölve van-e + * @param x + * @param y + * @return + */ public Boolean isFlagged(int x, int y) { if( this.squares[x][y].getText().equals("?") ) return true; return false; } + /** + * Mutassa meg az összes aknát + * @param color + */ public void showAllMines(Color color) { for (int i = 0; i < controller.game.game.settings.size; i++) @@ -176,8 +202,9 @@ public class Model } } } - /* - * A gomb uj kinezetet szamolja ki + /** + * A gomb kinézetét számolja ki, isetlegesen megállíthatja a játékot + * @param pos */ public void calculateButtonStyle(int[] pos) { @@ -252,6 +279,11 @@ public class Model } } } + /** + * Stringből pozíciót számol (névből) + * @param pos + * @return + */ public int[] getPosFromString(String pos) { String[] splitted; @@ -263,6 +295,12 @@ public class Model return po; } + /** + * Visszaadja, hogy a mező alatt van-e akna + * @param x + * @param y + * @return + */ public boolean isMined(int x, int y) { if( x < 0 || y < 0 || x > controller.game.game.settings.size || y > controller.game.game.settings.size ) @@ -278,6 +316,12 @@ public class Model } return false; } + /** + * A Megnézi, hogy hány akna van a közelben + * @param x + * @param y + * @return + */ public int calculateMinesAround(int x,int y) { int pos[] = new int[2]; @@ -296,6 +340,11 @@ public class Model } return minesAround; } + /** + * Létrehozza az aknákat + * @param minesYet + * @return + */ public boolean generateMines(int minesYet) { Random random = new Random(); @@ -307,9 +356,7 @@ public class Model rand = 3; else if( controller.game.game.settings.diff == 3) rand = 2; - - // System.out.println(rand); - //int fos = random.nextInt(100); + if( random.nextInt(100)%rand == 1 ) { @@ -318,6 +365,9 @@ public class Model } return false; } + /** + * Felépíti a pályát + */ public void build() { int minesYet = 0; @@ -362,6 +412,13 @@ public class Model this.controller.view.flagged = this.mines; System.out.println(this.mines); } + /** + * Megszinezi a mezőt + * @param x + * @param y + * @param color + * @param colorF + */ public void colorField(int x,int y, Color color, Color colorF) { this.squares[x][y].setBackground(color); diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/RecursiveNullFinder.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/RecursiveNullFinder.java index aaecb08..bc0a37e 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/RecursiveNullFinder.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/RecursiveNullFinder.java @@ -12,18 +12,25 @@ import java.util.ArrayList; */ public class RecursiveNullFinder extends Thread { - private Controller controller; - private int x; - private int y; - private ArrayList<int[]> nulls; - private ArrayList<int[]> wasThere; - private int depth = 0; - + private Controller controller; + private int x; + private int y; + private ArrayList<int[]> nulls; + private ArrayList<int[]> wasThere; + private int depth = 0; + /** + * + * @param x + * @param y + * @param nulls + * @param wasThere + * @param controller + */ public RecursiveNullFinder(int x, int y,ArrayList<int[]> nulls,ArrayList<int[]> wasThere,Controller controller) { - this.x =x; - this.y =y; - this.nulls = nulls; + this.x = x; + this.y = y; + this.nulls = nulls; this.wasThere = wasThere; this.controller = controller; } @@ -70,8 +77,6 @@ public class RecursiveNullFinder extends Thread this.depth++; ArrayList<int[]> newNulls = this.getNullFieldAround(); - - // nullsAround.addAll(newNulls); for( int[] actNull : newNulls ) { this.addUnique(nullsAround, actNull); diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ScoreCounter.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ScoreCounter.java index 308ae5e..0751e60 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ScoreCounter.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/ScoreCounter.java @@ -12,28 +12,38 @@ package hu.bme.szoftlab3.mindesweeper.GUI.game; */ public class ScoreCounter extends Thread { - Controller controller; - int score; - Boolean enabled; + Controller controller; + int score; + Boolean enabled; + public void setCounter() { this.score = 0; } + + /** + * + * @param controller + */ public ScoreCounter(Controller controller) { this.controller = controller; this.enabled = true; } - - /*Setterek*/ - - /*Getterek*/ - public void setCounter() { this.score = 0; } + /** + * Számláló indítása + */ public void startCounter() { this.enabled = true; } + /** + * Számláló leállítása + */ public void stopCounter() { this.enabled = false; } + /** + * Számláló futtatása + */ @Override public void run() { @@ -51,6 +61,7 @@ public class ScoreCounter extends Thread int uncovered = controller.model.getUncoveredFields(); int covered = ( controller.game.game.settings.size * controller.game.game.settings.size ) - uncovered; + /* Játékszabályok alapján */ if( controller.game.game.settings.diff == 0 ) { //this.score += this.score*1.5; diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/StopWatch.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/StopWatch.java index 3f498d3..a5a54aa 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/StopWatch.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/StopWatch.java @@ -10,16 +10,22 @@ package hu.bme.szoftlab3.mindesweeper.GUI.game; */ public class StopWatch extends Thread { - private Controller controller; - private int time; - private Boolean isStopped; + private Controller controller; + private int time; + private Boolean isStopped; + /** + * Kontroller + * @param controller + */ public StopWatch(Controller controller) { this.controller = controller; isStopped = true; } - + /** + * Futtatás + */ @Override public void run() { @@ -29,7 +35,6 @@ public class StopWatch extends Thread { try { - controller.timeLeft(); sleep(1000); } catch (InterruptedException ex) @@ -39,14 +44,23 @@ public class StopWatch extends Thread } } } + /** + * Reset + */ public void reset() { this.time = 0; } + /** + * Stop + */ public void stopTimer() { this.isStopped = true; } + /** + * Start + */ public void startTimer() { this.isStopped = false; diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/View.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/View.java index 15336bc..fdd3ce1 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/game/View.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/game/View.java @@ -9,7 +9,6 @@ package hu.bme.szoftlab3.mindesweeper.GUI.game; import hu.bme.szoftlab3.mindesweeper.GUI.window.Window; import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; @@ -26,17 +25,20 @@ import javax.swing.JPanel; */ public class View extends Window { - private Controller controller; - private Model model; - //private JFrame frame; - private JLabel timeLeftLabel; - private JLabel mineFlaggedLabel; - private JPanel buttons; - private int timeLeft; - int flagged; - JLabel scoreLabel; - + private Controller controller; + private Model model; + private JLabel timeLeftLabel; + private JLabel mineFlaggedLabel; + private JPanel buttons; + private int timeLeft; + int flagged; + JLabel scoreLabel; + /** + * + * @param game + * @param gameModel + */ public View(Controller game, Model gameModel) { this.flagged = 0; @@ -45,16 +47,26 @@ public class View extends Window this.controller = game; this.setLayout(new GridLayout(controller.game.game.settings.size,controller.game.game.settings.size)); } + /** + * Idő telt el (1mp) + */ public void timeLeft() { - // this.timeLeft++; this.timeLeftLabel.setText(Integer.toString(this.model.timeLeft)); } + /** + * Megváltozott az egyik gomb felülete + * @param i + */ public void flagChanged(int i) { this.flagged += i; this.mineFlaggedLabel.setText(Integer.toString(this.flagged)); } + /** + * Szélesség + * @return + */ private int calculateFrameWidth() { int width = controller.game.game.settings.size*46; @@ -63,10 +75,17 @@ public class View extends Window else return width; } + /** + * Magasság + * @return + */ private int calculateFrameHeight() { return (controller.game.game.settings.size+4)*26+100; } + /** + * Rajzolás + */ public void draw() { model.build(); @@ -125,15 +144,10 @@ public class View extends Window timeLeftPanel.add(timeLeftLabel); timeLeftPanel.add(this.timeLeftLabel,BorderLayout.CENTER); - - - upper.add(minesLeftPanel); upper.add(resetBTNpanel); upper.add(timeLeftPanel); - - panel.add(upper,c); JPanel buttons = new JPanel(); @@ -162,17 +176,13 @@ public class View extends Window panel.add(footer,c); - frame.add(panel); - - + this.setCenter(); } - // public void closeWindow() - // { - // this.frame.dispose(); - // } - + /** + * Változott ap ontszám + */ void scoreChanged() { this.scoreLabel.setText("Score:" + this.model.score); } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Controller.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Controller.java index b1f6128..cef256d 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Controller.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Controller.java @@ -13,7 +13,6 @@ package hu.bme.szoftlab3.mindesweeper.GUI.menu; */ public class Controller { - // private Boolean isNewGameButtonPressed = false; public View view; private Model model; @@ -25,36 +24,22 @@ public class Controller this.menu = menu; this.view = null; this.model = null; - // this.isNewGameButtonPressed = false; - } - public void registerView(View view) - { - this.view = view; - } - public void registerModel(Model model) - { - this.model = model; } + public void registerView(View view) { this.view = view; } + public void registerModel(Model model) { this.model = model;} + /** + * Uj játék gomb lenyomva + */ protected void newGameButtonPressed() { 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; - - // } - - void settingsBTNPressed() { + /** + * Beállítások gomb lenyomva + */ + void settingsBTNPressed() + { this.view.close(); this.menu.settingsButtonPressed(); } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Menu.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Menu.java index d460a43..9c5f715 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Menu.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Menu.java @@ -16,17 +16,21 @@ public class Menu { public Controller controller; public Program.Game game; - + /** + * + * @param game + */ public Menu(Program.Game game) { this.game = game; this.startGUI(); } - + /** + * Gui inditása: szükséges példányok létrehozása + */ public synchronized void startGUI() { hu.bme.szoftlab3.mindesweeper.GUI.menu.Controller menu = new hu.bme.szoftlab3.mindesweeper.GUI.menu.Controller(this); - hu.bme.szoftlab3.mindesweeper.GUI.menu.Model menuModel = new hu.bme.szoftlab3.mindesweeper.GUI.menu.Model(); hu.bme.szoftlab3.mindesweeper.GUI.menu.View menuView = new hu.bme.szoftlab3.mindesweeper.GUI.menu.View(menu,menuModel); menu.registerModel(menuModel); @@ -34,13 +38,16 @@ public class Menu this.controller = menu; } - + /** + * Modul managernek szól, hogyi inditsa a játékot + */ void startNewGameButtonPressed() { - this.game.windowManager(1); } - + /** + * Modul managernek szól, hogy indítsa el a beállításokat + */ void settingsButtonPressed() { this.game.windowManager(2); } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Model.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Model.java index d6be9a8..87ba388 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Model.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/Model.java @@ -17,11 +17,13 @@ public class Model private String settingsButtonText; private String aboutButtonText; - public String getNewGameButtonText() { return this.newGameButtonText; } - public String getSettingsButtonText() { return this.settingsButtonText; } - public String getAboutButtonText() { return this.aboutButtonText; } + public String getNewGameButtonText() { return this.newGameButtonText; } + public String getSettingsButtonText() { return this.settingsButtonText; } + public String getAboutButtonText() { return this.aboutButtonText; } - + /** + * Top játékoksok lekérése + */ public void getTopPlayers() { diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.form b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.form index bb2498f..c10b765 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.form +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.form @@ -41,9 +41,9 @@ <Group type="102" alignment="1" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="1" attributes="0"> - <Component id="jPanel2" pref="445" max="32767" attributes="0"/> + <Component id="jPanel2" pref="378" max="32767" attributes="0"/> <Component id="jSeparator1" alignment="0" max="32767" attributes="0"/> - <Component id="rightPanel" pref="445" max="32767" attributes="0"/> + <Component id="rightPanel" pref="378" max="32767" attributes="0"/> </Group> <EmptySpace max="-2" attributes="0"/> </Group> @@ -67,8 +67,8 @@ <EmptySpace min="-2" pref="93" max="-2" attributes="0"/> </Group> <Group type="102" alignment="0" attributes="0"> - <Component id="jScrollPane1" pref="0" max="32767" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> + <Component id="jScrollPane1" min="-2" pref="166" max="-2" attributes="0"/> + <EmptySpace min="0" pref="0" max="32767" attributes="0"/> </Group> </Group> </DimensionLayout> @@ -78,7 +78,7 @@ <EmptySpace min="-2" pref="34" max="-2" attributes="0"/> <Component id="jLabel3" min="-2" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/> - <Component id="jScrollPane1" min="-2" pref="375" max="-2" attributes="0"/> + <Component id="jScrollPane1" min="-2" pref="290" max="-2" attributes="0"/> <EmptySpace max="32767" attributes="0"/> </Group> </Group> diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.java index 230a07f..14a5c9c 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/menu/View.java @@ -26,25 +26,29 @@ public class View extends Window Boolean aboutButtonPresses = false; JTable topTable; + /** + * Konstruktor + * @param controller + * @param model + */ public View(Controller controller, Model model) { this.controller = controller; this.model = model; initComponents(); - //this.setSize(windowWidth,windowHeight); this.setVisible(true); - this.createWindow(); this.frame.setResizable( false ); this.getTopPlayers(); } + /** + * Top playerek listájának beállítása + */ public void getTopPlayers() { - this.topPlayerTable.setModel(this.controller.menu.game.settings); - - + this.topPlayerTable.setModel(this.controller.menu.game.settings); } @@ -100,8 +104,8 @@ public class View extends Window .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(93, 93, 93)) .addGroup(rightPanelLayout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addContainerGap()) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)) ); rightPanelLayout.setVerticalGroup( rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -109,7 +113,7 @@ public class View extends Window .addGap(34, 34, 34) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -183,7 +187,7 @@ public class View extends Window .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) - .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE) + .addComponent(rightPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 182, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( @@ -191,9 +195,9 @@ public class View extends Window .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE) .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)) + .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Controller.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Controller.java index 6b05aea..1b06548 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Controller.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Controller.java @@ -14,35 +14,58 @@ import hu.bme.szoftlab3.mindesweeper.GUI.window.Window; */ public class Controller { - public Model model; - public Window view; + public Model model; + public Window view; public Program.Settings progSettings; - public Settings settings; + public Settings settings; + /** + * + * @param settings + * @param progsettings + */ Controller(Settings settings, Program.Settings progsettings) { - this.settings = settings; - this.progSettings = progsettings; - + this.settings = settings; + this.progSettings = progsettings; } - + /** + * Model hozzáadása + * @param settingsModel + */ void setModel(Model settingsModel) { this.model = settingsModel; } - + /** + * View hozzáadása + * @param settingsView + */ void setView(Window settingsView) { this.view = settingsView; } - - void windowClosed() { + /** + * Ablak bezárása + */ + void windowClosed() + { this.settings.applyButtonPressed(); } + /** + * Beállítások elmentése + */ public void saveSettings() { this.model.saveSettingsToFile(); } + /** + * + */ + public void cancelButtonPressed() + { + this.settings.cancelButtonPressed(); + } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Model.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Model.java index bdbd059..5969659 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Model.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Model.java @@ -7,7 +7,6 @@ package hu.bme.szoftlab3.mindesweeper.GUI.settings; import Program.Player; -import java.util.ArrayList; /** * @@ -15,18 +14,17 @@ import java.util.ArrayList; */ public class Model { - private Controller controller; - private Program.Settings tempSettings; + private Controller controller; + private Program.Settings tempSettings; public Model(Controller controller) { - this.controller = controller; - this.tempSettings = new Program.Settings(this.controller.progSettings); + this.controller = controller; + this.tempSettings = new Program.Settings(this.controller.progSettings); } public String getTempSettingsPlayerName() { - //return this.tempSettings.playerName;3 return this.tempSettings.actualPlayer.name; } public int getTempSettingsBoardSize() @@ -56,41 +54,42 @@ public class Model } /** - * + * Temp beállítások mentése * * */ public void saveTempSettings() { - //this.controller.settings.game.settings = null; Program.Settings old = this.controller.settings.game.settings; - this.controller.settings.game.settings = new Program.Settings(tempSettings); - } - - void saveSettingsToFile() { + /** + * Fájlba mentés + */ + void saveSettingsToFile() + { this.controller.settings.game.settings.save(); } /** - * + * Játékos nevének beállítása * * @param text */ - void setPlayerName(String text) { - // this.tempSettings.playerName=text; - //this.tempSettings.actualPlayer.name = text; + void setPlayerName(String text) + { Player player = new Player(); player.date = this.tempSettings.actualPlayer.date; player.maxScore = this.tempSettings.actualPlayer.maxScore; player.name = text; this.tempSettings.actualPlayer = player; - - //this.tempSettings.setActualPlayer(player); } - - int getSettingsDiff() { + /** + * Nehézség lekérése + * @return + */ + int getSettingsDiff() + { return this.controller.progSettings.diff; } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Settings.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Settings.java index a40714f..c025acd 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Settings.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/Settings.java @@ -14,9 +14,9 @@ import hu.bme.szoftlab3.mindesweeper.GUI.window.Window; */ public class Settings { - public Controller controller; + public Controller controller; public Program.Game game; - public Model model; + public Model model; public Settings(Program.Game game) @@ -24,7 +24,9 @@ public class Settings this.game = game; this.startGUI(); } - + /** + * GUI indítás, példányosítás stb + */ public synchronized void startGUI() { hu.bme.szoftlab3.mindesweeper.GUI.settings.Controller settings = new hu.bme.szoftlab3.mindesweeper.GUI.settings.Controller(this,game.settings); @@ -36,16 +38,19 @@ public class Settings this.controller = settings; } - - + /** + * Mentés + */ void applyButtonPressed() { this.game.windowManager(0); - //lenyomtak az ok-t } + /** + * Mégse + */ void cancelButtonPressed() { - + this.game.windowManager(0); } diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.form b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.form index 04a270d..3b2c2ef 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.form +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.form @@ -211,6 +211,9 @@ <Properties> <Property name="text" type="java.lang.String" value="Cancel"/> </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/> + </Events> </Component> <Component class="javax.swing.JLabel" name="jLabel5"> <Properties> diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.java index ebbe0ed..0ffc13b 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/settings/SettingsViewPanel.java @@ -15,7 +15,8 @@ import javax.swing.JRadioButton; * * @author Dániel */ -public class SettingsViewPanel extends Window { +public class SettingsViewPanel extends Window +{ private Controller controller; public Model model; @@ -36,8 +37,6 @@ public class SettingsViewPanel extends Window { this.setValues(); - - ButtonGroup group = new ButtonGroup(); group.add(buttonEasy); group.add(buttonMedium); @@ -48,7 +47,9 @@ public class SettingsViewPanel extends Window { this.updateSummaryLabel(); } - + /** + * Öszsegző szöveg frissitése + */ private void updateSummaryLabel() { String diff = "hellyeah"; @@ -67,6 +68,9 @@ public class SettingsViewPanel extends Window { this.summaryText.setText("Your board's size will be: " + size + " and difficulty will be: " + diff + " with about " + mines + " mines"); } + /** + * Diff gombok beállítása + */ private void setDiffButton() { switch( this.model.getSettingsDiff()) @@ -81,6 +85,10 @@ public class SettingsViewPanel extends Window { break; } } + /** + * Diff gomb megávltozott + * @param button + */ private void difficultyButtonStateChanged(JRadioButton button) { String name = button.getName(); @@ -95,12 +103,18 @@ public class SettingsViewPanel extends Window { } } + /** + * Value-k beállításai (szövegek) + */ private void setValues() { this.playerNameText.setText(this.model.getTempSettingsPlayerName()); this.boardSize.setText(Integer.toString(this.model.getTempSettingsBoardSize())); this.boardSizeLabel.setText(this.model.getTempSettingsBoardSize() + "x" + this.model.getTempSettingsBoardSize()); } + /** + * Méret frissitése + */ private void updateBoardSizeLabel() { this.boardSizeLabel.setText(this.model.getTempSettingsBoardSize() + "x" + this.model.getTempSettingsBoardSize()); @@ -198,6 +212,11 @@ public class SettingsViewPanel extends Window { }); jButton1.setText("Cancel"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); jLabel5.setText("(Min 3 max 150)"); @@ -330,6 +349,10 @@ public class SettingsViewPanel extends Window { // TODO add your handling code here: }//GEN-LAST:event_playerNameTextActionPerformed + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // this.controller.cancelButtonPressed(); + }//GEN-LAST:event_jButton1ActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField boardSize; private javax.swing.JLabel boardSizeLabel; diff --git a/src/hu/bme/szoftlab3/mindesweeper/GUI/window/Window.java b/src/hu/bme/szoftlab3/mindesweeper/GUI/window/Window.java index fc038f5..123add8 100644 --- a/src/hu/bme/szoftlab3/mindesweeper/GUI/window/Window.java +++ b/src/hu/bme/szoftlab3/mindesweeper/GUI/window/Window.java @@ -16,32 +16,33 @@ import javax.swing.JPanel; * @author Kovax */ public class Window extends JPanel { - protected int windowHeight = 400; - protected int windowWidth = 400; - protected JFrame frame; + protected int windowHeight = 400; + protected int windowWidth = 400; + protected JFrame frame; + private String windowName = "Minesweeper"; - - private String windowName = "Minesweeper"; public Window() { } + /** + * Középre pozícionálás + */ public void setCenter() { - // Get the size of the screen Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - - // Determine the new location of the window - //int w = window.getSize().width; + int w = frame.getWidth(); int h = frame.getHeight(); int x = (dim.width-w)/2; int y = (dim.height-h)/2; - // Move the window frame.setLocation(x, y); } + /** + * Ablak léterhozása + */ protected void createWindow() { frame = new JFrame("Minesweeper"); @@ -50,10 +51,7 @@ public class Window extends JPanel { frame.setSize(windowWidth,windowHeight); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); - this.setCenter(); - - - + this.setCenter(); } /* @@ -61,13 +59,13 @@ public class Window extends JPanel { */ public int getWindowHeight() { return this.windowHeight; } public int getWindowWidth() { return this.windowWidth; } - public String getWindowName() {return this.windowName; } + public String getWindowName() { return this.windowName; } /* * setterek */ - public void setWindowHeight ( int windowHeight ) { this.windowHeight = windowHeight; } - public void setWindosWidth (int windowWidth ) { this.windowWidth = windowWidth; } - public void setWindowName ( String windowName ) { this.windowName = windowName; } + public void setWindowHeight ( int windowHeight ) { this.windowHeight = windowHeight; } + public void setWindosWidth ( int windowWidth ) { this.windowWidth = windowWidth; } + public void setWindowName ( String windowName ) { this.windowName = windowName; } public void close() { -- GitLab