change names of variables to correct

This commit is contained in:
ZakenChannel 2024-04-06 16:17:20 +04:00
parent 46ab512462
commit ed2d1ac174
12 changed files with 58 additions and 58 deletions

View File

@ -30,7 +30,7 @@ public abstract class AbstractCompany
/// <summary> /// <summary>
/// Коллекция автомобилей /// Коллекция автомобилей
/// </summary> /// </summary>
protected ICollectionGenericObjects<DrawningFighter>? _collection = null; protected ICollectionGenericObjects<DrawningWarPlane>? _collection = null;
/// <summary> /// <summary>
/// Вычисление максимального количества элементов, который можно разместить в окне /// Вычисление максимального количества элементов, который можно разместить в окне
@ -43,7 +43,7 @@ public abstract class AbstractCompany
/// <param name="picWidth">Ширина окна</param> /// <param name="picWidth">Ширина окна</param>
/// <param name="picHeight">Высота окна</param> /// <param name="picHeight">Высота окна</param>
/// <param name="collection">Коллекция автомобилей</param> /// <param name="collection">Коллекция автомобилей</param>
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningFighter> collection) public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningWarPlane> collection)
{ {
_pictureWidth = picWidth; _pictureWidth = picWidth;
_pictureHeight = picHeight; _pictureHeight = picHeight;
@ -57,13 +57,13 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param> /// <param name="company">Компания</param>
/// <param name="car">Добавляемый объект</param> /// <param name="car">Добавляемый объект</param>
/// <returns></returns> /// <returns></returns>
public static int operator +(AbstractCompany company, DrawningFighter fighter) public static int operator +(AbstractCompany company, DrawningWarPlane plane)
{ {
if (company._collection == null) if (company._collection == null)
{ {
return -1; return -1;
} }
return company._collection.Insert(fighter); return company._collection.Insert(plane);
} }
/// <summary> /// <summary>
@ -72,7 +72,7 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param> /// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param> /// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns> /// <returns></returns>
public static DrawningFighter operator -(AbstractCompany company, int position) public static DrawningWarPlane operator -(AbstractCompany company, int position)
{ {
return company._collection?.Remove(position) ?? null; return company._collection?.Remove(position) ?? null;
} }
@ -82,7 +82,7 @@ public abstract class AbstractCompany
/// Получение случайного объекта из коллекции /// Получение случайного объекта из коллекции
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public DrawningFighter? GetRandomObject() public DrawningWarPlane? GetRandomObject()
{ {
Random rnd = new(); Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount)); return _collection?.Get(rnd.Next(GetMaxCount));
@ -101,7 +101,7 @@ public abstract class AbstractCompany
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{ {
DrawningFighter? obj = _collection?.Get(i); DrawningWarPlane? obj = _collection?.Get(i);
obj?.DrawTransport(graphics); obj?.DrawTransport(graphics);
} }

View File

@ -13,7 +13,7 @@ public class Hangar : AbstractCompany
/// <param name="picWidth"></param> /// <param name="picWidth"></param>
/// <param name="picHeight"></param> /// <param name="picHeight"></param>
/// <param name="collection"></param> /// <param name="collection"></param>
public Hangar(int picWidth, int picHeight, ICollectionGenericObjects<DrawningFighter> collection) : base(picWidth, picHeight, collection) public Hangar(int picWidth, int picHeight, ICollectionGenericObjects<DrawningWarPlane> collection) : base(picWidth, picHeight, collection)
{ {
} }

View File

@ -5,7 +5,7 @@ namespace ProjectAirFighter.Drawnings;
/// <summary> /// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary> /// </summary>
public class DrawningAirFighter : DrawningFighter public class DrawningAirFighter : DrawningWarPlane
{ {
/// <summary> /// <summary>
/// Конструктор /// Конструктор

View File

@ -2,13 +2,13 @@
namespace ProjectAirFighter.Drawnings; namespace ProjectAirFighter.Drawnings;
public class DrawningFighter public class DrawningWarPlane
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityFighter? EntityFighter { get; protected set; } public EntityWarPlane? EntityFighter { get; protected set; }
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
@ -63,7 +63,7 @@ public class DrawningFighter
/// <summary> /// <summary>
/// Пустой конструктор /// Пустой конструктор
/// </summary> /// </summary>
protected DrawningFighter() protected DrawningWarPlane()
{ {
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
@ -77,9 +77,9 @@ public class DrawningFighter
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
public DrawningFighter(int speed, double weight, Color bodyColor) : this() public DrawningWarPlane(int speed, double weight, Color bodyColor) : this()
{ {
EntityFighter = new EntityFighter(speed, weight, bodyColor); EntityFighter = new EntityWarPlane(speed, weight, bodyColor);
} }
/// <summary> /// <summary>

View File

@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Класс-сущность "Истребитель" /// Класс-сущность "Истребитель"
/// </summary> /// </summary>
public class EntityAirFighter : EntityFighter public class EntityAirFighter : EntityWarPlane
{ {
/// <summary> /// <summary>

View File

@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Класс-сущность "Истребитель без доп опций" /// Класс-сущность "Истребитель без доп опций"
/// </summary> /// </summary>
public class EntityFighter public class EntityWarPlane
{ {
/// <summary> /// <summary>
/// Скорость /// Скорость
@ -31,7 +31,7 @@ public class EntityFighter
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес истребителя</param> /// <param name="weight">Вес истребителя</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
public EntityFighter(int speed, double weight, Color bodyColor) public EntityWarPlane(int speed, double weight, Color bodyColor)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;

View File

@ -13,7 +13,7 @@ public partial class FormAirFighter : Form
/// <summary> /// <summary>
/// Поле-объект для прорисовки объекта /// Поле-объект для прорисовки объекта
/// </summary> /// </summary>
private DrawningFighter? _drawningFighter; private DrawningWarPlane? _drawningWarPlane;
/// <summary> /// <summary>
/// Стратегия перемещения /// Стратегия перемещения
@ -23,12 +23,12 @@ public partial class FormAirFighter : Form
/// <summary> /// <summary>
/// Получение объекта /// Получение объекта
/// </summary> /// </summary>
public DrawningFighter SetFighter public DrawningWarPlane SetWarPlane
{ {
set set
{ {
_drawningFighter = value; _drawningWarPlane = value;
_drawningFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); _drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
comboBoxStrategy.Enabled = true; comboBoxStrategy.Enabled = true;
_strategy = null; _strategy = null;
Draw(); Draw();
@ -49,14 +49,14 @@ public partial class FormAirFighter : Form
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
if (_drawningFighter == null) if (_drawningWarPlane == null)
{ {
return; return;
} }
if (pictureBoxAirFighter.Width == 0 || pictureBoxAirFighter.Height == 0) return; if (pictureBoxAirFighter.Width == 0 || pictureBoxAirFighter.Height == 0) return;
Bitmap bitmap = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); Bitmap bitmap = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Graphics gr = Graphics.FromImage(bitmap); Graphics gr = Graphics.FromImage(bitmap);
_drawningFighter?.DrawTransport(gr); _drawningWarPlane?.DrawTransport(gr);
pictureBoxAirFighter.Image = bitmap; pictureBoxAirFighter.Image = bitmap;
} }
@ -67,7 +67,7 @@ public partial class FormAirFighter : Form
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawningFighter == null) if (_drawningWarPlane == null)
{ {
return; return;
} }
@ -77,19 +77,19 @@ public partial class FormAirFighter : Form
switch (name) switch (name)
{ {
case "buttonUp": case "buttonUp":
result = _drawningFighter.MoveTransport(DirectionType.Up); result = _drawningWarPlane.MoveTransport(DirectionType.Up);
break; break;
case "buttonLeft": case "buttonLeft":
result = _drawningFighter.MoveTransport(DirectionType.Left); result = _drawningWarPlane.MoveTransport(DirectionType.Left);
break; break;
case "buttonDown": case "buttonDown":
result = _drawningFighter.MoveTransport(DirectionType.Down); result = _drawningWarPlane.MoveTransport(DirectionType.Down);
break; break;
case "buttonRight": case "buttonRight":
result = _drawningFighter.MoveTransport(DirectionType.Right); result = _drawningWarPlane.MoveTransport(DirectionType.Right);
break; break;
} }
if (result) Draw(); if (result) Draw();
@ -97,13 +97,13 @@ public partial class FormAirFighter : Form
private void PictureBox_Resize(object sender, EventArgs e) private void PictureBox_Resize(object sender, EventArgs e)
{ {
_drawningFighter?.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); _drawningWarPlane?.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Draw(); Draw();
} }
private void ButtonStrategyStep_Click(object sender, EventArgs e) private void ButtonStrategyStep_Click(object sender, EventArgs e)
{ {
if (_drawningFighter == null) return; if (_drawningWarPlane == null) return;
if (comboBoxStrategy.Enabled) if (comboBoxStrategy.Enabled)
{ {
_strategy = comboBoxStrategy.SelectedIndex switch _strategy = comboBoxStrategy.SelectedIndex switch
@ -113,7 +113,7 @@ public partial class FormAirFighter : Form
_ => null, _ => null,
}; };
if (_strategy == null) return; if (_strategy == null) return;
_strategy.SetData(new MoveableFighter(_drawningFighter), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); _strategy.SetData(new MoveablePlane(_drawningWarPlane), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
} }
if (_strategy == null) return; if (_strategy == null) return;
comboBoxStrategy.Enabled = false; comboBoxStrategy.Enabled = false;

View File

@ -1,6 +1,6 @@
namespace ProjectAirFighter namespace ProjectAirFighter
{ {
partial class FormFighterCollection partial class FormWarPlaneCollection
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.

View File

@ -6,7 +6,7 @@ namespace ProjectAirFighter;
/// <summary> /// <summary>
/// Форма работы с компанией и ее коллекцией /// Форма работы с компанией и ее коллекцией
/// </summary> /// </summary>
public partial class FormFighterCollection : Form public partial class FormWarPlaneCollection : Form
{ {
/// <summary> /// <summary>
/// Компания /// Компания
@ -16,7 +16,7 @@ public partial class FormFighterCollection : Form
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormFighterCollection() public FormWarPlaneCollection()
{ {
InitializeComponent(); InitializeComponent();
} }
@ -31,7 +31,7 @@ public partial class FormFighterCollection : Form
switch (comboBoxSelectorCompany.Text) switch (comboBoxSelectorCompany.Text)
{ {
case "Хранилище": case "Хранилище":
_company = new Hangar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningFighter>()); _company = new Hangar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningWarPlane>());
break; break;
} }
} }
@ -45,20 +45,20 @@ public partial class FormFighterCollection : Form
if (_company == null) return; if (_company == null) return;
Random random = new(); Random random = new();
DrawningFighter drawningFighter; DrawningWarPlane drawningWarPlane;
switch (type) switch (type)
{ {
case nameof(DrawningFighter): case nameof(DrawningWarPlane):
drawningFighter = new DrawningFighter(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); drawningWarPlane = new DrawningWarPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break; break;
case nameof(DrawningAirFighter): case nameof(DrawningAirFighter):
drawningFighter = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000), drawningWarPlane = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break; break;
default: default:
return; return;
} }
if (_company + drawningFighter != -1) if (_company + drawningWarPlane != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
@ -91,7 +91,7 @@ public partial class FormFighterCollection : Form
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningFighter)); private void ButtonAddFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarPlane));
/// <summary> /// <summary>
/// Добавление истребителя с доп элементами /// Добавление истребителя с доп элементами
@ -151,11 +151,11 @@ public partial class FormFighterCollection : Form
return; return;
} }
DrawningFighter? fighter = null; DrawningWarPlane? warPlane = null;
int counter = 100; int counter = 100;
while (fighter == null) while (warPlane == null)
{ {
fighter = _company.GetRandomObject(); warPlane = _company.GetRandomObject();
counter--; counter--;
if (counter <= 0) if (counter <= 0)
{ {
@ -163,14 +163,14 @@ public partial class FormFighterCollection : Form
} }
} }
if (fighter == null) if (warPlane == null)
{ {
return; return;
} }
FormAirFighter form = new() FormAirFighter form = new()
{ {
SetFighter = fighter SetWarPlane = warPlane
}; };
form.ShowDialog(); form.ShowDialog();
} }

View File

@ -5,45 +5,45 @@ namespace ProjectAirFighter.MovementStrategy;
/// <summary> /// <summary>
/// Класс-реализация IMoveableObject с использованием DrawningCar /// Класс-реализация IMoveableObject с использованием DrawningCar
/// </summary> /// </summary>
public class MoveableFighter : IMoveableObject public class MoveablePlane : IMoveableObject
{ {
/// <summary> /// <summary>
/// Поле-объект класса DrawningFighter или его наследника /// Поле-объект класса DrawningWarPlane или его наследника
/// </summary> /// </summary>
private readonly DrawningFighter? _fighter = null; private readonly DrawningWarPlane? _warPlane = null;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="drawningFighter"></param> /// <param name="drawningWarPlane"></param>
public MoveableFighter(DrawningFighter drawningFighter) public MoveablePlane(DrawningWarPlane drawningWarPlane)
{ {
_fighter = drawningFighter; _warPlane = drawningWarPlane;
} }
public ObjectParameters? GetObjectPosition public ObjectParameters? GetObjectPosition
{ {
get get
{ {
if (_fighter == null || _fighter.EntityFighter == null || !_fighter.GetPosX.HasValue || !_fighter.GetPosY.HasValue) if (_warPlane == null || _warPlane.EntityFighter == null || !_warPlane.GetPosX.HasValue || !_warPlane.GetPosY.HasValue)
{ {
return null; return null;
} }
return new ObjectParameters(_fighter.GetPosX.Value, _fighter.GetPosY.Value, _fighter.GetWidth.Value, _fighter.GetHeight.Value); return new ObjectParameters(_warPlane.GetPosX.Value, _warPlane.GetPosY.Value, _warPlane.GetWidth.Value, _warPlane.GetHeight.Value);
} }
} }
public int GetStep => (int)(_fighter?.EntityFighter?.Step ?? 0); public int GetStep => (int)(_warPlane?.EntityFighter?.Step ?? 0);
public bool TryMoveObject(MovementDiraction direction) public bool TryMoveObject(MovementDiraction direction)
{ {
if (_fighter == null || _fighter.EntityFighter == null) if (_warPlane == null || _warPlane.EntityFighter == null)
{ {
return false; return false;
} }
return _fighter.MoveTransport(GetDirectionType(direction)); return _warPlane.MoveTransport(GetDirectionType(direction));
} }
/// <summary> /// <summary>

View File

@ -11,7 +11,7 @@ namespace ProjectAirFighter
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormFighterCollection()); Application.Run(new FormWarPlaneCollection());
} }
} }
} }