diff --git a/.gitignore b/.gitignore index 46cba4a7dd698d3709a826334085e3365667fbad..a5683908f0eacc552e2d6f24b5626c57b829c183 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /nbproject/private/ -/build/ \ No newline at end of file +/build/ +/dist/ \ No newline at end of file diff --git a/src/GUI/game/ButtonActionListener.java b/src/GUI/game/ButtonActionListener.java index de4bf036bb7af177490d6c1640b706288fc93562..c53e545748962a4178c5e784af945b095e7ebe9a 100644 --- a/src/GUI/game/ButtonActionListener.java +++ b/src/GUI/game/ButtonActionListener.java @@ -26,7 +26,7 @@ public class ButtonActionListener implements ActionListener { JButton button; button = (JButton) event.getSource(); - + System.out.println(button.getSize()); controller.gameMineButtonPressed(button.getName()); diff --git a/src/GUI/game/Controller.java b/src/GUI/game/Controller.java index e4b7be9d5107c519830a48b8127f622fca368de6..f881b67d50689c9211b9d33a6a33930fe536b2c3 100644 --- a/src/GUI/game/Controller.java +++ b/src/GUI/game/Controller.java @@ -61,6 +61,12 @@ public class Controller int[]pos = this.getButtonPos(button); model.calculateButtonStyle(pos); + + } + + public void reDraw() + { + this.view.draw(); } diff --git a/src/GUI/game/Model.java b/src/GUI/game/Model.java index 0d79939d283a1b720108943309ee134b964db4f5..7cc10b0bb40ac3a4266be9405a0777e248ed1792 100644 --- a/src/GUI/game/Model.java +++ b/src/GUI/game/Model.java @@ -6,6 +6,8 @@ package GUI.game; +import java.awt.List; +import java.util.ArrayList; import java.util.Random; import javax.swing.JButton; @@ -62,8 +64,46 @@ public class Model return neighbours; } + /* + * A gomb uj kinezetet szamolja ki + */ public void calculateButtonStyle(int[] pos) { + + + if( this.isMined(pos[0], pos[1])) + { + for (int i = 0; i < this.controller.settings.size; i++) + { + for (int j = 0; j < this.controller.settings.size; j++) + { + if( isMined(i, j)) + { + squares[i][j].setText("*"); + } + else + { + + } + } + } + } + else + { + int mines = this.calculateMinesAround(pos[0], pos[1]); + if( mines == 0 ) + { + ArrayList<int[]> nulls = this.getNullFieldAround(pos[0], pos[1], null,null); + for( int[] nullMiner : nulls ) + { + this.squares[nullMiner[0]][nullMiner[1]].setText("0"); + } + } + else + { + squares[pos[0]][pos[1]].setText(Integer.toString(mines)); + } + } // System.out.println("Actual:" + pos[0] + ":" + pos[1]); // for (int i = 0; i < 9; i++) { // System.out.println(i + "-" + this.getNeighbours(pos)[i]); @@ -96,6 +136,66 @@ public class Model } return false; } + private ArrayList<int[]> getNullFieldAround(int x, int y,ArrayList<int[]> nulls,ArrayList<int[]> wasThere) + { + if( wasThere == null ) + wasThere = new ArrayList<>(); + + ArrayList<int[]> nullsAround; + if( nulls != null ) + nullsAround = nulls; + else + nullsAround = new ArrayList<>(); + + int pos[] = new int[2]; + pos[0] = x; + pos[1] = y; + String[] neighbours = this.getNeighbours(pos); + + for (int i = 0; i < 9; i++) + { + int[] posN = getPosFromString(neighbours[i]); + if( posN[0] == -1 || posN[1] == -1 ) + { + int dummy = 10; + } + else if( this.calculateMinesAround(posN[0], posN[1]) == 0 ) + { + if( !this.isContains(wasThere, posN) ) + { + nullsAround.add(posN); + wasThere.add(posN); + ArrayList<int[]> newNulls = this.getNullFieldAround(posN[0], posN[1], nullsAround,wasThere); + + nullsAround.addAll(newNulls); + for( int[] actNull : newNulls ) + { + this.addUnique(nullsAround, actNull); + } + } + } + } + return nullsAround; + } + private ArrayList<int[]> addUnique(ArrayList<int[]> to, int[] add) + { + for (int[] actTo : to ) + { + if( actTo == add ) + return to; + } + to.add(add); + return to; + } + private Boolean isContains(ArrayList<int[]> container, int[] position) + { + for( int[] act : container) + { + if( act[0] == position[0] && act[1] == position[1] ) + return true; + } + return false; + } private int calculateMinesAround(int x,int y) { int pos[] = new int[2]; @@ -149,7 +249,7 @@ public class Model { //tegyunk be egyet name = Integer.toString(i) + ":" + Integer.toString(j) + ":b"; - squares[i][j].setText("*"); + squares[i][j].setText(" "); minesYet++; } else @@ -172,8 +272,10 @@ public class Model squares[i][j].setName(name + ":" + minesAround); - if( !(squares[i][j].getText() == "*") ) - squares[i][j].setText(Integer.toString(minesAround)); + // if( !(squares[i][j].getText() == "*") ) + // squares[i][j].setText(Integer.toString(minesAround)); + + // squares[i][j].setText(" "); } } } diff --git a/src/GUI/game/View.java b/src/GUI/game/View.java index fb253c9e82c08f2dc8e795f248533990a87598e0..964769243ab78260a5b857930b70927b91e12814 100644 --- a/src/GUI/game/View.java +++ b/src/GUI/game/View.java @@ -7,9 +7,14 @@ package GUI.game; import GUI.Window.Window; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; /** * @@ -20,19 +25,22 @@ public class View extends Window private Controller controller; private Model model; private JFrame frame; + private JPanel buttons; public View(Controller game, Model gameModel) { this.model = gameModel; this.controller = game; - this.setSize(400,400); + this.setSize(controller.settings.size*46,controller.settings.size*26); + //w41 h26 this.setLayout(new GridLayout(controller.settings.size,controller.settings.size)); this.draw(); } public void draw() { + model.build(); for(int i=0;i<controller.settings.size;i++) { @@ -45,12 +53,57 @@ public class View extends Window { frame.dispose(); } + //Kulso panel + JPanel panel = new JPanel(); + panel.setLayout(new GridBagLayout()); + //Frame this.frame = new JFrame("Aknakereső"); - frame.add(this); - frame.setSize(400,400); + frame.setSize(controller.settings.size*46,(controller.settings.size+4)*26); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); + GridBagConstraints c = new GridBagConstraints(); + + + JPanel upper = new JPanel(); + upper.setSize(controller.settings.size*41,100); + + + JLabel timeLeft = new JLabel(); + JLabel points = new JLabel(); + JButton stopButton = new JButton(); + + timeLeft.setText("asd"); + points.setText("points"); + stopButton.setText("buton"); + + timeLeft.setSize(1000, 100); + c.fill = GridBagConstraints.EAST; + c.gridx = 0; + c.gridy = 0; + + upper.add(timeLeft); + upper.add(stopButton); + upper.add(points); + + panel.add(upper,c); + + JPanel buttons = new JPanel(); + buttons.add(this); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 0; + c.gridy = 1; + + + + panel.add(buttons,c); + + frame.add(panel); + + + + + } diff --git a/src/GUI/window/Window.java b/src/GUI/window/Window.java index 9cf2ea0c06b2c07665cac74a70e3de18bb819468..41850c5746dd2be21c9b5647d3602430949da88b 100644 --- a/src/GUI/window/Window.java +++ b/src/GUI/window/Window.java @@ -14,8 +14,8 @@ import javax.swing.JPanel; * @author Kovax */ public class Window extends JPanel { - protected int windowHeight = 400; - protected int windowWidth = 400; + protected int windowHeight = 1000; + protected int windowWidth = 1000; protected JFrame frame; diff --git a/src/Program/Program.java b/src/Program/Program.java index a60fbe39a7d1521ed5efff2984db26ee6108a2b5..974f0e6f32614eb05beea417e191669174bf93d0 100644 --- a/src/Program/Program.java +++ b/src/Program/Program.java @@ -15,7 +15,7 @@ public class Program public static void main(String[] args) { - Settings settings = new Settings(5,"UnnamedPlayer",3); + Settings settings = new Settings(5,"UnnamedPlayer",1); Game game = new Game(settings); }