Newer
Older
package model;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.paint.Color;
import util.Position;
public class Square {
private List<Entity> entities;
private Position position;
public Square(Position position){
this.entities = new ArrayList<Entity>();
this.position = position;
}
public Square(Position position, Entity entity){
this.entities = new ArrayList<Entity>();
this.entities.add(entity);
this.position = position;
}
public List<Entity> getEntities(){
return this.entities;
}
public Position getPosition(){
return this.position;
}
public void addEntity(Entity entity){
entities.add(entity);
}
public void removeEntity(Entity entity){
entities.remove(entity);
}
public void setEntities(List<Entity> entities){
this.entities = entities;
}
public boolean isEmpty(){
return entities.isEmpty() ||(entities.size() == 1 && entities.get(0) instanceof EmptyEntity);
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
}
public int getMinimalAge(){
int minimalAge = 0;
for(Entity e : entities){
if(e.getAge() < minimalAge){
minimalAge = e.getAge();
}
}
return minimalAge;
}
public int getMaxAge(){
int maxAge = 0;
for(Entity e : entities){
if(e.getAge() > maxAge){
maxAge = e.getAge();
}
}
return maxAge;
}
public void incrementAllAges(){
for(Entity e : entities){
e.incrementAge();
}
}
public Color getViewColor(){
if (entities.isEmpty()) {
return Color.WHITE;
} else {
int sumRed = 0, sumGreen = 0, sumBlue = 0;
for (Entity e : entities) {
Color color = e.getViewColor();
if (color != null) {
Yanis OUALAN
committed
if(sumRed == 255 & sumGreen == 255 & sumBlue == 255){
continue;
}
sumRed += color.getRed();
sumGreen += color.getGreen();
sumBlue += color.getBlue();
}
}
int count = entities.size();
sumRed /= count;
sumGreen /= count;
sumBlue /= count;
Color color = new Color((double)(sumRed),(double)(sumGreen),(double)(sumBlue), 1.0);
return color;
}
}