diff --git a/src/main/java/model/Cloud.java b/src/main/java/model/Cloud.java index b68e95e2ecb7759fc536f32df35f41eedcfa49fe..e79eebdb4bf6eebe1eef04f3a74ce6bb695a2bf7 100644 --- a/src/main/java/model/Cloud.java +++ b/src/main/java/model/Cloud.java @@ -8,88 +8,6 @@ import java.util.Random; import java.util.Random; public class Cloud extends Element implements Extinguish { - // Additional attributes for Cloud - private Random random = new Random(); - // Constructor - public Cloud(Position position) { - super(position); - // Initialize cloud-specific attributes - } - - @Override - public void extinguish(Element target) { - if (target instanceof Fire) { - // Extinguish the fire - ((Fire) target).extinguish(); - } - } - - @Override - public void update() { - // Move the cloud randomly - moveRandomly(); - - // Extinguish fires in adjacent positions - extinguishFiresInAdjacentPositions(); - } - - private void moveRandomly() { - int newX = position.getX() + random.nextInt(3) - 1; // Move left, right, or stay in the same column - int newY = position.getY() + random.nextInt(3) - 1; // Move up, down, or stay in the same row - - // Update the cloud's position - position = new Position(newX, newY); - } - - private void extinguishFiresInAdjacentPositions() { - // Get adjacent positions - Position[] adjacentPositions = getAdjacentPositions(); - - // Extinguish fires in adjacent positions - for (Position adjacentPosition : adjacentPositions) { - Element element = getGrid().getElementAt(adjacentPosition); - extinguish(element); - } - } - - private Position[] getAdjacentPositions() { - int x = position.getX(); - int y = position.getY(); - - // Define adjacent positions - Position[] adjacentPositions = { - new Position(x - 1, y - 1), new Position(x - 1, y), new Position(x - 1, y + 1), - new Position(x, y - 1), new Position(x, y + 1), - new Position(x + 1, y - 1), new Position(x + 1, y), new Position(x + 1, y + 1) - }; - - return adjacentPositions; - } - - @Override - public List<Position> updatePosition() { - return null; - } - - @Override - public List<Position> neighbors() { - return null; - } - - @Override - public List<Position> getPosition() { - return null; - } - - @Override - public List<Position> setPosition() { - return null; - } - - @Override - public void action() { - - } } diff --git a/src/main/java/model/Element.java b/src/main/java/model/Element.java index c223d193ddc763c8a9a94cbca6dca416c28fd74d..c1997df13df8cf0961a5ca7abcb27d30b96f52d9 100644 --- a/src/main/java/model/Element.java +++ b/src/main/java/model/Element.java @@ -15,10 +15,10 @@ public abstract class Element { 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();*/ + private List<Position> updatePosition(); + + private List<Position> getPosition(); + private List<Position> setPosition(); diff --git a/src/main/java/model/Fire.java b/src/main/java/model/Fire.java index 0e26689ee4956a004cdd9ec09bd45e5e481ba468..a2cacefa3eef57e8c9ff34140519079336ddfe84 100644 --- a/src/main/java/model/Fire.java +++ b/src/main/java/model/Fire.java @@ -8,71 +8,7 @@ import java.util.Set; import java.util.Random; public class Fire extends Element implements State { - private boolean onFire; - private int propagationDelay; // Number of turns before the fire can spread - private int propagationCounter; // Counter to track the remaining turns for propagation - private Random random = new Random(); - // Constructor - public Fire(Position position, int propagationDelay) { - super(position); - this.onFire = true; - this.propagationDelay = propagationDelay; - this.propagationCounter = propagationDelay; - } - - // Implementing State interface method - @Override - public boolean isOnFire() { - return onFire; - } - - // Implementing Element class method - @Override - public void update() { - if (canSpread()) { - spreadFire(); - } - } - - // Method to check if the fire can spread - private boolean canSpread() { - return onFire && propagationCounter <= 0; - } - - // Method to spread the fire randomly to adjacent positions - private void spreadFire() { - Position[] adjacentPositions = getAdjacentPositions(); - if (adjacentPositions.length > 0) { - int randomIndex = random.nextInt(adjacentPositions.length); - Position randomAdjacentPosition = adjacentPositions[randomIndex]; - Element element = getGrid().getElementAt(randomAdjacentPosition); - - // Check if the adjacent position is not occupied by another fire - if (element == null || !(element instanceof Fire)) { - // Spread the fire to the adjacent position - getGrid().addElement(new Fire(randomAdjacentPosition, propagationDelay), randomAdjacentPosition); - } - } - - // Reset the propagation counter - propagationCounter = propagationDelay; - } - - // Method to get adjacent positions - private Position[] getAdjacentPositions() { - int x = position.getX(); - int y = position.getY(); - - // Define adjacent positions - Position[] adjacentPositions = { - new Position(x - 1, y - 1), new Position(x - 1, y), new Position(x - 1, y + 1), - new Position(x, y - 1), new Position(x, y + 1), - new Position(x + 1, y - 1), new Position(x + 1, y), new Position(x + 1, y + 1) - }; - - return adjacentPositions; - } } diff --git a/src/main/java/model/FireFighter.java b/src/main/java/model/FireFighter.java index 389e4a8ee7319139752a9690caa2d1ddbb5e290b..11b879fdf2ff39885f1cdc646f87a491c3da77de 100644 --- a/src/main/java/model/FireFighter.java +++ b/src/main/java/model/FireFighter.java @@ -6,58 +6,6 @@ import java.util.List; import java.util.Set; public class Firefighter extends Element implements Extinguish { - // Additional attributes for Firefighter, if any - // Constructor - public Firefighter(Position position) { - super(position); - // Initialize firefighter-specific attributes - } - - @Override - public void extinguish(Element target) { - if (target instanceof Fire) { - // Extinguish the fire - ((Fire) target).extinguish(); - } - } - - @Override - public void update() { - // Logic for firefighter's update, if needed - } - - // Enhanced move method to check terrain passability - public void move(int deltaX, int deltaY) { - int newX = position.getX() + deltaX; - int newY = position.getY() + deltaY; - - // Check if the new position is within the grid boundaries - if (isValidPosition(newX, newY)) { - Element targetElement = getGrid().getElementAt(new Position(newX, newY)); - - // Check terrain type before moving - if (targetElement instanceof Road) { - // Allow movement on roads - position = new Position(newX, newY); - } else if (targetElement instanceof Mountain) { - // Prevent movement on mountains - System.out.println("Cannot move on mountains!"); - } else { - // Default behavior for other terrains - position = new Position(newX, newY); - } - } - } - - // Check if a position is valid within the grid boundaries - private boolean isValidPosition(int x, int y) { - return x >= 0 && x < getGrid().getRows() && y >= 0 && y < getGrid().getColumns(); - } - - @Override - public void action() { - - } } diff --git a/src/main/java/model/Mobile.java b/src/main/java/model/Mobile.java index 4e44ed4ae14522c9186e03e42ff728b39c166926..6a828242b645403252297132587300b0877cacde 100644 --- a/src/main/java/model/Mobile.java +++ b/src/main/java/model/Mobile.java @@ -5,48 +5,6 @@ import util.Position; import java.util.List; public class Mobile extends Element implements Extinguish { - // Additional attributes for Mobile - private int moveRange; - // Constructor - public Mobile(Position position, int moveRange) { - super(position); - this.moveRange = moveRange; - } - - @Override - public void extinguish(Element target) { - if (target instanceof Fire) { - // Extinguish the fire - ((Fire) target).extinguish(); - } - } - - @Override - public void update() { - // Logic for mobile's update, if needed - } - - // Method to move the mobile element - public void move(int deltaX, int deltaY) { - int newX = position.getX() + deltaX; - int newY = position.getY() + deltaY; - - // Check if the new position is within the grid boundaries - if (isValidPosition(newX, newY)) { - // Move the mobile element - position = new Position(newX, newY); - } - } - - // Check if a position is valid within the grid boundaries - private boolean isValidPosition(int x, int y) { - return x >= 0 && x < getGrid().getRows() && y >= 0 && y < getGrid().getColumns(); - } - - @Override - public void action() { - - } } diff --git a/src/main/java/model/Moutain.java b/src/main/java/model/Moutain.java index 251a80acfc9b3ec74d51212df7c76c8ca0f51b80..1e082796d891f28f38716ffbe5110bdfe29b07d3 100644 --- a/src/main/java/model/Moutain.java +++ b/src/main/java/model/Moutain.java @@ -6,27 +6,6 @@ import java.util.List; public class Mountain extends Element implements StablePosition { // Additional attributes for Mountain - private boolean impassable; - // Constructor - public Mountain(Position position, boolean impassable) { - super(position); - this.impassable = impassable; - } - - @Override - public void stabilize() { - // Logic for stabilizing mountain - } - - @Override - public void update() { - // Logic for mountain's update, if needed - } - - // Method to check passability - public boolean isPassable() { - return !impassable; - } } diff --git a/src/main/java/model/Road.java b/src/main/java/model/Road.java index 736d9833637b408176ed9aaf69acb0894da1038f..f88c3b999b7721129fdafeebcf5efddad97826e4 100644 --- a/src/main/java/model/Road.java +++ b/src/main/java/model/Road.java @@ -5,23 +5,6 @@ import util.Position; import java.util.List; public class Road extends Element { - // Additional attributes for Road - private boolean passable; - // Constructor - public Road(Position position, boolean passable) { - super(position); - this.passable = passable; - } - - @Override - public void update() { - // Logic for road's update, if needed - } - - // Method to check passability - public boolean isPassable() { - return passable; - } } diff --git a/src/main/java/model/Rocks.java b/src/main/java/model/Rocks.java index f8aa3ce5bc07d69e4f3af57a016279e90f3e0c64..dc8e020492c22e900bf0d0fb4a2a0222c404bba1 100644 --- a/src/main/java/model/Rocks.java +++ b/src/main/java/model/Rocks.java @@ -6,32 +6,6 @@ import java.util.List; public class Rock extends Element implements Stable { // Additional attributes for Rock - private int propagationDelayCounter; - // Constructor - public Rock(Position position, int propagationDelay) { - super(position); - this.propagationDelayCounter = propagationDelay; - } - - @Override - public void stabilize() { - // Logic for stabilizing rock - } - - @Override - public void update() { - // Logic for rock's update, if needed - - // Check propagation delay - if (propagationDelayCounter > 0) { - propagationDelayCounter--; - } - } - - // Method to check propagation - public boolean canPropagate() { - return propagationDelayCounter <= 0; - } }