Skip to content

Project2#1

Open
devstarash wants to merge 70 commits intomasterfrom
project2
Open

Project2#1
devstarash wants to merge 70 commits intomasterfrom
project2

Conversation

@devstarash
Copy link
Copy Markdown
Owner

No description provided.

@@ -0,0 +1,5 @@
package actions;
import map.GameMap;
public interface Action {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

лучше назвать интерфейс прилагательным, например Actionable

src/Main.java Outdated
import simulation.Simulation;
public class Main {
public static void main(String[] args) {
new Simulation().startSimulation(200, 200);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

константы / переменные, а вообще почему бы не вынести эти параметры на пользователя?

private final MapPopulationAction populate = new MapPopulationAction();
private final PopulateGrassAction addingGrass = new PopulateGrassAction();
private int numberOfMove = 0;
private boolean isActiveLive = true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

после объявления полей ставь enter, аналогично с importaми

Rendered.withdrawCard(map);
System.out.println("Симуляция началась!");
try {
Thread.sleep(2000);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

константы

throw new RuntimeException(e);
}
try {
while (isActiveLive) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

мб лучше назвать переменную isGameContinue

stopSimulation();
}
}
private void stopSimulation() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

я бы лучше сделал класс который ставит симуляцию на паузу, выключает, стартует ее, назвал бы типо GameApi или Session, а то тут нарушается принцип SRP

correctPath.removeFirst();
return correctPath;
}
private static Coordinates searchPath(Coordinates start, Class<? extends Entity> targetClass, GameMap map, Map<Coordinates, Coordinates> path) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

вообще - класс не должен иметь статик методов, это не утилитарный класс, надо работать с объектом, если надо запретить создание более одного такого - надо сделать через паттерн Singleton

}
}
}
return null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

возвращать null плохая практика, может делать отрицательные координаты? и так ориентироваться уже

import map.GameMap;
import java.util.Locale;
public class Rendered {
private enum graphicCodes {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • enum выносим отдельно от класса
  • enum назвается так же как и класс а не как метод с мелкой буквы

@@ -0,0 +1,3 @@
package entities;
public abstract class Entity {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ты этот класс хранишь в map но equals и hashcode не переопределил

@@ -0,0 +1,5 @@
package actions;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Зачем тебе 64 комита на такой мелкий проект? старайся делать как можно более мелкие комиты но осмысленные, git squash на заметку

@@ -0,0 +1,5 @@
package actions;
import map.GameMap;
public interface Actionable {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

форматирование, разлепи

@@ -0,0 +1,5 @@
package actions;
import map.GameMap;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

любой комент который оставлю - относится ко всем файлам, тобишь нужно пройти все и просмотреть типовые ошибки везде

}
return possibleCoordinates;
}
private void populate(GameMap map, List<Coordinates> possibleCoordinates, String entityClass, int count) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

не круто то что метод принимает String entityClass, int count
надо сделать так что бы было всего 2 аргумента, иначе переиспользование данного метода усложнено

entityCount--;
}
}
private Entity createEntity(String entityClass) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

надо уйти от switch case путем enum, твоя реализация сейчас не расширяема

if (System.in.available() > 0) {
int pausedChar = System.in.read();
long ignored = System.in.skip(System.in.available());
if (pausedChar == 'P' || pausedChar == 'p') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

equalsIgnoreCase

import map.GameMap;
import java.util.*;
public class PathFinder {
public List<Coordinates> findPath(Coordinates start, Class<? extends Entity> targetClass, GameMap map)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

мы должны передавать координаты начала и координаты конца в параметры метода и ничего более, тут еще и рефлексия используется, этого нам не надо

public abstract class Creature extends Entity {
protected int speed;
protected int hitPoints;
protected PathFinder foodFinder;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

объект сущности не должен иметь в себе поле пути, надо перестроить логику

}
private List<Coordinates> getNeighbors(Coordinates coordinates, GameMap map) {
List<Coordinates> neighbors = new ArrayList<>();
for (int i = -1; i < 2; i += 2) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

можно проще, можно сделать массивы сдвигов в разные стороны, а потом уже итерироваться по ним, прибавляя их к основным координатам, таке будет более читаемо

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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

очень плохо, почему просто не сделать метод которые будут переопределять все классы и в этом методе они будут возвращать свой спрайт, просто пробегаешься и вызываешь его

старайся никогда не использовать рефлексию, это считается антипаттерном, только если это не исключение, например когда тебе в какой-то библиотеки надо посмотреть кол-во всех статик методов проекта

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants