Refactoring: vermeide identische Codeblöcke + entferne redundanten Code
This commit is contained in:
parent
bcd68cee42
commit
25b5a74454
Binary file not shown.
Binary file not shown.
@ -52,11 +52,12 @@ public class Life implements ILife {
|
|||||||
|
|
||||||
for (int y = 0; y < grid.length; y++) {
|
for (int y = 0; y < grid.length; y++) {
|
||||||
for (int x = 0; x < grid[y].length; x++) {
|
for (int x = 0; x < grid[y].length; x++) {
|
||||||
if (countAliveNeighbours(x, y) == 3) {
|
// Refactoring: vermeide zwei fast identische Codeblöcke (if-Abfragen)
|
||||||
|
if (countAliveNeighbours(x, y) == 3 || countAliveNeighbours(x, y) == 2) {
|
||||||
next.setAlive(x, y);
|
next.setAlive(x, y);
|
||||||
} else if (countAliveNeighbours(x, y) == 2) {
|
}
|
||||||
next.setAlive(x, y);
|
// Refactoring: zuvor gesetzte Bedingungen machen weitere Überprüfungen redundant
|
||||||
} else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) {
|
else {
|
||||||
next.setDead(x, y);
|
next.setDead(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user