Skip to content
Snippets Groups Projects
Commit 9a547962 authored by HEBBACHE Mohamed's avatar HEBBACHE Mohamed
Browse files

update Fire and FireFighter modification

parent 28f97b4a
No related branches found
No related tags found
No related merge requests found
Pipeline #24432 passed
Showing with 236 additions and 57 deletions
File added
File added
File added
File added
.background {
-fx-background-color: #1d1d1d;
}
.label {
-fx-font-size: 11pt;
-fx-font-family: "Segoe UI Semibold";
-fx-text-fill: white;
-fx-opacity: 0.6;
}
.label-bright {
-fx-font-size: 11pt;
-fx-font-family: "Segoe UI Semibold";
-fx-text-fill: white;
-fx-opacity: 1;
}
.label-header {
-fx-font-size: 32pt;
-fx-font-family: "Segoe UI Light";
-fx-text-fill: white;
-fx-opacity: 1;
}
.table-view {
-fx-base: #1d1d1d;
-fx-control-inner-background: #1d1d1d;
-fx-background-color: #1d1d1d;
-fx-table-cell-border-color: transparent;
-fx-table-header-border-color: transparent;
-fx-padding: 5;
}
.table-view .column-header-background {
-fx-background-color: transparent;
}
.table-view .column-header, .table-view .filler {
-fx-border-width: 0 0 1 0;
-fx-background-color: transparent;
-fx-border-color:
transparent
transparent
derive(-fx-base, 80%)
transparent;
-fx-border-insets: 0 10 1 0;
}
.table-view .column-header .label {
-fx-font-size: 20pt;
-fx-font-family: "Segoe UI Light";
-fx-text-fill: white;
-fx-alignment: center-left;
-fx-opacity: 1;
}
.table-view:focused .table-row-cell:filled:focused:selected {
-fx-background-color: -fx-focus-color;
}
.split-pane:horizontal > .split-pane-divider {
-fx-border-color: transparent #1d1d1d transparent #1d1d1d;
-fx-background-color: transparent, derive(#1d1d1d,20%);
}
.split-pane {
-fx-padding: 1 0 0 0;
}
.menu-bar {
-fx-background-color: derive(#1d1d1d,20%);
}
.context-menu {
-fx-background-color: derive(#1d1d1d,50%);
}
.menu-bar .label {
-fx-font-size: 14pt;
-fx-font-family: "Segoe UI Light";
-fx-text-fill: white;
-fx-opacity: 0.9;
}
.menu .left-container {
-fx-background-color: black;
}
.text-field {
-fx-font-size: 12pt;
-fx-font-family: "Segoe UI Semibold";
}
/*
* Metro style Push Button
* Author: Pedro Duque Vieira
* http://pixelduke.wordpress.com/2012/10/23/jmetro-windows-8-controls-on-java/
*/
.button {
-fx-padding: 5 22 5 22;
-fx-border-color: #e2e2e2;
-fx-border-width: 2;
-fx-background-radius: 0;
-fx-background-color: #1d1d1d;
-fx-font-family: "Segoe UI", Helvetica, Arial, sans-serif;
-fx-font-size: 11pt;
-fx-text-fill: #d8d8d8;
-fx-background-insets: 0 0 0 0, 0, 1, 2;
}
.button:hover {
-fx-background-color: #3a3a3a;
}
.button:pressed, .button:default:hover:pressed {
-fx-background-color: white;
-fx-text-fill: #1d1d1d;
}
.button:focused {
-fx-border-color: white, white;
-fx-border-width: 1, 1;
-fx-border-style: solid;
-fx-border-radius: 0, 0;
-fx-border-insets: 1 1 1 1, 0;
}
.button:disabled, .button:default:disabled {
-fx-opacity: 0.4;
-fx-background-color: #1d1d1d;
-fx-text-fill: white;
}
.button:default {
-fx-background-color: -fx-focus-color;
-fx-text-fill: #ffffff;
}
.button:default:hover {
-fx-background-color: derive(-fx-focus-color,30%);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import view.FirefighterGrid?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Label?>
<HBox styleClass="background" stylesheets="@DarkTheme.css"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
fx:controller="controller.Controller">
<VBox>
<Separator maxHeight="-Infinity" maxWidth="-Infinity"
prefHeight="24.0" prefWidth="200.0"/>
<Label maxHeight="-Infinity" maxWidth="-Infinity" alignment="CENTER" prefHeight="24.0" prefWidth="200.0"
text="Generation number"/>
<Label fx:id="generationNumberLabel" alignment="CENTER" contentDisplay="TEXT_ONLY"
maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="24.0" prefWidth="200.0"/>
<Separator maxHeight="-Infinity" maxWidth="-Infinity"
prefHeight="24.0" prefWidth="200.0"/>
<Button fx:id="restartButton" maxHeight="-Infinity" maxWidth="-Infinity"
mnemonicParsing="false" onAction="#restartButtonAction" prefHeight="24.0" prefWidth="200.0"
text="Restart"/>
<Button fx:id="oneStepButton" maxHeight="-Infinity" maxWidth="-Infinity"
mnemonicParsing="false" onAction="#oneStepButtonAction" prefHeight="24.0" prefWidth="200.0"
text="One step"/>
<ToggleButton fx:id="playToggleButton" maxHeight="-Infinity" maxWidth="-Infinity"
mnemonicParsing="false" onAction="#playToggleButtonAction" prefHeight="24.0"
prefWidth="200.0" styleClass="button" text="Play"/>
<ToggleButton fx:id="pauseToggleButton" maxHeight="-Infinity" maxWidth="-Infinity"
mnemonicParsing="false" onAction="#pauseToggleButtonAction" prefHeight="24.0"
prefWidth="200.0" styleClass="button" text="Pause"/>
</VBox>
<FirefighterGrid fx:id="grid" width="600.0" height="600.0"
xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml">
</FirefighterGrid>
</HBox>
File added
......@@ -6,10 +6,9 @@ import util.Position;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public interface ExtinguishFire extends BoardElement {
void update(GameBoard gameBoard , Position position);
void update(GameBoard gameBoard , Position position, HashMap<Position, ArrayList<BoardElement>> newElementPosition, ArrayList<Position> extinguishPosition);
}
......@@ -66,14 +66,10 @@ public class FireFighter implements ExtinguishFire {
}
@Override
public void update(GameBoard gameBoard, Position position) {
public void update(GameBoard gameBoard, Position position, HashMap<Position, ArrayList<BoardElement>> newElementPosition, ArrayList<Position> extinguishPosition) {
HashMap<Position, ArrayList<BoardElement>> elementPositionCopie = new HashMap<>();
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPosition.entrySet()){
elementPositionCopie.put(entry.getKey(),entry.getValue());
}
List<Position> firePositions = new ArrayList<>();
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPositionCopie.entrySet()) {
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPosition.entrySet()) {
for (BoardElement element : entry.getValue()) {
if (element.accept(new FireFinder())) {
firePositions.add(entry.getKey());
......@@ -81,40 +77,22 @@ public class FireFighter implements ExtinguishFire {
}
}
Position newFirefighterPosition = gameBoard.neighborClosestToFire(position);
//elementPosition.get(position).remove(this);
if(elementPosition.containsKey(newFirefighterPosition)){
elementPosition.get(newFirefighterPosition).add(this);
if(newElementPosition.containsKey(newFirefighterPosition)){
newElementPosition.get(newFirefighterPosition).add(this);
}
else{
ArrayList<BoardElement> boardElements = new ArrayList<>();
boardElements.add(this);
elementPosition.put(newFirefighterPosition,boardElements);
newElementPosition.put(newFirefighterPosition,boardElements);
}
gameBoard.extinguish(newFirefighterPosition);
extinguishPosition.add(newFirefighterPosition);
List<Position> neighborFirePositions = gameBoard.neighbors(newFirefighterPosition).stream()
.filter(firePositions::contains).toList();
for(Position firePosition : neighborFirePositions) {
gameBoard.extinguish(firePosition);
extinguishPosition.add(firePosition);
}
}
/*private List<Position> updateFirefighters() {
List<Position> result = new ArrayList<>();
List<Position> firefighterNewPositions = new ArrayList<>();
for (Position firefighterPosition : firefighterPositions) {
Position newFirefighterPosition = neighborClosestToFire(firefighterPosition);
firefighterNewPositions.add(newFirefighterPosition);
extinguish(newFirefighterPosition);
result.add(firefighterPosition);
result.add(newFirefighterPosition);
List<Position> neighborFirePositions = neighbors(newFirefighterPosition).stream()
.filter(firePositions::contains).toList();
for(Position firePosition : neighborFirePositions)
extinguish(firePosition);
result.addAll(neighborFirePositions);
}
firefighterPositions = firefighterNewPositions;
return result;
}*/
}
......@@ -64,19 +64,29 @@ public class Fire implements Flammable{
}
@Override // TODO: 15/11/2023
public void update(GameBoard gameBoard , Position position) {
public void update(GameBoard gameBoard , Position position,HashMap<Position, ArrayList<BoardElement>> newElementPosition, ArrayList<Position> extinguishPosition) {
if(extinguishPosition.contains(position)){
return ;
}
if (gameBoard.stepNumber() % 2 == 0) {
List<Position> newFirePositions = new ArrayList<>();
newFirePositions.addAll(gameBoard.neighbors(position));
for(Position newPosition : newFirePositions){
List<Position> newPositions = new ArrayList<>();
newPositions.addAll(gameBoard.neighbors(position));
if(newElementPosition.containsKey(position))
newElementPosition.get(position).add(this);
else {
newElementPosition.put(position,(new ArrayList<>()));
newElementPosition.get(position).add(this);
}
for(Position newPosition : newPositions){
//if(extinguishPosition.contains(newPosition))
//continue;
if(GameBoard.elementPosition.containsKey(newPosition)) {
for(BoardElement boardElement : GameBoard.elementPosition.get(newPosition)){
if(boardElement.accept(new FireFinder()) && boardElement.accept(new CrossRoad()) && boardElement.accept(new CrossMountain())){
break;
}
else if(!boardElement.accept( new FireFinder())&& !boardElement.accept(new CrossRoad()) && !boardElement.accept(new CrossMountain())){
GameBoard.elementPosition.get(newPosition).add(this);
newElementPosition.get(newPosition).add(this);
}
}
......@@ -84,11 +94,18 @@ public class Fire implements Flammable{
else{
ArrayList<BoardElement> boardElements = new ArrayList<>();
boardElements.add(this);
GameBoard.elementPosition.put(newPosition,boardElements);
newElementPosition.put(newPosition,boardElements);
System.out.println(GameBoard.elementPosition.get(position).get(0).getColor());
}
}
}else{
if(newElementPosition.containsKey(position))
newElementPosition.get(position).add(this);
else {
newElementPosition.put(position,(new ArrayList<>()));
newElementPosition.get(position).add(this);
}
}
}
......
......@@ -10,5 +10,5 @@ import java.util.List;
public interface Flammable extends BoardElement{
void update(GameBoard gameBoard, Position position);
void update(GameBoard gameBoard, Position position,HashMap<Position, ArrayList<BoardElement>> newElementPosition, ArrayList<Position> extinguishPosition);
}
......@@ -40,29 +40,35 @@ public class GameBoard implements Board{
}
@Override
public void updateToNextGeneration() {
HashMap<Position, ArrayList<BoardElement>> elementPositionCopie = new HashMap<>();
HashMap<Position, ArrayList<BoardElement>> newElementPosition = new HashMap<>();
ArrayList<Position> extinguishPosition = new ArrayList<>();
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPosition.entrySet()){
elementPositionCopie.put(entry.getKey(),entry.getValue());
}
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPositionCopie.entrySet()){
for(BoardElement element : entry.getValue()){
if (!element.accept(new FireFinder())){
ExtinguishFire element1 = (ExtinguishFire) element;
element1.update(this,entry.getKey());
element1.update(this,entry.getKey(),newElementPosition,extinguishPosition);
}
}
}
/*for (Map.Entry<Position, ArrayList<BoardElement>> entryCopie : elementPositionCopie.entrySet()){
for(BoardElement element : entryCopie.getValue()){
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPosition.entrySet()){
for(BoardElement element : entry.getValue()){
if (element.accept(new FireFinder())){
Flammable element1 = (Flammable) element;
element1.update(this,entryCopie.getKey());
element1.update(this,entry.getKey(),newElementPosition,extinguishPosition);
}
}
}*/
}
elementPosition.clear();
extinguishPosition.clear();
for (Map.Entry<Position, ArrayList<BoardElement>> entry : newElementPosition.entrySet()){
if(elementPosition.containsKey(entry.getKey())){
elementPosition.get(entry.getKey()).addAll(entry.getValue());
}else{
elementPosition.put(entry.getKey(),entry.getValue());
}
}
step++;
......@@ -112,16 +118,13 @@ public class GameBoard implements Board{
}
public Position neighborClosestToFire(Position position) {
HashMap<Position, ArrayList<BoardElement>> elementPositionCopie = new HashMap<>();
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPosition.entrySet()){
elementPositionCopie.put(entry.getKey(),entry.getValue());
}
FireFinder fireFinder = new FireFinder();
Set<Position> firePositions = new HashSet<>();
Set<Position> seen = new HashSet<>();
HashMap<Position, Position> firstMove = new HashMap<>();
Queue<Position> toVisit = new LinkedList<>(neighbors(position));
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPositionCopie.entrySet()){
for (Map.Entry<Position, ArrayList<BoardElement>> entry : elementPosition.entrySet()){
for(BoardElement element : entry.getValue()){
if (element.accept(fireFinder)){
firePositions.add(entry.getKey());
......@@ -144,7 +147,7 @@ public class GameBoard implements Board{
return position;
}
public void extinguish(Position position) {
/*public void extinguish(Position position) {
FireFinder fireFinder = new FireFinder();
HashMap<Position, ArrayList<BoardElement>> elementPositionCopie = new HashMap<>();
for (Map.Entry<Position, ArrayList<BoardElement>> entry : this.elementPosition.entrySet()){
......@@ -160,6 +163,6 @@ public class GameBoard implements Board{
this.elementPosition.remove(position);
}
}
}
}*/
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment