From 2dc4d2af23056cda20209161240994ac55e4db87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel?= <Dániel@kovax-pc> Date: Wed, 27 Nov 2013 15:54:46 +0100 Subject: [PATCH] =?UTF-8?q?Hiba:=20Aktu=C3=A1lis=20j=C3=A1t=C3=A9kossal=20?= =?UTF-8?q?fel=C3=BCl=C3=A9irja=20a=20j=C3=A1t=C3=A9kosok=20list=C3=A1j?= =?UTF-8?q?=C3=A1t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- settings2.dat | Bin 232 -> 411 bytes src/GUI/game/Controller.java | 9 ++- src/GUI/game/Game.java | 11 +-- src/GUI/game/Model.java | 90 ++++++++++++++++++------ src/GUI/game/ScoreCounter.java | 14 ++-- src/GUI/game/StopWatch.java | 2 +- src/GUI/game/View.java | 10 +-- src/GUI/menu/Model.java | 5 ++ src/GUI/settings/Controller.java | 4 ++ src/GUI/settings/Model.java | 18 +++-- src/GUI/settings/SettingsViewPanel.form | 40 ++++++++--- src/GUI/settings/SettingsViewPanel.java | 44 +++++++++--- src/Program/Game.java | 1 + src/Program/Player.java | 31 ++++++++ src/Program/Settings.java | 30 ++++---- 15 files changed, 228 insertions(+), 81 deletions(-) create mode 100644 src/Program/Player.java diff --git a/settings2.dat b/settings2.dat index 3319410d0347cb8dfb16ee8c84c45349cfab48e3..131979d294d0adc57b10ac0fb8627e0b547e2ad2 100644 GIT binary patch delta 285 zcmaFCIGcHb1oxQ(LFwGnr*bkea7<LzR`OxsNlY#&P0R_%NvupQDq#@t2`I`>FG|eS zhlp5D^b^-+F96FHmoSL>WF?j*>X(*e=IA>X6(v^sWEPiL`!MhnCzhqUW#*(#%#n<% zC}3b<U}RumU}0cjiU8r_A_hLFxq1+D%@gOCtx>Bz&BVa$$-t75Sd!|=z>%9+5uBV~ zl<LF4l9!m9TF6kxz*12VH1)>^1_p+@5(bv^jI8vDtCa%e7#J8dii;S8L9WpQxkeA} ynu^9tvNMk-&Shp`^kiTu&a6s>xTl;2<SLMv>=h*pyv3;{C7F5Y#YTE5i6sEGfLBKV delta 127 zcmbQu{DN_U1b1YBfVBbljx$UQ>=Tu>Cl-jiaTVkwR;CvDCFZ7<FbMf%C6*=X=OpH( z>j#$<W#*+@`!MhnCzhqUW#*)U)D$w*F)&pWFfcGMGB7YMU|?X10O84+j7riP3=9l5 aB@E1o#VI8Wyv3;{C7F5Y#YTE5i6sC^D<eSw diff --git a/src/GUI/game/Controller.java b/src/GUI/game/Controller.java index 9bb7627..406e9d0 100644 --- a/src/GUI/game/Controller.java +++ b/src/GUI/game/Controller.java @@ -18,7 +18,7 @@ public class Controller { public View view; public Model model; - public Settings settings; + // public Settings settings; public Game game; //Mutatók külső threadekre @@ -28,9 +28,10 @@ public class Controller //ha igaz, a játék leáll private Boolean isStopButtonPressed; - public Controller(Settings settings) + public Controller(Game game) { - this.settings = settings; + // this.settings = settings; + this.game = game; this.isStopButtonPressed = false; } @@ -91,6 +92,8 @@ public class Controller this.model.isGameOver = true; + + EndOfGamePopUp popup; popup = new EndOfGamePopUp(this); diff --git a/src/GUI/game/Game.java b/src/GUI/game/Game.java index 56999af..51d2d56 100644 --- a/src/GUI/game/Game.java +++ b/src/GUI/game/Game.java @@ -18,21 +18,23 @@ import Program.Settings; public class Game { public Controller controller; - public Settings settings; + // public Settings settings; public Program.Game game; public Game(Program.Settings settings, Program.Game game) { - this.settings = settings; - this.startGUI(null,null,null); + // this.settings = settings; this.game = game; + this.startGUI(null,null,null); + } public synchronized void startGUI(Controller controller, Model model, View view) { Controller game = controller; + if( game == null ) - game = new Controller(this.settings); + game = new Controller(this); Model gameModel = model ; if( gameModel == null ) @@ -42,6 +44,7 @@ public class Game if( gameView == null ) gameView = new View(game,gameModel); + game.setModel(gameModel); game.setView(gameView); game.setGame(this); diff --git a/src/GUI/game/Model.java b/src/GUI/game/Model.java index aacd7dd..b8cf67c 100644 --- a/src/GUI/game/Model.java +++ b/src/GUI/game/Model.java @@ -6,6 +6,7 @@ package GUI.game; +import Program.Player; import java.awt.Color; import java.util.ArrayList; import java.util.Random; @@ -34,7 +35,8 @@ public class Model { this.timeLeft = 0; this.controller = controller; - squares = new JButton[controller.settings.size][controller.settings.size]; + // squares = new JButton[controller.settings.size][controller.settings.size]; + // int mines = 0; isGameOver = false; isWinner = false; @@ -45,6 +47,7 @@ public class Model * 345 * 678 */ + public int getTimeLeft(){ return this.timeLeft; } public int getMines() { return this.mines; } public int getScore() { return this.score; } @@ -52,9 +55,9 @@ public class Model public int getUncoveredFields() { int uncovered = 0; - for (int i = 0; i < this.controller.settings.size; i++) + for (int i = 0; i < controller.game.game.settings.size; i++) { - for (int j = 0; j < this.controller.settings.size; j++) + for (int j = 0; j < controller.game.game.settings.size; j++) { if((this.squares[i][j].getText().length() == 0) || this.squares[i][j].getText().equals(" ") || this.squares[i][j].getText().equals("?") ) { @@ -82,13 +85,13 @@ public class Model neighbours[7] = (Integer.toString(actX) + ":" + Integer.toString(actY-1)); neighbours[8] = (Integer.toString(actX+1) + ":" + Integer.toString(actY-1)); - if( (actX + 1) >= this.controller.settings.size) + if( (actX + 1) >= controller.game.game.settings.size) { neighbours[2] = "-1:-1"; neighbours[5] = "-1:-1"; neighbours[8] = "-1:-1"; } - if( (actY+1) >= this.controller.settings.size ) + if( (actY+1) >= controller.game.game.settings.size ) { neighbours[0] = "-1:-1"; neighbours[1] = "-1:-1"; @@ -102,9 +105,9 @@ public class Model private Boolean isGameOverAndWinner() { Boolean isWinner = true ; - for (int i = 0; i < this.controller.settings.size; i++) + for (int i = 0; i < controller.game.game.settings.size; i++) { - for (int j = 0; j < this.controller.settings.size; j++) + for (int j = 0; j < controller.game.game.settings.size; j++) { if( this.isMined(i, j) ) { @@ -117,8 +120,41 @@ public class Model } } } + if( isWinner ) + { + if( controller.game.game.settings.actualPlayer.maxScore < this.score ) + controller.game.game.settings.actualPlayer.maxScore = this.score; + this.addPlayerToList(); + } return isWinner; } + public void addPlayerToList() + { + if( controller.game.game.settings.players.contains(controller.game.game.settings.actualPlayer)) + { + for( Player player : controller.game.game.settings.players ) + { + if( player.name.equals(controller.game.game.settings.actualPlayer.name) ) + { + if( player.maxScore < controller.game.game.settings.actualPlayer.maxScore ) + { + 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); + } + + } + } + } + else + { + //ha meg nincs benne + controller.game.game.settings.actualPlayer.maxScore = this.score; + controller.game.game.settings.players.add(controller.game.game.settings.actualPlayer); + } + + controller.game.game.settings.save(); + } public Boolean isFlagged(int x, int y) { if( this.squares[x][y].getText().equals("?") ) @@ -127,9 +163,9 @@ public class Model } public void showAllMines(Color color) { - for (int i = 0; i < this.controller.settings.size; i++) + for (int i = 0; i < controller.game.game.settings.size; i++) { - for (int j = 0; j < this.controller.settings.size; j++) + for (int j = 0; j < controller.game.game.settings.size; j++) { JButton actField = this.squares[i][j]; if( this.isMined(i, j) ) @@ -148,13 +184,13 @@ public class Model if( isGameOver ) return; - System.out.println(pos[0] + ":" + pos[1]); + //EndOfGamePopUp popup; if( this.isMined(pos[0], pos[1])) { - for (int i = 0; i < this.controller.settings.size; i++) + for (int i = 0; i < controller.game.game.settings.size; i++) { - for (int j = 0; j < this.controller.settings.size; j++) + for (int j = 0; j < controller.game.game.settings.size; j++) { if( isMined(i, j)) { @@ -229,7 +265,7 @@ public class Model } private boolean isMined(int x, int y) { - if( x < 0 || y < 0 || x > this.controller.settings.size || y > this.controller.settings.size ) + if( x < 0 || y < 0 || x > controller.game.game.settings.size || y > controller.game.game.settings.size ) { return false; } @@ -264,16 +300,19 @@ public class Model { Random random = new Random(); - int rand=0; - if( this.controller.settings.diff == 1 ) - rand = 8; - else if( this.controller.settings.diff == 2 ) + float rand=0; + if( controller.game.game.settings.diff == 1 ) rand = 5; - else if( this.controller.settings.diff == 3) + else if( controller.game.game.settings.diff == 2 ) rand = 3; + else if( controller.game.game.settings.diff == 3) + rand = 2; - if( random.nextInt(10000)%rand == 1 ) + // System.out.println(rand); + //int fos = random.nextInt(100); + if( random.nextInt(100)%rand == 1 ) { + this.mines++; return true; } @@ -282,9 +321,13 @@ public class Model public void build() { int minesYet = 0; - for(int i=0;i<controller.settings.size;i++) + + if( this.squares == null ) + squares = new JButton[controller.game.game.settings.size][controller.game.game.settings.size]; + + for(int i=0;i<controller.game.game.settings.size;i++) { - for(int j=0;j<controller.settings.size;j++) + for(int j=0;j<controller.game.game.settings.size;j++) { squares[i][j] = new JButton(); squares[i][j].setSize(400,400); @@ -306,9 +349,9 @@ public class Model squares[i][j].addMouseListener(new ButtonActionListener(controller)); } } - for(int i=0;i<controller.settings.size;i++) + for(int i=0;i<controller.game.game.settings.size;i++) { - for(int j=0;j<controller.settings.size;j++) + for(int j=0;j<controller.game.game.settings.size;j++) { int minesAround = 0; minesAround = this.calculateMinesAround(i,j); @@ -317,6 +360,7 @@ public class Model } } this.controller.view.flagged = this.mines; + System.out.println(this.mines); } public void colorField(int x,int y, Color color, Color colorF) { diff --git a/src/GUI/game/ScoreCounter.java b/src/GUI/game/ScoreCounter.java index 0e1820c..b2c947e 100644 --- a/src/GUI/game/ScoreCounter.java +++ b/src/GUI/game/ScoreCounter.java @@ -46,22 +46,24 @@ public class ScoreCounter extends Thread int time = controller.model.getTimeLeft(); int mines = controller.model.getMines(); + if( time <= 0 ) + time = 1; int uncovered = controller.model.getUncoveredFields(); - int covered = ( this.controller.settings.size * this.controller.settings.size ) - uncovered; + int covered = ( controller.game.game.settings.size * controller.game.game.settings.size ) - uncovered; - if( this.controller.settings.diff == 0 ) + if( controller.game.game.settings.diff == 0 ) { //this.score += this.score*1.5; } - else if( this.controller.settings.diff == 1 ) + else if( controller.game.game.settings.diff == 1 ) { this.score = ( covered * mines * 8 ) / (time+1) + covered; } - else if( this.controller.settings.diff == 2 ) + else if( controller.game.game.settings.diff == 2 ) { this.score = ( mines * 10 ) / time+1 + covered; } - else if( this.controller.settings.diff == 3 ) + else if( controller.game.game.settings.diff == 3 ) { this.score = ( mines * 15 ) / time+1 + covered; } @@ -71,7 +73,7 @@ public class ScoreCounter extends Thread sleep(1000); } catch (InterruptedException ex) { - System.out.println("int error"); + } } } diff --git a/src/GUI/game/StopWatch.java b/src/GUI/game/StopWatch.java index 1e54f67..61e6b7e 100644 --- a/src/GUI/game/StopWatch.java +++ b/src/GUI/game/StopWatch.java @@ -34,7 +34,7 @@ public class StopWatch extends Thread sleep(1000); } catch (InterruptedException ex) { - System.out.println("int error"); + } } } diff --git a/src/GUI/game/View.java b/src/GUI/game/View.java index 5fe8e26..790432e 100644 --- a/src/GUI/game/View.java +++ b/src/GUI/game/View.java @@ -42,7 +42,7 @@ public class View extends Window this.timeLeft = 0; this.model = gameModel; this.controller = game; - this.setLayout(new GridLayout(controller.settings.size,controller.settings.size)); + this.setLayout(new GridLayout(controller.game.game.settings.size,controller.game.game.settings.size)); } public void timeLeft() { @@ -56,7 +56,7 @@ public class View extends Window } private int calculateFrameWidth() { - int width = controller.settings.size*46; + int width = controller.game.game.settings.size*46; if( width < 350 ) return 350; else @@ -64,12 +64,12 @@ public class View extends Window } private int calculateFrameHeight() { - return (controller.settings.size+4)*26+100; + return (controller.game.game.settings.size+4)*26+100; } public void draw() { model.build(); - for(int i=0;i<controller.settings.size;i++) + for(int i=0;i<controller.game.game.settings.size;i++) { for(JButton actButton : model.squares[i]) { @@ -93,7 +93,7 @@ public class View extends Window JPanel upper = new JPanel(new FlowLayout()); - upper.setSize(controller.settings.size*41,100); + upper.setSize(controller.game.game.settings.size*41,100); this.timeLeftLabel = new JLabel(); this.mineFlaggedLabel = new JLabel(); diff --git a/src/GUI/menu/Model.java b/src/GUI/menu/Model.java index 5c94bd6..251e138 100644 --- a/src/GUI/menu/Model.java +++ b/src/GUI/menu/Model.java @@ -22,4 +22,9 @@ public class Model public String getAboutButtonText() { return this.aboutButtonText; } + public void getTopPlayers() + { + + } } + diff --git a/src/GUI/settings/Controller.java b/src/GUI/settings/Controller.java index c053ef8..b395f24 100644 --- a/src/GUI/settings/Controller.java +++ b/src/GUI/settings/Controller.java @@ -38,6 +38,10 @@ public class Controller void windowClosed() { this.settings.applyButtonPressed(); } + public void saveSettings() + { + this.model.saveSettingsToFile(); + } } diff --git a/src/GUI/settings/Model.java b/src/GUI/settings/Model.java index 211b9a4..a47e26c 100644 --- a/src/GUI/settings/Model.java +++ b/src/GUI/settings/Model.java @@ -6,6 +6,8 @@ package GUI.settings; +import Program.Player; + /** * * @author Kovax @@ -23,7 +25,8 @@ public class Model public String getTempSettingsPlayerName() { - return this.tempSettings.playerName; + //return this.tempSettings.playerName;3 + return this.tempSettings.actualPlayer.name; } public int getTempSettingsBoardSize() { @@ -47,9 +50,15 @@ public class Model public int getTempMinesPercent(int settingsDiff) { return this.tempSettings.availableDiff[settingsDiff]; } - void saveTempSettings() + public void saveSettings() + { + + } + 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); } @@ -59,12 +68,13 @@ public class Model } void setPlayerName(String text) { - this.tempSettings.playerName=text; + // this.tempSettings.playerName=text; + this.tempSettings.actualPlayer.name = text; } int getSettingsDiff() { return this.controller.progSettings.diff; } - + } diff --git a/src/GUI/settings/SettingsViewPanel.form b/src/GUI/settings/SettingsViewPanel.form index c934f3d..04a270d 100644 --- a/src/GUI/settings/SettingsViewPanel.form +++ b/src/GUI/settings/SettingsViewPanel.form @@ -34,12 +34,6 @@ </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"/> @@ -48,11 +42,21 @@ <EmptySpace min="-2" pref="2" max="-2" attributes="0"/> <Component id="buttonHard" min="-2" max="-2" attributes="0"/> </Group> + <Group type="103" alignment="0" groupAlignment="1" max="-2" 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"/> + <EmptySpace max="32767" attributes="0"/> + <Component id="jLabel5" min="-2" max="-2" attributes="0"/> + </Group> + <Component id="playerNameText" alignment="0" min="-2" pref="128" 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"/> + <EmptySpace min="0" pref="96" max="32767" attributes="0"/> </Group> <Group type="102" alignment="1" attributes="0"> <EmptySpace min="0" pref="0" max="32767" attributes="0"/> @@ -78,11 +82,19 @@ <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 type="103" groupAlignment="0" max="-2" 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" max="32767" attributes="0"/> + </Group> + <EmptySpace type="separate" max="-2" attributes="0"/> + </Group> + <Group type="102" attributes="0"> + <Component id="jLabel5" max="32767" attributes="0"/> + <EmptySpace min="-2" pref="18" max="-2" attributes="0"/> + </Group> </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"/> @@ -115,6 +127,7 @@ <Property name="name" type="java.lang.String" value="playerNameText" noResource="true"/> </Properties> <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="playerNameTextActionPerformed"/> <EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="playerNameTextFocusLost"/> </Events> </Component> @@ -199,5 +212,10 @@ <Property name="text" type="java.lang.String" value="Cancel"/> </Properties> </Component> + <Component class="javax.swing.JLabel" name="jLabel5"> + <Properties> + <Property name="text" type="java.lang.String" value="(Min 3 max 150)"/> + </Properties> + </Component> </SubComponents> </Form> diff --git a/src/GUI/settings/SettingsViewPanel.java b/src/GUI/settings/SettingsViewPanel.java index f9a95fe..e88cf0f 100644 --- a/src/GUI/settings/SettingsViewPanel.java +++ b/src/GUI/settings/SettingsViewPanel.java @@ -62,6 +62,7 @@ public class SettingsViewPanel extends Window { 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() { @@ -125,10 +126,16 @@ public class SettingsViewPanel extends Window { summaryText = new javax.swing.JTextPane(); saveBTN = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); + jLabel5 = new javax.swing.JLabel(); jLabel1.setText("Settings"); playerNameText.setName("playerNameText"); // NOI18N + playerNameText.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + playerNameTextActionPerformed(evt); + } + }); playerNameText.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { playerNameTextFocusLost(evt); @@ -189,6 +196,8 @@ public class SettingsViewPanel extends Window { jButton1.setText("Cancel"); + jLabel5.setText("(Min 3 max 150)"); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -206,20 +215,23 @@ public class SettingsViewPanel extends Window { .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(buttonHard)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .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) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel5)) + .addComponent(playerNameText, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(jLabel1)) - .addGap(0, 109, Short.MAX_VALUE)) + .addGap(0, 96, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(saveBTN) @@ -239,10 +251,15 @@ public class SettingsViewPanel extends Window { .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.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(boardSize)) + .addGap(18, 18, 18)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .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) @@ -306,6 +323,10 @@ public class SettingsViewPanel extends Window { this.model.setPlayerName(this.playerNameText.getText()); }//GEN-LAST:event_playerNameTextFocusLost + private void playerNameTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playerNameTextActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_playerNameTextActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField boardSize; private javax.swing.JLabel boardSizeLabel; @@ -318,6 +339,7 @@ public class SettingsViewPanel extends Window { private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField playerNameText; private javax.swing.JButton saveBTN; diff --git a/src/Program/Game.java b/src/Program/Game.java index d5f11f3..22efdc7 100644 --- a/src/Program/Game.java +++ b/src/Program/Game.java @@ -47,6 +47,7 @@ public class Game public void gameWindow() { this.game = new GUI.game.Game(this.settings,this); + // this.game = new GUI.game.Game(this.settings, this); } /* while( true ) diff --git a/src/Program/Player.java b/src/Program/Player.java new file mode 100644 index 0000000..96f1458 --- /dev/null +++ b/src/Program/Player.java @@ -0,0 +1,31 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Program; + +import java.io.Serializable; + +/** + * + * @author Dániel + */ +public class Player implements Serializable +{ + 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; + } +} diff --git a/src/Program/Settings.java b/src/Program/Settings.java index 64068e0..5b7745a 100644 --- a/src/Program/Settings.java +++ b/src/Program/Settings.java @@ -4,16 +4,13 @@ */ 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; +import java.util.ArrayList; /** * @@ -21,26 +18,30 @@ import java.io.Serializable; */ public class Settings implements Serializable { + public Player actualPlayer; public int size; - public String playerName; + //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 Settings(Settings progSettings) { this.size = progSettings.size; - this.playerName = progSettings.playerName; + // 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) { @@ -49,17 +50,19 @@ public class Settings implements Serializable } 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.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] =40; - this.availableDiff[3] =60; + 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"; } @@ -101,6 +104,7 @@ public class Settings implements Serializable } catch(IOException i) { + System.out.println(i.getMessage()); return; } catch(ClassNotFoundException c) -- GitLab