diff --git a/jogo-oito/pom.xml b/jogo-oito/pom.xml
index e11ec3a9..89650d41 100644
--- a/jogo-oito/pom.xml
+++ b/jogo-oito/pom.xml
@@ -1,55 +1,70 @@
- 4.0.0
- com.bempaggo.jogo
- jogo-do-oito-do-estagiario-gpt
- 0.0.1-SNAPSHOT
-
- UTF-8
-
-
- rest-unity-test
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.8.0
-
- 18
- 18
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.22.0
-
-
-
-
+ 4.0.0
+ com.bempaggo.jogo
+ jogo-do-oito-do-estagiario-gpt
+ 0.0.1-SNAPSHOT
+
+ UTF-8
+ 5.9.2
+ 4.13.2
+ 3.24.2
+ 1.6.13
+
+
+ rest-unity-test
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.0
+
+ 18
+ 18
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.0
+
+
+
+
org.junit.jupiter
junit-jupiter-api
- 5.6.0
+ ${junit-jupiter-api.version}
test
org.junit.jupiter
junit-jupiter-params
- 5.6.0
+ ${junit-jupiter-api.version}
test
org.junit.jupiter
junit-jupiter-engine
- 5.6.0
+ ${junit-jupiter-api.version}
test
junit
junit
- 4.4
+ ${junit.version}
test
jar
+
+ org.assertj
+ assertj-core
+ ${assertj-core.version}
+ test
+
+
+ com.jtattoo
+ JTattoo
+ ${jtattoo.version}
+
\ No newline at end of file
diff --git a/jogo-oito/src/main/java/Application.java b/jogo-oito/src/main/java/Application.java
new file mode 100644
index 00000000..b9eeca20
--- /dev/null
+++ b/jogo-oito/src/main/java/Application.java
@@ -0,0 +1,22 @@
+import builder.JogoDosOitoBuilder;
+import view.JogoDosOito;
+
+import javax.swing.*;
+
+public class Application {
+
+ public static void main(String[] args) {
+ new JogoDosOitoBuilder()
+ .createButtons()
+ .configureMenu()
+ .configureInterface()
+ .build();
+ try {
+ UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(JogoDosOito.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ java.awt.EventQueue.invokeLater(() -> new JogoDosOito().setVisible(true));
+ }
+
+}
diff --git a/jogo-oito/src/main/java/builder/JogoDosOitoBuilder.java b/jogo-oito/src/main/java/builder/JogoDosOitoBuilder.java
new file mode 100644
index 00000000..355da904
--- /dev/null
+++ b/jogo-oito/src/main/java/builder/JogoDosOitoBuilder.java
@@ -0,0 +1,31 @@
+package builder;
+
+import view.JogoDosOito;
+
+public class JogoDosOitoBuilder {
+
+ private JogoDosOito jogoDosOito;
+
+ public JogoDosOitoBuilder() {
+ this.jogoDosOito = new JogoDosOito();
+ }
+
+ public JogoDosOitoBuilder createButtons() {
+ this.jogoDosOito.createButtons();
+ return this;
+ }
+
+ public JogoDosOitoBuilder configureMenu() {
+ this.jogoDosOito.configureMenu();
+ return this;
+ }
+
+ public JogoDosOitoBuilder configureInterface() {
+ this.jogoDosOito.configureInterface();
+ return this;
+ }
+
+ public JogoDosOito build() {
+ return this.jogoDosOito;
+ }
+}
diff --git a/jogo-oito/src/main/java/command/Command.java b/jogo-oito/src/main/java/command/Command.java
new file mode 100644
index 00000000..d7207341
--- /dev/null
+++ b/jogo-oito/src/main/java/command/Command.java
@@ -0,0 +1,7 @@
+package command;
+
+public interface Command {
+
+ void execute();
+
+}
diff --git a/jogo-oito/src/main/java/model/Keyboard.java b/jogo-oito/src/main/java/enums/Keyboard.java
similarity index 50%
rename from jogo-oito/src/main/java/model/Keyboard.java
rename to jogo-oito/src/main/java/enums/Keyboard.java
index ada8bb7a..f23be44a 100644
--- a/jogo-oito/src/main/java/model/Keyboard.java
+++ b/jogo-oito/src/main/java/enums/Keyboard.java
@@ -2,13 +2,9 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
-package model;
+package enums;
import java.awt.event.KeyEvent;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
public enum Keyboard {
@@ -19,20 +15,8 @@ public enum Keyboard {
private final Integer value;
- private static final Map map = Arrays.stream(Keyboard.values())
- .collect(Collectors.toMap(Keyboard::getValue, Function.identity()));
-
-
Keyboard(Integer value) {
this.value = value;
}
- public Integer getValue() {
- return value;
- }
-
- public static Keyboard fromValue(Integer value) {
- return map.get(value);
- }
-
}
diff --git a/jogo-oito/src/main/java/facade/Controller.java b/jogo-oito/src/main/java/facade/Controller.java
index 28c6df1b..d5f02bc5 100644
--- a/jogo-oito/src/main/java/facade/Controller.java
+++ b/jogo-oito/src/main/java/facade/Controller.java
@@ -1,16 +1,25 @@
package facade;
+import command.Command;
import interfaces.Graph;
+import interfaces.Status;
import interfaces.Vertex;
-import java.util.List;
import util.Board;
+import util.Click;
+import util.GameStatus;
+
+import java.util.List;
public class Controller {
private final Graph board;
+ private final Status gameStatus;
+ private final Command click;
public Controller() {
this.board = new Board();
+ this.gameStatus = GameStatus.of(this.board);
+ this.click = Click.of(this.board);
}
public void feedback() {
@@ -25,17 +34,13 @@ public List getCells() {
return this.board.getCells();
}
- public void swap(Integer keyCode) {
- this.board.swap(keyCode);
- }
-
public Boolean checkGameOver() {
- return this.board.checkGameOver();
-
+ return this.gameStatus.isOver();
}
- public void click(Integer cellValue) {
- this.board.click(cellValue);
+ public void click(Integer currentCellValue) {
+ this.board.setCurrentCellValue(currentCellValue);
+ this.click.execute();
}
}
diff --git a/jogo-oito/src/main/java/interfaces/Action.java b/jogo-oito/src/main/java/interfaces/Action.java
new file mode 100644
index 00000000..61bf0f66
--- /dev/null
+++ b/jogo-oito/src/main/java/interfaces/Action.java
@@ -0,0 +1,7 @@
+package interfaces;
+
+public interface Action {
+
+ Vertex swapCells(Integer currentCellValue);
+
+}
diff --git a/jogo-oito/src/main/java/interfaces/Edge.java b/jogo-oito/src/main/java/interfaces/Edge.java
index 20e56cd0..e6a312e5 100644
--- a/jogo-oito/src/main/java/interfaces/Edge.java
+++ b/jogo-oito/src/main/java/interfaces/Edge.java
@@ -4,7 +4,7 @@
*/
package interfaces;
-import model.Keyboard;
+import enums.Keyboard;
/**
*
@@ -15,5 +15,6 @@ public interface Edge {
Keyboard getKey();
Vertex getCell();
-
+
+ Boolean cellValueIsEqual(Integer value);
}
diff --git a/jogo-oito/src/main/java/interfaces/Graph.java b/jogo-oito/src/main/java/interfaces/Graph.java
index e22aad8e..f3cb1411 100644
--- a/jogo-oito/src/main/java/interfaces/Graph.java
+++ b/jogo-oito/src/main/java/interfaces/Graph.java
@@ -16,13 +16,14 @@ public interface Graph {
void setting();
- void swap(Integer keyCode);
-
List getCells();
Vertex getEmptyCell();
- void click(Integer cellValue);
+ void setEmptyCell(Vertex cell);
+
+ void setCurrentCellValue(Integer cellValue);
+
+ Integer getCurrentCellValue();
- Boolean checkGameOver();
}
diff --git a/jogo-oito/src/main/java/interfaces/Status.java b/jogo-oito/src/main/java/interfaces/Status.java
new file mode 100644
index 00000000..c05050bc
--- /dev/null
+++ b/jogo-oito/src/main/java/interfaces/Status.java
@@ -0,0 +1,6 @@
+package interfaces;
+
+public interface Status {
+
+ Boolean isOver();
+}
diff --git a/jogo-oito/src/main/java/interfaces/Vertex.java b/jogo-oito/src/main/java/interfaces/Vertex.java
index 4ff55e4b..815587d0 100644
--- a/jogo-oito/src/main/java/interfaces/Vertex.java
+++ b/jogo-oito/src/main/java/interfaces/Vertex.java
@@ -4,8 +4,9 @@
*/
package interfaces;
+import enums.Keyboard;
+
import java.util.List;
-import model.Keyboard;
/**
*
@@ -17,20 +18,16 @@ public interface Vertex {
Integer getValue();
- void creatingHorizontalAdjacent(Vertex cell);
+ void createHorizontalAdjacent(Vertex cell);
- void creatingVerticalAdjacent(Vertex cell);
+ void createVerticalAdjacent(Vertex cell);
String valueToText();
Edge getAdjacentByKeyCode(Keyboard key);
- Vertex click(Keyboard key);
-
List getAdjacents();
void addAdjacents(Edge edge);
-
- Vertex swapCells(Integer value);
}
diff --git a/jogo-oito/src/main/java/model/Adjacent.java b/jogo-oito/src/main/java/model/Adjacent.java
index 6573c4f4..580b900f 100644
--- a/jogo-oito/src/main/java/model/Adjacent.java
+++ b/jogo-oito/src/main/java/model/Adjacent.java
@@ -4,8 +4,10 @@
*/
package model;
+import enums.Keyboard;
import interfaces.Edge;
import interfaces.Vertex;
+
import java.util.Objects;
/**
@@ -17,11 +19,15 @@ public class Adjacent implements Edge{
private final Keyboard key;
private final Vertex cell;
- public Adjacent(Keyboard key, Vertex cell) {
+ private Adjacent(Keyboard key, Vertex cell) {
this.key = key;
this.cell = cell;
}
+ public static Adjacent of(Keyboard key, Vertex cell) {
+ return new Adjacent(key, cell);
+ }
+
@Override
public Keyboard getKey() {
return this.key;
@@ -32,9 +38,19 @@ public Vertex getCell() {
return this.cell;
}
+ @Override
+ public Boolean cellValueIsEqual(Integer value) {
+ return this.getCell().getValue().equals(value);
+ }
+
@Override
public boolean equals(Object obj) {
return Objects.equals(((Adjacent) obj).getKey(), this.getKey());
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(key);
+ }
+
}
diff --git a/jogo-oito/src/main/java/model/Cell.java b/jogo-oito/src/main/java/model/Cell.java
index 744d8d39..da8df05e 100644
--- a/jogo-oito/src/main/java/model/Cell.java
+++ b/jogo-oito/src/main/java/model/Cell.java
@@ -1,7 +1,9 @@
package model;
+import enums.Keyboard;
import interfaces.Edge;
import interfaces.Vertex;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -11,9 +13,9 @@ public class Cell implements Vertex {
private Integer value;
private final List adjacents;
- public static Integer content;
+ protected static Integer content;
- public Cell(Integer value) {
+ private Cell(Integer value) {
this.value = value;
this.adjacents = new ArrayList<>();
}
@@ -23,26 +25,12 @@ public Cell() {
this.adjacents = new ArrayList<>();
}
- @Override
- public void setValue(Integer value) {
- this.value = value;
+ public static Cell of(Integer value) {
+ return new Cell(value);
}
- @Override
- public Integer getValue() {
- return this.value;
- }
-
- @Override
- public void creatingHorizontalAdjacent(Vertex cell) {
- this.adjacents.add(new Adjacent(Keyboard.LEFT, cell));
- cell.getAdjacents().add(new Adjacent(Keyboard.RIGHT, this));
- }
-
- @Override
- public void creatingVerticalAdjacent(Vertex cell) {
- this.adjacents.add(new Adjacent(Keyboard.UP, cell));
- cell.getAdjacents().add(new Adjacent(Keyboard.DOWN, this));
+ public static String valueToText(List cells, Integer index) {
+ return cells.get(index).valueToText();
}
@Override
@@ -54,41 +42,35 @@ public String valueToText() {
}
@Override
- public Edge getAdjacentByKeyCode(Keyboard key) {
- Adjacent edge = new Adjacent(key, null);
- Integer indexEdge = this.adjacents.indexOf(edge);
- return Optional.of(indexEdge)
- .filter(index -> index != -1)
- .map(this.adjacents::get)
- .orElse(null);
+ public void setValue(Integer value) {
+ this.value = value;
}
@Override
- public Vertex click(Keyboard key) {
- Edge adjacent = this.getAdjacentByKeyCode(key);
- return this.movement(adjacent);
+ public Integer getValue() {
+ return this.value;
}
- private Vertex movement(Edge adjacent) {
- return Optional.ofNullable(adjacent)
- .map(Edge::getCell)
- .map(this::swapCells)
- .orElse(this);
+ @Override
+ public void createHorizontalAdjacent(Vertex cell) {
+ this.adjacents.add(Adjacent.of(Keyboard.LEFT, cell));
+ cell.addAdjacents(Adjacent.of(Keyboard.RIGHT, this));
}
- private Vertex swapCells(Vertex movementCell) {
- this.setValue(movementCell.getValue());
- movementCell.setValue(0);
- return movementCell;
+ @Override
+ public void createVerticalAdjacent(Vertex cell) {
+ this.adjacents.add(Adjacent.of(Keyboard.UP, cell));
+ cell.addAdjacents(Adjacent.of(Keyboard.DOWN, this));
}
@Override
- public Vertex swapCells(Integer value) {
- return this.adjacents.stream()
- .filter(adjacent -> Objects.equals(adjacent.getCell().getValue(), value))
- .findFirst()
- .map(this::movement)
- .orElse(this);
+ public Edge getAdjacentByKeyCode(Keyboard key) {
+ Edge edge = Adjacent.of(key, null);
+ Integer indexEdge = this.adjacents.indexOf(edge);
+ return Optional.of(indexEdge)
+ .filter(index -> index != -1)
+ .map(this.adjacents::get)
+ .orElse(null);
}
@Override
@@ -106,4 +88,9 @@ public boolean equals(Object obj) {
return Objects.equals(this.value, ((Cell) obj).value);
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(value);
+ }
+
}
diff --git a/jogo-oito/src/main/java/model/JFrameAbstractCustom.java b/jogo-oito/src/main/java/model/JFrameAbstractCustom.java
new file mode 100644
index 00000000..b0e000c1
--- /dev/null
+++ b/jogo-oito/src/main/java/model/JFrameAbstractCustom.java
@@ -0,0 +1,30 @@
+package model;
+
+import javax.swing.*;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+public abstract class JFrameAbstractCustom extends JFrame implements KeyListener {
+
+ public JFrameAbstractCustom(String title) {
+ super(title);
+ }
+
+ public abstract void centerFrameInTheScreen(JFrame frame);
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+
+ }
+
+}
diff --git a/jogo-oito/src/main/java/model/JFrameCustom.java b/jogo-oito/src/main/java/model/JFrameCustom.java
new file mode 100644
index 00000000..71ee0023
--- /dev/null
+++ b/jogo-oito/src/main/java/model/JFrameCustom.java
@@ -0,0 +1,26 @@
+package model;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class JFrameCustom extends JFrameAbstractCustom {
+
+ private Integer width;
+ private Integer height;
+ private Integer xAxis;
+ private Integer yAxis;
+
+ public JFrameCustom(String title) {
+ super(title);
+ }
+
+ public void centerFrameInTheScreen(JFrame frame) {
+ Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
+ this.width = frame.getSize().width;
+ this.height = frame.getSize().height;
+ this.xAxis = (dimension.width - width) / 2;
+ this.yAxis = (dimension.height - height) / 2;
+ frame.setLocation(xAxis, yAxis);
+ }
+
+}
diff --git a/jogo-oito/src/main/java/model/Matrix.java b/jogo-oito/src/main/java/model/Matrix.java
index 29586eaa..8e8f17c8 100644
--- a/jogo-oito/src/main/java/model/Matrix.java
+++ b/jogo-oito/src/main/java/model/Matrix.java
@@ -5,6 +5,7 @@
package model;
import interfaces.Vertex;
+
import java.util.ArrayList;
import java.util.List;
@@ -17,8 +18,7 @@ public final class Matrix {
private final Row firstRow;
private final Row secondRow;
private final Row thirdRow;
- public static List cells;
-
+ protected static List cells;
public Matrix() {
Matrix.cells = new ArrayList<>();
@@ -30,16 +30,25 @@ public Matrix() {
}
private void defineAdjacent() {
- this.firstRow.initial.creatingVerticalAdjacent(secondRow.initial);
- this.secondRow.initial.creatingVerticalAdjacent(thirdRow.initial);
+ createVerticalAdjacentInTheInitialCell();
+ createVerticalAdjacentInTheCentralCell();
+ createVerticalAdjacentInTheLastCell();
+ this.changePositionToValidateTemplate();
+ }
+
+ private void createVerticalAdjacentInTheLastCell() {
+ this.firstRow.last.createVerticalAdjacent(secondRow.last);
+ this.secondRow.last.createVerticalAdjacent(thirdRow.last);
+ }
- this.firstRow.center.creatingVerticalAdjacent(secondRow.center);
- this.secondRow.center.creatingVerticalAdjacent(thirdRow.center);
+ private void createVerticalAdjacentInTheCentralCell() {
+ this.firstRow.center.createVerticalAdjacent(secondRow.center);
+ this.secondRow.center.createVerticalAdjacent(thirdRow.center);
+ }
- this.firstRow.last.creatingVerticalAdjacent(secondRow.last);
- this.secondRow.last.creatingVerticalAdjacent(thirdRow.last);
-
- this.changePositionToValidateTemplate();
+ private void createVerticalAdjacentInTheInitialCell() {
+ this.firstRow.initial.createVerticalAdjacent(secondRow.initial);
+ this.secondRow.initial.createVerticalAdjacent(thirdRow.initial);
}
private void changePositionToValidateTemplate(){
@@ -72,9 +81,9 @@ public void loadCells() {
}
public void defineAdjacent() {
- this.initial.creatingHorizontalAdjacent(this.center);
- this.center.creatingHorizontalAdjacent(this.last);
+ this.initial.createHorizontalAdjacent(this.center);
+ this.center.createHorizontalAdjacent(this.last);
}
-
}
+
}
diff --git a/jogo-oito/src/main/java/model/Movement.java b/jogo-oito/src/main/java/model/Movement.java
new file mode 100644
index 00000000..d450a7ee
--- /dev/null
+++ b/jogo-oito/src/main/java/model/Movement.java
@@ -0,0 +1,46 @@
+package model;
+
+import interfaces.Action;
+import interfaces.Edge;
+import interfaces.Vertex;
+
+import java.util.Optional;
+
+public class Movement implements Action {
+
+ private final Vertex emptyCell;
+
+ private Movement(Vertex emptyCell) {
+ this.emptyCell = emptyCell;
+ }
+
+ public static Movement of(Vertex emptyCell) {
+ return new Movement(emptyCell);
+ }
+
+ public Vertex swapCells(Integer currentCellValue) {
+ for (Edge adjacent : emptyCell.getAdjacents()) {
+ if (adjacent.cellValueIsEqual(currentCellValue)) {
+ return swapCells(adjacent);
+ }
+ }
+ return emptyCell;
+ }
+
+ private Vertex swapCells(Edge adjacent) {
+ return Optional.ofNullable(adjacent)
+ .map(Edge::getCell)
+ .map(this::swapCells)
+ .orElse(emptyCell);
+ }
+
+ private Vertex swapCells(Vertex currentCell) {
+ emptyCell.setValue(currentCell.getValue());
+ currentCell.setValue(0);
+ return currentCell;
+ }
+
+}
+
+
+
diff --git a/jogo-oito/src/main/java/util/Board.java b/jogo-oito/src/main/java/util/Board.java
index e71e83ea..0ba8a475 100644
--- a/jogo-oito/src/main/java/util/Board.java
+++ b/jogo-oito/src/main/java/util/Board.java
@@ -2,55 +2,50 @@
import interfaces.Graph;
import interfaces.Vertex;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.IntStream;
-import model.Keyboard;
import model.Matrix;
+import java.util.*;
+
public class Board implements Graph {
private List cells;
private Vertex emptyCell;
- private Integer length;
private Matrix matrix;
+ private Integer currentCellValue;
public Board() {
}
@Override
public void feedback() {
- this.matrix = new Matrix();
- this.cells = this.matrix.getCells();
- this.length = cells.size();
+ this.resetMatrix();
this.defineEmptyCell();
}
@Override
public void setting() {
- this.matrix = new Matrix();
- this.cells = this.matrix.getCells();
- this.length = cells.size();
+ this.resetMatrix();
this.shuffleCell();
this.defineEmptyCell();
+ }
+ private void resetMatrix() {
+ this.matrix = new Matrix();
+ this.cells = this.matrix.getCells();
}
private void shuffleCell() {
Iterator iterator = this.shuffleValues().iterator();
- this.cells.stream()
- .forEach(vertex -> vertex.setValue(iterator.next()));
+ for (Vertex cell : this.cells) {
+ cell.setValue(iterator.next());
+ }
}
private List shuffleValues() {
List values = new ArrayList<>();
- this.cells.stream()
- .map(Vertex::getValue)
- .forEach(values::add);
+ for (Vertex cell : this.cells) {
+ values.add(cell.getValue());
+ }
Collections.shuffle(values);
return values;
}
@@ -64,31 +59,41 @@ private void defineEmptyCell() {
}
@Override
- public void click(Integer cellValue) {
- this.emptyCell = this.emptyCell.swapCells(cellValue);
+ public List getCells() {
+ return this.cells;
}
@Override
- public void swap(Integer keyCode) {
- Keyboard key = Keyboard.fromValue(keyCode);
- this.emptyCell = this.emptyCell.click(key);
+ public Vertex getEmptyCell() {
+ return this.emptyCell;
}
@Override
- public List getCells() {
- return this.cells;
+ public void setEmptyCell(Vertex cell) {
+ this.emptyCell = cell;
}
@Override
- public Vertex getEmptyCell() {
- return this.emptyCell;
+ public Integer getCurrentCellValue() {
+ return this.currentCellValue;
}
@Override
- public Boolean checkGameOver() {
- return IntStream.range(0, this.length)
- .allMatch(index -> this.cells.get(index).getValue() == (index + 1) % this.length);
+ public void setCurrentCellValue(Integer currentCellValue) {
+ this.currentCellValue = currentCellValue;
+ }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Board board = (Board) o;
+ return cells.equals(board.cells);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(cells);
}
}
diff --git a/jogo-oito/src/main/java/util/Click.java b/jogo-oito/src/main/java/util/Click.java
new file mode 100644
index 00000000..d92747bd
--- /dev/null
+++ b/jogo-oito/src/main/java/util/Click.java
@@ -0,0 +1,27 @@
+package util;
+
+import command.Command;
+import interfaces.Action;
+import interfaces.Graph;
+import interfaces.Vertex;
+import model.Movement;
+
+public class Click implements Command {
+
+ private final Graph board;
+
+ private Click(Graph board) {
+ this.board = board;
+ }
+
+ public static Click of(Graph board) {
+ return new Click(board);
+ }
+
+ public void execute() {
+ Action movement = Movement.of(this.board.getEmptyCell());
+ Vertex currentCell = movement.swapCells(this.board.getCurrentCellValue());
+ this.board.setEmptyCell(currentCell);
+ }
+
+}
\ No newline at end of file
diff --git a/jogo-oito/src/main/java/util/GameStatus.java b/jogo-oito/src/main/java/util/GameStatus.java
new file mode 100644
index 00000000..5998e5b9
--- /dev/null
+++ b/jogo-oito/src/main/java/util/GameStatus.java
@@ -0,0 +1,37 @@
+package util;
+
+import interfaces.Graph;
+import interfaces.Status;
+import interfaces.Vertex;
+
+import java.util.List;
+import java.util.stream.IntStream;
+
+public class GameStatus implements Status {
+
+ private final Graph board;
+
+ private GameStatus(Graph board) {
+ this.board = board;
+ }
+
+ public static GameStatus of(Graph board) {
+ return new GameStatus(board);
+ }
+
+ @Override
+ public Boolean isOver() {
+ Integer size = getCells().size();
+ return IntStream.range(0, size)
+ .allMatch(index -> getCellValueByIndex(index) == (index + 1) % size);
+ }
+
+ private Integer getCellValueByIndex(Integer index) {
+ return this.getCells().get(index).getValue();
+ }
+
+ private List getCells() {
+ return this.board.getCells();
+ }
+
+}
diff --git a/jogo-oito/src/main/java/view/JogoDosOito.java b/jogo-oito/src/main/java/view/JogoDosOito.java
index 2b687559..f51cf51c 100644
--- a/jogo-oito/src/main/java/view/JogoDosOito.java
+++ b/jogo-oito/src/main/java/view/JogoDosOito.java
@@ -2,22 +2,18 @@
import facade.Controller;
import interfaces.Vertex;
-import java.awt.Font;
-import java.awt.GridLayout;
+import model.JFrameCustom;
+
+import javax.swing.*;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import java.util.stream.IntStream;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-public class JogoDosOito extends JFrame implements KeyListener {
+public class JogoDosOito extends JFrameCustom {
private final List buttons;
private final Controller controller;
@@ -31,30 +27,60 @@ public JogoDosOito() {
this.buttons = new ArrayList<>();
}
- private void configureInterface() {
+ public void createButtons() {
+ for (Vertex cell : this.getCells()) {
+ this.createButton(cell);
+ }
+ }
+
+ public void configureMenu() {
+ this.reset = this.configureReset();
+ this.feedback = this.configureFeedback();
+ add(this.feedback);
+ add(this.reset);
+ add(new JLabel(""));
+ }
+
+ public void configureInterface() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
setLayout(new GridLayout(4, 3));
setVisible(true);
addKeyListener(this);
setFocusable(true);
+ centerFrameInTheScreen(this);
}
- private void createButtons() {
- this.controller.getCells().forEach(cell -> {
- JButton button = this.configButton(cell);
- add(button);
- buttons.add(button);
- });
+ public List getButtons() {
+ return this.buttons;
+ }
+
+ public JButton getReset() {
+ return this.reset;
+ }
+
+ public JButton getFeedback() {
+ return this.feedback;
+ }
+
+ private List getCells() {
+ return this.controller.getCells();
+ }
+
+ private void createButton(Vertex cell) {
+ JButton button = this.configureButton(cell);
+ add(button);
+ buttons.add(button);
}
private Integer textToValue(String text) {
return Optional.ofNullable(text)
+ .filter(textValue -> !textValue.equals(""))
.map(Integer::valueOf)
.orElse(0);
}
- private JButton configButton(Vertex cell) {
+ private JButton configureButton(Vertex cell) {
JButton button = new JButton();
button.setFont(new Font("Arial", Font.BOLD, 36));
button.setText(cell.valueToText());
@@ -65,7 +91,6 @@ private JButton configButton(Vertex cell) {
SwingUtilities.getRoot(button).requestFocus();
});
return button;
-
}
private void checkGameOver() {
@@ -77,15 +102,7 @@ private void checkGameOver() {
});
}
- private void configMenu() {
- this.reset = this.configReset();
- this.feedback = this.configFeedback();
- add(this.feedback);
- add(this.reset);
- add(new JLabel(""));
- }
-
- private JButton configReset() {
+ private JButton configureReset() {
JButton buttonReset = new JButton("Reiniciar");
buttonReset.addActionListener((ActionEvent e) -> {
this.resetGame();
@@ -93,8 +110,8 @@ private JButton configReset() {
});
return buttonReset;
}
-
- private JButton configFeedback() {
+
+ private JButton configureFeedback() {
JButton buttonFeedback = new JButton("Gabarito");
buttonFeedback.addActionListener((ActionEvent e) -> {
this.showFeedback();
@@ -103,7 +120,6 @@ private JButton configFeedback() {
return buttonFeedback;
}
-
private void resetGame() {
this.controller.setting();
this.updateBoard();
@@ -115,34 +131,16 @@ private void showFeedback() {
}
private void updateBoard() {
- List cells = this.controller.getCells();
- IntStream.range(0, cells.size())
- .forEach(index -> {
- JButton button = this.buttons.get(index);
- button.setText(cells.get(index).valueToText());
- });
+ Iterator iterator = getCells().iterator();
+ for (JButton button : this.buttons) {
+ button.setText(iterator.next().valueToText());
+ }
}
@Override
- public void keyTyped(KeyEvent e) {
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- this.controller.swap(e.getKeyCode());
+ public void keyPressed(KeyEvent event) {
this.updateBoard();
this.checkGameOver();
}
- @Override
- public void keyReleased(KeyEvent e) {
- }
-
- public static void main(String[] args) {
- JogoDosOito game = new JogoDosOito();
- game.createButtons();
- game.configMenu();
- game.configureInterface();
-
- }
}
diff --git a/jogo-oito/src/test/java/game/AdjacentTest.java b/jogo-oito/src/test/java/game/AdjacentTest.java
index 49dd2ac3..5069ef79 100644
--- a/jogo-oito/src/test/java/game/AdjacentTest.java
+++ b/jogo-oito/src/test/java/game/AdjacentTest.java
@@ -1,39 +1,64 @@
package game;
-import model.Adjacent;
-import model.Cell;
-import model.Keyboard;
+import enums.Keyboard;
import interfaces.Edge;
import interfaces.Vertex;
+import model.Adjacent;
+import model.Cell;
import org.junit.jupiter.api.Test;
+
import static org.junit.jupiter.api.Assertions.*;
-public class AdjacentTest {
+class AdjacentTest {
@Test
- public void testGetKey() {
- Edge edge = new Adjacent(Keyboard.RIGHT, null);
+ void testGetKey() {
+ Edge edge = Adjacent.of(Keyboard.RIGHT, null);
assertEquals(Keyboard.RIGHT, edge.getKey());
}
@Test
- public void testGetCell() {
- Vertex cell = new Cell(1);
- Edge edge = new Adjacent(Keyboard.RIGHT, cell);
+ void testGetCell() {
+ Vertex cell = Cell.of(1);
+ Edge edge = Adjacent.of(Keyboard.RIGHT, cell);
assertEquals(cell, edge.getCell());
}
@Test
- public void testEquals() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ void testEquals() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(1);
+
+ Edge edge1 = Adjacent.of(Keyboard.RIGHT, cell2);
+ Edge edge2 = Adjacent.of(Keyboard.RIGHT, cell1);
+
+ assertTrue(edge1.getCell().equals(cell2));
+ assertTrue(edge2.getCell().equals(cell1));
+ }
+
+ @Test
+ void testOf() {
+ Vertex cell = Cell.of(1);
+ Edge edge = Adjacent.of(Keyboard.LEFT, cell);
+
+ assertEquals(edge.getCell(), cell);
+ assertEquals(edge.getKey(), Keyboard.LEFT);
+ }
+
+ @Test
+ void testCellValueIsEqualTrue() {
+ Vertex cell = Cell.of(1);
+ Edge edge = Adjacent.of(Keyboard.LEFT, cell);
- Edge edge1 = new Adjacent(Keyboard.RIGHT, cell2);
- Edge edge2 = new Adjacent(Keyboard.LEFT, cell1);
+ assertTrue(edge.cellValueIsEqual(1));
+ }
- assertEquals(edge1.getCell().click(Keyboard.RIGHT), cell2);
- assertEquals(edge2.getCell().click(Keyboard.LEFT), cell1);
+ @Test
+ void testCellValueIsEqualFalse() {
+ Vertex cell = Cell.of(2);
+ Edge edge = Adjacent.of(Keyboard.RIGHT, cell);
+ assertFalse(edge.cellValueIsEqual(1));
}
}
diff --git a/jogo-oito/src/test/java/game/BoardTest.java b/jogo-oito/src/test/java/game/BoardTest.java
index 7b39668f..36b091f5 100644
--- a/jogo-oito/src/test/java/game/BoardTest.java
+++ b/jogo-oito/src/test/java/game/BoardTest.java
@@ -8,42 +8,33 @@
*
* @author allen
*/
-import model.Cell;
-import util.Board;
+
+import enums.Keyboard;
import interfaces.Edge;
+import interfaces.Graph;
import interfaces.Vertex;
+import model.Cell;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+import util.Board;
import java.util.List;
-import model.Keyboard;
-import org.junit.jupiter.api.Assertions;
-public class BoardTest {
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class BoardTest {
- private Board board;
+ private Graph board;
@BeforeEach
- public void setUp() {
+ void setUp() {
board = new Board();
board.feedback();
}
@Test
- public void testSwap() {
- Vertex emptyCell = board.getEmptyCell();
- Vertex cell = board.getCells().get(7);
- Integer cellValue = cell.getValue();
-
- board.click(cellValue);
-
- assertEquals(cellValue, emptyCell.getValue());
- assertEquals(0, cell.getValue());
- }
-
- @Test
- public void testGetCells() {
+ void testGetCells() {
List cells = board.getCells();
assertNotNull(cells);
@@ -51,69 +42,48 @@ public void testGetCells() {
}
@Test
- public void testDefineCellRelationships() {
+ void testDefineCellRelationships() {
Vertex cell1 = board.getCells().get(1);
Vertex cell2 = board.getCells().get(2);
- Edge adjacent1 = cell1.getAdjacentByKeyCode(model.Keyboard.LEFT);
- Edge adjacent2 = cell2.getAdjacentByKeyCode(model.Keyboard.RIGHT);
+ Edge adjacent1 = cell1.getAdjacentByKeyCode(Keyboard.LEFT);
+ Edge adjacent2 = cell2.getAdjacentByKeyCode(Keyboard.RIGHT);
assertEquals(cell2, adjacent1.getCell());
assertEquals(cell1, adjacent2.getCell());
}
@Test
- public void testClick() {
- Vertex emptyCell = board.getEmptyCell();
- Vertex cell = board.getCells().get(7);
- Integer cellValue = cell.getValue();
-
- board.click(cellValue);
-
- assertEquals(cellValue, emptyCell.getValue());
- assertEquals(0, cell.getValue());
- }
-
- @Test
- public void testCheckGameOver() {
- Assertions.assertTrue(this.board.checkGameOver());
- board = new Board();
- board.setting();
- Assertions.assertFalse(board.checkGameOver());
-
- }
-
- @Test
- public void testCellCreatingHorizontalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ void testCellCreateHorizontalAdjacent() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ cell1.createHorizontalAdjacent(cell2);
- Edge adjacent1 = cell1.getAdjacentByKeyCode(model.Keyboard.LEFT);
- Edge adjacent2 = cell2.getAdjacentByKeyCode(model.Keyboard.RIGHT);
+ Edge adjacent1 = cell1.getAdjacentByKeyCode(Keyboard.LEFT);
+ Edge adjacent2 = cell2.getAdjacentByKeyCode(Keyboard.RIGHT);
assertEquals(cell2, adjacent1.getCell());
assertEquals(cell1, adjacent2.getCell());
}
@Test
- public void testCellCreatingVerticalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ void testCellCreateVerticalAdjacent() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(2);
- cell1.creatingVerticalAdjacent(cell2);
+ cell1.createVerticalAdjacent(cell2);
- Edge adjacent1 = cell1.getAdjacentByKeyCode(model.Keyboard.UP);
- Edge adjacent2 = cell2.getAdjacentByKeyCode(model.Keyboard.DOWN);
+ Edge adjacent1 = cell1.getAdjacentByKeyCode(Keyboard.UP);
+ Edge adjacent2 = cell2.getAdjacentByKeyCode(Keyboard.DOWN);
assertEquals(cell2, adjacent1.getCell());
assertEquals(cell1, adjacent2.getCell());
}
@Test
- public void testValueToText() {
- Vertex cell = new Cell(0);
+ void testValueToText() {
+ Vertex cell = Cell.of(0);
assertEquals("", cell.valueToText());
cell.setValue(5);
@@ -121,38 +91,14 @@ public void testValueToText() {
}
@Test
- public void testGetAdjacentByKeyCode() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ void testGetAdjacentByKeyCode() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ cell1.createHorizontalAdjacent(cell2);
- Edge adjacent = cell1.getAdjacentByKeyCode(model.Keyboard.LEFT);
+ Edge adjacent = cell1.getAdjacentByKeyCode(Keyboard.LEFT);
assertEquals(cell2, adjacent.getCell());
}
-
- @Test
- public void testClickDown() {
- board.swap(Keyboard.DOWN.getValue());
- Assertions.assertEquals(5, board.getCells().indexOf(board.getEmptyCell()));
- }
-
- @Test
- public void testClickUp() {
- board.swap(Keyboard.UP.getValue());
- Assertions.assertEquals(8, board.getCells().indexOf(board.getEmptyCell()));
- }
-
- @Test
- public void testClickRight() {
- board.swap(Keyboard.RIGHT.getValue());
- Assertions.assertEquals(7, board.getCells().indexOf(board.getEmptyCell()));
- }
-
- @Test
- public void testClickLeft() {
- board.swap(Keyboard.LEFT.getValue());
- Assertions.assertEquals(8, board.getCells().indexOf(board.getEmptyCell()));
- }
}
diff --git a/jogo-oito/src/test/java/game/CellTest.java b/jogo-oito/src/test/java/game/CellTest.java
index a2742248..5bb77379 100644
--- a/jogo-oito/src/test/java/game/CellTest.java
+++ b/jogo-oito/src/test/java/game/CellTest.java
@@ -4,97 +4,77 @@
*/
package game;
+import enums.Keyboard;
import interfaces.Edge;
import interfaces.Vertex;
-import java.util.List;
import model.Adjacent;
import model.Cell;
-import model.Keyboard;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
-public class CellTest{
+class CellTest{
@Test
- public void testSetValue() {
- Vertex cell = new Cell(0);
+ void testSetValue() {
+ Vertex cell = Cell.of(0);
cell.setValue(5);
assertEquals(5, cell.getValue());
}
@Test
- public void testGetValue() {
- Vertex cell = new Cell(10);
+ void testGetValue() {
+ Vertex cell = Cell.of(10);
assertEquals(10, cell.getValue());
}
@Test
- public void testCreatingHorizontalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ void testCreateHorizontalAdjacent() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ cell1.createHorizontalAdjacent(cell2);
assertEquals(1, cell1.getAdjacents().size());
assertEquals(1, cell2.getAdjacents().size());
}
@Test
- public void testCreatingVerticalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ void testCreateVerticalAdjacent() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(2);
- cell1.creatingVerticalAdjacent(cell2);
+ cell1.createVerticalAdjacent(cell2);
assertEquals(1, cell1.getAdjacents().size());
assertEquals(1, cell2.getAdjacents().size());
}
@Test
- public void testValueToText() {
- Vertex cell1 = new Cell(0);
- Vertex cell2 = new Cell(5);
+ void testValueToText() {
+ Vertex cell1 = Cell.of(0);
+ Vertex cell2 = Cell.of(5);
assertEquals("", cell1.valueToText());
assertEquals("5", cell2.valueToText());
}
@Test
- public void testGetAdjacentByKeyCode() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ void testGetAdjacentByKeyCode() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(2);
+ cell1.createHorizontalAdjacent(cell2);
assertEquals(cell2, cell1.getAdjacentByKeyCode(Keyboard.LEFT).getCell());
}
@Test
- public void testClick() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
- cell1.creatingHorizontalAdjacent(cell2);
-
- assertEquals(cell2, cell1.click(Keyboard.LEFT));
- }
-
- @Test
- public void testSwapCells() {
- Vertex cell1 = new Cell(0);
- Vertex cell2 = new Cell(2);
- cell1.creatingHorizontalAdjacent(cell2);
-
- cell1.swapCells(cell2.getValue());
-
- assertEquals(2, cell1.getValue());
- assertEquals(0, cell2.getValue());
- }
-
- @Test
- public void testAddAdjacents() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
- Edge edge = new Adjacent(Keyboard.RIGHT, cell2);
+ void testAddAdjacents() {
+ Vertex cell1 = Cell.of(1);
+ Vertex cell2 = Cell.of(2);
+ Edge edge = Adjacent.of(Keyboard.RIGHT, cell2);
cell1.addAdjacents(edge);
@@ -104,19 +84,48 @@ public void testAddAdjacents() {
}
@Test
- public void defineAdjacents() {
- Vertex cell1 = new Cell(5);
- Vertex cell2 = new Cell(10);
- Vertex cell3 = new Cell(15);
- Vertex cell4 = new Cell(20);
+ void testCreateAdjacents() {
+ Vertex cell1 = Cell.of(5);
+ Vertex cell2 = Cell.of(10);
+ Vertex cell3 = Cell.of(15);
+ Vertex cell4 = Cell.of(20);
- cell1.creatingVerticalAdjacent(cell2);
- cell1.creatingVerticalAdjacent(cell3);
- cell1.creatingHorizontalAdjacent(cell4);
+ cell1.createVerticalAdjacent(cell2);
+ cell1.createVerticalAdjacent(cell3);
+ cell1.createHorizontalAdjacent(cell4);
List adjacents = cell1.getAdjacents();
assertEquals(cell2, adjacents.get(0).getCell());
assertEquals(cell3, adjacents.get(1).getCell());
assertEquals(cell4, adjacents.get(2).getCell());
}
+
+ @Test
+ void testOf() {
+ Vertex cell1 = Cell.of(5);
+ Vertex cell2 = Cell.of(10);
+ Vertex cell3 = Cell.of(15);
+ Vertex cell4 = Cell.of(20);
+
+ assertEquals(cell1.getValue(), 5);
+ assertEquals(cell2.getValue(), 10);
+ assertEquals(cell3.getValue(), 15);
+ assertEquals(cell4.getValue(), 20);
+ }
+
+ @Test
+ void testStaticValueToText() {
+ Vertex cell1 = Cell.of(5);
+ Vertex cell2 = Cell.of(10);
+ Vertex cell3 = Cell.of(15);
+ Vertex cell4 = Cell.of(20);
+
+ List cells = List.of(cell1, cell2, cell3, cell4);
+
+ assertEquals(Cell.valueToText(cells, 0), "5");
+ assertEquals(Cell.valueToText(cells, 1), "10");
+ assertEquals(Cell.valueToText(cells, 2), "15");
+ assertEquals(Cell.valueToText(cells, 3), "20");
+ }
+
}
diff --git a/jogo-oito/src/test/java/game/ClickTest.java b/jogo-oito/src/test/java/game/ClickTest.java
new file mode 100644
index 00000000..4a029225
--- /dev/null
+++ b/jogo-oito/src/test/java/game/ClickTest.java
@@ -0,0 +1,38 @@
+package game;
+
+import command.Command;
+import interfaces.Graph;
+import interfaces.Vertex;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import util.Board;
+import util.Click;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ClickTest {
+
+ private Command click;
+ private Graph board;
+
+ @BeforeEach
+ void setUp() {
+ board = new Board();
+ board.feedback();
+ click = Click.of(board);
+ }
+
+ @Test
+ void testExecute() {
+ Vertex emptyCell = board.getEmptyCell();
+ Vertex cell = board.getCells().get(7);
+ Integer currentCellValue = cell.getValue();
+ board.setCurrentCellValue(currentCellValue);
+
+ click.execute();
+
+ assertEquals(currentCellValue, emptyCell.getValue());
+ assertEquals(0, cell.getValue());
+ }
+
+}
\ No newline at end of file
diff --git a/jogo-oito/src/test/java/game/GameStatusTest.java b/jogo-oito/src/test/java/game/GameStatusTest.java
new file mode 100644
index 00000000..17c42245
--- /dev/null
+++ b/jogo-oito/src/test/java/game/GameStatusTest.java
@@ -0,0 +1,31 @@
+package game;
+
+import interfaces.Graph;
+import interfaces.Status;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import util.Board;
+import util.GameStatus;
+
+class GameStatusTest {
+
+ private Status gameStatus;
+ private Graph board;
+
+ @BeforeEach
+ void setUp() {
+ board = new Board();
+ board.feedback();
+ gameStatus = GameStatus.of(board);
+ }
+
+ @Test
+ void testIsOver() {
+ Assertions.assertTrue(this.gameStatus.isOver());
+
+ board.setting();
+ Assertions.assertFalse(this.gameStatus.isOver());
+ }
+
+}
\ No newline at end of file
diff --git a/jogo-oito/src/test/java/game/JFrameCustomTest.java b/jogo-oito/src/test/java/game/JFrameCustomTest.java
new file mode 100644
index 00000000..739074e2
--- /dev/null
+++ b/jogo-oito/src/test/java/game/JFrameCustomTest.java
@@ -0,0 +1,30 @@
+package game;
+
+import model.JFrameCustom;
+import org.junit.jupiter.api.Test;
+
+import java.awt.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class JFrameCustomTest {
+
+ @Test
+ public void testCenterFrameInTheScreen() {
+ JFrameCustom frame = new JFrameCustom("Test Frame");
+ frame.setSize(800, 600);
+
+ frame.centerFrameInTheScreen(frame);
+
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ Integer expectedXAxis = (screenSize.width - frame.getWidth()) / 2;
+ Integer expectedYAxis = (screenSize.height - frame.getHeight()) / 2;
+
+ assertThat(expectedXAxis).isEqualTo(frame.getX());
+ assertThat(expectedXAxis).isEqualTo(283);
+
+ assertThat(expectedYAxis).isEqualTo( frame.getY());
+ assertThat(expectedXAxis).isEqualTo(283);
+ }
+
+}
diff --git a/jogo-oito/src/test/java/game/JogoDosOitoBuilderTest.java b/jogo-oito/src/test/java/game/JogoDosOitoBuilderTest.java
new file mode 100644
index 00000000..308601d8
--- /dev/null
+++ b/jogo-oito/src/test/java/game/JogoDosOitoBuilderTest.java
@@ -0,0 +1,63 @@
+package game;
+
+import builder.JogoDosOitoBuilder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import view.JogoDosOito;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class JogoDosOitoBuilderTest {
+
+ private JogoDosOito jogoDosOito;
+
+ @BeforeEach
+ void setUp() {
+ jogoDosOito = new JogoDosOito();
+ }
+
+ @Test
+ void testCreateButtons() {
+ assertThat(jogoDosOito.getButtons()).isEmpty();
+
+ jogoDosOito = new JogoDosOitoBuilder()
+ .createButtons()
+ .build();
+
+ assertThat(jogoDosOito.getButtons()).
+ hasSize(9)
+ .extracting("text")
+ .containsExactlyInAnyOrder("1","2","3", "4", "5", "6", "7", "8", "");
+ }
+
+ @Test
+ void testConfigureMenu() {
+ assertThat(jogoDosOito.getReset()).isNull();
+ assertThat(jogoDosOito.getFeedback()).isNull();
+
+ jogoDosOito = new JogoDosOitoBuilder()
+ .configureMenu()
+ .build();
+
+ assertThat(jogoDosOito.getReset()).isNotNull();
+ assertThat(jogoDosOito.getFeedback()).isNotNull();
+ }
+
+ @Test
+ void testConfigureInterface() {
+ assertThat(jogoDosOito.isVisible()).isFalse();
+ assertThat(jogoDosOito.getSize())
+ .extracting("width", "height")
+ .containsExactly(0.0, 0.0);
+
+ jogoDosOito = new JogoDosOitoBuilder()
+ .configureInterface()
+ .build();
+
+ assertThat(jogoDosOito.isVisible()).isTrue();
+ assertThat(jogoDosOito.getSize())
+ .extracting("width", "height")
+ .containsExactly(300.0, 300.0);
+ }
+
+}
diff --git a/jogo-oito/src/test/java/game/MatrixTest.java b/jogo-oito/src/test/java/game/MatrixTest.java
new file mode 100644
index 00000000..73f886c7
--- /dev/null
+++ b/jogo-oito/src/test/java/game/MatrixTest.java
@@ -0,0 +1,22 @@
+package game;
+
+import model.Matrix;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class MatrixTest {
+
+ @Test
+ void testGetCells() {
+ Matrix matrix = new Matrix();
+
+ assertNotNull(matrix.getCells());
+ assertThat(matrix.getCells())
+ .hasSize(9)
+ .extracting("value")
+ .containsExactly(1 ,2, 3, 4, 5, 6, 7, 8, 0);
+ }
+
+}
diff --git a/jogo-oito/src/test/java/game/MovementTest.java b/jogo-oito/src/test/java/game/MovementTest.java
new file mode 100644
index 00000000..716783ac
--- /dev/null
+++ b/jogo-oito/src/test/java/game/MovementTest.java
@@ -0,0 +1,36 @@
+package game;
+
+import interfaces.Vertex;
+import model.Cell;
+import model.Movement;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class MovementTest {
+
+ private Movement movement;
+ private Vertex emptyCell;
+
+ @BeforeEach
+ void setUp() {
+ emptyCell = Cell.of(0);
+ movement = Movement.of(emptyCell);
+ }
+
+ @Test
+ void testSwapCells() {
+ Vertex cell = Cell.of(2);
+ cell.createHorizontalAdjacent(emptyCell);
+
+ assertEquals(2, cell.getValue());
+ assertEquals(0, emptyCell.getValue());
+
+ movement.swapCells(cell.getValue());
+
+ assertEquals(0, cell.getValue());
+ assertEquals(2, emptyCell.getValue());
+ }
+
+}