Skip to content
Snippets Groups Projects
Commit 7335bcbf authored by steyer's avatar steyer
Browse files

Magyar

parent c48e5df0
No related branches found
No related tags found
No related merge requests found
...@@ -24,8 +24,8 @@ public class Cell { ...@@ -24,8 +24,8 @@ public class Cell {
public void checkNextState() { public void checkNextState() {
int aliveNeighbours = 0; int aliveNeighbours = 0;
for (int i = 0; i < neighbours.size(); i++) for (Cell neighbour : neighbours)
if (neighbours.get(i).isAlive()) if (neighbour.isAlive())
aliveNeighbours++; aliveNeighbours++;
if (alive) if (alive)
......
...@@ -25,9 +25,9 @@ public class GameWindow extends JFrame { ...@@ -25,9 +25,9 @@ public class GameWindow extends JFrame {
add(table, BorderLayout.CENTER); add(table, BorderLayout.CENTER);
JPanel bottomPanel = new JPanel(); JPanel bottomPanel = new JPanel();
JButton startButton = new JButton("Start"); JButton startButton = new JButton("Indítás");
JButton stopButton = new JButton("Stop"); JButton stopButton = new JButton("Megállítás");
JButton saveButton = new JButton("Save"); JButton saveButton = new JButton("Mentés");
GameWindowButtonsListener buttonListener = new GameWindowButtonsListener(model); GameWindowButtonsListener buttonListener = new GameWindowButtonsListener(model);
...@@ -68,7 +68,6 @@ public class GameWindow extends JFrame { ...@@ -68,7 +68,6 @@ public class GameWindow extends JFrame {
menuBar.add(menu); menuBar.add(menu);
setJMenuBar(menuBar); setJMenuBar(menuBar);
setVisible(true);
pack(); pack();
setResizable(false); setResizable(false);
setLocationRelativeTo(null); setLocationRelativeTo(null);
......
...@@ -17,9 +17,6 @@ public class StartMenuButtonsListener implements ActionListener { ...@@ -17,9 +17,6 @@ public class StartMenuButtonsListener implements ActionListener {
case "load": case "load":
model.loadFromFile(); model.loadFromFile();
break; break;
case "delete":
model.delete();
break;
case "start": case "start":
model.startGame(); model.startGame();
break; break;
......
...@@ -12,14 +12,15 @@ public class StartModel { ...@@ -12,14 +12,15 @@ public class StartModel {
private JFileChooser fileChooser; private JFileChooser fileChooser;
private GameModel game; private GameModel game;
private GameBoard board; private GameBoard board;
private final int defaultHeight = 15;
private final int defaultWidth = 15;
public StartModel() { public StartModel() {
startFrame = new StartWindow(this); //startFrame = new StartWindow(this); // TODO törölheő?
fileChooser = new JFileChooser(); fileChooser = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("JSON File (.json)", "json"); FileFilter filter = new FileNameExtensionFilter("JSON File (.json)", "json");
fileChooser.setFileFilter(filter); fileChooser.setFileFilter(filter);
} }
//TODO frameinit?
public void setStartFrame(StartWindow frame) { public void setStartFrame(StartWindow frame) {
startFrame = frame; startFrame = frame;
...@@ -40,23 +41,31 @@ public class StartModel { ...@@ -40,23 +41,31 @@ public class StartModel {
} }
} }
public void delete() {
board = null;
startFrame.setTextFieldMessage("No file loaded.");
}
public void startGame() { public void startGame() {
if (board == null) { 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); GameWindow game = new GameWindow(model);
//TODO GameWindow game.setVisible(true);
} }
public void newBoard(int height, int width) { public void newBoard(int height, int width) {
board = new GameBoard(height, width); board = new GameBoard(height, width);
startFrame.setTextFieldMessage(String.format("Üres pálya betöltve. (%d x %d)", 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;
}
} }
...@@ -8,11 +8,14 @@ public class StartNewButtonListener implements ActionListener { ...@@ -8,11 +8,14 @@ public class StartNewButtonListener implements ActionListener {
private JTextField heightTextField, widthTextField; private JTextField heightTextField, widthTextField;
private StartModel model; private StartModel model;
private final int defaultHight, defaultWidth;
public StartNewButtonListener(StartModel model, JTextField heightText, JTextField widthText) { public StartNewButtonListener(StartModel model, JTextField heightText, JTextField widthText) {
heightTextField = heightText; heightTextField = heightText;
widthTextField = widthText; widthTextField = widthText;
this.model = model; this.model = model;
this.defaultHight = model.getDefaultHeight();
this.defaultWidth = model.getDefaultWidth();
} }
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
...@@ -22,21 +25,21 @@ public class StartNewButtonListener implements ActionListener { ...@@ -22,21 +25,21 @@ public class StartNewButtonListener implements ActionListener {
try { try {
height = Integer.parseInt(heightTextField.getText()); height = Integer.parseInt(heightTextField.getText());
} catch (Exception exc) { } catch (Exception exc) {
height = 10; height = defaultHight;
} }
try { try {
width = Integer.parseInt(widthTextField.getText()); width = Integer.parseInt(widthTextField.getText());
} catch (Exception exc) { } catch (Exception exc) {
width = 10; width = defaultWidth;
} }
if (height < 10) { if (height < 10) {
height =10; height = defaultHight;
} }
if (width < 10) { if (width < 10) {
width = 10; width = defaultWidth;
} }
model.newBoard(height, width); model.newBoard(height, width);
......
...@@ -7,13 +7,10 @@ import java.awt.event.ActionListener; ...@@ -7,13 +7,10 @@ import java.awt.event.ActionListener;
public class StartWindow extends JFrame { public class StartWindow extends JFrame {
private JTextField loadFileTextField; private JTextField loadFileTextField;
private StartModel model; private StartModel model;
private final int defaultHeight = 15;
private final int defaultWidth = 15;
public StartWindow(StartModel model){ public StartWindow(StartModel model){
super("Game of life - Menu"); super("Game of life - Menü");
this.model = model; this.model = model;
model.setStartFrame(this);
setLayout(new GridLayout(0,1)); setLayout(new GridLayout(0,1));
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
...@@ -34,26 +31,27 @@ public class StartWindow extends JFrame { ...@@ -34,26 +31,27 @@ public class StartWindow extends JFrame {
loadFileTextField = new JTextField("No file loaded."); loadFileTextField = new JTextField("No file loaded.");
loadFileTextField.setEditable(false); loadFileTextField.setEditable(false);
loadFileTextField.setHorizontalAlignment(SwingConstants.CENTER); loadFileTextField.setHorizontalAlignment(SwingConstants.CENTER);
loadFileTextField.setColumns(20);
JPanel middlePanel = new JPanel(new BorderLayout()); JPanel middlePanel = new JPanel(new BorderLayout());
middlePanel.add(loadFileTextField); middlePanel.add(loadFileTextField);
ActionListener listener = new StartMenuButtonsListener(model); ActionListener listener = new StartMenuButtonsListener(model);
JButton loadButton = new JButton("Load"); JButton loadButton = new JButton("Fájl betöltése");
loadButton.setActionCommand("load"); loadButton.setActionCommand("load");
loadButton.addActionListener(listener); loadButton.addActionListener(listener);
JButton deleteButton = new JButton("Delete");
deleteButton.setActionCommand("delete");
deleteButton.addActionListener(listener);
middlePanel.add(loadButton, BorderLayout.LINE_END); middlePanel.add(loadButton, BorderLayout.LINE_END);
add(middlePanel); add(middlePanel);
JButton startButton = new JButton("Start"); JButton startButton = new JButton("Indítás");
startButton.setActionCommand("start"); startButton.setActionCommand("start");
startButton.addActionListener(listener); startButton.addActionListener(listener);
add(startButton); add(startButton);
pack(); pack();
setLocationRelativeTo(null); setLocationRelativeTo(null);
setResizable(false); setResizable(false);
this.model.setStartFrame(this);
this.model.newBoard();
} }
public void setTextFieldMessage (String message){ public void setTextFieldMessage (String message){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment