Skip to content
Snippets Groups Projects
Commit 9ab8fe6d authored by Yanis O's avatar Yanis O
Browse files

Complétion de certaines méthodes de FireFighterScenario

parent f5d08246
Branches
No related tags found
No related merge requests found
Pipeline #38835 failed
......@@ -2,9 +2,9 @@ package model;
import util.Position;
public class Fire implements Entity{
Board b;
private Position position;
public Fire(Position position){
public Fire(Position position, Board b){
this.position = position;
}
......
......@@ -13,7 +13,7 @@ public class FireFighter implements Entity{
//Sinon
//Se déplacer vers le feu le plus proche
//Si un feu est à proximité : éteindre les feux à x + 1 y, x y+1, x+1 y-1, x-1 y+1
// Ajouter un feu à x + 1 y, x y+1, x+1 y-1, x-1 y+1
// Ajouter un feu à x + 1 y, x y+1, x-1 y, x y-1
}
......
package model;
import java.util.ArrayList;
import java.util.List;
import util.*;
import util.Matrix;
import util.Position;
public class FireFighterScenario implements Board<Entity>{
/**
* Get the state of the board at a specific position.
*
* @param position The position on the board for which to retrieve the state.
* @return The state at the specified position.
*/
private Matrix<Entity> matrix
public FireFighterScenario(int boardSize){
this.matrix = new Matrix();
}
public Entity getState(Position position){
throw new IllegalStateException("Method not implemented");
if(position.x() > matrix.size() || position.y() > matrix.get(0).size()){
throw new IllegalArgumentException("The position x:" + position.x() + " y:" + position.y() + " is out of the board.");
}
return matrix.get(position.x()).get(position.y());
}
/**
* Set the state of a specific position on the board to the specified state.
*
* @param state The state to set for the given position.
* @param position The position on the board for which to set the state.
*/
public void setState(Entity state, Position position){
throw new IllegalStateException("Method not implemented");
matrix.get(position.x()).set(position.y(), state);
}
/**
* Get the number of rows in the board.
*
* @return The number of rows in the board.
*/
public int rowCount(){
throw new IllegalStateException("Method not implemented");
return matrix.size();
}
/**
* Get the number of columns in the board.
*
* @return The number of columns in the board.
*/
public int columnCount(){
throw new IllegalStateException("Method not implemented");
return matrix.get(0).size();
}
/**
......@@ -50,7 +40,12 @@ public class FireFighterScenario implements Board<Entity>{
* @return A list of positions that have changed during the update.
*/
public List<Position> updateToNextGeneration(){
throw new IllegalStateException("Method not implemented");
for(ArrayList<Entity> l : matrix){
for(Entity e : l){
e.nextTurn(this);
}
}
return matrix;
}
/**
......
......@@ -12,6 +12,9 @@ public class Matrix<E> {
public E set(int x, int y, E object){
return matrix.get(x).set(y, object);
}
public void clear(){
this.matrix = new ArrayList<ArrayList<E>>();
}
public int size(){
return matrix != null ? matrix.get(0).size()*matrix.size() : 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment