Skip to content

Commit 6bc080a

Browse files
committed
Java 8 adaption
1 parent 3b92e6c commit 6bc080a

File tree

9 files changed

+57
-32
lines changed

9 files changed

+57
-32
lines changed

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Java template
3+
# Compiled class file
4+
*.class
5+
6+
# Log file
7+
*.log
8+
9+
# BlueJ files
10+
*.ctxt
11+
12+
# Mobile Tools for Java (J2ME)
13+
.mtj.tmp/
14+
15+
# Package Files #
16+
*.jar
17+
*.war
18+
*.nar
19+
*.ear
20+
*.zip
21+
*.tar.gz
22+
*.rar
23+
24+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
25+
hs_err_pid*
26+

pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<groupId>sirtet</groupId>
88
<artifactId>sirtet</artifactId>
99
<version>1.0-SNAPSHOT</version>
10-
10+
11+
<properties>
12+
<maven.compiler.target>1.8</maven.compiler.target>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
</properties>
1115

1216
</project>

src/main/java/triest/Triest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class Triest {
99
public static void main(String[] args) {
10-
View view = new Gui().getView(new Grid(10,20)); //view
11-
new GameLoop(view); //controller
10+
View view = new Gui().getView(new Grid(10, 20)); //view
11+
new GameLoop(view); //controller
1212
}
1313
}

src/main/java/triest/model/Pos.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class Pos {
44
public final int x;
55
public final int y;
66

7-
public Pos(int x, int y) {
7+
Pos(int x, int y) {
88
this.x = x;
99
this.y = y;
1010
}

src/main/java/triest/model/Shape.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public enum Shape {
1515

1616
private boolean[][] shape;
1717

18-
private Shape(boolean[][] shape) {
18+
Shape(boolean[][] shape) {
1919
this.shape = shape;
2020
}
2121

src/main/java/triest/view/GridPanel.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class GridPanel extends JPanel implements View {
2323
private int posX = 0;
2424
private int posY = 0;
2525

26-
public GridPanel(final Grid grid) {
26+
GridPanel(final Grid grid) {
2727
this.grid = grid;
2828
this.size = new Dimension(grid.width * BLOCK_SIZE, grid.height * BLOCK_SIZE);
2929
this.addMouseMotionListener(new MouseMotionAdapter() {
@@ -75,10 +75,9 @@ public void setPiece(Piece piece) {
7575
}
7676

7777
public boolean newGame() {
78-
return JOptionPane.showConfirmDialog(this, "Play again?","Game Over!",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
78+
return JOptionPane.showConfirmDialog(this, "Play again?", "Game Over!", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
7979
}
8080

81-
@Override
8281
public Grid getGrid() {
8382
return grid;
8483
}
@@ -99,13 +98,13 @@ private void drawBlocks(Graphics2D g2) {
9998
for (int y = 0; y < grid.height; y++) {
10099
double f = (double) y / grid.height;
101100
int green = (int) (120 + f * (240 - 120));
102-
int red = (int) (120 + (1-f) * (240 - 120));
101+
int red = (int) (120 + (1 - f) * (240 - 120));
103102
Color blockColor = new Color(red, green, 100);
104103
for (int x = 0; x < grid.width; x++) {
105104
if (grid.get(x, y)) {
106105
g2.setPaint(new GradientPaint(
107-
x * BLOCK_SIZE, y * BLOCK_SIZE, blockColor,
108-
(x + 1) * BLOCK_SIZE, (y + 1) * BLOCK_SIZE, blockColor.darker())
106+
x * BLOCK_SIZE, y * BLOCK_SIZE, blockColor,
107+
(x + 1) * BLOCK_SIZE, (y + 1) * BLOCK_SIZE, blockColor.darker())
109108
);
110109
g2.fillRect(x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE);
111110
g2.setPaint(null);
@@ -142,6 +141,6 @@ private void drawHud(Graphics2D g2) {
142141
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
143142
g2.setFont(hudFont);
144143
g2.setColor(hudColor);
145-
g2.drawString(String.format("%05d pieces, %03d lines",grid.getPieceCount(), grid.getLineCount()), 10, 20);
144+
g2.drawString(String.format("%05d pieces, %03d lines", grid.getPieceCount(), grid.getLineCount()), 10, 20);
146145
}
147146
}

src/main/java/triest/view/Gui.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ public class Gui {
1010
//returns the component that needs to be repainted
1111
public View getView(Grid grid) {
1212
final GridPanel gridPanel = new GridPanel(grid);
13-
SwingUtilities.invokeLater(new Runnable() {
14-
@Override
15-
public void run() {
16-
JFrame frame = new JFrame("Triest");
17-
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
18-
frame.setLayout(new GridLayout(1, 1));
19-
frame.add(gridPanel);
20-
frame.setResizable(false);
21-
frame.pack();
22-
centerOnScreen(frame);
23-
frame.setVisible(true);
24-
}
13+
SwingUtilities.invokeLater(() -> {
14+
JFrame frame = new JFrame("Triest");
15+
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
16+
frame.setLayout(new GridLayout(1, 1));
17+
frame.add(gridPanel);
18+
frame.setResizable(false);
19+
frame.pack();
20+
centerOnScreen(frame);
21+
frame.setVisible(true);
2522
});
2623
return gridPanel;
2724
}

src/main/java/triest/view/View.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
public interface View {
77

8-
public void repaint();
8+
void repaint();
99

10-
public void setPiece(Piece piece);
10+
void setPiece(Piece piece);
1111

12-
public boolean newGame();
12+
boolean newGame();
1313

14-
public Grid getGrid();
14+
Grid getGrid();
1515

1616
}

triest.iml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" inherit-compiler-output="false">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
66
<content url="file://$MODULE_DIR$">
77
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8-
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
98
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
1010
<excludeFolder url="file://$MODULE_DIR$/target" />
1111
</content>
1212
<orderEntry type="inheritedJdk" />
1313
<orderEntry type="sourceFolder" forTests="false" />
1414
</component>
15-
</module>
16-
15+
</module>

0 commit comments

Comments
 (0)