Skip to content
Snippets Groups Projects
Commit d75d0b87 authored by etienne's avatar etienne
Browse files

bug de clignotement corrigé

parent 7c215aef
No related branches found
No related tags found
No related merge requests found
...@@ -22,8 +22,9 @@ public class GameOfLifeGUI extends JFrame { ...@@ -22,8 +22,9 @@ public class GameOfLifeGUI extends JFrame {
labelGrid[x][y] = new JLabel("*"); labelGrid[x][y] = new JLabel("*");
JLabel label; JLabel label;
if(g.getCell(x,y).isAlive()){ if(g.getCell(x,y).isAlive()){
if (g.getCell(x,y).isRed()) labelGrid[x][y].setForeground(Color.red); labelGrid[x][y].setForeground(Color.red);
else labelGrid[x][y].setForeground(Color.BLUE); //if (g.getCell(x,y).isRed()) labelGrid[x][y].setForeground(Color.red);
//else labelGrid[x][y].setForeground(Color.BLUE);
} }
else else
labelGrid[x][y].setForeground(Color.white); labelGrid[x][y].setForeground(Color.white);
......
...@@ -132,10 +132,15 @@ public class Grid implements Iterable<Cell> { ...@@ -132,10 +132,15 @@ public class Grid implements Iterable<Cell> {
private boolean calculateNextColor(int rowIndex, int columnIndex) { private boolean calculateNextColor(int rowIndex, int columnIndex) {
int aliveNeighbours = countAliveNeighbours(rowIndex,columnIndex); //int aliveNeighbours = countAliveNeighbours(rowIndex,columnIndex);
int redNeighbours = countRedNeighbours(rowIndex,columnIndex); //int redNeighbours = countRedNeighbours(rowIndex,columnIndex);
if (aliveNeighbours == 3) return (redNeighbours > aliveNeighbours - redNeighbours); //if (aliveNeighbours == 3) return (redNeighbours >= aliveNeighbours - redNeighbours);
return !(redNeighbours > aliveNeighbours - redNeighbours); //return !(redNeighbours >= aliveNeighbours - redNeighbours);
if (getCell(rowIndex,columnIndex).isDead() && calculateNextState(rowIndex,columnIndex)){
return countRedNeighbours(rowIndex,columnIndex)>=countAliveNeighbours(rowIndex,columnIndex)-countRedNeighbours(rowIndex,columnIndex);
}
return getCell(rowIndex,columnIndex).isRed();
} }
private int countAliveNeighbours(int rowIndex, int columnIndex) { private int countAliveNeighbours(int rowIndex, int columnIndex) {
...@@ -226,8 +231,9 @@ public class Grid implements Iterable<Cell> { ...@@ -226,8 +231,9 @@ public class Grid implements Iterable<Cell> {
for (int row = 0; row < this.numberOfRows; row++){ for (int row = 0; row < this.numberOfRows; row++){
for (int col = 0; col < this.numberOfColumns; col++) { for (int col = 0; col < this.numberOfColumns; col++) {
if (random.nextBoolean()){ if (random.nextBoolean()){
this.cells[row][col].setAlive();
this.cells[row][col].setColor(random.nextBoolean()); this.cells[row][col].setColor(random.nextBoolean());
this.cells[row][col].setAlive();
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment