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