Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
/**
* Returns a List of all neighbours. The List contains 1x2 arrays
* with coordinates.
*
* @param i height
* @param j width
* @return coordinate list
*/
public List<int[]> detectNeighbours(int i, int j) {
List<int[]> list = new ArrayList<int[]>();
/*
* All possible neighbours
* 123
* 4X6
* 789
*/
// 1
if (isInMatrix(i - 1, j - 1))
list.add(new int[] {i - 1, j - 1});
// 2
if (isInMatrix(i - 1, j))
list.add(new int[] {i - 1, j});
// 3
if (isInMatrix(i - 1, j + 1))
list.add(new int[] {i - 1, j + 1});
// 4
if (isInMatrix(i, j - 1))
list.add(new int[] {i, j - 1});
// 6
if (isInMatrix(i, j + 1))
list.add(new int[] {i, j + 1});
// 7
if (isInMatrix(i + 1, j - 1))
list.add(new int[] {i + 1, j - 1});
// 8
if (isInMatrix(i + 1, j))
list.add(new int[] {i + 1, j});
// 9
if (isInMatrix(i + 1, j + 1))
list.add(new int[] {i + 1, j + 1});
return list;
}
/**
* Are the coordinates within our matrix?
* @param x
* @param y
* @return point is in matrix
*/
private boolean isInMatrix(int x, int y) {
return !(x < 0 || x >= height || y < 0 || y >= width);
}
for (x=i-1; x<=i+1; x++) {
for (y=j-1; y<=j+1; y++) {
if (isInMatrix(x, y))
list.add(new int[] {x, y});
}
}
GenauMHertwig hat gesagt.:Da fehlt dann noch die Überpüfung ob (i,j) (x,y) entspricht, sollen ja nur die Nachbarpunkte sein, hier einfach eine Zeile Code unterschlagen, das geht ja nicht![]()