Skip to content
Snippets Groups Projects
Commit 23813b29 authored by PHAM Thi ngoc linh's avatar PHAM Thi ngoc linh
Browse files

upgrade

parent db66faa5
Branches
No related tags found
No related merge requests found
Pipeline #24887 failed
......@@ -86,5 +86,10 @@ public class Cloud extends Element implements Extinguish {
public List<Position> setPosition() {
return null;
}
@Override
public void action() {
}
}
......@@ -6,35 +6,22 @@ import java.util.List;
import java.util.Random;
public abstract class Element {
protected Position position; // Attribute to represent the current position
protected Grid grid; // Attribute to represent the reference to the grid
protected Position position;
public void initializeElements() {}
private Position randomPosition() {}
public List<ModelElement> getState(Position position) {}
public List<Position> updateToNextGeneration() {}
private List<Position> updateFires() {}
private List<Position> neighbors(Position position) {}
private Position neighborClosestToFire(Position position) {}
public void setState(List<ModelElement> state, Position position) {}
/*List<Position> updatePosition();
List<Position> neighbors();
List<Position> getPosition();
List<Position> setPosition();*/
// Constructor
public Element(Position position, Grid grid) {
this.position = position;
this.grid = grid;
}
// Abstract method for updating the state of the element
public abstract void update();
// Getters and Setters for Position
public Position getPosition() {
return position;
}
public void setPosition(Position position) {
this.position = position;
}
// Getters and Setters for Grid Reference
public Grid getGrid() {
return grid;
}
public void setGrid(Grid grid) {
this.grid = grid;
}
}
......@@ -5,9 +5,7 @@ import util.Position;
import java.util.List;
public interface Extinguish {
List<Position> updatePosition();
List<Position> neighbors();
List<Position> getPosition();
List<Position> setPosition();
void action();
}
......@@ -54,5 +54,10 @@ public class Firefighter extends Element implements Extinguish {
private boolean isValidPosition(int x, int y) {
return x >= 0 && x < getGrid().getRows() && y >= 0 && y < getGrid().getColumns();
}
@Override
public void action() {
}
}
......@@ -57,7 +57,7 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
return columnCount;
}
public List<Position> updateToNextGeneration() {// chua hieu lam gi
public List<Position> updateToNextGeneration() {// chua hieu lam gi// sua cai nay
List<Position> result = updateFirefighters();
result.addAll(updateFires());
step++;
......
package model;
import util.Position;
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
public class Grid {
private int rows;
private int columns;
private Element[][] elements;
// Constructor
public Grid(int rows, int columns) {
this.rows = rows;
this.columns = columns;
this.elements = new Element[rows][columns];
}
// Method to add an element to the grid at a specific position
public void addElement(Element element, Position position) {
elements[position.getX()][position.getY()] = element;
element.setGrid(this);
element.setPosition(position);
}
// Method to get the element at a specific position on the grid
public Element getElementAt(Position position) {
return elements[position.getX()][position.getY()];
}
// Method to update all elements in the grid
public void update() {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
Element element = elements[i][j];
if (element != null) {
element.update();
}
}
}
}
// Getters for grid size
public int getRows() {
return rows;
}
public int getColumns() {
return columns;
}
}
......@@ -43,5 +43,10 @@ public class Mobile extends Element implements Extinguish {
private boolean isValidPosition(int x, int y) {
return x >= 0 && x < getGrid().getRows() && y >= 0 && y < getGrid().getColumns();
}
@Override
public void action() {
}
}
......@@ -4,7 +4,7 @@ import util.Position;
import java.util.List;
public class Mountain extends Element implements Stable {
public class Mountain extends Element implements StablePosition {
// Additional attributes for Mountain
private boolean impassable;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment