Skip to content

Commit

Permalink
Improved naming & minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoaftq committed Jan 22, 2023
1 parent 77d78c0 commit f5d4d22
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 59 deletions.
6 changes: 5 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-openjdk-amd64"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-19.0.2">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
6 changes: 3 additions & 3 deletions src/thbt/webng/com/AboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import javax.swing.JLabel;
import javax.swing.JPanel;

import thbt.webng.com.game.common.WindowUtil;
import thbt.webng.com.game.util.WindowUtil;

/**
* Puzzle about dialog
Expand Down Expand Up @@ -102,10 +102,10 @@ public void mouseExited(MouseEvent e) {
setResizable(false);
}

private static final String VERSION = "1.1.0";
private static final String VERSION = "1.0.0";
/**
* My home page address
*/
private static final String THBT_WEB_ADDRESS = "https://github.com/hoaftq";
private static final String THBT_WEB_ADDRESS = "https://github.com/hoaftq/Lines-98";
private static final long serialVersionUID = 1L;
}
14 changes: 7 additions & 7 deletions src/thbt/webng/com/GameFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

import thbt.webng.com.game.GameBoard;
import thbt.webng.com.game.GamePanel;
import thbt.webng.com.game.common.WindowUtil;
import thbt.webng.com.game.info.GameInfoBoard;
import thbt.webng.com.game.info.HighScoreDialog;
import thbt.webng.com.game.info.PlayerScore;
import thbt.webng.com.game.info.PlayerScoreHistory;
import thbt.webng.com.game.option.GameType;
import thbt.webng.com.game.option.OptionDialog;
import thbt.webng.com.game.status.GameInfoBoard;
import thbt.webng.com.game.status.HighScoreDialog;
import thbt.webng.com.game.status.PlayerScore;
import thbt.webng.com.game.status.PlayerScoreHistory;
import thbt.webng.com.game.option.OptionsDialog;
import thbt.webng.com.game.util.WindowUtil;

public class GameFrame extends JFrame {

Expand Down Expand Up @@ -95,7 +95,7 @@ private void addGameMenu() {
JMenuItem optionsMenuItem = new JMenuItem("Options", 'O');
gameMenu.add(optionsMenuItem);
optionsMenuItem.addActionListener((e) -> {
OptionDialog optionDialog = new OptionDialog(this);
OptionsDialog optionDialog = new OptionsDialog(this);
optionDialog.setVisible(true);
gamePanel.repaint();
});
Expand Down
14 changes: 7 additions & 7 deletions src/thbt/webng/com/game/Ball.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.awt.Color;
import java.util.List;

import thbt.webng.com.game.common.PrimitiveBall;
import thbt.webng.com.game.option.GameInfo;
import thbt.webng.com.game.option.GameOptions;
import thbt.webng.com.game.sound.SoundManager;
import thbt.webng.com.game.util.PrimitiveBall;

public class Ball extends PrimitiveBall {

Expand Down Expand Up @@ -67,7 +67,7 @@ public void select() {
top += 2;
} else {
isUpDirect = !isUpDirect;
if (GameInfo.getCurrentInstance().isBallJumpingSound()) {
if (GameOptions.getCurrentInstance().isBallJumpingSound()) {
SoundManager.playJumSound();
}
}
Expand All @@ -76,7 +76,7 @@ public void select() {
square.repaint();

try {
Thread.sleep(GameInfo.getCurrentInstance().getJumpValue());
Thread.sleep(GameOptions.getCurrentInstance().getJumpValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -123,7 +123,7 @@ public static void growBall(final List<Square> squareList) {
}

try {
Thread.sleep(GameInfo.getCurrentInstance().getAppearanceValue());
Thread.sleep(GameOptions.getCurrentInstance().getAppearanceValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -147,7 +147,7 @@ public static void hideBall(final List<Square> squareList) {
}

try {
Thread.sleep(GameInfo.getCurrentInstance().getExplosionValue());
Thread.sleep(GameOptions.getCurrentInstance().getExplosionValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -158,7 +158,7 @@ public static void hideBall(final List<Square> squareList) {
square.repaint();
}

if (GameInfo.getCurrentInstance().isDestroySound()) {
if (GameOptions.getCurrentInstance().isDestroySound()) {
SoundManager.playDestroySound();
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/thbt/webng/com/game/GameBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import java.util.Queue;
import java.util.Random;

import thbt.webng.com.game.common.ColorUtil;
import thbt.webng.com.game.option.GameInfo;
import thbt.webng.com.game.info.GameInfoBoard;
import thbt.webng.com.game.option.GameOptions;
import thbt.webng.com.game.option.GameType;
import thbt.webng.com.game.option.NextBallDisplayType;
import thbt.webng.com.game.sound.SoundManager;
import thbt.webng.com.game.status.GameInfoBoard;
import thbt.webng.com.game.util.ColorUtil;

public class GameBoard {

Expand All @@ -34,9 +34,9 @@ public GameBoard(GamePanel gamePanel) {
public void draw(Graphics g) {
gameInfoBoard.draw(g);

boolean displayGrowingBalls = GameInfo.getCurrentInstance()
boolean displayGrowingBalls = GameOptions.getCurrentInstance()
.getNextBallDisplayType() == NextBallDisplayType.ShowBoth
|| GameInfo.getCurrentInstance().getNextBallDisplayType() == NextBallDisplayType.ShowOnField;
|| GameOptions.getCurrentInstance().getNextBallDisplayType() == NextBallDisplayType.ShowOnField;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
squareArray[i][j].draw(g, displayGrowingBalls);
Expand Down Expand Up @@ -67,13 +67,13 @@ public void newGame(GameType gameType) {
gameInfoBoard.getScore().setScore(0);
gameInfoBoard.setClockState(true);

GameInfo.getCurrentInstance().setGameType(gameType);
GameOptions.getCurrentInstance().setGameType(gameType);

gamePanel.repaint();
}

public void newGame() {
newGame(GameInfo.getCurrentInstance().getDefaultGameType());
newGame(GameOptions.getCurrentInstance().getDefaultGameType());
}

public Square getSquare(Position pos) {
Expand Down Expand Up @@ -158,7 +158,7 @@ public boolean moveTo(final Position positionTo) {
selectedPos = null;
squareFrom.setBall(null);

if (GameInfo.getCurrentInstance().isMovementSound()) {
if (GameOptions.getCurrentInstance().isMovementSound()) {
SoundManager.playMoveSound();
}

Expand Down Expand Up @@ -397,9 +397,9 @@ private List<Position2> getNeighborsSquare(Position2 pos) {
}

private List<Square> getCompleteSquare(Position pos) {
if (GameInfo.getCurrentInstance().getGameType() == GameType.LINE) {
if (GameOptions.getCurrentInstance().getGameType() == GameType.LINE) {
return getLinesComplete(pos);
} else if (GameInfo.getCurrentInstance().getGameType() == GameType.SQUARE) {
} else if (GameOptions.getCurrentInstance().getGameType() == GameType.SQUARE) {
return getSquaresComplete(pos);
} else {
return getBlocksComplete(pos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;
import java.awt.Color;
import java.awt.Graphics;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;

import java.awt.Graphics;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;

import java.awt.Color;
import java.awt.Font;
Expand All @@ -7,7 +7,7 @@
import javax.swing.Timer;

import thbt.webng.com.game.GamePanel;
import thbt.webng.com.game.option.GameInfo;
import thbt.webng.com.game.option.GameOptions;
import thbt.webng.com.game.option.NextBallDisplayType;

public class GameInfoBoard {
Expand Down Expand Up @@ -39,7 +39,7 @@ public void draw(Graphics g) {
highestScore.draw(g);
score.draw(g);

NextBallDisplayType displayType = GameInfo.getCurrentInstance().getNextBallDisplayType();
NextBallDisplayType displayType = GameOptions.getCurrentInstance().getNextBallDisplayType();
if (displayType == NextBallDisplayType.ShowBoth || displayType == NextBallDisplayType.ShowOnTop) {
nextBallBoard.draw(g);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public void setClockState(boolean isRun) {
}

private void drawGameType(Graphics g) {
String gameTypeString = GameInfo.getCurrentInstance().getGameType().toString().toUpperCase();
String gameTypeString = GameOptions.getCurrentInstance().getGameType().toString().toUpperCase();

g.setFont(g.getFont().deriveFont(Font.BOLD, 7f));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;

import java.awt.BorderLayout;
import java.security.InvalidParameterException;
Expand All @@ -14,7 +14,7 @@
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;

import thbt.webng.com.game.common.WindowUtil;
import thbt.webng.com.game.util.WindowUtil;

public class HighScoreDialog extends JDialog {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;

import java.awt.Color;
import java.awt.Graphics;

import thbt.webng.com.game.common.PrimitiveBall;
import thbt.webng.com.game.util.PrimitiveBall;

public class NextBallBoard {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import thbt.webng.com.game.common.StorageUtil;
import thbt.webng.com.game.util.StorageUtil;

public class PlayerScoreHistory {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.status;
package thbt.webng.com.game.info;
import java.awt.Graphics;

public class Score {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.io.Serializable;

import thbt.webng.com.game.common.StorageUtil;
import thbt.webng.com.game.util.StorageUtil;

public class GameInfo implements Cloneable, Serializable {
public class GameOptions implements Cloneable, Serializable {

private static final long serialVersionUID = -4449406179310549758L;

Expand Down Expand Up @@ -88,18 +88,18 @@ public void setMovementSound(boolean movementSound) {
this.movementSound = movementSound;
}

public static GameInfo getCurrentInstance() {
public static GameOptions getCurrentInstance() {
return currentInstance;
}

public static void setCurrentInstance(GameInfo gameInfo) {
public static void setCurrentInstance(GameOptions gameInfo) {
currentInstance = gameInfo;
StorageUtil.save(currentInstance, CONFIG_FILE_NAME);
}

@Override
protected GameInfo clone() {
GameInfo gi = new GameInfo();
protected GameOptions clone() {
GameOptions gi = new GameOptions();
gi.setGameType(gameType);
gi.setDefaultGameType(defaultGameType);
gi.setNextBallDisplayType(nextBallDisplayType);
Expand Down Expand Up @@ -127,9 +127,9 @@ protected GameInfo clone() {
private boolean destroySound = true;
private boolean movementSound = true;

private static GameInfo currentInstance;
private static GameOptions currentInstance;
private final static String CONFIG_FILE_NAME = "Config";
static {
currentInstance = StorageUtil.<GameInfo>load(CONFIG_FILE_NAME).orElse(new GameInfo());
currentInstance = StorageUtil.<GameOptions>load(CONFIG_FILE_NAME).orElse(new GameOptions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import thbt.webng.com.game.common.WindowUtil;
import thbt.webng.com.game.util.WindowUtil;

public class OptionDialog extends JDialog implements ActionListener, ItemListener {
public class OptionsDialog extends JDialog implements ActionListener, ItemListener {

private static final long serialVersionUID = -3458511180350780500L;

private GameInfo gameInfo = GameInfo.getCurrentInstance().clone();
private GameOptions gameInfo = GameOptions.getCurrentInstance().clone();

private JRadioButton lineButton;

Expand All @@ -47,7 +47,7 @@ public class OptionDialog extends JDialog implements ActionListener, ItemListene

private JButton okButton;

public OptionDialog(JFrame owner) {
public OptionsDialog(JFrame owner) {
super(owner, "Options", true);

JPanel optionPane = new JPanel();
Expand Down Expand Up @@ -132,7 +132,7 @@ public void actionPerformed(ActionEvent e) {
} else if (e.getSource() == nextBallDisplayComboBox) {
gameInfo.setNextBallDisplayType((NextBallDisplayType) nextBallDisplayComboBox.getSelectedItem());
} else if (e.getSource() == okButton) {
GameInfo.setCurrentInstance(gameInfo);
GameOptions.setCurrentInstance(gameInfo);
setVisible(false);
dispose();
} else if (e.getSource() == cancelButton) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.common;
package thbt.webng.com.game.util;

import java.awt.Color;
import java.util.Random;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.common;
package thbt.webng.com.game.util;

import java.awt.Color;
import java.awt.GradientPaint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.common;
package thbt.webng.com.game.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package thbt.webng.com.game.common;
package thbt.webng.com.game.util;

import java.awt.Component;
import java.awt.Dimension;
Expand Down

0 comments on commit f5d4d22

Please sign in to comment.