Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
No results found
Select Git revision
  • master
1 result
Show changes

Commits on Source 1

16 files
+ 193
50
Compare changes
  • Side-by-side
  • Inline

Files

+26 −20
Original line number Diff line number Diff line
@@ -4,11 +4,16 @@

public class Cell {
    private boolean isAlive;
    private String color = "Black";

    public Cell(){
        this.isAlive = false;
    }

    public void setColor(String hisColor) { color = hisColor; }

    public String getColor() { return color; }

    /**
     * Determines whether this {@link Cell} is alive or not.
     *
@@ -19,6 +24,7 @@ public class Cell {
        return this.isAlive;
    }


    /**
     * Determines whether this {@link Cell} is dead or not.
     *
+27 −21
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ public class GameOfLifeGUI extends JFrame {
                labelGrid[x][y] = new JLabel("*");
                JLabel label;
                if(g.getCell(x,y).isAlive())
		   labelGrid[x][y].setForeground(Color.red);
                    labelGrid[x][y].setForeground(Color.black);
                else
                    labelGrid[x][y].setForeground(Color.white);
                gridPanel.add(labelGrid[x][y]);
@@ -39,10 +39,16 @@ public class GameOfLifeGUI extends JFrame {
        for (int x = 0; x < numberOfColumns; x++)
            for (int y = 0; y < numberOfRows; y++){
                JLabel label = labelGrid[x][y];
		if(g.getCell(x,y).isAlive())
		    label.setForeground(Color.red);
                if(g.getCell(x,y).isAlive()) {
                    if ((g.getCell(x,y).getColor()).equals("Black")) {
                        label.setForeground(Color.black);
                    } else {
                        label.setForeground(Color.blue);
                    }
                }
                else
                    label.setForeground(Color.white);
            }
    }
}
+89 −9
Original line number Diff line number Diff line
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.*;

/**
 * {@code Grid} instances represent the grid in <i>The Game of Life</i>.
@@ -98,29 +95,95 @@ public class Grid implements Iterable<Cell> {
    }

    private boolean[][] calculateNextStates() {
        return null;
        boolean[][] tableau=new boolean[numberOfRows][numberOfColumns];
        for (int row=0;row<numberOfRows;row++){
            for (int column=0;column<numberOfColumns;column++){
                tableau[row][column]=calculateNextState(row,column,getCell(row,column));
            }
        }
        return tableau;
    }

    private boolean calculateNextState(int rowIndex, int columnIndex, Cell cell) {
	return false;
        boolean Nextstate = cell.isAliveInNextState(this.countAliveNeighbours(rowIndex, columnIndex));
        if (Nextstate) {
            if (this.countAliveNeighbours(rowIndex, columnIndex) != 2) {
                cell.setColor(this.countColorNeighbours(rowIndex, columnIndex));
            }
        }
        return Nextstate;
    }

    private int countAliveNeighbours(int rowIndex, int columnIndex) {
        return 0;
        int AliveNeighbours=0;
        List<Cell> Neighbours=getNeighbours(rowIndex,columnIndex);
        for(Cell cell:Neighbours){
            if(cell.isAlive()){
                AliveNeighbours++;
            }
        }
        return AliveNeighbours;
    }


    private List<Cell> getNeighbours(int rowIndex, int columnIndex) {
	return null;
        List<Cell> listofNeighbours= new ArrayList<Cell>(0);
        listofNeighbours.add(getCell(rowIndex+1,columnIndex-1));
        listofNeighbours.add(getCell(rowIndex+1,columnIndex));
        listofNeighbours.add(getCell(rowIndex+1,columnIndex+1));
        listofNeighbours.add(getCell(rowIndex,columnIndex+1));
        listofNeighbours.add(getCell(rowIndex-1,columnIndex+1));
        listofNeighbours.add(getCell(rowIndex-1,columnIndex));
        listofNeighbours.add(getCell(rowIndex-1,columnIndex-1));
        listofNeighbours.add(getCell(rowIndex,columnIndex-1));
        return listofNeighbours;
    }

    private String countColorNeighbours(int rowIndex, int columnIndex) {
        String CounterColorCell;
        int Black = 0;
        int Blue = 0;
        for (Cell NeighboursCell : this.getNeighbours(rowIndex, columnIndex)) {
            if (NeighboursCell.isAlive()) {
                if ((NeighboursCell.getColor()).equals("Black")) {
                    Black+=1;
                }
                else {
                    Blue+=1;
                }
            }
        }
        if (Black>Blue) {
            CounterColorCell="Black";
        }
        else {
            CounterColorCell="Blue";
        }

        return CounterColorCell;
    }

    private void goToNextState(boolean[][] nextState) {
        for (int ligne = 0; ligne < numberOfRows; ligne++) {
            for (int column = 0; column < numberOfColumns; column++) {
                if (nextState[ligne][column])
                    getCell(ligne, column).setAlive();

                else
                    getCell(ligne, column).setDead();
            }
        }
    }

    /**
     * Sets all {@link Cell}s in this {@code Grid} as dead.
     */
    void clear() {
        for(int ligne=0;ligne<numberOfRows;ligne++){
            for(int column=0;column<numberOfColumns;column++){
                getCell(ligne,column).setDead();
            }
        }
    }

    /**
@@ -131,6 +194,23 @@ public class Grid implements Iterable<Cell> {
     */

    void randomGeneration(Random random) {
        for(int ligne=0;ligne<numberOfRows;ligne++){
            for(int column=0;column<numberOfColumns;column++){
                Cell cell=getCell(ligne,column);
                if(random.nextBoolean()){
                    cell.setAlive();
                    if (random.nextBoolean()) {
                        cell.setColor("Black");
                    }
                    else {
                        cell.setColor("Blue");
                    }
                }
                else
                    cell.isDead();
            }

        }
    }

}
+8 −0
Original line number Diff line number Diff line
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
+6 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="15" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/out" />
  </component>
</project>
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/tp3.iml" filepath="$PROJECT_DIR$/tp3.iml" />
    </modules>
  </component>
</project>
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="VcsDirectoryMappings">
    <mapping directory="" vcs="Git" />
  </component>
</project>
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>
 No newline at end of file

tp3.iml

0 → 100644
+11 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>
 No newline at end of file