diff --git a/src/game/Cell.java b/src/game/Cell.java index 05a37ecdb4fd679adac6779ef76fe2d8aa1012b5..6873529046fdc7d22517d01cada8983652915d39 100644 --- a/src/game/Cell.java +++ b/src/game/Cell.java @@ -24,8 +24,8 @@ public class Cell { public void checkNextState() { int aliveNeighbours = 0; - for (int i = 0; i < neighbours.size(); i++) - if (neighbours.get(i).isAlive()) + for (Cell neighbour : neighbours) + if (neighbour.isAlive()) aliveNeighbours++; if (alive) diff --git a/src/game/GameWindow.java b/src/game/GameWindow.java index 023288d1d33f98e64e3cd956f4868726ba535a6a..b2ebe2002a6b7aad1fc8fa72f6aa7dc321c22b17 100644 --- a/src/game/GameWindow.java +++ b/src/game/GameWindow.java @@ -25,9 +25,9 @@ public class GameWindow extends JFrame { add(table, BorderLayout.CENTER); JPanel bottomPanel = new JPanel(); - JButton startButton = new JButton("Start"); - JButton stopButton = new JButton("Stop"); - JButton saveButton = new JButton("Save"); + JButton startButton = new JButton("Indítás"); + JButton stopButton = new JButton("Megállítás"); + JButton saveButton = new JButton("Mentés"); GameWindowButtonsListener buttonListener = new GameWindowButtonsListener(model); @@ -68,7 +68,6 @@ public class GameWindow extends JFrame { menuBar.add(menu); setJMenuBar(menuBar); - setVisible(true); pack(); setResizable(false); setLocationRelativeTo(null); diff --git a/src/game/StartMenuButtonsListener.java b/src/game/StartMenuButtonsListener.java index 208ba68ac4c8454becfd204af375ca2d2fe198c9..560d01646b72798b8ea68c0636663f5fb0fc6e93 100644 --- a/src/game/StartMenuButtonsListener.java +++ b/src/game/StartMenuButtonsListener.java @@ -17,9 +17,6 @@ public class StartMenuButtonsListener implements ActionListener { case "load": model.loadFromFile(); break; - case "delete": - model.delete(); - break; case "start": model.startGame(); break; diff --git a/src/game/StartModel.java b/src/game/StartModel.java index 758f3c1877fd09d72b80f74d80ea931a582937cb..92113b2175c5cae8a4b96cd131344904270390e3 100644 --- a/src/game/StartModel.java +++ b/src/game/StartModel.java @@ -12,14 +12,15 @@ public class StartModel { private JFileChooser fileChooser; private GameModel game; private GameBoard board; + private final int defaultHeight = 15; + private final int defaultWidth = 15; public StartModel() { - startFrame = new StartWindow(this); + //startFrame = new StartWindow(this); // TODO törölheő? fileChooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("JSON File (.json)", "json"); fileChooser.setFileFilter(filter); } - //TODO frameinit? public void setStartFrame(StartWindow frame) { startFrame = frame; @@ -40,23 +41,31 @@ public class StartModel { } } - public void delete() { - board = null; - startFrame.setTextFieldMessage("No file loaded."); - } - public void startGame() { if (board == null) { - board = new GameBoard(10, 10); //TODO méret + return; } - GameModel model = new GameModel(board); //TODO clone + GameModel model = new GameModel(board); + newBoard(); GameWindow game = new GameWindow(model); - //TODO GameWindow + game.setVisible(true); } public void newBoard(int height, int width) { board = new GameBoard(height, width); startFrame.setTextFieldMessage(String.format("Üres pálya betöltve. (%d x %d)", height, width)); } + + public void newBoard(){ + newBoard(defaultHeight, defaultWidth); + } + + public int getDefaultHeight() { + return defaultHeight; + } + + public int getDefaultWidth() { + return defaultWidth; + } } diff --git a/src/game/StartNewButtonListener.java b/src/game/StartNewButtonListener.java index 90cacc92e169e9ff9750c84477fc9899edd6f816..cc5b43154d7449fe530347c219ae567e2698932a 100644 --- a/src/game/StartNewButtonListener.java +++ b/src/game/StartNewButtonListener.java @@ -8,11 +8,14 @@ public class StartNewButtonListener implements ActionListener { private JTextField heightTextField, widthTextField; private StartModel model; + private final int defaultHight, defaultWidth; public StartNewButtonListener(StartModel model, JTextField heightText, JTextField widthText) { heightTextField = heightText; widthTextField = widthText; this.model = model; + this.defaultHight = model.getDefaultHeight(); + this.defaultWidth = model.getDefaultWidth(); } public void actionPerformed(ActionEvent e) { @@ -21,22 +24,22 @@ public class StartNewButtonListener implements ActionListener { try { height = Integer.parseInt(heightTextField.getText()); - } catch (Exception exc){ - height = 10; + } catch (Exception exc) { + height = defaultHight; } try { width = Integer.parseInt(widthTextField.getText()); - } catch (Exception exc){ - width = 10; + } catch (Exception exc) { + width = defaultWidth; } - if (height<10) { - height =10; + if (height < 10) { + height = defaultHight; } - if (width<10){ - width = 10; + if (width < 10) { + width = defaultWidth; } model.newBoard(height, width); diff --git a/src/game/StartWindow.java b/src/game/StartWindow.java index 3fc7580bb6d61020041c31452c973a901357fb3e..12a278db2fdded9e75d53d873d7705a4a0e76390 100644 --- a/src/game/StartWindow.java +++ b/src/game/StartWindow.java @@ -7,13 +7,10 @@ import java.awt.event.ActionListener; public class StartWindow extends JFrame { private JTextField loadFileTextField; private StartModel model; - private final int defaultHeight = 15; - private final int defaultWidth = 15; public StartWindow(StartModel model){ - super("Game of life - Menu"); + super("Game of life - Menü"); this.model = model; - model.setStartFrame(this); setLayout(new GridLayout(0,1)); setDefaultCloseOperation(EXIT_ON_CLOSE); @@ -34,26 +31,27 @@ public class StartWindow extends JFrame { loadFileTextField = new JTextField("No file loaded."); loadFileTextField.setEditable(false); loadFileTextField.setHorizontalAlignment(SwingConstants.CENTER); + loadFileTextField.setColumns(20); JPanel middlePanel = new JPanel(new BorderLayout()); middlePanel.add(loadFileTextField); ActionListener listener = new StartMenuButtonsListener(model); - JButton loadButton = new JButton("Load"); + JButton loadButton = new JButton("Fájl betöltése"); loadButton.setActionCommand("load"); loadButton.addActionListener(listener); - JButton deleteButton = new JButton("Delete"); - deleteButton.setActionCommand("delete"); - deleteButton.addActionListener(listener); middlePanel.add(loadButton, BorderLayout.LINE_END); add(middlePanel); - JButton startButton = new JButton("Start"); + JButton startButton = new JButton("Indítás"); startButton.setActionCommand("start"); startButton.addActionListener(listener); add(startButton); pack(); setLocationRelativeTo(null); setResizable(false); + + this.model.setStartFrame(this); + this.model.newBoard(); } public void setTextFieldMessage (String message){