From 40981004e2e4b20949d65f0719e4330f70a644e6 Mon Sep 17 00:00:00 2001 From: Hang <thi-hang.NGUYEN@etu.univ-amu.fr> Date: Wed, 16 Nov 2022 08:49:47 +0100 Subject: [PATCH] THN --- app/src/main/java/model/ArrayGrid.java | 26 +++++++++++++++++-- .../main/java/model/ColoredCellIerator.java | 2 +- app/src/main/java/model/ComputerPlayer.java | 4 +-- .../java/model/DistinctColorGenerator.java | 3 ++- app/src/main/java/model/SquareCell.java | 2 +- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/model/ArrayGrid.java b/app/src/main/java/model/ArrayGrid.java index c75fa18..8838c64 100644 --- a/app/src/main/java/model/ArrayGrid.java +++ b/app/src/main/java/model/ArrayGrid.java @@ -1,6 +1,8 @@ package model; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; public class ArrayGrid implements Grid{ @@ -17,10 +19,30 @@ public class ArrayGrid implements Grid{ for (int i=0; i< numberOfRows;i++){ for (int j=0; j < numberOfColumns; j++){ cells[i][j] = new SquareCell(); + } } } - - }} + for(int i=0; i< this.numberOfRows;i++){ + for(int j=0; j< this.numberOfColumns; j++){ + List<Cell> neighbours= new ArrayList<Cell>(); + if (i==0) + neighbours.add(getCell(i+1,j)); + if (i==numberOfRows-1) + neighbours.add(getCell(i-1,j)); + if (j==0) + neighbours.add(getCell(i,j+1)); + if (j==numberOfColumns-1) + neighbours.add(getCell(i, j-1)); + else { + neighbours.add(getCell(i - 1, j)); + neighbours.add(getCell(i, j - 1)); + neighbours.add(getCell(i + 1, j)); + neighbours.add(getCell(i, j + 1)); + } + getCell(i,j).setNeighbours(neighbours); + } + } + } @Override public Cell getCell(int row, int column) { return this.cells[row][column]; diff --git a/app/src/main/java/model/ColoredCellIerator.java b/app/src/main/java/model/ColoredCellIerator.java index 0800efb..43dfb40 100644 --- a/app/src/main/java/model/ColoredCellIerator.java +++ b/app/src/main/java/model/ColoredCellIerator.java @@ -7,7 +7,7 @@ import util.SetUtil; import java.util.*; -public class ColoredCellIerator{ /*implements Iterator<Cell> { +public class ColoredCellIerator {/*implements Iterator<Cell> { Color color; List<Cell> cells; diff --git a/app/src/main/java/model/ComputerPlayer.java b/app/src/main/java/model/ComputerPlayer.java index a869940..b97bf17 100644 --- a/app/src/main/java/model/ComputerPlayer.java +++ b/app/src/main/java/model/ComputerPlayer.java @@ -3,7 +3,7 @@ package model; import com.sun.prism.paint.Color; public class ComputerPlayer implements Player{ - PlayStrate sdfdsfdsfm + //PlayStrate sdfdsfdsfm @Override public boolean isHuman() { return false; @@ -24,7 +24,7 @@ public class ComputerPlayer implements Player{ return null; } public javafx.scene.paint.Color play(){ - return Color.RED; + return null ;// Color.RED; } } diff --git a/app/src/main/java/model/DistinctColorGenerator.java b/app/src/main/java/model/DistinctColorGenerator.java index f2eb4e2..3a70a73 100644 --- a/app/src/main/java/model/DistinctColorGenerator.java +++ b/app/src/main/java/model/DistinctColorGenerator.java @@ -27,7 +27,8 @@ public class DistinctColorGenerator implements ColorGenerator { } for (int i = 0; i < colors.size(); i++) { for (int j = 0; j < neighbor_colors.size(); j++) { - //if (colors.get(i)==neighbor_colors.get(j)) //break;//if (!(neighbor_colors.contains(colors.get(i)))){ + if (colors.get(i)==neighbor_colors.get(j)) + break;//if (!(neighbor_colors.contains(colors.get(i)))){ } return this.colors.get(i); diff --git a/app/src/main/java/model/SquareCell.java b/app/src/main/java/model/SquareCell.java index d4941b2..617bb82 100644 --- a/app/src/main/java/model/SquareCell.java +++ b/app/src/main/java/model/SquareCell.java @@ -10,10 +10,10 @@ public class SquareCell extends AbstractCell{ private List<Cell> neighbours; - public SquareCell (){ this.setColor( DEFAULT_CELL_COLOR); this.neighbours=new ArrayList<Cell>(); + } public SquareCell(Color color){ this.setColor(color); -- GitLab