diff --git a/settings2.dat b/settings2.dat new file mode 100644 index 0000000000000000000000000000000000000000..3319410d0347cb8dfb16ee8c84c45349cfab48e3 Binary files /dev/null and b/settings2.dat differ diff --git a/src/GUI/game/Model.java b/src/GUI/game/Model.java index 4c6b1342460296b16c17e6d65f63724b70bd04fa..aacd7dd5424d9a225b08ad11f93b5602fb3c2f74 100644 --- a/src/GUI/game/Model.java +++ b/src/GUI/game/Model.java @@ -265,11 +265,11 @@ public class Model Random random = new Random(); int rand=0; - if( this.controller.settings.level == 1 ) + if( this.controller.settings.diff == 1 ) rand = 8; - else if( this.controller.settings.level == 2 ) + else if( this.controller.settings.diff == 2 ) rand = 5; - else if( this.controller.settings.level == 3) + else if( this.controller.settings.diff == 3) rand = 3; if( random.nextInt(10000)%rand == 1 ) diff --git a/src/GUI/game/ScoreCounter.java b/src/GUI/game/ScoreCounter.java index 79ce96d91d551e8feffe29297e241eadc628c569..0e1820cbeda4fb58070f994f03ea3afb12734188 100644 --- a/src/GUI/game/ScoreCounter.java +++ b/src/GUI/game/ScoreCounter.java @@ -49,19 +49,19 @@ public class ScoreCounter extends Thread int uncovered = controller.model.getUncoveredFields(); int covered = ( this.controller.settings.size * this.controller.settings.size ) - uncovered; - if( this.controller.settings.level == 0 ) + if( this.controller.settings.diff == 0 ) { //this.score += this.score*1.5; } - else if( this.controller.settings.level == 1 ) + else if( this.controller.settings.diff == 1 ) { this.score = ( covered * mines * 8 ) / (time+1) + covered; } - else if( this.controller.settings.level == 2 ) + else if( this.controller.settings.diff == 2 ) { this.score = ( mines * 10 ) / time+1 + covered; } - else if( this.controller.settings.level == 3 ) + else if( this.controller.settings.diff == 3 ) { this.score = ( mines * 15 ) / time+1 + covered; } diff --git a/src/GUI/menu/Controller.java b/src/GUI/menu/Controller.java index 3967ba0f84bc29c8d0ebc63200badddf2c6de1b9..c46680ffe7c0b03f67a626b41a3c143e5113bf90 100644 --- a/src/GUI/menu/Controller.java +++ b/src/GUI/menu/Controller.java @@ -53,6 +53,11 @@ public class Controller // return -1; // } + + void settingsBTNPressed() { + this.view.close(); + this.menu.settingsButtonPressed(); + } diff --git a/src/GUI/menu/Menu.java b/src/GUI/menu/Menu.java index 92658532963288ca10121c747cc5d48fcffc0e97..7a74d4d25c51300c4ce49403d7ebe09e62a7736a 100644 --- a/src/GUI/menu/Menu.java +++ b/src/GUI/menu/Menu.java @@ -41,5 +41,9 @@ public class Menu this.game.windowManager(1); } + void settingsButtonPressed() { + this.game.windowManager(2); + } + } diff --git a/src/GUI/menu/View.java b/src/GUI/menu/View.java index 81567f1e2d729f5362e67a9b3b97e6a9310fe9b9..f7e2b24a8f3aff0155364e6e3c2e75aea98ff9e6 100644 --- a/src/GUI/menu/View.java +++ b/src/GUI/menu/View.java @@ -171,7 +171,7 @@ public class View extends Window }//GEN-LAST:event_newGameBTNActionPerformed private void settingsBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsBTNActionPerformed - + controller.settingsBTNPressed(); }//GEN-LAST:event_settingsBTNActionPerformed private void aboutBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutBTNActionPerformed diff --git a/src/GUI/settings/Controller.java b/src/GUI/settings/Controller.java index 7059fba00370a1bb7b8dc8db37433a52a1ca059d..c053ef894658f99beaab94639ca3aedbb9ca3edf 100644 --- a/src/GUI/settings/Controller.java +++ b/src/GUI/settings/Controller.java @@ -6,10 +6,38 @@ package GUI.settings; +import GUI.Window.Window; + /** * * @author Kovax */ -public class Controller { +public class Controller +{ + public Model model; + public Window view; + public Program.Settings progSettings; + public Settings settings; + + Controller(Settings settings, Program.Settings progsettings) + { + this.settings = settings; + this.progSettings = progsettings; + } + + void setModel(Model settingsModel) + { + this.model = settingsModel; + } + + void setView(Window settingsView) + { + this.view = settingsView; + } + + void windowClosed() { + this.settings.applyButtonPressed(); + } + } diff --git a/src/GUI/settings/Model.java b/src/GUI/settings/Model.java index 6066471038a4405675a98afb85f1dbfb10998140..211b9a42fef1d94089a02546c7f2c01dad388fec 100644 --- a/src/GUI/settings/Model.java +++ b/src/GUI/settings/Model.java @@ -10,6 +10,61 @@ package GUI.settings; * * @author Kovax */ -public class Model { +public class Model +{ + private Controller controller; + private Program.Settings tempSettings; + public Model(Controller controller) + { + this.controller = controller; + this.tempSettings = new Program.Settings(this.controller.progSettings); + } + + public String getTempSettingsPlayerName() + { + return this.tempSettings.playerName; + } + public int getTempSettingsBoardSize() + { + return this.tempSettings.size; + } + public int getTempSettingsDiff() + { + return this.tempSettings.diff; + } + public int[] getTempSettingsDiffTypes() + { + return this.tempSettings.availableDiff; + } + void updateTempBoardSize(int newSize) + { + this.tempSettings.setBoardSize(newSize); + } + void updateTempDifficulty(int i) { + this.tempSettings.setDiff(i); + } + public int getTempMinesPercent(int settingsDiff) { + return this.tempSettings.availableDiff[settingsDiff]; + } + void saveTempSettings() + { + //this.controller.settings.game.settings = null; + this.controller.settings.game.settings = new Program.Settings(tempSettings); + + } + + void saveSettingsToFile() { + this.controller.settings.game.settings.save(); + } + + void setPlayerName(String text) { + this.tempSettings.playerName=text; + } + + int getSettingsDiff() { + return this.controller.progSettings.diff; + } + + } diff --git a/src/GUI/settings/Settings.java b/src/GUI/settings/Settings.java index 1a9386edbc8fd854f1276d930c3f1ae85e1a2371..f2aa33fa7ed37fbf85132d53c5999aa614340c1e 100644 --- a/src/GUI/settings/Settings.java +++ b/src/GUI/settings/Settings.java @@ -6,10 +6,47 @@ package GUI.settings; +import GUI.Window.Window; + /** * * @author Kovax */ -public class Settings { +public class Settings +{ + public Controller controller; + public Program.Game game; + public Model model; + + + public Settings(Program.Game game) + { + this.game = game; + this.startGUI(); + } + + public synchronized void startGUI() + { + GUI.settings.Controller settings = new GUI.settings.Controller(this,game.settings); + + GUI.settings.Model settingsModel = new GUI.settings.Model(settings); + Window settingsView = new GUI.settings.SettingsViewPanel(settings,settingsModel); + settings.setModel(settingsModel); + settings.setView(settingsView); + + this.controller = settings; + } + + + void applyButtonPressed() + { + this.game.windowManager(0); + //lenyomtak az ok-t + } + void cancelButtonPressed() + { + + } + } diff --git a/src/GUI/settings/SettingsViewPanel.form b/src/GUI/settings/SettingsViewPanel.form new file mode 100644 index 0000000000000000000000000000000000000000..c934f3dd5a00aaa437e882adb406f85026246826 --- /dev/null +++ b/src/GUI/settings/SettingsViewPanel.form @@ -0,0 +1,203 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> + <NonVisualComponents> + <Component class="javax.swing.ButtonGroup" name="buttonGroup2"> + </Component> + </NonVisualComponents> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + </AuxValues> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jScrollPane1" max="32767" attributes="0"/> + <Group type="102" attributes="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <Component id="boardSize" min="-2" pref="29" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="boardSizeLabel" min="-2" pref="62" max="-2" attributes="0"/> + </Group> + <Component id="playerNameText" alignment="0" min="-2" pref="128" max="-2" attributes="0"/> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="4" max="-2" attributes="0"/> + <Component id="buttonEasy" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="buttonMedium" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="2" max="-2" attributes="0"/> + <Component id="buttonHard" min="-2" max="-2" attributes="0"/> + </Group> + </Group> + </Group> + <Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace min="0" pref="109" max="32767" attributes="0"/> + </Group> + <Group type="102" alignment="1" attributes="0"> + <EmptySpace min="0" pref="0" max="32767" attributes="0"/> + <Component id="saveBTN" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="jButton1" min="-2" max="-2" attributes="0"/> + </Group> + </Group> + <EmptySpace max="-2" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Component id="jLabel1" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="37" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="playerNameText" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="boardSize" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabel4" alignment="3" min="-2" pref="23" max="-2" attributes="0"/> + <Component id="buttonEasy" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="buttonMedium" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="buttonHard" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + </Group> + <Component id="boardSizeLabel" min="-2" pref="20" max="-2" attributes="0"/> + </Group> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Component id="jScrollPane1" min="-2" pref="98" max="-2" attributes="0"/> + <EmptySpace pref="44" max="32767" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="saveBTN" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + </Layout> + <SubComponents> + <Component class="javax.swing.JLabel" name="jLabel1"> + <Properties> + <Property name="text" type="java.lang.String" value="Settings"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="playerNameText"> + <Properties> + <Property name="name" type="java.lang.String" value="playerNameText" noResource="true"/> + </Properties> + <Events> + <EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="playerNameTextFocusLost"/> + </Events> + </Component> + <Component class="javax.swing.JLabel" name="jLabel2"> + <Properties> + <Property name="text" type="java.lang.String" value="Player Name"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabel3"> + <Properties> + <Property name="text" type="java.lang.String" value="Board Size"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabel4"> + <Properties> + <Property name="text" type="java.lang.String" value="Difficulty"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="boardSize"> + <Properties> + <Property name="toolTipText" type="java.lang.String" value=""/> + <Property name="name" type="java.lang.String" value="boardSize" noResource="true"/> + </Properties> + <Events> + <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="boardSizeKeyReleased"/> + <EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="boardSizeKeyTyped"/> + </Events> + </Component> + <Component class="javax.swing.JRadioButton" name="buttonMedium"> + <Properties> + <Property name="text" type="java.lang.String" value="Medium"/> + <Property name="name" type="java.lang.String" value="buttonMedium" noResource="true"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonMediumActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JRadioButton" name="buttonEasy"> + <Properties> + <Property name="text" type="java.lang.String" value="Easy"/> + <Property name="name" type="java.lang.String" value="buttonEasy" noResource="true"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonEasyActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JRadioButton" name="buttonHard"> + <Properties> + <Property name="text" type="java.lang.String" value="Hard"/> + <Property name="name" type="java.lang.String" value="buttonHard" noResource="true"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonHardActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JLabel" name="boardSizeLabel"> + <Properties> + <Property name="toolTipText" type="java.lang.String" value=""/> + </Properties> + </Component> + <Container class="javax.swing.JScrollPane" name="jScrollPane1"> + <AuxValues> + <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> + <SubComponents> + <Component class="javax.swing.JTextPane" name="summaryText"> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JButton" name="saveBTN"> + <Properties> + <Property name="text" type="java.lang.String" value="Save"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="saveBTNActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="jButton1"> + <Properties> + <Property name="text" type="java.lang.String" value="Cancel"/> + </Properties> + </Component> + </SubComponents> +</Form> diff --git a/src/GUI/settings/SettingsViewPanel.java b/src/GUI/settings/SettingsViewPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..f9a95feae2bdab359e67d4bcc659466d62b6fb49 --- /dev/null +++ b/src/GUI/settings/SettingsViewPanel.java @@ -0,0 +1,326 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package GUI.settings; + +import GUI.Window.Window; +import java.awt.event.KeyEvent; +import javax.swing.ButtonGroup; +import javax.swing.JRadioButton; + +/** + * + * @author Dániel + */ +public class SettingsViewPanel extends Window { + + private Controller controller; + public Model model; + + /** + * Creates new form SettingsViewPanel + */ + public SettingsViewPanel(Controller controller,Model model) + { + this.controller = controller; + this.setVisible(true); + + this.model = model; + + this.createWindow(); + this.frame.setResizable( false ); + initComponents(); + + this.setValues(); + + + + ButtonGroup group = new ButtonGroup(); + group.add(buttonEasy); + group.add(buttonMedium); + group.add(buttonHard); + + this.setDiffButton(); + + this.updateSummaryLabel(); + + } + private void updateSummaryLabel() + { + String diff = "hellyeah"; + switch( this.model.getTempSettingsDiff() ) + { + case 1 : diff = "easy"; + break; + case 2 : diff = "medium"; + break; + case 3 : diff ="hard"; + break; + } + int size = this.model.getTempSettingsBoardSize(); + int mines = size*size*this.model.getTempMinesPercent(this.model.getTempSettingsDiff())/100; + this.summaryText.setEditable(false); + this.summaryText.setText("Your board's size will be: " + size + " and difficulty will be: " + diff + " with about " + mines + " mines"); + } + private void setDiffButton() + { + switch( this.model.getSettingsDiff()) + { + case 0 : this.buttonEasy.setSelected(true); + break; + case 1 : this.buttonEasy.setSelected(true); + break; + case 2 : this.buttonMedium.setSelected(true); + break; + case 3 : this.buttonHard.setSelected(true); + break; + } + } + private void difficultyButtonStateChanged(JRadioButton button) + { + String name = button.getName(); + switch( name ) + { + case "buttonEasy": this.model.updateTempDifficulty(1); + break; + case "buttonMedium":this.model.updateTempDifficulty(2); + break; + case "buttonHard": this.model.updateTempDifficulty(3); + break; + } + + } + 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()); + } + private void updateBoardSizeLabel() + { + this.boardSizeLabel.setText(this.model.getTempSettingsBoardSize() + "x" + this.model.getTempSettingsBoardSize()); + } + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + buttonGroup2 = new javax.swing.ButtonGroup(); + jLabel1 = new javax.swing.JLabel(); + playerNameText = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + boardSize = new javax.swing.JTextField(); + buttonMedium = new javax.swing.JRadioButton(); + buttonEasy = new javax.swing.JRadioButton(); + buttonHard = new javax.swing.JRadioButton(); + boardSizeLabel = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + summaryText = new javax.swing.JTextPane(); + saveBTN = new javax.swing.JButton(); + jButton1 = new javax.swing.JButton(); + + jLabel1.setText("Settings"); + + playerNameText.setName("playerNameText"); // NOI18N + playerNameText.addFocusListener(new java.awt.event.FocusAdapter() { + public void focusLost(java.awt.event.FocusEvent evt) { + playerNameTextFocusLost(evt); + } + }); + + jLabel2.setText("Player Name"); + + jLabel3.setText("Board Size"); + + jLabel4.setText("Difficulty"); + + boardSize.setToolTipText(""); + boardSize.setName("boardSize"); // NOI18N + boardSize.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyReleased(java.awt.event.KeyEvent evt) { + boardSizeKeyReleased(evt); + } + public void keyTyped(java.awt.event.KeyEvent evt) { + boardSizeKeyTyped(evt); + } + }); + + buttonMedium.setText("Medium"); + buttonMedium.setName("buttonMedium"); // NOI18N + buttonMedium.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonMediumActionPerformed(evt); + } + }); + + buttonEasy.setText("Easy"); + buttonEasy.setName("buttonEasy"); // NOI18N + buttonEasy.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonEasyActionPerformed(evt); + } + }); + + buttonHard.setText("Hard"); + buttonHard.setName("buttonHard"); // NOI18N + buttonHard.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonHardActionPerformed(evt); + } + }); + + boardSizeLabel.setToolTipText(""); + + jScrollPane1.setViewportView(summaryText); + + saveBTN.setText("Save"); + saveBTN.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + saveBTNActionPerformed(evt); + } + }); + + jButton1.setText("Cancel"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jLabel4) + .addComponent(jLabel3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(boardSize, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(boardSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(playerNameText, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addGap(4, 4, 4) + .addComponent(buttonEasy) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonMedium) + .addGap(2, 2, 2) + .addComponent(buttonHard)))) + .addComponent(jLabel1)) + .addGap(0, 109, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(saveBTN) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addGap(37, 37, 37) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(playerNameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(boardSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonEasy) + .addComponent(buttonMedium) + .addComponent(buttonHard))) + .addComponent(boardSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(saveBTN) + .addComponent(jButton1)) + .addContainerGap()) + ); + }// </editor-fold>//GEN-END:initComponents + + private void buttonEasyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEasyActionPerformed + this.difficultyButtonStateChanged((JRadioButton) evt.getSource()); + this.updateSummaryLabel(); + }//GEN-LAST:event_buttonEasyActionPerformed + + private void boardSizeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_boardSizeKeyReleased + char c = evt.getKeyChar(); + if( c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE) + { + return; + } + this.updateSummaryLabel(); + this.model.updateTempBoardSize(Integer.parseInt(this.boardSize.getText())); + this.updateBoardSizeLabel(); + }//GEN-LAST:event_boardSizeKeyReleased + + private void boardSizeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_boardSizeKeyTyped + char c = evt.getKeyChar(); + if( !(('A' - c) >= 8 && ('A' - c) <= 17 ) || ( c == KeyEvent.VK_BACK_SPACE || (c == KeyEvent.VK_DELETE))) + { + getToolkit().beep(); + evt.consume(); + } + }//GEN-LAST:event_boardSizeKeyTyped + + private void buttonMediumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMediumActionPerformed + this.difficultyButtonStateChanged((JRadioButton) evt.getSource()); + this.updateSummaryLabel(); + }//GEN-LAST:event_buttonMediumActionPerformed + + private void buttonHardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonHardActionPerformed + this.difficultyButtonStateChanged((JRadioButton) evt.getSource()); + this.updateSummaryLabel(); + }//GEN-LAST:event_buttonHardActionPerformed + + private void saveBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBTNActionPerformed + + this.model.saveTempSettings(); + this.close(); + this.controller.windowClosed(); + this.model.saveSettingsToFile(); + }//GEN-LAST:event_saveBTNActionPerformed + + private void playerNameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_playerNameTextFocusLost + this.model.setPlayerName(this.playerNameText.getText()); + }//GEN-LAST:event_playerNameTextFocusLost + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTextField boardSize; + private javax.swing.JLabel boardSizeLabel; + private javax.swing.JRadioButton buttonEasy; + private javax.swing.ButtonGroup buttonGroup2; + private javax.swing.JRadioButton buttonHard; + private javax.swing.JRadioButton buttonMedium; + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextField playerNameText; + private javax.swing.JButton saveBTN; + private javax.swing.JTextPane summaryText; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/settings/View.java b/src/GUI/settings/View.java index d0337841608568ad39a52fde58322b6d8937d0b0..cdba9311b80f5a54dadad5abd8955b79ae46f1f8 100644 --- a/src/GUI/settings/View.java +++ b/src/GUI/settings/View.java @@ -6,10 +6,16 @@ package GUI.settings; +import GUI.Window.Window; + /** * * @author Kovax */ -public class View { +public class View extends Window { + + View(Controller settings, Model settingsModel) { + + } } diff --git a/src/Program/Game.java b/src/Program/Game.java index eee85253c9d2ab269a30ee5894daf59f28bb7739..d5f11f3fc933bb56df4016d10b1f18af57848af3 100644 --- a/src/Program/Game.java +++ b/src/Program/Game.java @@ -16,7 +16,8 @@ public class Game { Menu menu; GUI.game.Game game; - Settings settings; + public Settings settings; + GUI.settings.Settings settingsWindow; private int window; @@ -38,6 +39,8 @@ public class Game break; case 1: this.gameWindow(); break; + case 2: this.settingsWindow(); + break; } } @@ -100,5 +103,10 @@ public class Game } * */ } + + private void settingsWindow() { + GUI.settings.Settings settings = new GUI.settings.Settings(this); + this.settingsWindow = settings; + } } \ No newline at end of file diff --git a/src/Program/Program.java b/src/Program/Program.java index e0da45ec9d285106bd1ffd7b1c704476c66b9739..286cbd80a5aba35aebd4dffca95ac1a57a911082 100644 --- a/src/Program/Program.java +++ b/src/Program/Program.java @@ -14,9 +14,15 @@ public class Program { public static void main(String[] args) { - Settings settings = new Settings(4,"UnnamedPlayer",1,600,600); + Game game = new Game(settings); + + settings.setGame(game); + settings.load(); + + + } diff --git a/src/Program/Settings.java b/src/Program/Settings.java index 0881670c2212c7f384bf72a2bb3bdf0f62a3c939..64068e02433f70422429d6b32763bd3dfe396a83 100644 --- a/src/Program/Settings.java +++ b/src/Program/Settings.java @@ -4,25 +4,109 @@ */ package Program; +import java.io.BufferedOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; + /** * * @author Dániel */ -public class Settings +public class Settings implements Serializable { public int size; public String playerName; - public int level; + public int diff; public int windowWidth; public int windowHeight; + public int[] availableDiff; + public transient Game game; + public String saveFileName; - public Settings(int size,String playerName, int level,int windowWidth, int windowHeight) + + 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"; + } + 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.level = level; + 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] =40; + this.availableDiff[3] =60; + this.saveFileName = "settings2.dat"; + } + + + 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(); + + + } + catch(IOException i) + { + return; + } + catch(ClassNotFoundException c) + { + return; + } + this.game.settings = e; } }