Select Git revision
FirefighterBoard.java
Forked from
COUETOUX Basile / FirefighterStarter
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Mobile.java 1.20 KiB
package model;
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();
}
}