Skip to content

Army#3

Open
dmithorzh wants to merge 7 commits into
iaulitin:mainfrom
dmithorzh:army
Open

Army#3
dmithorzh wants to merge 7 commits into
iaulitin:mainfrom
dmithorzh:army

Conversation

@dmithorzh

Copy link
Copy Markdown

No description provided.

Comment thread src/Army/Main.java Outdated
Comment thread src/Army/Main.java Outdated
Comment thread .gitignore
Comment thread src/Army/Main.java Outdated
Comment thread src/Army/Soldier.java Outdated
", имя='" + getName() + '\'' +
", живой ли=" + getAlive() +
'}';
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Если ты все свойства держишь в классе Unit, почему ты toString два раза переопределяешь в классах-потомках (Soldier и Medic)? И формат неодинаковый, кстати. И необычный - обычно пишут так:
класс: {
имя поля 1 = значение поля 1,
имя поля 2 = значение поля 2,
...
}

Comment thread src/tkhorzhevskiy/BubbleSort.java Outdated
Comment thread src/Army/Soldier.java Outdated
Comment thread src/Army/Soldier.java Outdated
Comment thread src/Army/Soldier.java Outdated
Comment thread src/army/Soldier.java Outdated

System.out.println(name + " стреляет по " + target.name + " и наносит " + atk + " урона ");
target.setHp((int) (target.hp - atk * (1 - target.armor)));
target.status(this);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

А зачем в статус передается объект атакующего юнита? Вроде, и не используешь его там никак и по смыслу непонятно, зачем оно там нужно

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

В статус передается юнит "цель" , и , если она умирает, выводится прощальный лай "Press F", возможно я тебя неправильно понял.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  • в статусе меняется значение isAlive на false, если цель умирает

Comment thread src/army/Medic.java
class Medic extends Unit {
Medic(int atk, double armor, String name) {
super(atk, armor, name);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Если для медика предполагается отсутствие атаки, почему бы не устранить аргумент "сила атаки" из конструктора для медика?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил, сделал у юнита базовую атаку = 0, убрал у медика atk из конструктора

Comment thread src/army/Medic.java
@Override
void attack(Unit target) {
if (hp > 0) {
System.out.println(this.name + " не может атаковать");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Здесь требования нарушены.

Юниты с силой атаки = 0 не могут атаковать других юнитов.

Больше ничего про ограничения на атаку не говорится.
Однако сейчас можно создать медика с атакой >0, и он не сможет атаковать.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил, так же добавил early return для солдата, если его сила атаки = 0.

Comment thread src/army/Main.java Outdated
valera.attack(lena);
valera.attack(lena);
valera.attack(lena);
valera.attack(lena);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Вот, кстати, можно бы было на цикл while как раз переложить (это там где мы не знаем, сколько итераций потребуется. Пишем while (пока лена жива) {valera.attack(lena);}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Добавил цикл while

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