Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Merge branch 'Final-stretch' of https://github.com/johannes67890/Mini…
Browse files Browse the repository at this point in the history
…tuareWorld into Final-stretch
  • Loading branch information
johannes67890 committed Dec 21, 2023
2 parents 0203cc2 + d55995b commit e3fde4c
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 41 deletions.
5 changes: 0 additions & 5 deletions src/main/Bear.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void act(World world) {
age++;
}

System.out.println(hunger);
setTerritory(territoryC, world); // set territory

//sleep at night
Expand Down Expand Up @@ -108,13 +107,11 @@ public void act(World world) {
//move from center
if (world.getLocation(this).equals(territoryC)) {
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Bear move from C");
return;
}

//move towards center
moveTowards(territoryC, world);
System.out.println("Bear move towards C");
}

public boolean protectTerritory(World world){
Expand All @@ -123,7 +120,6 @@ public boolean protectTerritory(World world){
for (Location view : world.getSurroundingTiles()) {
if (location.equals(view) && world.getTile(view) instanceof Animal) {
attack(view, world);
System.out.println("Bear attack to protect");
return true;
}
}
Expand All @@ -134,7 +130,6 @@ public boolean protectTerritory(World world){
for (Location view : world.getSurroundingTiles(vision)) {
if (location.equals(view) && world.getTile(view) instanceof Animal) {
moveTowards(view, world);
System.out.println("Bear move to attack to protect");
return true;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/Carcass.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void act(World world) {
// Chance for a fungus to spawn inside the carcass
if (!hasFungus && new Random().nextInt(5) == 0) {
addFungus(world.getLocation(this), world);
System.out.println("Fungus spawned in carcass");
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main/Fungus.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void spread(World world) {
Carcass carcass = (Carcass) world.getTile(location);
if (!carcass.hasFungus()) {
carcass.addFungus(world.getLocation(carcass), world);
System.out.println("Fungus spread");
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/Predator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public boolean attackForFood(World world) {
!world.getTile(location).getClass().equals(this.getClass())
) {
attack(location, world);
System.out.println(this.getClass().getSimpleName() + " Attack");
return true;
}
}
Expand All @@ -47,7 +46,6 @@ public boolean attackForFood(World world) {
!world.getTile(location).getClass().equals(this.getClass())) {
if(moveTowards(location, world)){
moveTowards(location, world);
System.out.println(this.getClass().getSimpleName() + " Move to attack");
return true;
} else return false;
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/Rabbit.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ public boolean moveAwayFromPredator(World world) {
for (Location location : world.getSurroundingTiles(vision)) {
if (world.getTile(location) instanceof Predator) {
if(moveAway(location, world)){
System.out.println("Rabbit move away from predator");
return true;
} else {
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Rabbit move random");
return true;
}
}
Expand All @@ -139,7 +137,7 @@ public boolean digBurrow(World world) {

public boolean reproduce(World world) {
for (Location location : world.getSurroundingTiles()) {
if (world.getTile(location) instanceof Rabbit) {
if (world.getTile(location) instanceof Rabbit && world.getTile(location) != this) {
Rabbit temp = (Rabbit) world.getTile(location);
if (temp.isAdult && world.getEmptySurroundingTiles().size() != 0) {
world.setTile(getRandomEmptySurroundingTile(world), new Rabbit());
Expand Down
13 changes: 1 addition & 12 deletions src/main/Snake.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,54 @@ public void act(World world) {
age++;
}

System.out.println(hunger);
//sleep at night
isSleeping = world.isNight();
if (isSleeping) {
System.out.println("Snake sleeping");
return;
}

if (life(world)) {
System.out.println("Snake dead");
return;
}

// if starving
if (starving) {
if (food(world)) {
System.out.println("Snake starving, food");
return;
}
if (attackForFood(world)) {
System.out.println("Snake starving, attack for food");
return;
}
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Snake move cuz starving");
}

//try to reproduce
if (new Random().nextInt(10) == 0 && isAdult) {
if (reproduce(world)) {
System.out.println("Snake reproduce");
return;
}
}

// if hungry
if (hungry) {
if (food(world)) {
System.out.println("Snake hungry, food");
return;
}
if (attackForFood(world)) {
System.out.println("Snake hungry, attack for food");
return;
}
}

// 50% for random move 50% for no move
if (new Random().nextBoolean()) {
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Snake move random");
return;
}
System.out.println("Snake do nothing");
}

public boolean reproduce(World world) {
for (Location location : world.getSurroundingTiles()) {
if (world.getTile(location) instanceof Snake) {
if (world.getTile(location) instanceof Snake && world.getTile(location) != this) {
Snake temp = (Snake) world.getTile(location);
if (temp.isAdult && world.getEmptySurroundingTiles().size()!=0) {
world.setTile(getRandomEmptySurroundingTile(world), new SnakeEgg());
Expand Down
16 changes: 0 additions & 16 deletions src/main/Wolf.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void act(World world) {
age++;
}

System.out.println(hunger);
// if in lair dont do anything
if (isInLair) {
return;
Expand All @@ -46,15 +45,12 @@ public void act(World world) {
if (world.isNight() && myPack.getHome(world) != null) {
if (world.getLocation(this).equals(world.getLocation(myPack.getHome(world)))) {
myPack.addToHome(this, world);
System.out.println("Wolf enters home");
return;
}
if(moveTowards(world.getLocation(myPack.getHome(world)), world)){
System.out.println("Wolf moved towards home");
return;
} else {
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Wolf move random because could not get to home");
return;
}
}
Expand All @@ -68,7 +64,6 @@ public void act(World world) {
return;
}
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Wolf move cuz starving");
}

// If far way from leader, go towards leader
Expand All @@ -83,11 +78,9 @@ public void act(World world) {
}
if (!closeToLeader) {
if(moveTowards(world.getLocation(myPack.getLeader()), world)){
System.out.println("Wolf moved closer to leader");
return;
} else {
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Wolf move random because could not get to leader");
return;
}
}
Expand All @@ -109,7 +102,6 @@ public void act(World world) {
if (world.getTile(location) instanceof Wolf &&
!myPack.isInPack((Wolf) world.getTile(location))) {
attack(location, world);
System.out.println("Wolf attacked wolf");
return;
}
}
Expand All @@ -119,7 +111,6 @@ public void act(World world) {
if (world.getTile(location) instanceof Wolf &&
!myPack.isInPack((Wolf) world.getTile(location))) {
if(moveAway(location, world)){
System.out.println("Wolf moved away from other wolf");
return;
}
}
Expand All @@ -128,7 +119,6 @@ public void act(World world) {
Lair temp = (Lair) world.getNonBlocking(location);
if (temp.getAnimalsInLair().getClass().isInstance(Wolf.class) && !myPack.getHome(world).equals(temp)) {
if(moveAway(location, world)){
System.out.println("Wolf moved away from other lair");
return;
}
}
Expand All @@ -139,10 +129,8 @@ public void act(World world) {
// 50% for random move 50% for no move
if (new Random().nextBoolean()) {
move(getRandomEmptySurroundingTile(world), world);
System.out.println("Wolf move random");
return;
}
System.out.println("Wolf do nothing");
}

// Wolf attack to get food
Expand All @@ -162,13 +150,11 @@ public boolean attackForFood(World world) {
// If theres is atleast 2 other wolfs nearby attack the bear
if (otherWolfs >= 2) {
attack(location, world);
System.out.println(this.getClass().getSimpleName() + " Attacked bear");
return true;
}
} else if (world.getTile(location) instanceof Animal &&
!world.getTile(location).getClass().equals(this.getClass())) {
attack(location, world);
System.out.println(this.getClass().getSimpleName() + " Attack");
return true;
}
}
Expand All @@ -187,14 +173,12 @@ public boolean attackForFood(World world) {
// If theres is atleast 2 other wolfs nearby go towards the bear
if (otherWolfs >= 2) {
moveTowards(location, world);
System.out.println(this.getClass().getSimpleName() + " Move to bear to attack");
return true;
}
}
else if (world.getTile(location) instanceof Animal &&
!world.getTile(location).getClass().equals(this.getClass())) {
moveTowards(location, world);
System.out.println(this.getClass().getSimpleName() + " Move to attack");
return true;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/WolfPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void reproduce(World world){
Wolf newWolf = new Wolf(this);
world.add(newWolf);
home.addAnimal(newWolf, world);
System.out.println("Pack reproduced");
}
}
}
Expand Down

0 comments on commit e3fde4c

Please sign in to comment.