Skip to content
Snippets Groups Projects
Commit 565e3537 authored by BACHTARZI Imed eddine's avatar BACHTARZI Imed eddine
Browse files

cloud DONE

parent 698cbfaa
Branches
No related tags found
No related merge requests found
Pipeline #39331 passed
Showing
with 100 additions and 3 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File deleted
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File deleted
No preview for this file type
......@@ -25,7 +25,25 @@ import java.util.List;
import static java.util.Objects.requireNonNull;
public class Controller {
public static String toString(ViewElement[][] matrice) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < matrice.length; i++) {
sb.append("[ ");
for (int j = 0; j < matrice[i].length; j++) {
sb.append(matrice[i][j].toString());
if (j < matrice[i].length - 1) {
sb.append(", "); // Ajouter une virgule entre les éléments
}
}
sb.append(" ]");
if (i < matrice.length - 1) {
sb.append("\n"); // Sauter une ligne entre les lignes de la matrice
}
}
return sb.toString();
}
public static final int PERIOD_IN_MILLISECONDS = 50;
@FXML
public Button restartButton;
......@@ -78,15 +96,19 @@ public class Controller {
for(int row = 0; row < rowCount; row++)
viewElements[row][column] = getViewElement(board.getState(new Position(row, column)));
grid.repaint(viewElements);
System.out.println(toString(viewElements));
updateGenerationLabel(board.stepNumber());
}
private ViewElement getViewElement(List<ModelElement> squareState) {
if (squareState.contains(ModelElement.FIRE)){
return ViewElement.FIRE;
}
if(squareState.contains(ModelElement.FIREFIGHTER)){
return ViewElement.FIREFIGHTER;
}
if (squareState.contains(ModelElement.FIRE)){
return ViewElement.FIRE;
if(squareState.contains(ModelElement.CLOUD)){
return ViewElement.CLOUD;
}
if (squareState.contains(ModelElement.MOUNTAIN)){
return ViewElement.MOUNTAIN;
......
......@@ -5,7 +5,7 @@ import util.Position;
import java.util.List;
public interface Behavior {
public List<Position> getNext(BoardData boarddata,List<Position>positions);
public List<Position> getNext(BoardData boardData);
public default Boolean isLegalMove(){
return true;
}
......
package model;
import util.Position;
import util.TargetStrategy;
import java.util.ArrayList;
import java.util.List;
public class Cloud extends Element {
public Cloud() {
super(ModelElement.CLOUD,
new CloudBehavior(ModelElement.CLOUD));
}
@Override
public List<Position> Update(BoardData boardData, List<Position> modifiedPositions) {
List<Position> cloudPositions=boardData.getPositions().get(type.ordinal());
List<Position> newCloudPositions=behavior.getNext(boardData);
modifiedPositions.removeAll(cloudPositions);
modifiedPositions.addAll(cloudPositions);
modifiedPositions.removeAll(newCloudPositions);
modifiedPositions.addAll(newCloudPositions);
cloudPositions.clear();
cloudPositions.addAll(newCloudPositions);
return modifiedPositions;
}
}
package model;
import util.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class CloudBehavior implements RemoverBehavior<ModelElement> {
private ModelElement element;
private ModelElement removedElement=ModelElement.FIRE;
private Random random=new Random();
public CloudBehavior(ModelElement modelElement) {
this.element=modelElement;
}
@Override
public List<Position> getNext(BoardData boardData) {
List<Position> cloudPositions=boardData.getPositions().get(element.ordinal());
List<Position> newCloudPositions=new ArrayList<>();
for (Position cloudPosition:cloudPositions) {
List<Position> newPossibleCloudPosition=boardData.getNeighbors().get(cloudPosition);
Position newCloudPosition= newPossibleCloudPosition.get(random.nextInt(newPossibleCloudPosition.size()));
newCloudPositions.add(newCloudPosition);
remove(boardData,newCloudPosition);
}
return newCloudPositions;
}
@Override
public ModelElement getElementToRemove() {
return removedElement;
}
@Override
public void removePartial(BoardData boardData,Position p) {
List<Position> firePositions = boardData.getPositions().get(getElementToRemove().ordinal());
firePositions.remove(p);
}
@Override
public List<Position> remove(BoardData boardData, Position p) {
removePartial(boardData,p);
return List.of(p);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment