Conversation
src/actions/Action.java
Outdated
| @@ -0,0 +1,5 @@ | |||
| package actions; | |||
| import map.GameMap; | |||
| public interface Action { | |||
There was a problem hiding this comment.
лучше назвать интерфейс прилагательным, например Actionable
src/Main.java
Outdated
| import simulation.Simulation; | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
| new Simulation().startSimulation(200, 200); |
There was a problem hiding this comment.
константы / переменные, а вообще почему бы не вынести эти параметры на пользователя?
src/simulation/Simulation.java
Outdated
| private final MapPopulationAction populate = new MapPopulationAction(); | ||
| private final PopulateGrassAction addingGrass = new PopulateGrassAction(); | ||
| private int numberOfMove = 0; | ||
| private boolean isActiveLive = true; |
There was a problem hiding this comment.
после объявления полей ставь enter, аналогично с importaми
src/simulation/Simulation.java
Outdated
| Rendered.withdrawCard(map); | ||
| System.out.println("Симуляция началась!"); | ||
| try { | ||
| Thread.sleep(2000); |
src/simulation/Simulation.java
Outdated
| throw new RuntimeException(e); | ||
| } | ||
| try { | ||
| while (isActiveLive) { |
There was a problem hiding this comment.
мб лучше назвать переменную isGameContinue
src/simulation/Simulation.java
Outdated
| stopSimulation(); | ||
| } | ||
| } | ||
| private void stopSimulation() { |
There was a problem hiding this comment.
я бы лучше сделал класс который ставит симуляцию на паузу, выключает, стартует ее, назвал бы типо GameApi или Session, а то тут нарушается принцип SRP
src/pathfinding/PathFinder.java
Outdated
| correctPath.removeFirst(); | ||
| return correctPath; | ||
| } | ||
| private static Coordinates searchPath(Coordinates start, Class<? extends Entity> targetClass, GameMap map, Map<Coordinates, Coordinates> path) { |
There was a problem hiding this comment.
вообще - класс не должен иметь статик методов, это не утилитарный класс, надо работать с объектом, если надо запретить создание более одного такого - надо сделать через паттерн Singleton
src/pathfinding/PathFinder.java
Outdated
| } | ||
| } | ||
| } | ||
| return null; |
There was a problem hiding this comment.
возвращать null плохая практика, может делать отрицательные координаты? и так ориентироваться уже
src/rendering/Rendered.java
Outdated
| import map.GameMap; | ||
| import java.util.Locale; | ||
| public class Rendered { | ||
| private enum graphicCodes { |
There was a problem hiding this comment.
- enum выносим отдельно от класса
- enum назвается так же как и класс а не как метод с мелкой буквы
| @@ -0,0 +1,3 @@ | |||
| package entities; | |||
| public abstract class Entity { | |||
There was a problem hiding this comment.
ты этот класс хранишь в map но equals и hashcode не переопределил
| @@ -0,0 +1,5 @@ | |||
| package actions; | |||
There was a problem hiding this comment.
Зачем тебе 64 комита на такой мелкий проект? старайся делать как можно более мелкие комиты но осмысленные, git squash на заметку
| @@ -0,0 +1,5 @@ | |||
| package actions; | |||
| import map.GameMap; | |||
| public interface Actionable { | |||
| @@ -0,0 +1,5 @@ | |||
| package actions; | |||
| import map.GameMap; | |||
There was a problem hiding this comment.
любой комент который оставлю - относится ко всем файлам, тобишь нужно пройти все и просмотреть типовые ошибки везде
src/actions/MapPopulationAction.java
Outdated
| } | ||
| return possibleCoordinates; | ||
| } | ||
| private void populate(GameMap map, List<Coordinates> possibleCoordinates, String entityClass, int count) { |
There was a problem hiding this comment.
не круто то что метод принимает String entityClass, int count
надо сделать так что бы было всего 2 аргумента, иначе переиспользование данного метода усложнено
src/actions/MapPopulationAction.java
Outdated
| entityCount--; | ||
| } | ||
| } | ||
| private Entity createEntity(String entityClass) { |
There was a problem hiding this comment.
надо уйти от switch case путем enum, твоя реализация сейчас не расширяема
src/simulation/GameApi.java
Outdated
| if (System.in.available() > 0) { | ||
| int pausedChar = System.in.read(); | ||
| long ignored = System.in.skip(System.in.available()); | ||
| if (pausedChar == 'P' || pausedChar == 'p') { |
src/pathfinding/PathFinder.java
Outdated
| import map.GameMap; | ||
| import java.util.*; | ||
| public class PathFinder { | ||
| public List<Coordinates> findPath(Coordinates start, Class<? extends Entity> targetClass, GameMap map) |
There was a problem hiding this comment.
мы должны передавать координаты начала и координаты конца в параметры метода и ничего более, тут еще и рефлексия используется, этого нам не надо
| public abstract class Creature extends Entity { | ||
| protected int speed; | ||
| protected int hitPoints; | ||
| protected PathFinder foodFinder; |
There was a problem hiding this comment.
объект сущности не должен иметь в себе поле пути, надо перестроить логику
src/pathfinding/PathFinder.java
Outdated
| } | ||
| private List<Coordinates> getNeighbors(Coordinates coordinates, GameMap map) { | ||
| List<Coordinates> neighbors = new ArrayList<>(); | ||
| for (int i = -1; i < 2; i += 2) { |
There was a problem hiding this comment.
можно проще, можно сделать массивы сдвигов в разные стороны, а потом уже итерироваться по ним, прибавляя их к основным координатам, таке будет более читаемо
src/rendering/Rendered.java
Outdated
| for (int x = 0; x < map.getWidth(); x++) { | ||
| for (int y = 0; y < map.getHeight(); y++) { | ||
| Entity entity = map.getEntity(new Coordinates(x, y)); | ||
| String entityClass = entity.getClass().getSimpleName().toUpperCase(Locale.ROOT); |
There was a problem hiding this comment.
очень плохо, почему просто не сделать метод которые будут переопределять все классы и в этом методе они будут возвращать свой спрайт, просто пробегаешься и вызываешь его
старайся никогда не использовать рефлексию, это считается антипаттерном, только если это не исключение, например когда тебе в какой-то библиотеки надо посмотреть кол-во всех статик методов проекта
No description provided.