Skip to content

Commit 09f5369

Browse files
committed
Possible to check if board character deceased and should be deleted from board (+ meadow-board template)
1 parent de90deb commit 09f5369

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/main/java/Animal.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public Animal(int toReproduce, int endurance, int health){
1414
this.roundsStarving = 0;
1515
}
1616

17+
@Override
18+
public boolean didDeceased() {
19+
return this.health <= 0;
20+
}
21+
1722
@Override
1823
public BoardMovement makeInteraction(BoardMovement with){
1924
if (this.canEat(with)){

src/main/java/BoardMovement.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
public interface BoardMovement {
22

3-
public String getEmoji();
3+
String getEmoji();
44

5-
public BoardMovement makeInteraction(BoardMovement with);
5+
BoardMovement makeInteraction(BoardMovement with);
6+
7+
boolean didDeceased();
68
}

src/main/java/MeadowBoard.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ public void makeTurn(int iX, int iY){
7070
if (isFieldEmpty(xNew, yNew)){
7171
this.move(iX, iY, xNew, yNew);
7272
} else {
73-
BoardMovement possibleReproduction = this.getMeadow()[iX][iY].makeInteraction(this.getMeadow()[xNew][yNew]);
73+
BoardMovement interacted = this.getMeadow()[xNew][yNew];
74+
BoardMovement possibleReproduction = this.getMeadow()[iX][iY].makeInteraction(interacted);
75+
if (interacted.didDeceased()){
76+
// erase from board
77+
}
7478
if (possibleReproduction != null){
7579
// placing new
7680
}

src/main/java/Plant.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import lombok.Getter;
2+
13
public abstract class Plant implements BoardMovement{
24

35
int roundToReproduce;
46
int rounds;
57
double reproduceChance;
8+
private boolean deceased;
69

710
public Plant(int toReproduce, int reproduceChance){
811
this.roundToReproduce = toReproduce;
912
this.rounds = 0;
1013
this.reproduceChance = (double) reproduceChance / 100;
14+
this.deceased = false;
1115
}
1216

1317
public Plant(int toReproduce, double reproduceChance){
@@ -21,5 +25,14 @@ public BoardMovement makeInteraction(BoardMovement with){
2125
return null;
2226
}
2327

28+
@Override
29+
public boolean didDeceased() {
30+
return this.deceased;
31+
}
32+
33+
public void beingEaten(){
34+
this.deceased = true;
35+
}
36+
2437
public abstract Plant reproduce();
2538
}

0 commit comments

Comments
 (0)