Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# NewIsland

Симуляция острова с животными и растениями.

## 🚀 Запуск программы

1. Открыть проект в IntelliJ IDEA
2. Найти класс `Main`
3. Запустить метод `main()` → Run

## ⚙️ Настройки симуляции

В классе `Main` можно изменить параметры (в коде есть комментарии):

- размер острова (карты)
- количество животных и растений
- количество шагов симуляции

После изменения параметров перезапусти программу.

## 📌 Описание

Программа моделирует жизнь экосистемы острова:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Принято!

перемещение животных, размножение, питание и рост растений.
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Boar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Boar extends Herbivores{


public Boar() {
super("Boar", 400, 50, 2, 50);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Boar baby = new Boar();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Buffalo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Buffalo extends Herbivores{


public Buffalo() {
super("Buffalo", 700, 10, 3, 100);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Buffalo baby = new Buffalo();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Caterpillar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Caterpillar extends Herbivores{


public Caterpillar() {
super("Caterpillar", 0.01, 1000, 0, 0);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Caterpillar baby = new Caterpillar();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Deer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Deer extends Herbivores{


public Deer() {
super("Deer", 300, 20, 4, 50);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Deer baby = new Deer();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Duck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Duck extends Herbivores{


public Duck() {
super("Duck", 1, 200, 4, 0.15);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Duck baby = new Duck();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Goat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Goat extends Herbivores{


public Goat() {
super("Goat", 60, 140, 3, 10);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Goat baby = new Goat();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
52 changes: 52 additions & 0 deletions src/Fauna/AllHerbivores/Herbivores.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package Fauna.AllHerbivores;

import Fauna.Herbs;
import Fauna.Animal;
import SupportClasses.Statistics;

import java.util.List;

public abstract class Herbivores extends Animal {

public Herbivores(String name, double maxWeight, int maxCountOnCell, int speed, double foodNeed) {
super(name, maxWeight, maxCountOnCell, speed, foodNeed);
}

/**
* Общая логика травоядных — они едят растения.
*/
@Override
public void eat(List<Animal> others) {
for (Object other : others) {
if (other instanceof Herbs herb && herb.isAlive()) {
System.out.println(name + " ate some grass 🌿");
herb.beEaten();
hunger = 1.0;

// ✅ добавляем запись в статистику
Statistics.markGrassEaten(this);

return;
}
}
}

/**
* Попытка съесть траву (из отдельного списка растений, если он есть).
*/
public boolean tryEatPlants(List<Herbs> plants) {
if (plants != null && !plants.isEmpty()) {
Herbs herb = plants.remove(0); // съели один пучок
if (herb != null && herb.isAlive()) {
// System.out.println(name + " ate some grass 🌿");
hunger = 1.0;

// ✅ статистика
Statistics.markGrassEaten(this);

return true;
}
}
return false;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Horse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Horse extends Herbivores{


public Horse() {
super("Horse", 400, 20, 4, 60);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Horse baby = new Horse();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Mouse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Mouse extends Herbivores{


public Mouse() {
super("Mouse", 0.05, 500, 1, 0.01);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Mouse baby = new Mouse();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
21 changes: 21 additions & 0 deletions src/Fauna/AllHerbivores/Rabbit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Rabbit extends Herbivores {

public Rabbit() {
super("Rabbit", 2, 150, 2, 0.45);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Rabbit baby = new Rabbit();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
22 changes: 22 additions & 0 deletions src/Fauna/AllHerbivores/Sheep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Fauna.AllHerbivores;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Sheep extends Herbivores{


public Sheep() {
super("Sheep", 70, 140, 3, 15);
setMaxAge(10);
}

@Override
protected Animal createChild() {
Sheep baby = new Sheep();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
35 changes: 35 additions & 0 deletions src/Fauna/AllPredators/Bear.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package Fauna.AllPredators;

import Fauna.Animal;
import MapEngine.Coordinate;

public class Bear extends Predators{


public Bear() {
super("Bear", 500, 5, 2, 80);
setMaxAge(50);
}

@Override
protected double getEatChance(Animal prey) {
// Упрощённая таблица вероятностей
return switch (prey.getName()) {
case "Mouse"-> 0.9;
case "Rabbit","Boa","Deer" -> 0.8;
case "Goat", "Sheep" -> 0.7;
case "Horse" -> 0.4;
default -> 0.0;
};
}

@Override
protected Animal createChild() {
Bear baby = new Bear();
// Копируем позицию родителя, если она установлена
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}
34 changes: 34 additions & 0 deletions src/Fauna/AllPredators/Boa.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

package Fauna.AllPredators;
import Fauna.Animal;
import MapEngine.Coordinate;

public class Boa extends Predators {

public Boa() {
super("Boa", 15, 30, 1, 3);
setMaxAge(40);
}

@Override
protected double getEatChance(Animal prey) {
return switch (prey.getName()) {
case "Rabbit" -> 0.2;
case "Mouse" -> 0.4;
case "Fox" -> 0.15;

default -> 0.0;
};
}

@Override
protected Animal createChild() {
Boa baby = new Boa();
if (this.getPosition() != null) {
baby.setPosition(new Coordinate(this.getPosition().x, this.getPosition().y));
}
return baby;
}
}


Loading