├── src ├── main │ ├── java │ │ ├── .gitkeep │ │ ├── gui │ │ │ ├── package-info.java │ │ │ ├── Main.java │ │ │ ├── GameApplication.java │ │ │ ├── PlayerNameController.java │ │ │ ├── StartController.java │ │ │ ├── ScoreBoardController.java │ │ │ └── GameController.java │ │ ├── model │ │ │ ├── package-info.java │ │ │ ├── States.java │ │ │ ├── Cell.java │ │ │ └── Table.java │ │ └── jsondatas │ │ │ ├── package-info.java │ │ │ ├── PlayerDatas.java │ │ │ ├── PlayersRep.java │ │ │ ├── Repository.java │ │ │ ├── GsonRepository.java │ │ │ └── JsonMaker.java │ └── resources │ │ ├── .gitkeep │ │ ├── tinylog.properties │ │ ├── goal.png │ │ ├── piece.png │ │ ├── start.png │ │ ├── white.png │ │ ├── circle.png │ │ ├── coverRec.png │ │ ├── rectangle.png │ │ ├── scoreBoard.fxml │ │ ├── startPage.fxml │ │ ├── playerName.fxml │ │ └── game.fxml ├── test │ ├── java │ │ ├── .gitkeep │ │ ├── jsondatas │ │ │ └── JsonMakerTest.java │ │ └── model │ │ │ └── TableTest.java │ └── resources │ │ └── .gitkeep └── site │ └── site.xml ├── README.md ├── checkstyle.xml ├── testF.json ├── winners.json ├── .gitignore ├── pom.xml └── LICENSE /src/main/java/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/java/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | level = info -------------------------------------------------------------------------------- /src/main/resources/goal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Whisky92/GameProject/HEAD/src/main/resources/goal.png -------------------------------------------------------------------------------- /src/main/resources/piece.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Whisky92/GameProject/HEAD/src/main/resources/piece.png -------------------------------------------------------------------------------- /src/main/resources/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Whisky92/GameProject/HEAD/src/main/resources/start.png -------------------------------------------------------------------------------- /src/main/resources/white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Whisky92/GameProject/HEAD/src/main/resources/white.png -------------------------------------------------------------------------------- /src/main/resources/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Whisky92/GameProject/HEAD/src/main/resources/circle.png -------------------------------------------------------------------------------- /src/main/resources/coverRec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Whisky92/GameProject/HEAD/src/main/resources/coverRec.png -------------------------------------------------------------------------------- /src/main/resources/rectangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Whisky92/GameProject/HEAD/src/main/resources/rectangle.png -------------------------------------------------------------------------------- /src/main/java/gui/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A package for containing the GUI of the model, with which the user can interact. 3 | */ 4 | 5 | package gui; 6 | -------------------------------------------------------------------------------- /src/main/java/model/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A package containing the model of the program, that provides the basic functionality. 3 | */ 4 | 5 | package model; -------------------------------------------------------------------------------- /src/main/java/jsondatas/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A package containing the necessary classes for storing the data to a json file and reading from the file. 3 | */ 4 | 5 | package jsondatas; -------------------------------------------------------------------------------- /src/main/java/jsondatas/PlayerDatas.java: -------------------------------------------------------------------------------- 1 | package jsondatas; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | @Builder 7 | public class PlayerDatas { 8 | 9 | String name; 10 | int steps; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/model/States.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | /** 4 | * An enum for containing the possible states of cells 5 | */ 6 | public enum States { 7 | EMPTY, 8 | START, 9 | CIRCLE, 10 | RECTANGLE, 11 | GOAL; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/jsondatas/PlayersRep.java: -------------------------------------------------------------------------------- 1 | package jsondatas; 2 | 3 | public class PlayersRep extends GsonRepository { 4 | 5 | /** 6 | * A constructor for PlayersRep 7 | */ 8 | public PlayersRep() { 9 | super(PlayerDatas.class); 10 | } 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/gui/Main.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import javafx.application.Application; 4 | import org.tinylog.Logger; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | Logger.trace("Entering the main method in Main class"); 9 | Application.launch(GameApplication.class, args); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About the Game 2 | 3 | There is a board, on which we have some rectangles, circles and empty cells. 4 | From the top-left corner of the table you have to move the figure to the bottom-left corner. 5 | We can move on the table both horizontally and vertically, by doing 2 or 3 steps in each turn. But in the first turn we can only make 2 steps. 6 | We can't step on rectangles (dark cells), and stepping on a circle results in a step forward or backward depending on the number of steps we make. 7 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | org.apache.maven.skins 10 | maven-fluido-skin 11 | 1.10.0 12 | 13 | 14 | -------------------------------------------------------------------------------- /checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/gui/GameApplication.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import javafx.application.Application; 4 | import javafx.fxml.FXMLLoader; 5 | import javafx.scene.Parent; 6 | import javafx.scene.Scene; 7 | import javafx.stage.Stage; 8 | import org.tinylog.Logger; 9 | 10 | import java.io.IOException; 11 | 12 | 13 | public class GameApplication extends Application { 14 | 15 | @Override 16 | public void start(Stage stage) throws IOException { 17 | Logger.trace("Entering the start method of GameApplication class"); 18 | Parent root = FXMLLoader.load(getClass().getResource("/startPage.fxml")); 19 | stage.setTitle("Table Game"); 20 | Scene scene = new Scene(root); 21 | stage.setScene(scene); 22 | stage.setResizable(false); 23 | stage.show(); 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/gui/PlayerNameController.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import javafx.event.ActionEvent; 4 | import javafx.fxml.FXML; 5 | import javafx.fxml.FXMLLoader; 6 | import javafx.scene.Node; 7 | import javafx.scene.Parent; 8 | import javafx.scene.Scene; 9 | import javafx.scene.control.Button; 10 | import javafx.scene.control.TextField; 11 | import javafx.stage.Stage; 12 | import org.tinylog.Logger; 13 | 14 | import java.io.IOException; 15 | 16 | public class PlayerNameController { 17 | 18 | @FXML 19 | Button playerNameButton; 20 | 21 | @FXML 22 | TextField playerNameTextField; 23 | 24 | @FXML 25 | private void handlePlayerName(ActionEvent event) throws IOException { 26 | Logger.trace("Entering the handlePlayerName method of PlayerNameController class"); 27 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/game.fxml")); 28 | Parent root = fxmlLoader.load(); 29 | GameController gameController = fxmlLoader.getController(); 30 | gameController.setPlayerName(playerNameTextField.getText()); 31 | Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); 32 | Scene scene = new Scene(root); 33 | stage.setScene(scene); 34 | stage.show(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/jsondatas/JsonMakerTest.java: -------------------------------------------------------------------------------- 1 | package jsondatas; 2 | 3 | import model.Table; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.FileNotFoundException; 7 | import java.io.IOException; 8 | import java.io.PrintWriter; 9 | import java.util.List; 10 | 11 | import static org.junit.jupiter.api.Assertions.*; 12 | 13 | class JsonMakerTest { 14 | 15 | @Test 16 | void testFileReadandWrite() 17 | { 18 | Table testTable = new Table(); 19 | int s = testTable.getStepCounter(); 20 | String n = "testPlayer"; 21 | 22 | JsonMaker jsonMakerTest = new JsonMaker(); 23 | try { 24 | jsonMakerTest.saveToFile("testF.json",n, s); 25 | } catch (IOException ex) { 26 | throw new RuntimeException(ex); 27 | } 28 | 29 | List players; 30 | try { 31 | players = jsonMakerTest.readFromFile("testF.json"); 32 | } catch (IOException e) { 33 | throw new RuntimeException(e); 34 | } 35 | int fileStep = players.get(players.size()-1).steps; 36 | String fileName = players.get(players.size()-1).name; 37 | assertEquals(n, fileName); 38 | assertEquals(s, fileStep); 39 | 40 | 41 | 42 | 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /testF.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "testPlayer", 4 | "steps": 0 5 | }, 6 | { 7 | "name": "testPlayer", 8 | "steps": 0 9 | }, 10 | { 11 | "name": "testPlayer", 12 | "steps": 0 13 | }, 14 | { 15 | "name": "testPlayer", 16 | "steps": 0 17 | }, 18 | { 19 | "name": "testPlayer", 20 | "steps": 0 21 | }, 22 | { 23 | "name": "testPlayer", 24 | "steps": 0 25 | }, 26 | { 27 | "name": "testPlayer", 28 | "steps": 0 29 | }, 30 | { 31 | "name": "testPlayer", 32 | "steps": 0 33 | }, 34 | { 35 | "name": "testPlayer", 36 | "steps": 0 37 | }, 38 | { 39 | "name": "testPlayer", 40 | "steps": 0 41 | }, 42 | { 43 | "name": "testPlayer", 44 | "steps": 0 45 | }, 46 | { 47 | "name": "testPlayer", 48 | "steps": 0 49 | }, 50 | { 51 | "name": "testPlayer", 52 | "steps": 0 53 | }, 54 | { 55 | "name": "testPlayer", 56 | "steps": 0 57 | }, 58 | { 59 | "name": "testPlayer", 60 | "steps": 0 61 | }, 62 | { 63 | "name": "testPlayer", 64 | "steps": 0 65 | }, 66 | { 67 | "name": "testPlayer", 68 | "steps": 0 69 | }, 70 | { 71 | "name": "testPlayer", 72 | "steps": 0 73 | }, 74 | { 75 | "name": "testPlayer", 76 | "steps": 0 77 | } 78 | ] -------------------------------------------------------------------------------- /src/main/java/jsondatas/Repository.java: -------------------------------------------------------------------------------- 1 | package jsondatas; 2 | 3 | import org.tinylog.Logger; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.List; 8 | import java.util.function.Predicate; 9 | 10 | public abstract class Repository { 11 | 12 | protected Class elementType; 13 | 14 | protected List elements; 15 | 16 | /** 17 | * A constructor for Repository class 18 | * @param elementType the type of used object 19 | */ 20 | protected Repository(Class elementType) { 21 | Logger.info("Entering the constructor of Repository class"); 22 | this.elementType = elementType; 23 | elements = new ArrayList<>(); 24 | } 25 | 26 | /** 27 | * A function that adds the element given as a parameter to the List of elements 28 | * @param element the element being added 29 | */ 30 | public void add(T element) { 31 | Logger.info("Entering the add method of Repository class"); 32 | elements.add(element); 33 | } 34 | 35 | /** 36 | * {@return the unmodifiable List of elements} 37 | */ 38 | public List findAll() { 39 | Logger.info("Entering the findAll method of Repository class"); 40 | return Collections.unmodifiableList(elements); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/main/java/model/Cell.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import org.tinylog.Logger; 4 | 5 | import java.awt.*; 6 | 7 | /** 8 | * A class containing the properties of a Cell 9 | */ 10 | public class Cell { 11 | Point p; 12 | States st; 13 | 14 | /** 15 | * A constructor for create a cell instance 16 | * @param a the x coordinate of the point 17 | * @param b the y coordinate of the point 18 | */ 19 | public Cell(int a, int b) 20 | { 21 | Logger.info("Invoking the constructor of Cell class"); 22 | p = new Point(a, b); 23 | st=States.EMPTY; 24 | } 25 | /** 26 | * Set the state of a cell to the given state 27 | * @param s a state to which the state member of the class instance will be set 28 | */ 29 | public void setState(States s) 30 | { 31 | Logger.info("Using the setState method of Cell class"); 32 | st=s; 33 | } 34 | 35 | /** 36 | * Returns with the state of the cell 37 | * @return the state of the cell 38 | */ 39 | public States getState() 40 | { 41 | Logger.info("Using the getState method of Cell class"); 42 | return st; 43 | } 44 | 45 | /** 46 | * Returns with the position of the cell 47 | * @return the position of the cell 48 | */ 49 | public Point getPosition() 50 | { 51 | Logger.info("Using the getPosition method of Cell class"); 52 | return p; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/gui/StartController.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import javafx.event.ActionEvent; 4 | import javafx.fxml.FXML; 5 | import javafx.fxml.FXMLLoader; 6 | import javafx.scene.Node; 7 | import javafx.scene.Parent; 8 | import javafx.scene.Scene; 9 | import javafx.scene.control.Button; 10 | import javafx.stage.Stage; 11 | import org.tinylog.Logger; 12 | 13 | import java.io.IOException; 14 | 15 | public class StartController { 16 | @FXML 17 | Button playButton; 18 | @FXML 19 | Button statsButton; 20 | 21 | 22 | @FXML 23 | private void handleStartButton(ActionEvent event) throws IOException { 24 | Logger.trace("Entering the handleStartButton method of StartController class"); 25 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/playerName.fxml")); 26 | Parent root = fxmlLoader.load(); 27 | Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); 28 | Scene scene = new Scene(root); 29 | stage.setScene(scene); 30 | stage.show(); 31 | } 32 | 33 | @FXML 34 | private void handleScoreboardButton(ActionEvent event) throws IOException { 35 | Logger.trace("Scoreboard button is pressed"); 36 | Logger.info("Scoreboard will appear"); 37 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/scoreBoard.fxml")); 38 | Parent root = fxmlLoader.load(); 39 | Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); 40 | Scene scene = new Scene(root); 41 | stage.setScene(scene); 42 | stage.show(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/resources/scoreBoard.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/resources/startPage.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 20 | 28 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/resources/playerName.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/jsondatas/GsonRepository.java: -------------------------------------------------------------------------------- 1 | package jsondatas; 2 | 3 | import java.io.File; 4 | import java.io.FileReader; 5 | import java.io.FileWriter; 6 | import java.io.IOException; 7 | import java.util.List; 8 | 9 | import com.google.gson.Gson; 10 | import com.google.gson.GsonBuilder; 11 | import com.google.gson.reflect.TypeToken; 12 | import org.tinylog.Logger; 13 | 14 | public class GsonRepository extends Repository { 15 | 16 | private static final Gson GSON = new GsonBuilder() 17 | .setPrettyPrinting() 18 | .create(); 19 | 20 | /** 21 | * A constructor for the GsonRepository class 22 | * @param elementType the type of element being used 23 | */ 24 | public GsonRepository(Class elementType) { 25 | super(elementType); 26 | } 27 | 28 | /** 29 | * A method for reading the data from the file given in parameter 30 | * @param file the file from which the data is being read 31 | * @throws IOException 32 | */ 33 | public void loadFromFile(File file) throws IOException { 34 | Logger.info("Entering the loadFromFile method of GsonRepository class"); 35 | try (var reader = new FileReader(file)) { 36 | var listType = TypeToken.getParameterized(List.class, elementType).getType(); 37 | elements = GSON.fromJson(reader, listType); 38 | } 39 | 40 | } 41 | 42 | /** 43 | * A method for saving the data for the file given in parameter 44 | * @param file the file in which the data will be stored 45 | * @throws IOException 46 | */ 47 | public void saveToFile(File file) throws IOException { 48 | Logger.info("Entering the saveToFile method of GsonRepository class"); 49 | try (var writer = new FileWriter(file)) { 50 | GSON.toJson(elements, writer); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/jsondatas/JsonMaker.java: -------------------------------------------------------------------------------- 1 | package jsondatas; 2 | 3 | 4 | import org.tinylog.Logger; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.util.List; 9 | 10 | public class JsonMaker { 11 | 12 | /** 13 | * Saves the winner of the game with name and the number of steps they made 14 | * @param jsonFile the file where the data will be saved 15 | * @param name String, name of the player 16 | * @param step the number of steps the player made 17 | * @throws IOException an error in case data can't be saved to the file for some reasons 18 | */ 19 | public void saveToFile(String jsonFile, String name, int step) throws IOException { 20 | Logger.trace("Entering to saveToFile method of JsonBuilder class"); 21 | var repository = new PlayersRep(); 22 | var data = PlayerDatas.builder().name(name).steps(step).build(); 23 | File dataFile = new File(jsonFile); 24 | if (dataFile.exists() == true) 25 | { 26 | Logger.info("The file exists"); 27 | repository.loadFromFile(dataFile); 28 | } 29 | repository.add(data); 30 | repository.saveToFile(dataFile); 31 | } 32 | 33 | /** 34 | * A method for reading data from the file given in parameter 35 | * @param jsonFile the file from which the data is being read 36 | * {@return list of player name-color pairs} 37 | * @throws IOException an error in case data can't be read from the file for some reasons 38 | */ 39 | 40 | public List readFromFile(String jsonFile) throws IOException { 41 | Logger.trace("Entering the readFromFile method of JsonMaker class"); 42 | var repository = new PlayersRep(); 43 | File dataFile = new File(jsonFile); 44 | repository.loadFromFile(dataFile); 45 | 46 | return repository.findAll(); 47 | } 48 | 49 | 50 | 51 | 52 | } -------------------------------------------------------------------------------- /src/main/java/gui/ScoreBoardController.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import javafx.collections.FXCollections; 4 | import javafx.collections.ObservableList; 5 | import javafx.event.ActionEvent; 6 | import javafx.fxml.FXML; 7 | import javafx.fxml.FXMLLoader; 8 | import javafx.scene.Node; 9 | import javafx.scene.Parent; 10 | import javafx.scene.Scene; 11 | import javafx.scene.control.Button; 12 | import javafx.scene.control.TableColumn; 13 | import javafx.scene.control.TableView; 14 | import javafx.scene.control.cell.PropertyValueFactory; 15 | import javafx.stage.Stage; 16 | 17 | import java.io.IOException; 18 | import java.util.List; 19 | 20 | import jsondatas.JsonMaker; 21 | import jsondatas.PlayerDatas; 22 | import org.tinylog.Logger; 23 | 24 | public class ScoreBoardController { 25 | 26 | @FXML 27 | private TableView dataTable; 28 | @FXML 29 | private TableColumn playerCol; 30 | @FXML 31 | private TableColumn stepCol; 32 | @FXML 33 | private Button backButton; 34 | 35 | JsonMaker builder = new JsonMaker(); 36 | 37 | @FXML 38 | private void initialize() throws IOException { 39 | Logger.trace("Scoreboard is initializing"); 40 | playerCol.setCellValueFactory(new PropertyValueFactory<>("name")); 41 | stepCol.setCellValueFactory(new PropertyValueFactory<>("steps")); 42 | List players = builder.readFromFile("winners.json"); 43 | ObservableList observableList = FXCollections.observableArrayList(); 44 | observableList.addAll(players); 45 | dataTable.setItems(observableList); 46 | } 47 | 48 | @FXML 49 | private void handleCancelButton(ActionEvent event) throws IOException { 50 | Logger.trace("Entering the handleCancelButton of ScoreBoardController"); 51 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/startPage.fxml")); 52 | Parent root = fxmlLoader.load(); 53 | Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); 54 | Scene scene = new Scene(root); 55 | stage.setScene(scene); 56 | stage.show(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /winners.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Tomi", 4 | "steps": 5 5 | }, 6 | { 7 | "name": "Player", 8 | "steps": 18 9 | }, 10 | { 11 | "name": "Player", 12 | "steps": 13 13 | }, 14 | { 15 | "name": "David", 16 | "steps": 6 17 | }, 18 | { 19 | "name": "Player", 20 | "steps": 13 21 | }, 22 | { 23 | "name": "Player", 24 | "steps": 13 25 | }, 26 | { 27 | "name": "Player", 28 | "steps": 11 29 | }, 30 | { 31 | "name": "Player", 32 | "steps": 23 33 | }, 34 | { 35 | "name": "Player", 36 | "steps": 11 37 | }, 38 | { 39 | "name": "Player", 40 | "steps": 6 41 | }, 42 | { 43 | "name": "Player", 44 | "steps": 6 45 | }, 46 | { 47 | "name": "Player", 48 | "steps": 6 49 | }, 50 | { 51 | "name": "Player", 52 | "steps": 6 53 | }, 54 | { 55 | "name": "Player", 56 | "steps": 6 57 | }, 58 | { 59 | "name": "Player", 60 | "steps": 6 61 | }, 62 | { 63 | "name": "Player", 64 | "steps": 6 65 | }, 66 | { 67 | "name": "Player", 68 | "steps": 6 69 | }, 70 | { 71 | "name": "Player", 72 | "steps": 6 73 | }, 74 | { 75 | "name": "Player", 76 | "steps": 6 77 | }, 78 | { 79 | "name": "Player", 80 | "steps": 59 81 | }, 82 | { 83 | "name": "Player", 84 | "steps": 6 85 | }, 86 | { 87 | "name": "Player", 88 | "steps": 6 89 | }, 90 | { 91 | "name": "Player", 92 | "steps": 5 93 | }, 94 | { 95 | "name": "Player", 96 | "steps": 5 97 | }, 98 | { 99 | "name": "Tmi", 100 | "steps": 103 101 | }, 102 | { 103 | "name": "Patrik2", 104 | "steps": 5 105 | }, 106 | { 107 | "name": "Player", 108 | "steps": 5 109 | }, 110 | { 111 | "name": "Player", 112 | "steps": 6 113 | }, 114 | { 115 | "name": "Zalan", 116 | "steps": 11 117 | }, 118 | { 119 | "name": "Davidka", 120 | "steps": 17 121 | }, 122 | { 123 | "name": "Player", 124 | "steps": 20 125 | }, 126 | { 127 | "name": "Player", 128 | "steps": 6 129 | }, 130 | { 131 | "name": "Player", 132 | "steps": 6 133 | }, 134 | { 135 | "name": "Player", 136 | "steps": 6 137 | }, 138 | { 139 | "name": "Player", 140 | "steps": 6 141 | }, 142 | { 143 | "name": "Lacika", 144 | "steps": 6 145 | }, 146 | { 147 | "name": "Player", 148 | "steps": 6 149 | }, 150 | { 151 | "name": "David2", 152 | "steps": 6 153 | }, 154 | { 155 | "name": "Laci", 156 | "steps": 6 157 | }, 158 | { 159 | "name": "Player", 160 | "steps": 11 161 | }, 162 | { 163 | "name": "Player", 164 | "steps": 23 165 | }, 166 | { 167 | "name": "Player", 168 | "steps": 14 169 | }, 170 | { 171 | "name": "Player", 172 | "steps": 13 173 | }, 174 | { 175 | "name": "Thomas", 176 | "steps": 6 177 | }, 178 | { 179 | "name": "Player", 180 | "steps": 60 181 | }, 182 | { 183 | "name": "Player", 184 | "steps": 6 185 | } 186 | ] -------------------------------------------------------------------------------- /src/main/resources/game.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 | 44 | 45 | 46 | 54 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/maven,intellij+all,eclipse,netbeans 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=maven,intellij+all,eclipse,netbeans 4 | 5 | ### Eclipse ### 6 | .metadata 7 | bin/ 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .settings/ 15 | .loadpath 16 | .recommenders 17 | 18 | # External tool builders 19 | .externalToolBuilders/ 20 | 21 | # Locally stored "Eclipse launch configurations" 22 | *.launch 23 | 24 | # PyDev specific (Python IDE for Eclipse) 25 | *.pydevproject 26 | 27 | # CDT-specific (C/C++ Development Tooling) 28 | .cproject 29 | 30 | # CDT- autotools 31 | .autotools 32 | 33 | # Java annotation processor (APT) 34 | .factorypath 35 | 36 | # PDT-specific (PHP Development Tools) 37 | .buildpath 38 | 39 | # sbteclipse plugin 40 | .target 41 | 42 | # Tern plugin 43 | .tern-project 44 | 45 | # TeXlipse plugin 46 | .texlipse 47 | 48 | # STS (Spring Tool Suite) 49 | .springBeans 50 | 51 | # Code Recommenders 52 | .recommenders/ 53 | 54 | # Annotation Processing 55 | .apt_generated/ 56 | .apt_generated_test/ 57 | 58 | # Scala IDE specific (Scala & Java development for Eclipse) 59 | .cache-main 60 | .scala_dependencies 61 | .worksheet 62 | 63 | # Uncomment this line if you wish to ignore the project description file. 64 | # Typically, this file would be tracked if it contains build/dependency configurations: 65 | #.project 66 | 67 | ### Eclipse Patch ### 68 | # Spring Boot Tooling 69 | .sts4-cache/ 70 | 71 | ### Intellij+all ### 72 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 73 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 74 | 75 | # User-specific stuff 76 | .idea/**/workspace.xml 77 | .idea/**/tasks.xml 78 | .idea/**/usage.statistics.xml 79 | .idea/**/dictionaries 80 | .idea/**/shelf 81 | 82 | # AWS User-specific 83 | .idea/**/aws.xml 84 | 85 | # Generated files 86 | .idea/**/contentModel.xml 87 | 88 | # Sensitive or high-churn files 89 | .idea/**/dataSources/ 90 | .idea/**/dataSources.ids 91 | .idea/**/dataSources.local.xml 92 | .idea/**/sqlDataSources.xml 93 | .idea/**/dynamic.xml 94 | .idea/**/uiDesigner.xml 95 | .idea/**/dbnavigator.xml 96 | 97 | # Gradle 98 | .idea/**/gradle.xml 99 | .idea/**/libraries 100 | 101 | # Gradle and Maven with auto-import 102 | # When using Gradle or Maven with auto-import, you should exclude module files, 103 | # since they will be recreated, and may cause churn. Uncomment if using 104 | # auto-import. 105 | # .idea/artifacts 106 | # .idea/compiler.xml 107 | # .idea/jarRepositories.xml 108 | # .idea/modules.xml 109 | # .idea/*.iml 110 | # .idea/modules 111 | # *.iml 112 | # *.ipr 113 | 114 | # CMake 115 | cmake-build-*/ 116 | 117 | # Mongo Explorer plugin 118 | .idea/**/mongoSettings.xml 119 | 120 | # File-based project format 121 | *.iws 122 | 123 | # IntelliJ 124 | out/ 125 | 126 | # mpeltonen/sbt-idea plugin 127 | .idea_modules/ 128 | 129 | # JIRA plugin 130 | atlassian-ide-plugin.xml 131 | 132 | # Cursive Clojure plugin 133 | .idea/replstate.xml 134 | 135 | # SonarLint plugin 136 | .idea/sonarlint/ 137 | 138 | # Crashlytics plugin (for Android Studio and IntelliJ) 139 | com_crashlytics_export_strings.xml 140 | crashlytics.properties 141 | crashlytics-build.properties 142 | fabric.properties 143 | 144 | # Editor-based Rest Client 145 | .idea/httpRequests 146 | 147 | # Android studio 3.1+ serialized cache file 148 | .idea/caches/build_file_checksums.ser 149 | 150 | ### Intellij+all Patch ### 151 | # Ignore everything but code style settings and run configurations 152 | # that are supposed to be shared within teams. 153 | 154 | .idea/* 155 | 156 | !.idea/codeStyles 157 | !.idea/runConfigurations 158 | 159 | ### Maven ### 160 | target/ 161 | pom.xml.tag 162 | pom.xml.releaseBackup 163 | pom.xml.versionsBackup 164 | pom.xml.next 165 | release.properties 166 | dependency-reduced-pom.xml 167 | buildNumber.properties 168 | .mvn/timing.properties 169 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 170 | .mvn/wrapper/maven-wrapper.jar 171 | 172 | # Eclipse m2e generated files 173 | # Eclipse Core 174 | .project 175 | # JDT-specific (Eclipse Java Development Tools) 176 | .classpath 177 | 178 | ### NetBeans ### 179 | **/nbproject/private/ 180 | **/nbproject/Makefile-*.mk 181 | **/nbproject/Package-*.bash 182 | build/ 183 | nbbuild/ 184 | dist/ 185 | nbdist/ 186 | .nb-gradle/ 187 | 188 | # End of https://www.toptal.com/developers/gitignore/api/maven,intellij+all,eclipse,netbeans 189 | -------------------------------------------------------------------------------- /src/test/java/model/TableTest.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.awt.*; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | class TableTest { 11 | 12 | @Test 13 | void isGoalState1() 14 | { 15 | Table testTable = new Table(); 16 | testTable.showPossibleSteps(); 17 | Point[] pointSequence = new Point[] { 18 | new Point(2,0), new Point(4,0), new Point(4,3), 19 | new Point(4,5), new Point(4,7), new Point(7,7) 20 | }; 21 | for(var point : pointSequence) 22 | { 23 | testTable.movePiece(point); 24 | } 25 | assertTrue(testTable.isGoalState()); 26 | } 27 | @Test 28 | void isGoalState2() 29 | { 30 | Table testTable = new Table(); 31 | assertFalse(testTable.isGoalState()); 32 | } 33 | 34 | @Test 35 | void showPossibleSteps1() 36 | { 37 | Table testTable = new Table(); 38 | testTable.showPossibleSteps(); 39 | assertTrue(testTable.getPossibleSteps().size()==2); 40 | assertTrue(testTable.getPossibleSteps().get(1).getPosition().x == 0 && testTable.getPossibleSteps().get(1).getPosition().y == 2); 41 | assertTrue(testTable.getPossibleSteps().get(0).getPosition().x == 2 && testTable.getPossibleSteps().get(0).getPosition().y == 0); 42 | } 43 | 44 | @Test 45 | void showPossibleSteps2() 46 | { 47 | Table testTable = new Table(); 48 | testTable.showPossibleSteps(); 49 | Point[] pointSequence = new Point[] { 50 | new Point(0,2), new Point(0,4), new Point(3,4) }; 51 | for(var point : pointSequence) 52 | testTable.movePiece(point); 53 | assertFalse(testTable.getPossibleSteps().size()==2); 54 | assertTrue(testTable.getPossibleSteps().size()==4); 55 | assertTrue(testTable.getPossibleSteps().get(0).getPosition().x == 3 && testTable.getPossibleSteps().get(0).getPosition().y == 2); 56 | assertTrue(testTable.getPossibleSteps().get(1).getPosition().x == 3 && testTable.getPossibleSteps().get(1).getPosition().y == 6); 57 | assertTrue(testTable.getPossibleSteps().get(2).getPosition().x == 1 && testTable.getPossibleSteps().get(2).getPosition().y == 4); 58 | assertTrue(testTable.getPossibleSteps().get(3).getPosition().x == 5 && testTable.getPossibleSteps().get(3).getPosition().y == 4); 59 | } 60 | 61 | @Test 62 | void showPossibleSteps3() 63 | { 64 | Table testTable = new Table(); 65 | testTable.showPossibleSteps(); 66 | Point[] pointSequence = new Point[] { 67 | new Point(0,2), new Point(0,4), new Point(3,4), 68 | new Point(3,2), new Point(3,5), new Point(3,2), 69 | new Point(3,4)}; 70 | for(var point : pointSequence) 71 | testTable.movePiece(point); 72 | assertFalse(testTable.getPossibleSteps().size()==2); 73 | assertTrue(testTable.getPossibleSteps().size()==4); 74 | assertTrue(testTable.getPossibleSteps().get(0).getPosition().x == 3 && testTable.getPossibleSteps().get(0).getPosition().y == 1); 75 | assertTrue(testTable.getPossibleSteps().get(1).getPosition().x == 3 && testTable.getPossibleSteps().get(1).getPosition().y == 7); 76 | assertTrue(testTable.getPossibleSteps().get(2).getPosition().x == 0 && testTable.getPossibleSteps().get(2).getPosition().y == 4); 77 | assertTrue(testTable.getPossibleSteps().get(3).getPosition().x == 6 && testTable.getPossibleSteps().get(3).getPosition().y == 4); 78 | } 79 | 80 | @Test 81 | void movePiece1() 82 | { 83 | Table testTable = new Table(); 84 | testTable.showPossibleSteps(); 85 | testTable.movePiece(new Point(0,2)); 86 | assertTrue(testTable.getPlayerPoint().x==0 && testTable.getPlayerPoint().y==2); 87 | } 88 | 89 | @Test 90 | void movePiece2() 91 | { 92 | Table testTable = new Table(); 93 | testTable.showPossibleSteps(); 94 | Point[] pointSequence = new Point[] { 95 | new Point(0,2), new Point(0,4) }; 96 | for(var point : pointSequence) 97 | testTable.movePiece(point); 98 | assertTrue(testTable.getPlayerPoint().x==0 && testTable.getPlayerPoint().y==4); 99 | } 100 | 101 | 102 | @Test 103 | void movePiece3() 104 | { 105 | Table testTable = new Table(); 106 | testTable.showPossibleSteps(); 107 | Point[] pointSequence = new Point[] { 108 | new Point(0,2), new Point(0,4), new Point(3,4) }; 109 | for(var point : pointSequence) 110 | testTable.movePiece(point); 111 | assertTrue(testTable.getPlayerPoint().x==3 && testTable.getPlayerPoint().y==4); 112 | } 113 | 114 | @Test 115 | void movePiece4() 116 | { 117 | Table testTable = new Table(); 118 | testTable.showPossibleSteps(); 119 | testTable.movePiece(new Point(0,1)); 120 | assertTrue(testTable.getPlayerPoint().x==0 && testTable.getPlayerPoint().y==0); 121 | } 122 | 123 | @Test 124 | void movePiece5() 125 | { 126 | Table testTable = new Table(); 127 | testTable.showPossibleSteps(); 128 | Point[] pointSequence = new Point[] { 129 | new Point(2,0), new Point(4,0), new Point(4,3), 130 | new Point(4,5), new Point(4,7), new Point(7,7) 131 | }; 132 | for(var point : pointSequence) 133 | { 134 | testTable.movePiece(point); 135 | } 136 | assertTrue(testTable.getPlayerPoint().x==7 && testTable.getPlayerPoint().y==7); 137 | } 138 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | hu.unideb.inf 7 | table.game 8 | 1.0 9 | A game in which you have to reach the goal cell by making 2 or 3 steps in each turn. 10 | 11 | 12 | olahtomi92 13 | Tamas Olah 14 | olah.tomi.92@gmail.com 15 | Faculty of Informatics, University of Debrecen 16 | https://www.inf.unideb.hu/ 17 | 18 | 19 | 20 | UTF-8 21 | UTF-8 22 | 17 23 | 18 24 | 5.8.2 25 | 3.3.2 26 | 3.1.2 27 | 3.0.0-M6 28 | 0.8.8 29 | 2.13.2.2 30 | 2.4.1 31 | gui.Main 32 | 33 | 34 | 35 | org.projectlombok 36 | lombok 37 | 1.18.24 38 | compile 39 | 40 | 41 | org.tinylog 42 | tinylog-api 43 | 2.4.1 44 | compile 45 | 46 | 47 | org.tinylog 48 | tinylog-impl 49 | 2.4.1 50 | runtime 51 | 52 | 53 | com.google.code.gson 54 | gson 55 | 2.9.0 56 | 57 | 58 | org.openjfx 59 | javafx-controls 60 | ${javafx.version} 61 | compile 62 | 63 | 64 | org.openjfx 65 | javafx-fxml 66 | ${javafx.version} 67 | compile 68 | 69 | 70 | org.junit.jupiter 71 | junit-jupiter-engine 72 | ${junit.jupiter.version} 73 | test 74 | 75 | 76 | org.junit.jupiter 77 | junit-jupiter-params 78 | ${junit.jupiter.version} 79 | test 80 | 81 | 82 | com.fasterxml.jackson.core 83 | jackson-databind 84 | ${jackson.version} 85 | compile 86 | 87 | 88 | com.fasterxml.jackson.core 89 | jackson-annotations 90 | 2.13.2 91 | compile 92 | 93 | 94 | com.fasterxml.jackson.datatype 95 | jackson-datatype-jsr310 96 | 2.13.2 97 | compile 98 | 99 | 100 | 101 | 102 | 103 | org.apache.maven.plugins 104 | maven-compiler-plugin 105 | 3.10.1 106 | 107 | 108 | org.apache.maven.plugins 109 | maven-site-plugin 110 | 3.11.0 111 | 112 | 113 | org.apache.maven.plugins 114 | maven-javadoc-plugin 115 | ${maven.javadoc.version} 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-surefire-plugin 120 | ${maven.surefire.version} 121 | 122 | 123 | org.jacoco 124 | jacoco-maven-plugin 125 | ${jacoco.version} 126 | 127 | 128 | initialize 129 | 130 | prepare-agent 131 | 132 | 133 | 134 | 135 | 136 | org.apache.maven.plugins 137 | maven-checkstyle-plugin 138 | ${maven.checkstyle.version} 139 | 140 | 141 | com.puppycrawl.tools 142 | checkstyle 143 | 10.1 144 | 145 | 146 | 147 | 148 | org.apache.maven.plugins 149 | maven-shade-plugin 150 | 3.3.0 151 | 152 | 153 | 154 | shade 155 | 156 | 157 | false 158 | 159 | 160 | ${exec.mainClass} 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | org.apache.maven.plugins 173 | maven-jxr-plugin 174 | 3.2.0 175 | 176 | 177 | org.apache.maven.plugins 178 | maven-javadoc-plugin 179 | ${maven.javadoc.version} 180 | 181 | 182 | 183 | javadoc 184 | 185 | 186 | 187 | 188 | 189 | org.apache.maven.plugins 190 | maven-surefire-report-plugin 191 | ${maven.surefire.version} 192 | 193 | 194 | org.jacoco 195 | jacoco-maven-plugin 196 | ${jacoco.version} 197 | 198 | 199 | 200 | report 201 | 202 | 203 | 204 | 205 | 206 | org.apache.maven.plugins 207 | maven-checkstyle-plugin 208 | ${maven.checkstyle.version} 209 | 210 | checkstyle.xml 211 | 212 | 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/main/java/model/Table.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import org.tinylog.Logger; 4 | 5 | import java.awt.*; 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.LinkedList; 9 | 10 | import static java.lang.String.format; 11 | public class Table { 12 | 13 | private final int tableSize = 8; 14 | private int stepCounter = 0; 15 | private int steps = 2; 16 | 17 | private LinkedList possibleSteps = new LinkedList<>(); 18 | 19 | private Point playerPoint = new Point(0, 0); 20 | Cell gameTable[][] = new Cell[tableSize][tableSize]; 21 | 22 | private Point[] PositionsOfCircleTiles = new Point[] 23 | { 24 | new Point(0, 4), 25 | new Point(1, 2), 26 | new Point(1, 6), 27 | new Point(3, 2), 28 | new Point(3, 4), 29 | new Point(4, 0), 30 | new Point(4, 3), 31 | new Point(4, 7), 32 | new Point(5, 3), 33 | new Point(5, 6), 34 | new Point(6, 2), 35 | new Point(6, 7), 36 | new Point(7, 0) 37 | }; 38 | 39 | 40 | private Point[] PositionsOfRectangleTiles = new Point[] 41 | { 42 | new Point(2, 2), 43 | new Point(2, 7), 44 | new Point(4, 1), 45 | new Point(5, 5), 46 | new Point(7, 3) 47 | }; 48 | private Point startPosition = new Point(0, 0); 49 | private Point goalPosition = new Point(7, 7); 50 | 51 | /** 52 | * Creates a {@code Table} object that corresponds to the original 53 | * initial state to the puzzle. 54 | */ 55 | public Table() { 56 | Logger.info("Using the constructor of Table class"); 57 | playerPoint.x = 0; 58 | playerPoint.y = 0; 59 | 60 | for (int i = 0; i < tableSize; i++) { 61 | for (int j = 0; j < tableSize; j++) { 62 | gameTable[i][j] = new Cell(i, j); 63 | addStatesToTableCells(i, j); 64 | } 65 | } 66 | } 67 | 68 | /** 69 | * Returns with the position of the player 70 | * @return the position of the player 71 | */ 72 | public Point getPlayerPoint() 73 | { 74 | return playerPoint; 75 | } 76 | 77 | /** 78 | * Returns with the gametable 79 | * @return the gametable that is getting returned 80 | */ 81 | public Cell[][] getGameTable() 82 | { 83 | Logger.info("Using the getGameTable method of Table class"); 84 | return gameTable; 85 | } 86 | 87 | /** 88 | * Returns with the LinkedList containing the possible steps 89 | * 90 | * @return the LinkedList which contains the possible steps 91 | */ 92 | public LinkedList getPossibleSteps() 93 | { 94 | Logger.info("Using the getPossibleSteps method of Table class"); 95 | return possibleSteps; 96 | } 97 | 98 | /** 99 | * Returns with the stepCounter, that counts the number of moves 100 | * 101 | * @return the variable containing the number of moves made 102 | */ 103 | public int getStepCounter() 104 | { 105 | Logger.info("Using the getStepCounter method of Table class"); 106 | return stepCounter; 107 | } 108 | 109 | /** 110 | * 111 | * {@return whether the current state of the game is GoalState or not} 112 | */ 113 | public boolean isGoalState() 114 | { 115 | return playerPoint.x==7 && playerPoint.y==7; 116 | } 117 | 118 | /** 119 | * Moves the piece to the point given as parameter. 120 | * 121 | * @param p the point where the point has to go 122 | */ 123 | public void movePiece(Point p) { 124 | Logger.trace("Entering the movePiece method of Table with Point {}",p); 125 | boolean contain = false; 126 | for (Cell cell : possibleSteps) { 127 | if (p.x == cell.getPosition().x && p.y == cell.getPosition().y) 128 | contain = true; 129 | } 130 | if (!contain) { 131 | Logger.warn("You can't step on this cell"); 132 | } else { 133 | Cell c = cellOfGivenPos(p); 134 | if(c.getState()==States.GOAL) { 135 | playerPoint.x=p.x; 136 | playerPoint.y=p.y; 137 | Logger.info("Goal successfully reached!"); 138 | }else if(c.getState()==States.CIRCLE) { 139 | Logger.info("Entered to a Cell with Circle State"); 140 | if(steps==2) 141 | steps=3; 142 | else 143 | steps=2; 144 | playerPoint.x=p.x; 145 | playerPoint.y=p.y; 146 | }else{ 147 | Logger.info("Entered to a cell with Empty or Start State"); 148 | playerPoint.x=p.x; 149 | playerPoint.y=p.y; 150 | } 151 | } 152 | stepCounter++; 153 | Logger.info("Player's current position: x: {} y: {}", playerPoint.x, playerPoint.y); 154 | Logger.info("Possible steps:"); 155 | showPossibleSteps(); 156 | } 157 | 158 | /** 159 | * Shows the cells where the piece is able to step to. 160 | */ 161 | public void showPossibleSteps() 162 | { 163 | Logger.info("Entering to the showPossibleSteps method of Table class"); 164 | possibleSteps.clear(); 165 | if(stepCounter==0) { 166 | showStepsIfStart(); 167 | for(Cell c : possibleSteps){ 168 | Logger.info("x: {}, y: {}",c.getPosition().x, c.getPosition().y); 169 | } 170 | } else { 171 | showSteps(); 172 | for(Cell c : possibleSteps) { 173 | Logger.info("x: {}, y: {}", c.getPosition().x, c.getPosition().y); 174 | } 175 | } 176 | } 177 | 178 | private void showStepsIfStart() 179 | { 180 | Logger.info("Entering to the showPossibleStepsIfStart method of Table class"); 181 | if(correctCell(getRightTwo(playerPoint))) 182 | possibleSteps.add(cellOfGivenPos(getRightTwo(playerPoint).get(1))); 183 | if(correctCell(getDownTwo(playerPoint))) 184 | possibleSteps.add(cellOfGivenPos(getDownTwo(playerPoint).get(1))); 185 | } 186 | 187 | 188 | private void showSteps() 189 | { 190 | Logger.info("Entering to the showSteps method of Table class"); 191 | if(steps==2) { 192 | Logger.info("Steps: {}", steps); 193 | if (correctCell(getUpTwo(playerPoint))) 194 | possibleSteps.add(cellOfGivenPos(getUpTwo(playerPoint).get(1))); 195 | if (correctCell(getDownTwo(playerPoint))) 196 | possibleSteps.add(cellOfGivenPos(getDownTwo(playerPoint).get(1))); 197 | if (correctCell(getLeftTwo(playerPoint))) 198 | possibleSteps.add(cellOfGivenPos(getLeftTwo(playerPoint).get(1))); 199 | if (correctCell(getRightTwo(playerPoint))) 200 | possibleSteps.add(cellOfGivenPos(getRightTwo(playerPoint).get(1))); 201 | }else { 202 | Logger.info("Steps: {}", steps); 203 | if (correctCell(getUpThree(playerPoint))) 204 | possibleSteps.add(cellOfGivenPos(getUpThree(playerPoint).get(1))); 205 | if (correctCell(getDownThree(playerPoint))) 206 | possibleSteps.add(cellOfGivenPos(getDownThree(playerPoint).get(1))); 207 | if (correctCell(getLeftThree(playerPoint))) 208 | possibleSteps.add(cellOfGivenPos(getLeftThree(playerPoint).get(1))); 209 | if (correctCell(getRightThree(playerPoint))) 210 | possibleSteps.add(cellOfGivenPos(getRightThree(playerPoint).get(1))); 211 | } 212 | } 213 | 214 | 215 | 216 | private void addStatesToTableCells(int a, int b) { 217 | Point temporaryPosition = new Point(a, b); 218 | Logger.info("Entering the addStatesToTableCells with {} and {} coordinates",a,b); 219 | if (checkIfArrayContainsPoint(temporaryPosition, PositionsOfCircleTiles)) 220 | gameTable[a][b].setState(States.CIRCLE); 221 | else if (checkIfArrayContainsPoint(temporaryPosition, PositionsOfRectangleTiles)) 222 | gameTable[a][b].setState(States.RECTANGLE); 223 | else if (temporaryPosition.getX() == startPosition.getX() && temporaryPosition.getY() == startPosition.getY()) 224 | gameTable[a][b].setState(States.START); 225 | else if (temporaryPosition.getX() == goalPosition.getX() && temporaryPosition.getY() == goalPosition.getY()) 226 | gameTable[a][b].setState(States.GOAL); 227 | else 228 | gameTable[a][b].setState(States.EMPTY); 229 | 230 | } 231 | 232 | 233 | private boolean correctCell(ArrayList points) 234 | { 235 | Logger.info("Entering the correctCell method of Table class"); 236 | if(!partOfTable(points.get(1))) 237 | return false; 238 | else 239 | if(cellOfGivenPos(points.get(1)).getState()==States.RECTANGLE) 240 | return false; 241 | else 242 | return true; 243 | } 244 | 245 | 246 | private boolean partOfTable(Point p) 247 | { 248 | Logger.info("Entering to the partOfTable method with Point {}",p); 249 | if(p.x>=0 && p.x=0 && p.y getRightTwo(Point p) 289 | { 290 | Logger.info("Entering to the getRightTwo method with Point {}",p); 291 | return new ArrayList<>(Arrays.asList(p, new Point((playerPoint.x)+2, playerPoint.y))); 292 | } 293 | 294 | private ArrayList getRightThree(Point p) 295 | { 296 | Logger.info("Entering to the getRightThree method with Point {}",p); 297 | return new ArrayList<>(Arrays.asList(p, new Point((playerPoint.x)+3, playerPoint.y))); 298 | } 299 | 300 | 301 | private ArrayList getLeftTwo(Point p) 302 | { 303 | Logger.info("Entering to the getLeftTwo method with Point {}",p); 304 | return new ArrayList<>(Arrays.asList(p, new Point((playerPoint.x)-2, playerPoint.y))); 305 | } 306 | 307 | private ArrayList getLeftThree(Point p) 308 | { 309 | Logger.info("Entering to the getLeftThree method with Point {}",p); 310 | return new ArrayList<>(Arrays.asList(p, new Point((playerPoint.x)-3, playerPoint.y))); 311 | } 312 | 313 | private ArrayList getDownTwo(Point p) 314 | { 315 | Logger.info("Entering to the getDownTwo method with Point {}",p); 316 | return new ArrayList<>(Arrays.asList(p, new Point(playerPoint.x, (playerPoint.y)+2))); 317 | } 318 | 319 | private ArrayList getDownThree(Point p) 320 | { 321 | Logger.info("Entering to the getDownThree method with Point {}",p); 322 | return new ArrayList<>(Arrays.asList(p, new Point(playerPoint.x, (playerPoint.y)+3))); 323 | } 324 | 325 | 326 | private ArrayList getUpTwo(Point p) 327 | { 328 | Logger.info("Entering to the getUpTwo method with Point {}",p); 329 | return new ArrayList<>(Arrays.asList(p, new Point(playerPoint.x, (playerPoint.y)-2))); 330 | } 331 | 332 | private ArrayList getUpThree(Point p) 333 | { 334 | Logger.info("Entering to the getUpThree method with Point {}",p); 335 | return new ArrayList<>(Arrays.asList(p, new Point(playerPoint.x, (playerPoint.y)-3))); 336 | } 337 | 338 | 339 | } 340 | -------------------------------------------------------------------------------- /src/main/java/gui/GameController.java: -------------------------------------------------------------------------------- 1 | package gui; 2 | 3 | import javafx.beans.property.IntegerProperty; 4 | import javafx.beans.property.SimpleIntegerProperty; 5 | import javafx.beans.property.SimpleStringProperty; 6 | import javafx.beans.property.StringProperty; 7 | import javafx.fxml.FXMLLoader; 8 | import javafx.geometry.Insets; 9 | import javafx.geometry.Pos; 10 | import javafx.scene.Node; 11 | import javafx.scene.Parent; 12 | import javafx.scene.Scene; 13 | import javafx.scene.control.Button; 14 | import javafx.scene.control.Label; 15 | import javafx.scene.control.TextField; 16 | import javafx.scene.input.MouseEvent; 17 | import javafx.scene.layout.*; 18 | import javafx.scene.paint.Color; 19 | import javafx.scene.text.Font; 20 | import javafx.stage.Modality; 21 | import javafx.stage.Stage; 22 | import jsondatas.JsonMaker; 23 | import model.Cell; 24 | import java.awt.Point; 25 | import model.States; 26 | import model.Table; 27 | import javafx.fxml.FXML; 28 | import javafx.scene.image.Image; 29 | import javafx.scene.image.ImageView; 30 | import org.tinylog.Logger; 31 | import java.io.IOException; 32 | import java.util.ArrayList; 33 | import java.util.LinkedList; 34 | 35 | public class GameController { 36 | @FXML 37 | private GridPane board; 38 | @FXML 39 | private StackPane outerPane; 40 | @FXML 41 | private HBox hBoxContainer; 42 | @FXML 43 | private VBox vBoxContainer; 44 | @FXML 45 | private TextField stepTextField; 46 | @FXML 47 | private Label playerLabel = new Label(); 48 | private Image circleImage = new Image("circle.png"); 49 | private Image rectangleImage = new Image("rectangle.png"); 50 | private Image goalImage = new Image("goal.png"); 51 | private Image startImage = new Image("start.png"); 52 | private Image emptyImage = new Image("white.png"); 53 | private Image piece = new Image("piece.png"); 54 | private Image coverRec = new Image("coverRec.png"); 55 | private Table table = new Table(); 56 | 57 | JsonMaker jsonMaker = new JsonMaker(); 58 | 59 | private static StringProperty playerName = new SimpleStringProperty(); 60 | 61 | private ArrayList listOfPossibleStackPanes = new ArrayList(); 62 | 63 | private IntegerProperty stepCount = new SimpleIntegerProperty(); 64 | 65 | @FXML 66 | public void initialize() { 67 | Logger.info("Entering the initialize method in GameController class"); 68 | createBinding(); 69 | setProperties(); 70 | fillTableWithPicturesOfStates(); 71 | StackPane sp = getStackPaneByRowAndColIndex(0, 0); 72 | sp.getChildren().add(new ImageView(piece)); 73 | table.showPossibleSteps(); 74 | readValuesFromList(); 75 | } 76 | 77 | public void readValuesFromList() { 78 | Logger.info("Entering the readValuesFromList method in GameController class"); 79 | LinkedList listOfPositions = table.getPossibleSteps(); 80 | listOfPossibleStackPanes.clear(); 81 | for (int i = 0; i < listOfPositions.size(); i++) { 82 | int xPos = listOfPositions.get(i).getPosition().x; 83 | int yPos = listOfPositions.get(i).getPosition().y; 84 | StackPane temporaryPane = getStackPaneByRowAndColIndex(xPos, yPos); 85 | listOfPossibleStackPanes.add(temporaryPane); 86 | temporaryPane.getChildren().add(createRectangleToCover()); 87 | } 88 | Logger.info("Reaching the end of readValuesFromList method"); 89 | } 90 | 91 | private void handleMouseClick(MouseEvent e) { 92 | Logger.info("Entering the handleMouseClick method in GameController class"); 93 | StackPane source = (StackPane) e.getSource(); 94 | if (listOfPossibleStackPanes.contains(source)) { 95 | Logger.info("The event target is part of the possible steps"); 96 | int xPos = board.getRowIndex(source); 97 | int yPos = board.getColumnIndex(source); 98 | Point temporaryPoint = new Point(xPos, yPos); 99 | clearIllegalCells(); 100 | restoreOpacity(); 101 | table.movePiece(temporaryPoint); 102 | stepCount.set(table.getStepCounter()); 103 | ifGoalState(xPos, yPos); 104 | reduceOpacity(source); 105 | source.getChildren().add(new ImageView(piece)); 106 | readValuesFromList(); 107 | } else 108 | Logger.warn("You can't step on this cell"); 109 | } 110 | 111 | public void clearIllegalCells() { 112 | Logger.info("Entering the clearIllegalCells method in GameController class"); 113 | for (int i = 0; i < board.getRowCount(); i++) { 114 | for (int j = 0; j < board.getColumnCount(); j++) { 115 | StackPane temporaryPane=getStackPaneByRowAndColIndex(i,j); 116 | int sizeOfCurrentPane = temporaryPane.getChildren().size(); 117 | if(sizeOfCurrentPane>=1) { 118 | Logger.info("The number of children of the current StackPane is greater than or equal to 1"); 119 | ImageView currentImageView = (ImageView) temporaryPane.getChildren().get(sizeOfCurrentPane - 1); 120 | if (sizeOfCurrentPane > 1) { 121 | Logger.info("The number of children of the current StackPane is greater than 1"); 122 | for (int k = 0; k < temporaryPane.getChildren().size(); k++) { 123 | if (k > 0) 124 | temporaryPane.getChildren().remove(k); 125 | } 126 | } else if (((sizeOfCurrentPane == 1) && (currentImageView.getImage() == piece || currentImageView.getImage() == coverRec))) { 127 | Logger.info("The size of current pane is 1 and the image on the ImageView is a piece or a rectangle used for marking the position of possible steps"); 128 | temporaryPane.getChildren().remove(0); 129 | } 130 | } 131 | } 132 | } 133 | } 134 | 135 | public void restoreOpacity() { 136 | Logger.info("Entering the restoreOpacity method of GameController class"); 137 | for (int i = 0; i < board.getRowCount(); i++) { 138 | for (int j = 0; j < board.getColumnCount(); j++) { 139 | StackPane p = (StackPane) getStackPaneByRowAndColIndex(i, j); 140 | if(p.getChildren().size()>0) { 141 | Logger.info("The number of children of the current StackPane is greater than 0"); 142 | ImageView temporaryImageView = (ImageView) p.getChildren().get(p.getChildren().size() - 1); 143 | if (temporaryImageView.getOpacity() != 1) { 144 | temporaryImageView.setOpacity(1); 145 | Logger.info("The opacity of the current ImageView is less than 1"); 146 | } 147 | } 148 | } 149 | } 150 | } 151 | 152 | 153 | public ImageView createRectangleToCover() { 154 | Logger.info("Entering the createRectangle method in GameController class"); 155 | ImageView coverImg = new ImageView(coverRec); 156 | return coverImg; 157 | } 158 | 159 | 160 | public void reduceOpacity(StackPane source) 161 | { 162 | Logger.info("Entering the reduceOpacity method of GameController class"); 163 | if(source.getChildren().size()>0) { 164 | Logger.info("The number of children of the current StackPane is greater than 0"); 165 | ImageView temporaryImageView = (ImageView) source.getChildren().get(source.getChildren().size() - 1); 166 | temporaryImageView.setOpacity(0.5); 167 | } 168 | 169 | } 170 | private void createBinding() 171 | { 172 | Logger.info("Entering the createBinding method in GameController class"); 173 | stepTextField.textProperty().bind(stepCount.asString()); 174 | playerLabel.textProperty().bind(playerName); 175 | } 176 | 177 | public StackPane getStackPaneByRowAndColIndex(int i, int j) { 178 | Logger.info("Entering the getStackPaneByRowAndColIndex method in GameController class with i: {}, and j: {}",i,j); 179 | int childrenIndex = i * 8 + (j + 1); 180 | StackPane returnPane = (StackPane) board.getChildren().get(childrenIndex); 181 | return returnPane; 182 | } 183 | public void setProperties() 184 | { 185 | Logger.info("Entering the setProperties method in GameController class"); 186 | setPropertiesOfHBoxContainer(); 187 | setPropertiesOfVBoxContainer(); 188 | setPropertiesOfOuterPane(); 189 | } 190 | public void setPropertiesOfOuterPane() 191 | { 192 | Logger.info("Entering the SetPropertiesOfOuterPane method in GameController class"); 193 | outerPane.setBackground( 194 | new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))); 195 | outerPane.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.FULL))); 196 | } 197 | public void setPropertiesOfHBoxContainer() 198 | { 199 | Logger.info("Entering the setPropertiesOfHBoxContainer method in GameController class"); 200 | hBoxContainer.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.FULL))); 201 | } 202 | public void setPropertiesOfVBoxContainer() 203 | { 204 | Logger.info("Entering setPropertiesOfVBoxContainer method in GameController class"); 205 | vBoxContainer.setBackground( 206 | new Background(new BackgroundFill(Color.LIGHTGRAY, CornerRadii.EMPTY, Insets.EMPTY))); 207 | vBoxContainer.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1,1,1,5)))); 208 | } 209 | 210 | public static void setPlayerName(String p) 211 | { 212 | Logger.info("Entering the setPlayerName method in GameController class"); 213 | playerName.set(p); 214 | } 215 | 216 | public void fillTableWithPicturesOfStates() { 217 | Logger.info("Entering the fillTableWithPicturesOfStates method in GameController class"); 218 | for (int i = 0; i < board.getRowCount(); i++) 219 | for (int j = 0; j < board.getColumnCount(); j++) { 220 | StackPane sp = new StackPane(); 221 | addPictures(sp, i, j); 222 | } 223 | } 224 | 225 | public void addPictures(StackPane p, int i, int j) { 226 | Logger.info("Entering the addPictures method in GameController class"); 227 | if (table.getGameTable()[i][j].getState() == States.CIRCLE) { 228 | Logger.info("Current state is Circle"); 229 | ImageView temp = new ImageView(circleImage); 230 | p.getChildren().add(temp); 231 | } 232 | else if (table.getGameTable()[i][j].getState() == States.RECTANGLE) { 233 | Logger.info("Current state is Rectangle"); 234 | ImageView temp = new ImageView(rectangleImage); 235 | p.getChildren().add(temp); 236 | } 237 | else if (table.getGameTable()[i][j].getState() == States.START) { 238 | Logger.info("Current state is Start"); 239 | ImageView temp = new ImageView(startImage); 240 | temp.setOpacity(0.5); 241 | p.getChildren().add(temp); 242 | } 243 | else if (table.getGameTable()[i][j].getState() == States.GOAL) { 244 | Logger.info("Current state is Goal"); 245 | ImageView temp = new ImageView(goalImage); 246 | p.getChildren().add(temp); 247 | } 248 | p.setAlignment(Pos.CENTER); 249 | p.setOnMouseClicked(this::handleMouseClick); 250 | board.add(p, j, i); 251 | } 252 | 253 | 254 | public void ifGoalState(int x, int y) 255 | { 256 | Logger.info("Entering thew ifGoalState method of GameController class"); 257 | if(table.isGoalState()) { 258 | try { 259 | Logger.info("Trying to save the data to a File"); 260 | jsonMaker.saveToFile("winners.json", playerName.get(),(stepCount.get())); 261 | displayVictory(board); 262 | } catch (IOException ex) { 263 | Logger.error(ex); 264 | Logger.error("An error occured: {}",ex); 265 | throw new RuntimeException(ex); 266 | } 267 | } 268 | } 269 | 270 | public void displayVictory(GridPane grid) { 271 | Logger.info("Entering the displayVictory method of GameController class"); 272 | Stage window = new Stage(); 273 | window.initModality(Modality.APPLICATION_MODAL); 274 | window.setTitle("You Won!"); 275 | Label label = new Label(); 276 | label.setFont(new Font("Arial BLACK",20)); 277 | label.setText("Congratulations! You Won!"); 278 | Button backButton = new Button("Back to main menu"); 279 | Button victoryButton = new Button("Exit"); 280 | backButtonSetOnAction(window, grid, backButton); 281 | victoryButtonSetOnAction(window, grid, victoryButton); 282 | setOnWindowCloseRequest(window, grid); 283 | VBox layout = new VBox(30); 284 | layout.getChildren().add(label); 285 | layout.getChildren().add(backButton); 286 | layout.getChildren().add(victoryButton); 287 | layout.setAlignment(Pos.CENTER); 288 | Scene scene = new Scene(layout, 300, 200); 289 | window.setScene(scene); 290 | window.showAndWait(); 291 | Logger.info("Reaching the end of displayVictory method"); 292 | } 293 | 294 | public void victoryButtonSetOnAction(Stage window, GridPane grid, Button victoryButton) 295 | { 296 | Logger.info("Entering the victoryButtonSetOnAction method of GameController class"); 297 | victoryButton.setOnAction(e->{ 298 | window.close(); 299 | Stage win = (Stage) grid.getParent().getParent().getScene().getWindow(); 300 | win.close(); 301 | }); 302 | 303 | } 304 | 305 | public void backButtonSetOnAction(Stage window, GridPane grid, Button backButton) 306 | { 307 | Logger.info("Entering the backButtonSetOnAction method of GameController class"); 308 | backButton.setOnAction(e->{ 309 | window.close(); 310 | Logger.trace("Entering the start method of GameApplication class"); 311 | Parent root; 312 | Stage stage = (Stage) grid.getParent().getParent().getScene().getWindow(); 313 | try { 314 | Logger.info("Trying to load the FXML file to root from startPage.fxml"); 315 | root = FXMLLoader.load(getClass().getResource("/startPage.fxml")); 316 | } catch (IOException ex) { 317 | Logger.error("An error occured: {}",ex); 318 | throw new RuntimeException(ex); 319 | } 320 | stage.setTitle("Table Game"); 321 | Scene scene = new Scene(root); 322 | stage.setScene(scene); 323 | stage.setResizable(false); 324 | stage.show(); 325 | }); 326 | } 327 | 328 | public void setOnWindowCloseRequest(Stage window, GridPane grid) 329 | { 330 | Logger.info("Entering the setOnWindowCloseRequest method of GameController class"); 331 | window.setOnCloseRequest(e ->{ 332 | window.close(); 333 | Stage win = (Stage) grid.getParent().getParent().getScene().getWindow(); 334 | win.close(); 335 | }); 336 | } 337 | 338 | 339 | } --------------------------------------------------------------------------------