Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • ImprovedMouseInteraction
  • correction_video
  • going_further
  • main
  • ModifGUI
  • final2023
  • template
7 results

Target

Select target project
  • s20026898/tp-6
  • boukenze.b/jeu-de-la-vie-tp-3
  • b22015696/game-of-life-template
  • s23026062/sahin-game-of-life-template
  • m22023183/game-of-life-MALEK
  • z23012739/game-of-life-template
  • p23021107/poussardin-malo-game-of-life-template
  • o21225801/game-of-life-template
  • alaboure/game-fo-life-template
  • t22007439/game-of-life-toullec
  • b23021750/game-of-life
  • c22029830/game-of-life-template-rafi
  • b23025683/game-of-life-template-tp-6
  • gnaves/game-of-life-template
  • a22025223/game-of-life-template-cristel
  • f22024692/game-of-life-template-paolo-mathis-erwan
  • t21233923/game-fo-life-template
  • h21231335/game-fo-life-template
  • l22023519/game-of-life-template-salma
  • p23020787/game-of-life-template
  • b21232450/game-of-life-template
  • s22031458/game-of-life
  • n21223697/tp-4-ngom
  • a22027291/game-of-life-of-salim
  • k22029508/tp-4
  • s19033421/game-of-life-template
  • b21229750/jeu-de-la-vie-tp-3
  • saddem.r/game-of-life-template
  • l3_s3_infoamu/s3/programmation-2/game-fo-life-template
29 results
Select Git revision
  • ImprovedMouseInteraction
  • correction_video
  • going_further
  • main
  • ModifGUI
  • final2023
  • template
7 results
Show changes
Commits on Source (3)
...@@ -9,6 +9,8 @@ import javafx.stage.Stage; ...@@ -9,6 +9,8 @@ import javafx.stage.Stage;
import model.CellularAutomatonSimulation; import model.CellularAutomatonSimulation;
import model.automata.BiColorAutomaton; import model.automata.BiColorAutomaton;
import model.automata.SeedsAutomaton; import model.automata.SeedsAutomaton;
import model.automata.WireWorldAutomata;
import model.automata.WireWorldState;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
...@@ -38,7 +40,7 @@ public class SimulatorApplication extends Application { ...@@ -38,7 +40,7 @@ public class SimulatorApplication extends Application {
public SimulatorApplication() { public SimulatorApplication() {
this.simulation = this.simulation =
new CellularAutomatonSimulation<>( new CellularAutomatonSimulation<>(
new BiColorAutomaton(NUMBER_OF_COLUMNS,NUMBER_OF_ROWS), new WireWorldAutomata(NUMBER_OF_COLUMNS,NUMBER_OF_ROWS),
GENERATOR GENERATOR
); );
} }
......
...@@ -28,7 +28,7 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit ...@@ -28,7 +28,7 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
@Override @Override
public S initialValueAt(Coordinate coordinate) { public S initialValueAt(Coordinate coordinate) {
List<State<S>> neighbours = new ArrayList<>(); List<S> neighbours = new ArrayList<>();
for (Coordinate neighbourCoord : coordinate.orthodiagonalNeighbours()) { for (Coordinate neighbourCoord : coordinate.orthodiagonalNeighbours()) {
Coordinate wrapped = wrap(neighbourCoord); Coordinate wrapped = wrap(neighbourCoord);
neighbours.add(this.simulation.at(wrapped).get()); neighbours.add(this.simulation.at(wrapped).get());
...@@ -45,7 +45,7 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit ...@@ -45,7 +45,7 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @param coordinate a {@link Coordinate} that may be outside the grid. * @param coordinate a {@link Coordinate} that may be outside the grid.
* @return a corresponding {@link Coordinate}, that is inside the grid. * @return a corresponding {@link Coordinate}, that is inside the grid.
*/ */
private Coordinate wrap(Coordinate coordinate) { Coordinate wrap(Coordinate coordinate) {
return new Coordinate( return new Coordinate(
modulo(coordinate.x(),this.simulation.numberOfColumns()), modulo(coordinate.x(),this.simulation.numberOfColumns()),
modulo(coordinate.y(),this.simulation.numberOfRows()) modulo(coordinate.y(),this.simulation.numberOfRows())
...@@ -58,7 +58,7 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit ...@@ -58,7 +58,7 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @param d a non-zero integer. * @param d a non-zero integer.
* @return the remainder of {@code n/d}, between {@code 0} and {@code n-1}. * @return the remainder of {@code n/d}, between {@code 0} and {@code n-1}.
*/ */
private static int modulo(int n, int d) { static int modulo(int n, int d) {
int result = n % d; int result = n % d;
return n < 0 ? result + d : result; return n < 0 ? result + d : result;
} }
......
package model.automata;
import model.CellularAutomaton;
import java.util.Random;
public class WireWorldAutomata implements CellularAutomaton<WireWorldState> {
private final int numberOfColumns;
private final int numberOfRows;
public WireWorldAutomata(int numberOfColumns, int numberOfRows) {
this.numberOfColumns = numberOfColumns;
this.numberOfRows = numberOfRows;
}
@Override
public int numberOfColumns() {
return this.numberOfColumns;
}
@Override
public int numberOfRows() {
return this.numberOfRows;
}
@Override
public WireWorldState defaultState() {
return WireWorldState.DEAD;
}
@Override
public WireWorldState randomState(Random generator) {
int r = generator.nextInt(18);
return r < 5 ? WireWorldState.CONDUCTOR:
r == 5 ? WireWorldState.HEAD:
WireWorldState.DEAD;
}
}
package model.automata;
import javafx.scene.paint.Color;
import model.State;
import java.util.List;
public enum WireWorldState implements State<WireWorldState> {
DEAD, CONDUCTOR, HEAD, TAIL;
@Override
public Color getColor() {
return switch (this) {
case DEAD -> Color.BLACK;
case CONDUCTOR -> Color.GOLD;
case HEAD -> Color.BLUE;
case TAIL -> Color.RED;
};
}
@Override
public WireWorldState next() {
return switch (this) {
case DEAD -> CONDUCTOR;
case CONDUCTOR -> HEAD;
case HEAD -> TAIL;
case TAIL -> DEAD;
};
}
@Override
public WireWorldState update(List<WireWorldState> neighbours) {
return switch (this) {
case DEAD -> DEAD;
case CONDUCTOR -> {
int heads = State.count(HEAD,neighbours);
yield heads == 1 || heads == 2 ? HEAD: CONDUCTOR;
}
case HEAD -> TAIL;
case TAIL -> CONDUCTOR;
};
}
}
...@@ -3,12 +3,12 @@ package view; ...@@ -3,12 +3,12 @@ package view;
import datastruct.Coordinate; import datastruct.Coordinate;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
public class FillingMouseListener implements MouseListener { public class DraggingListener implements MouseListener {
private final MatrixPane matrix; private final MatrixPane matrix;
private final Coordinate source; private final Coordinate source;
public FillingMouseListener(MatrixPane matrix, Coordinate source) { public DraggingListener(MatrixPane matrix, Coordinate source) {
this.matrix = matrix; this.matrix = matrix;
this.source = source; this.source = source;
} }
...@@ -29,9 +29,8 @@ public class FillingMouseListener implements MouseListener { ...@@ -29,9 +29,8 @@ public class FillingMouseListener implements MouseListener {
@Override @Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) { public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().next(coordinate);
this.matrix.setMouseListener( this.matrix.setMouseListener(
new FillingMouseListener(this.matrix, coordinate) new MousePressedListener(this.matrix, coordinate)
); );
} }
......
...@@ -8,6 +8,8 @@ import javafx.scene.layout.GridPane; ...@@ -8,6 +8,8 @@ import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import java.util.List;
/** /**
* Created by Arnaud Labourel on 22/11/2018. * Created by Arnaud Labourel on 22/11/2018.
*/ */
...@@ -62,7 +64,11 @@ public class MatrixPane extends GridPane { ...@@ -62,7 +64,11 @@ public class MatrixPane extends GridPane {
event -> this.startFullDrag() event -> this.startFullDrag()
); );
cellRectangle.addEventHandler( cellRectangle.addEventHandler(
MouseDragEvent.MOUSE_DRAG_RELEASED, MouseEvent.MOUSE_CLICKED,
event -> mouseListener.onMouseClicked(event, coord)
);
cellRectangle.addEventHandler(
MouseDragEvent.MOUSE_RELEASED,
event -> mouseListener.onMouseReleased(event, coord) event -> mouseListener.onMouseReleased(event, coord)
); );
cellRectangle.addEventHandler( cellRectangle.addEventHandler(
...@@ -78,6 +84,8 @@ public class MatrixPane extends GridPane { ...@@ -78,6 +84,8 @@ public class MatrixPane extends GridPane {
} }
void resetWaitingListener() { void resetWaitingListener() {
this.mouseListener = new WaitingMouseListener(this); setMouseListener(new WaitingMouseListener(this));
} }
} }
...@@ -5,6 +5,7 @@ import javafx.scene.input.MouseEvent; ...@@ -5,6 +5,7 @@ import javafx.scene.input.MouseEvent;
interface MouseListener { interface MouseListener {
default void onMouseClicked(MouseEvent event, Coordinate coordinate) {}
default void onMousePressed(MouseEvent event, Coordinate coordinate) {} default void onMousePressed(MouseEvent event, Coordinate coordinate) {}
default void onMouseReleased(MouseEvent event, Coordinate coordinate) {} default void onMouseReleased(MouseEvent event, Coordinate coordinate) {}
default void onMouseEntered(MouseEvent event, Coordinate coordinate) {}; default void onMouseEntered(MouseEvent event, Coordinate coordinate) {};
......
package view;
import datastruct.Coordinate;
import javafx.scene.input.MouseEvent;
public class MousePressedListener implements MouseListener {
private final Coordinate pressedCoordinate;
private final MatrixPane matrix;
public MousePressedListener(MatrixPane matrix, Coordinate coordinate) {
this.matrix = matrix;
this.pressedCoordinate = coordinate;
}
@Override
public void onMouseEntered(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().copy(pressedCoordinate,coordinate);
this.matrix.setMouseListener(new DraggingListener(this.matrix, pressedCoordinate));
}
@Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.setMouseListener(new MousePressedListener(this.matrix, coordinate));
}
@Override
public void onMouseReleased(MouseEvent event, Coordinate coordinate) {
if (coordinate.equals(pressedCoordinate)) {
this.matrix.getController().getSimulation().next(coordinate);
} else {
this.matrix.getController().getSimulation().copy(pressedCoordinate,coordinate);
}
this.matrix.resetWaitingListener();
}
}
...@@ -14,8 +14,7 @@ class WaitingMouseListener implements MouseListener { ...@@ -14,8 +14,7 @@ class WaitingMouseListener implements MouseListener {
@Override @Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) { public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().next(coordinate); this.matrix.setMouseListener(new MousePressedListener(this.matrix, coordinate));
this.matrix.setMouseListener(new FillingMouseListener(this.matrix, coordinate));
} }
......