parent
5376edb37a
commit
c098ee634e
@ -0,0 +1,17 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class CellulesVivantes {
|
||||||
|
private HashMap<Position, Cellule> cellVivantes;
|
||||||
|
|
||||||
|
public Cellule getAt(int x, int y){
|
||||||
|
Position p = new Position(x, y);
|
||||||
|
return cellVivantes.get(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPeer(int x, int y, Cellule cell){
|
||||||
|
Position p = new Position(x, y);
|
||||||
|
cellVivantes.put(p, cell);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public class CompteurDeCellule {
|
||||||
|
public int compteNombreCellulesAutour(int x, int y, Plateau plateau){
|
||||||
|
int cpt = 0;
|
||||||
|
try {
|
||||||
|
if(plateau.getCell(x-1, y-1).estAlive())
|
||||||
|
{
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (plateau.getCell(x, y - 1).estAlive()) {
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(plateau.getCell(x+1, y-1).estAlive())
|
||||||
|
{
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(plateau.getCell(x+1, y).estAlive())
|
||||||
|
{
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (plateau.getCell(x + 1, y + 1).estAlive()) {
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (plateau.getCell(x, y + 1).estAlive()) {
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (plateau.getCell(x - 1, y + 1).estAlive()) {
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (plateau.getCell(x - 1, y).estAlive()) {
|
||||||
|
++cpt;
|
||||||
|
}
|
||||||
|
}catch (IllegalArgumentException e){}
|
||||||
|
|
||||||
|
return cpt;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
public abstract class ObservableCellule {
|
||||||
|
Collection<Observer> observeurs;
|
||||||
|
public ObservableCellule(){
|
||||||
|
observeurs = new TreeSet<>();
|
||||||
|
}
|
||||||
|
public void attacher(Observer o) throws IllegalArgumentException{
|
||||||
|
if(o == null){
|
||||||
|
throw new IllegalArgumentException("L'observer ne doit pas être null");
|
||||||
|
}
|
||||||
|
observeurs.add(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void detacher(Observer o) throws IllegalArgumentException{
|
||||||
|
if(o == null){
|
||||||
|
throw new IllegalArgumentException("L'observer ne doit pas être null");
|
||||||
|
}
|
||||||
|
observeurs.remove(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifier() {
|
||||||
|
for (Observer observeur : observeurs) {
|
||||||
|
observeur.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public class Position {
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
|
||||||
|
public Position(int x, int y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
public enum Regles {
|
|
||||||
ConwaySStyle
|
|
||||||
}
|
|
Loading…
Reference in new issue