Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions jogo-oito/src/main/java/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package controller;

import service.interfaces.Cell;
import java.util.List;
import service.GraphImpl;

public class Controller {

private final service.interfaces.Graph graph;

public Controller() {
this.graph = new GraphImpl();
}

public void feedback() {
this.graph.feedback();
}

public void setter() {
this.graph.setter();
}

public List<Cell> getCells() {
return this.graph.getCells();
}

public void swap(Integer keyCode) {
this.graph.swap(keyCode);
}

public Boolean checkGameOver() {
return this.graph.checkGameOver();

}

public void click(Integer cellValue) {
this.graph.click(cellValue);
}

}
41 changes: 0 additions & 41 deletions jogo-oito/src/main/java/facade/Controller.java

This file was deleted.

39 changes: 20 additions & 19 deletions jogo-oito/src/main/java/model/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/
package model;

import interfaces.Vertex;
import service.CellImpl;
import service.interfaces.Cell;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -17,27 +18,27 @@ public final class Matrix {
private final Row firstRow;
private final Row secondRow;
private final Row thirdRow;
public static List<Vertex> cells;
public static List<Cell> cells;


public Matrix() {
Matrix.cells = new ArrayList<>();
Cell.content = 1;
CellImpl.content = 1;
this.firstRow = new Row();
this.secondRow = new Row();
this.thirdRow = new Row();
this.defineAdjacent();
}

private void defineAdjacent() {
this.firstRow.initial.creatingVerticalAdjacent(secondRow.initial);
this.secondRow.initial.creatingVerticalAdjacent(thirdRow.initial);
this.firstRow.initial.createVerticalAdjacent(secondRow.initial);
this.secondRow.initial.createVerticalAdjacent(thirdRow.initial);

this.firstRow.center.creatingVerticalAdjacent(secondRow.center);
this.secondRow.center.creatingVerticalAdjacent(thirdRow.center);
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.firstRow.last.createVerticalAdjacent(secondRow.last);
this.secondRow.last.createVerticalAdjacent(thirdRow.last);

this.changePositionToValidateTemplate();
}
Expand All @@ -47,20 +48,20 @@ private void changePositionToValidateTemplate(){
}


public List<Vertex> getCells() {
public List<Cell> getCells() {
return Matrix.cells;
}

private final class Row {
private static final class Row {

public final Cell initial;
public final Cell center;
public final Cell last;
public final CellImpl initial;
public final CellImpl center;
public final CellImpl last;

public Row() {
this.initial = new Cell();
this.center = new Cell();
this.last = new Cell();
this.initial = new CellImpl();
this.center = new CellImpl();
this.last = new CellImpl();
this.defineAdjacent();
this.loadCells();
}
Expand All @@ -72,8 +73,8 @@ 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);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package model;
package service;

import service.interfaces.Cell;
import service.interfaces.Edge;
import util.Keyboard;

import interfaces.Edge;
import interfaces.Vertex;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class Cell implements Vertex {
public class CellImpl implements Cell {

private Integer value;
private final List<Edge> adjacents;
public static Integer content;

public Cell(Integer value) {
public CellImpl(Integer value) {
this.value = value;
this.adjacents = new ArrayList<>();
}

public Cell() {
this.value = Cell.content++;
public CellImpl() {
this.value = CellImpl.content++;
this.adjacents = new ArrayList<>();
}

Expand All @@ -34,15 +36,15 @@ public Integer getValue() {
}

@Override
public void creatingHorizontalAdjacent(Vertex cell) {
this.adjacents.add(new Adjacent(Keyboard.LEFT, cell));
cell.getAdjacents().add(new Adjacent(Keyboard.RIGHT, this));
public void createHorizontalAdjacent(service.interfaces.Cell cell) {
this.adjacents.add(new EdgeImpl(Keyboard.LEFT, cell));
cell.getAdjacents().add(new EdgeImpl(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 void createVerticalAdjacent(service.interfaces.Cell cell) {
this.adjacents.add(new EdgeImpl(Keyboard.UP, cell));
cell.getAdjacents().add(new EdgeImpl(Keyboard.DOWN, this));
}

@Override
Expand All @@ -55,7 +57,7 @@ public String valueToText() {

@Override
public Edge getAdjacentByKeyCode(Keyboard key) {
Adjacent edge = new Adjacent(key, null);
EdgeImpl edge = new EdgeImpl(key, null);
Integer indexEdge = this.adjacents.indexOf(edge);
return Optional.of(indexEdge)
.filter(index -> index != -1)
Expand All @@ -64,26 +66,26 @@ public Edge getAdjacentByKeyCode(Keyboard key) {
}

@Override
public Vertex click(Keyboard key) {
public service.interfaces.Cell click(Keyboard key) {
Edge adjacent = this.getAdjacentByKeyCode(key);
return this.movement(adjacent);
}

private Vertex movement(Edge adjacent) {
private service.interfaces.Cell movement(Edge adjacent) {
return Optional.ofNullable(adjacent)
.map(Edge::getCell)
.map(this::swapCells)
.orElse(this);
}

private Vertex swapCells(Vertex movementCell) {
private service.interfaces.Cell swapCells(service.interfaces.Cell movementCell) {
this.setValue(movementCell.getValue());
movementCell.setValue(0);
return movementCell;
}

@Override
public Vertex swapCells(Integer value) {
public service.interfaces.Cell swapCells(Integer value) {
return this.adjacents.stream()
.filter(adjacent -> Objects.equals(adjacent.getCell().getValue(), value))
.findFirst()
Expand All @@ -97,13 +99,13 @@ public List<Edge> getAdjacents() {
}

@Override
public void addAdjacents(Edge edge) {
public void addAdjacent(Edge edge) {
this.adjacents.add(edge);
}

@Override
public boolean equals(Object obj) {
return Objects.equals(this.value, ((Cell) obj).value);
return Objects.equals(this.value, ((CellImpl) obj).value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
* 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 service;

import service.interfaces.Edge;
import service.interfaces.Cell;
import util.Keyboard;

import interfaces.Edge;
import interfaces.Vertex;
import java.util.Objects;

/**
*
* @author allen
*/
public class Adjacent implements Edge{
public class EdgeImpl implements Edge{

private final Keyboard key;
private final Vertex cell;
private final Cell cell;

public Adjacent(Keyboard key, Vertex cell) {
public EdgeImpl(Keyboard key, Cell cell) {
this.key = key;
this.cell = cell;
}
Expand All @@ -28,13 +30,13 @@ public Keyboard getKey() {
}

@Override
public Vertex getCell() {
public Cell getCell() {
return this.cell;
}

@Override
public boolean equals(Object obj) {
return Objects.equals(((Adjacent) obj).getKey(), this.getKey());
return Objects.equals(((EdgeImpl) obj).getKey(), this.getKey());
}

}
Loading