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; ...@@ -2,9 +2,9 @@ package model;
import util.Position; import util.Position;
public class Fire implements Entity{ public class Fire implements Entity{
Board b;
private Position position; private Position position;
public Fire(Position position){ public Fire(Position position, Board b){
this.position = position; this.position = position;
} }
......
...@@ -13,7 +13,7 @@ public class FireFighter implements Entity{ ...@@ -13,7 +13,7 @@ public class FireFighter implements Entity{
//Sinon //Sinon
//Se déplacer vers le feu le plus proche //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 //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; package model;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import util.*; import util.Matrix;
import util.Position;
public class FireFighterScenario implements Board<Entity>{ public class FireFighterScenario implements Board<Entity>{
/**
* Get the state of the board at a specific position. private Matrix<Entity> matrix
* public FireFighterScenario(int boardSize){
* @param position The position on the board for which to retrieve the state. this.matrix = new Matrix();
* @return The state at the specified position. }
*/
public Entity getState(Position position){ 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){ 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(){ 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(){ public int columnCount(){
throw new IllegalStateException("Method not implemented"); return matrix.get(0).size();
} }
/** /**
...@@ -50,7 +40,12 @@ public class FireFighterScenario implements Board<Entity>{ ...@@ -50,7 +40,12 @@ public class FireFighterScenario implements Board<Entity>{
* @return A list of positions that have changed during the update. * @return A list of positions that have changed during the update.
*/ */
public List<Position> updateToNextGeneration(){ 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> { ...@@ -12,6 +12,9 @@ public class Matrix<E> {
public E set(int x, int y, E object){ public E set(int x, int y, E object){
return matrix.get(x).set(y, object); return matrix.get(x).set(y, object);
} }
public void clear(){
this.matrix = new ArrayList<ArrayList<E>>();
}
public int size(){ public int size(){
return matrix != null ? matrix.get(0).size()*matrix.size() : 0; 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