-
Notifications
You must be signed in to change notification settings - Fork 0
new-project-for-PR #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Roman-M-git
wants to merge
2
commits into
master
Choose a base branch
from
feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # NewIsland | ||
|
|
||
| Симуляция острова с животными и растениями. | ||
|
|
||
| ## 🚀 Запуск программы | ||
|
|
||
| 1. Открыть проект в IntelliJ IDEA | ||
| 2. Найти класс `Main` | ||
| 3. Запустить метод `main()` → Run | ||
|
|
||
| ## ⚙️ Настройки симуляции | ||
|
|
||
| В классе `Main` можно изменить параметры (в коде есть комментарии): | ||
|
|
||
| - размер острова (карты) | ||
| - количество животных и растений | ||
| - количество шагов симуляции | ||
|
|
||
| После изменения параметров перезапусти программу. | ||
|
|
||
| ## 📌 Описание | ||
|
|
||
| Программа моделирует жизнь экосистемы острова: | ||
| перемещение животных, размножение, питание и рост растений. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Принято!