Agliullov D. A. Lab Work 3 Advanced #4

Merged
eegov merged 13 commits from Lab3 into Lab2 2022-10-14 10:14:31 +04:00
2 changed files with 77 additions and 1 deletions
Showing only changes of commit 3d0fd13bec - Show all commits

View File

@ -47,7 +47,11 @@
Airplane = new EntityAirplane(speed, weight, bodyColor);
DrawningEngines = typeAirplaneEngines;
}
public DrawningAirplane(EntityAirplane entityAirplane, IAirplaneEngines? typeAirplaneEngines = null)
{
Airplane = entityAirplane;
DrawningEngines = typeAirplaneEngines;
}
/// <summary>
/// Инициализация свойств
/// </summary>

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
/// <summary>
/// Класс, который генирирует самолет из разнообразного количества сущностей и типа двигателей
/// </summary>
/// <typeparam name="T">Класс Сущность самолет</typeparam>
/// <typeparam name="U">Класс двигателя самолета</typeparam>
internal class GeneratorAirplane<T, U>
where T : EntityAirplane
where U : class, IAirplaneEngines
{
private readonly T[] typesOfEntity;
private readonly U[] typesOfEngines;
public int NumTypesOfEntity { get; private set; }
public int NumTypesOfEngines { get; private set; }
public GeneratorAirplane(int countTypesOfEntity, int countTypesOfEngines)
{
typesOfEntity = new T[countTypesOfEntity];
typesOfEngines = new U[countTypesOfEngines];
}
/// <summary>
/// Добавляет возможный тип сущности при генерации самолета
/// </summary>
/// <param name="type">тип</param>
/// <returns>Успешно ли проведена операция</returns>
public bool AddTypeOfEntity(T type)
Review

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников
Методы должны были быть полиморные

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников Методы должны были быть полиморные
{
if (NumTypesOfEntity >= typesOfEntity.Length)
{
return false;
}
typesOfEntity[NumTypesOfEntity++] = type;
return true;
}
/// <summary>
/// Добавляет возможный тип двигателей при генерации самолета
/// </summary>
/// <param name="type">тип</param>
/// <returns>Успешно ли проведена операция</returns>
public bool AddTypeOfEngines(U type)
Review

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников
Методы должны были быть полиморные

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников Методы должны были быть полиморные
{
if (NumTypesOfEngines >= typesOfEngines.Length)
{
return false;
}
typesOfEngines[NumTypesOfEngines++] = type;
return true;
}
/// <summary>
/// Генерирует объект отрисовки
/// </summary>
/// <returns>Возвращает объект отрисовки, либо null, если не были добавлены типы для выборки</returns>
public DrawningObject? Generate()
{
if (NumTypesOfEngines == 0 || NumTypesOfEntity == 0)
{
return null;
}
var rnd = new Random();
var airplane = new DrawningAirplane(typesOfEntity[rnd.Next() % NumTypesOfEntity], typesOfEngines[rnd.Next() % NumTypesOfEngines]);
return new DrawningObject(airplane);
}
}
}