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

bug de répartition des couleur corrigé

parent d75d0b87
No related branches found
No related tags found
No related merge requests found
import java.util.Random;
/**
* {@link Cell} instances represent the cells of <i>The Game of Life</i>.
*/
......@@ -9,7 +11,7 @@ public class Cell {
public Cell(){
this.isAlive = false;
this.isRed = false;
this.isRed = new Random().nextBoolean();
}
......@@ -18,7 +20,7 @@ public class Cell {
}
public boolean isRed(){
return isRed;
return this.isRed;
}
/**
* Determines whether this {@link Cell} is alive or not.
......
......@@ -25,8 +25,7 @@ public class GameOfLifeGUI extends JFrame {
labelGrid[x][y].setForeground(Color.red);
//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);
gridPanel.add(labelGrid[x][y]);
}
......@@ -45,9 +44,7 @@ public class GameOfLifeGUI extends JFrame {
if (g.getCell(x, y).isAlive()) {
if (g.getCell(x, y).isRed()) label.setForeground(Color.red);
else label.setForeground(Color.BLUE);
}
else
} else
label.setForeground(Color.white);
}
}
......
......@@ -202,8 +202,7 @@ public class Grid implements Iterable<Cell> {
private void goToNextColor(boolean[][] nextColor) {
for (int row = 0; row < this.numberOfRows; row++){
for (int col = 0; col < this.numberOfColumns; col++){
if (nextColor[row][col]) this.cells[row][col].setColor(true);
else this.cells[row][col].setColor(false);
this.cells[row][col].setColor(nextColor[row][col]);
}
}
......@@ -230,8 +229,9 @@ public class Grid implements Iterable<Cell> {
void randomGeneration(Random random) {
for (int row = 0; row < this.numberOfRows; row++){
for (int col = 0; col < this.numberOfColumns; col++) {
if (random.nextBoolean()){
this.cells[row][col].setColor(random.nextBoolean());
int a = random.nextInt(100);
if (a<=50){
this.cells[row][col].setColor(a<25);
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