Skip to content

Conversation

@Gv1don
Copy link

@Gv1don Gv1don commented Sep 13, 2022

No description provided.

@jskonst jskonst changed the title Add solution for first task Hamraev_Ivan_Dilshodovich - Add solution for first task Sep 17, 2022
private string model;
private int maxSpeed;

public Hydroplane(int power, int length, int weight, int landingSpeed, int takeoffSpeed, int lengthFloat, int numberWings, string model, int maxSpeed)
Copy link
Contributor

Choose a reason for hiding this comment

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

А вам точно нужно такое число параметров при инициализации?

Copy link
Author

Choose a reason for hiding this comment

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

Для работы методов не обязательно, могу уменьшить, не вопрос

Copy link
Contributor

Choose a reason for hiding this comment

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

можно завести еще конструктор с меньшим числом параметров

this.model = model;
this.maxSpeed = maxSpeed;
direction = string.Empty;
speed = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

это не обязательно - оно и так будет выставлено в значение по умолчанию

Copy link
Author

Choose a reason for hiding this comment

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

Понял, спасибо

}

public override void GetInfo()
=> Console.WriteLine($"Model: {model} \nPower: {power}horsepower \nLength: {length}m \nWeight: {weight}kg \nLanding speed: {landingSpeed}km/h \nTakeoff speed: {takeoffSpeed}km/h \nMax speed: {maxSpeed}km/h");
Copy link
Contributor

Choose a reason for hiding this comment

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

не очень хорошая практика использовать \n - поскольку это сильно зависит от ОС
Посмотрите на многострочные строки в c# (начинаются с @)

Copy link
Author

Choose a reason for hiding this comment

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

Да, хотел их изначально использовать, но потом в сторону \n склонился, всё поправлю

public override void GetInfo()
=> Console.WriteLine($"Model: {model} \nPower: {power}horsepower \nLength: {length}m \nWeight: {weight}kg \nLanding speed: {landingSpeed}km/h \nTakeoff speed: {takeoffSpeed}km/h \nMax speed: {maxSpeed}km/h");

public override void Movement() => Console.WriteLine($"Самолёт движется со скоростью {speed} км/ч, в направлении: {direction}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Протестировать метод - который просто выводит в консоль будет сложно - проще - возвращать значение (пусть даже и строковое)

Copy link
Author

Choose a reason for hiding this comment

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

Сделаем

Comment on lines 40 to 42
public override void TakeSpeed() => Console.WriteLine($"Speed right now: {speed}km/h");

public int GetSpeed() => speed;
Copy link
Contributor

Choose a reason for hiding this comment

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

Это лучше реализовать через свойства в C#

Comment on lines 50 to 51
Console.Write("Введите направление, курс полёта: ");
direction = Console.ReadLine();
Copy link
Contributor

Choose a reason for hiding this comment

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

Вот так не надо делать - просто передайте параметры извне
SetDirection(int direction))

Copy link
Author

Choose a reason for hiding this comment

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

Решил тоже свойством оформить и поколдовать с Movement)

@jskonst
Copy link
Contributor

jskonst commented Sep 17, 2022

а куда делся каталог с .github ? почему actions не запустились?

this.landingSpeed = landingSpeed;
this.takeoffSpeed = takeoffSpeed;
this.lengthFloat = lengthFloat;
this.numberWings = numberWings;
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

стоп - конструктор то у вас есть у родительского с такими параметрами?

Comment on lines 22 to 24
this.power = power;
this.length = length;
this.weight = weight;
Copy link
Contributor

Choose a reason for hiding this comment

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

не характерны ли эти свойства для всех самолетов в целом? эти поля стоит унести в базовый класс

Copy link
Contributor

Choose a reason for hiding this comment

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

В этом классе стоит оставить только те поля - которые характерны только для гидросамолетов

Comment on lines 21 to 22
hydroplane.SpeedUp();
var result = hydroplane.SpeedUp();
Copy link
Contributor

Choose a reason for hiding this comment

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

а зачем 2 раза,

  • вы можете в рамках первого теста проверить

Copy link
Contributor

Choose a reason for hiding this comment

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

Тесты необходимо добавить для всех методов - ну как минимум для getInfo точно

hydroplane.SpeedUp();
hydroplane.Braking();

Assert.Equal(0, hydroplane.GetSpeed());
Copy link
Contributor

Choose a reason for hiding this comment

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

необходимы тесты на конструктор

@Gv1don Gv1don changed the title Hamraev_Ivan_Dilshodovich - Add solution for first task Hamraev_Ivan_Dilshodovich Sep 21, 2022
direction = "some direction";
}

public string Exc { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

а это что означает?

Comment on lines 45 to 49
catch (Exception e)
{
Exc = $"Error: {e.Message}";
Console.WriteLine(Exc);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines 53 to 64
public string Direction
{
get
{
return direction;
}

set
{
direction = value;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

если нет внутри логики - то просто {get; set;}

Comment on lines +3 to +5
/// <summary>
/// Types of actions.
/// </summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

Зачем ?

Comment on lines 20 to 28
Console.Write("Введите кол-во героев: ");
int numberOfPlayers = Convert.ToInt16(Console.ReadLine());
Console.WriteLine();
if (numberOfPlayers % 2.0 != 0)
{
Console.WriteLine("Количество героев нечетное!");
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

ввод и непосредственную работу следует разделить

Copy link
Author

Choose a reason for hiding this comment

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

Сделаем

Comment on lines 29 to 47
for (int i = 0; i < numberOfPlayers; i++)
{
var randomName = _names[_random.Next(0, 20)];
switch (CreatePlayers.GetHeroType())
{
case PlayerTypes.NotType:
new Exception("Player has not type");
break;
case PlayerTypes.Knight:
players.Add(new Knight(randomName));
break;
case PlayerTypes.Archer:
players.Add(new Archer(randomName));
break;
case PlayerTypes.Wizard:
players.Add(new Wizard(randomName));
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

можно это в фабричный метод вынести?

Copy link
Author

Choose a reason for hiding this comment

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

Можно конечно

}
else
{
battle[0].GetDamage(battle[1].GiveDamage());
Copy link
Contributor

Choose a reason for hiding this comment

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

а если у меня иммунитет?

Copy link
Author

Choose a reason for hiding this comment

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

Вы получаете 0 урона, там дальше в логике это прописано, однако в логере всё же будет сообщение, что вам нанесли урон, но по факту он будет отражён иммунитетом

Copy link
Author

Choose a reason for hiding this comment

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

image

Copy link
Author

@Gv1don Gv1don Jan 13, 2023

Choose a reason for hiding this comment

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

Это в Wizard идёт проверка при получении урона. Соответственно Invisible становится True, когда используется ульт

return $"(Лучник) {Name}";
}

public override void Ultimate()
Copy link
Contributor

Choose a reason for hiding this comment

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

какой паттерн тут бы подошел?

Copy link
Author

Choose a reason for hiding this comment

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

Фабрика?

Copy link
Author

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