Check if the baord is completed and return to main menu
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Debucquoy Anthony 2023-05-11 12:24:56 +02:00
parent e424cdca4e
commit def25d9e38
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
4 changed files with 35 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package school_project;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.input.MouseButton; import javafx.scene.input.MouseButton;
import school_project.Menu.MenuAcceuil;
import school_project.Utils.MatrixShape; import school_project.Utils.MatrixShape;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -70,6 +71,9 @@ public class GameUI extends Group{
_piece.setLayoutX(grid.getLayoutX() + p.getPosition().y * (SEGMENT_SIZE+SPACE_SIZE)); _piece.setLayoutX(grid.getLayoutX() + p.getPosition().y * (SEGMENT_SIZE+SPACE_SIZE));
_piece.setLayoutY(grid.getLayoutY() + p.getPosition().x * (SEGMENT_SIZE+SPACE_SIZE)); _piece.setLayoutY(grid.getLayoutY() + p.getPosition().x * (SEGMENT_SIZE+SPACE_SIZE));
} }
if(level.gameDone()){
Controller.switchRoot(new MenuAcceuil());
}
} }
}); });

View File

@ -68,6 +68,18 @@ public class Map extends Shape{
return true; return true;
} }
/**
* Check if every pieces has a space on the board to know if the game is finished
* @return true if the game is finished, false if not
*/
public boolean gameDone(){
ArrayList<Vec2> posList = getPosList();
for(Piece p: pieces){
posList.removeAll(p.getOccupation());
}
return posList.isEmpty();
}
/** /**
* Return a matrix with all used space on the map to see if a piece can fit in a space * Return a matrix with all used space on the map to see if a piece can fit in a space
* *

View File

@ -42,6 +42,8 @@ public class Piece extends Shape{
public ArrayList<Vec2> getOccupation(){ public ArrayList<Vec2> getOccupation(){
ArrayList<Vec2> ret = new ArrayList<>(); ArrayList<Vec2> ret = new ArrayList<>();
if(Position == null)
return ret;
for (int x = 0; x < height; x++) { for (int x = 0; x < height; x++) {
for (int y = 0; y < width; y++) { for (int y = 0; y < width; y++) {
if(getShape()[x][y]){ if(getShape()[x][y]){

View File

@ -4,6 +4,7 @@ package school_project;
import school_project.Utils.Array; import school_project.Utils.Array;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
/** /**
* Base class for everything that is a shape kind, like map and pieces * Base class for everything that is a shape kind, like map and pieces
@ -84,6 +85,22 @@ public class Shape implements Serializable, Cloneable{
return matrix; return matrix;
} }
/**
* Get the list of all the open possition of the map
* @return ArrayList of vec2 of all the positions
*/
public ArrayList<Vec2> getPosList(){
ArrayList<Vec2> ret = new ArrayList<>();
for (int x = 0; x < height; x++) {
for (int y = 0; y < width; y++) {
if(matrix[x][y]){
ret.add(new Vec2(x, y));
}
}
}
return ret;
}
@Override @Override
public String toString() { public String toString() {
String ret = ""; String ret = "";