Skip to content
Snippets Groups Projects
Commit 544ea43d authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

PointType moved to view

parent 98108d52
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ public enum CardinalDirection { ...@@ -6,6 +6,8 @@ public enum CardinalDirection {
SOUTH(1, 0), SOUTH(1, 0),
WEST(0, -1); WEST(0, -1);
public static final int NUMBER_OF_DIRECTIONS = values().length;
public final int deltaRow; public final int deltaRow;
public final int deltaColumn; public final int deltaColumn;
......
package model; package model;
import javafx.scene.paint.Color;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Random;
public class Grid implements Iterable<Square> { public class Grid implements Iterable<Square> {
private final int numberOfRows; private final int numberOfRows;
...@@ -21,6 +16,10 @@ public class Grid implements Iterable<Square> { ...@@ -21,6 +16,10 @@ public class Grid implements Iterable<Square> {
* less than or equal to 0 * less than or equal to 0
*/ */
public Grid(int numberOfRows, int numberOfColumns) { public Grid(int numberOfRows, int numberOfColumns) {
if(numberOfRows <= 0)
throw new IllegalArgumentException("The number of rows must be positive and not equal to " + numberOfRows);
if(numberOfColumns <= 0)
throw new IllegalArgumentException("The number of columns must be positive and not equal to " + numberOfColumns);
this.numberOfRows = numberOfRows; this.numberOfRows = numberOfRows;
this.numberOfColumns = numberOfColumns; this.numberOfColumns = numberOfColumns;
squares = new Square[getNumberOfRows()][getNumberOfColumns()]; squares = new Square[getNumberOfRows()][getNumberOfColumns()];
...@@ -32,6 +31,12 @@ public class Grid implements Iterable<Square> { ...@@ -32,6 +31,12 @@ public class Grid implements Iterable<Square> {
initializeNeighborhood(); initializeNeighborhood();
} }
private void initializeSquares() {
for(int row = 0; row < getNumberOfRows(); row++)
for(int column = 0; column < getNumberOfColumns(); column++)
squares[row][column] = new Square();
}
private void initializeNeighborhood() { private void initializeNeighborhood() {
for(int row = 0; row < getNumberOfRows(); row++) for(int row = 0; row < getNumberOfRows(); row++)
for(int column = 0; column < getNumberOfColumns(); column++) { for(int column = 0; column < getNumberOfColumns(); column++) {
...@@ -44,12 +49,6 @@ public class Grid implements Iterable<Square> { ...@@ -44,12 +49,6 @@ public class Grid implements Iterable<Square> {
} }
} }
private void initializeSquares() {
for(int row = 0; row < getNumberOfRows(); row++)
for(int column = 0; column < getNumberOfColumns(); column++)
squares[row][column] = new Square();
}
private boolean containsCoordinates(int row, int column){ private boolean containsCoordinates(int row, int column){
return 0 <= row && row < numberOfRows && 0 <= column && column < numberOfColumns; return 0 <= row && row < numberOfRows && 0 <= column && column < numberOfColumns;
} }
...@@ -71,6 +70,7 @@ public class Grid implements Iterable<Square> { ...@@ -71,6 +70,7 @@ public class Grid implements Iterable<Square> {
public Square getSquare(int rowIndex, int columnIndex) { public Square getSquare(int rowIndex, int columnIndex) {
return squares[rowIndex][columnIndex]; return squares[rowIndex][columnIndex];
} }
public int getNumberOfRows() { public int getNumberOfRows() {
return numberOfRows; return numberOfRows;
} }
......
...@@ -3,6 +3,7 @@ package model; ...@@ -3,6 +3,7 @@ package model;
import java.util.Optional; import java.util.Optional;
public class Square { public class Square {
private Tile tile; private Tile tile;
private Square[] neighboringSquares; private Square[] neighboringSquares;
...@@ -12,10 +13,9 @@ public class Square { ...@@ -12,10 +13,9 @@ public class Square {
} }
public Square(){ public Square(){
this(null, new Square[4]); this(null, new Square[CardinalDirection.NUMBER_OF_DIRECTIONS]);
} }
public Optional<Tile> getSquareTile(){ public Optional<Tile> getSquareTile(){
if(!hasTile()) if(!hasTile())
return Optional.empty(); return Optional.empty();
...@@ -36,9 +36,6 @@ public class Square { ...@@ -36,9 +36,6 @@ public class Square {
return neighboringSquares[side.ordinal()].getSquareTile(); return neighboringSquares[side.ordinal()].getSquareTile();
} }
public void setNeighboringSquares(Square[] neighboringSquares) {
this.neighboringSquares = neighboringSquares;
}
public void setNeighboringSquare(Square neighboringSquare, CardinalDirection direction) { public void setNeighboringSquare(Square neighboringSquare, CardinalDirection direction) {
this.neighboringSquares[direction.ordinal()] = neighboringSquare; this.neighboringSquares[direction.ordinal()] = neighboringSquare;
} }
......
...@@ -3,12 +3,10 @@ package view; ...@@ -3,12 +3,10 @@ package view;
import javafx.beans.NamedArg; import javafx.beans.NamedArg;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import model.*; import model.*;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Random;
public class GridTileCanvas extends Canvas { public class GridTileCanvas extends Canvas {
......
package model; package view;
import model.CardinalDirection;
import java.util.List; import java.util.List;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment