PIbd-22.Kurbanova A.A. Lab work 04 #4 #6

Closed
ALINA_KURBANOVA wants to merge 2 commits from Laba4 into Laba3
11 changed files with 436 additions and 178 deletions

View File

@ -2,12 +2,12 @@
namespace WarmlyLocomotive.MovementStrategy
{
internal class DrawningObjectCar : IMoveableObject
internal class DrawningObjectWarmlyLocomotive : IMoveableObject
{
private readonly DrawningWarmlyLocomotive? _drawningWarmlyLocomotive = null;
public DrawningObjectCar(DrawningWarmlyLocomotive drawningCar)
public DrawningObjectWarmlyLocomotive(DrawningWarmlyLocomotive drawningWarmlylocomotive)
{
_drawningWarmlyLocomotive = drawningCar;
_drawningWarmlyLocomotive = drawningWarmlylocomotive;
}
public ObjectParameters? GetObjectPosition
{

View File

@ -12,7 +12,7 @@ public class DrawningWarmlyLocomotive
/// Класс-сущность
/// </summary>
public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; protected set; }
public IMoveableObject GetMoveableObject => new DrawningObjectCar(this);
public IMoveableObject GetMoveableObject => new DrawningObjectWarmlyLocomotive(this);
/// <summary>
/// Ширина окна
/// </summary>
@ -22,19 +22,19 @@ public class DrawningWarmlyLocomotive
/// </summary>
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки локомотива
/// Левая координата прорисовки тепловоза
/// </summary>
protected int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки локомотива
/// Верхняя кооридната прорисовки тепловоза
/// </summary>
protected int _startPosY;
/// <summary>
/// Ширина прорисовки локомотива
/// Ширина прорисовки тепловоза
/// </summary>
protected readonly int _WarmlyLocomotiveWidth = 200;
/// <summary>
/// Высота прорисовки локомотива
/// Высота прорисовки тепловоза
/// </summary>
protected readonly int _WarmlyLocomotiveHeight = 75;
private readonly int _trumpetHeight = 25;

View File

@ -1,7 +1,7 @@
namespace WarmlyLocomotive.Entities
{
/// <summary>
/// Класс-сущность "Автомобиль"
/// Класс-сущность "Тепловоз"
/// </summary>
public class EntityWarmlyLocomotive
{

View File

@ -30,12 +30,19 @@
{
labelCollection = new Label();
panelCollectionWarmlyLocomotive = new Panel();
labelGenericCollection = new Label();
panel1 = new Panel();
buttonDelObject = new Button();
textBoxStorageName = new TextBox();
listBoxStorages = new ListBox();
buttonAddObject = new Button();
buttonreFreshCollection = new Button();
textBoxCollectionWarmlyLocomotive = new TextBox();
maskedTextBoxNumber = new TextBox();
buttonRemove = new Button();
buttonadd = new Button();
buttonAdd = new Button();
pictureBoxCollectionWarmlyLocomotive = new PictureBox();
panelCollectionWarmlyLocomotive.SuspendLayout();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollectionWarmlyLocomotive).BeginInit();
SuspendLayout();
//
@ -51,18 +58,77 @@
//
// panelCollectionWarmlyLocomotive
//
panelCollectionWarmlyLocomotive.Controls.Add(labelGenericCollection);
panelCollectionWarmlyLocomotive.Controls.Add(panel1);
panelCollectionWarmlyLocomotive.Controls.Add(buttonreFreshCollection);
panelCollectionWarmlyLocomotive.Controls.Add(textBoxCollectionWarmlyLocomotive);
panelCollectionWarmlyLocomotive.Controls.Add(maskedTextBoxNumber);
panelCollectionWarmlyLocomotive.Controls.Add(buttonRemove);
panelCollectionWarmlyLocomotive.Controls.Add(buttonadd);
panelCollectionWarmlyLocomotive.Controls.Add(buttonAdd);
panelCollectionWarmlyLocomotive.Location = new Point(662, 28);
panelCollectionWarmlyLocomotive.Name = "panelCollectionWarmlyLocomotive";
panelCollectionWarmlyLocomotive.Size = new Size(149, 350);
panelCollectionWarmlyLocomotive.Size = new Size(149, 410);
panelCollectionWarmlyLocomotive.TabIndex = 1;
//
// labelGenericCollection
//
labelGenericCollection.AutoSize = true;
labelGenericCollection.Location = new Point(17, -1);
labelGenericCollection.Name = "labelGenericCollection";
labelGenericCollection.Size = new Size(52, 15);
labelGenericCollection.TabIndex = 5;
labelGenericCollection.Text = "Наборы";
//
// panel1
//
panel1.Controls.Add(buttonDelObject);
panel1.Controls.Add(textBoxStorageName);
panel1.Controls.Add(listBoxStorages);
panel1.Controls.Add(buttonAddObject);
panel1.Location = new Point(3, 16);
panel1.Name = "panel1";
panel1.Size = new Size(143, 209);
panel1.TabIndex = 4;
//
// buttonDelObject
//
buttonDelObject.Location = new Point(15, 175);
buttonDelObject.Name = "buttonDelObject";
buttonDelObject.Size = new Size(115, 23);
buttonDelObject.TabIndex = 3;
buttonDelObject.Text = "Удалить набор";
buttonDelObject.UseVisualStyleBackColor = true;
buttonDelObject.Click += buttonDelObject_Click;
//
// textBoxStorageName
//
textBoxStorageName.Location = new Point(13, 13);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(117, 23);
textBoxStorageName.TabIndex = 2;
//
// listBoxStorages
//
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 15;
listBoxStorages.Location = new Point(14, 90);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(119, 79);
listBoxStorages.TabIndex = 1;
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
//
// buttonAddObject
//
buttonAddObject.Location = new Point(15, 51);
buttonAddObject.Name = "buttonAddObject";
buttonAddObject.Size = new Size(118, 22);
buttonAddObject.TabIndex = 0;
buttonAddObject.Text = "Добавить набор";
buttonAddObject.UseVisualStyleBackColor = true;
buttonAddObject.Click += buttonAddObject_Click;
//
// buttonreFreshCollection
//
buttonreFreshCollection.Location = new Point(3, 193);
buttonreFreshCollection.Location = new Point(3, 325);
buttonreFreshCollection.Name = "buttonreFreshCollection";
buttonreFreshCollection.Size = new Size(146, 23);
buttonreFreshCollection.TabIndex = 3;
@ -70,38 +136,38 @@
buttonreFreshCollection.UseVisualStyleBackColor = true;
buttonreFreshCollection.Click += buttonreFreshCollection_Click;
//
// textBoxCollectionWarmlyLocomotive
// maskedTextBoxNumber
//
textBoxCollectionWarmlyLocomotive.Location = new Point(17, 128);
textBoxCollectionWarmlyLocomotive.Name = "textBoxCollectionWarmlyLocomotive";
textBoxCollectionWarmlyLocomotive.Size = new Size(117, 23);
textBoxCollectionWarmlyLocomotive.TabIndex = 2;
maskedTextBoxNumber.Location = new Point(16, 296);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(117, 23);
maskedTextBoxNumber.TabIndex = 2;
//
// buttonRemove
//
buttonRemove.Location = new Point(3, 71);
buttonRemove.Location = new Point(6, 369);
buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(131, 23);
buttonRemove.Size = new Size(143, 23);
buttonRemove.TabIndex = 1;
buttonRemove.Text = "Удалить тепловоз";
buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += buttonRemove_Click;
//
// buttonadd
// buttonAdd
//
buttonadd.Location = new Point(3, 22);
buttonadd.Name = "buttonadd";
buttonadd.Size = new Size(131, 23);
buttonadd.TabIndex = 0;
buttonadd.Text = "Добавить тепловоз";
buttonadd.UseVisualStyleBackColor = true;
buttonadd.Click += buttonAdd_Click;
buttonAdd.Location = new Point(6, 247);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(143, 22);
buttonAdd.TabIndex = 0;
buttonAdd.Text = "Добавить тепловоз";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// pictureBoxCollectionWarmlyLocomotive
//
pictureBoxCollectionWarmlyLocomotive.Location = new Point(12, 28);
pictureBoxCollectionWarmlyLocomotive.Name = "pictureBoxCollectionWarmlyLocomotive";
pictureBoxCollectionWarmlyLocomotive.Size = new Size(647, 350);
pictureBoxCollectionWarmlyLocomotive.Size = new Size(647, 410);
pictureBoxCollectionWarmlyLocomotive.TabIndex = 2;
pictureBoxCollectionWarmlyLocomotive.TabStop = false;
//
@ -117,6 +183,8 @@
Text = "FormWarmlyLocomotiveCollection";
panelCollectionWarmlyLocomotive.ResumeLayout(false);
panelCollectionWarmlyLocomotive.PerformLayout();
panel1.ResumeLayout(false);
panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollectionWarmlyLocomotive).EndInit();
ResumeLayout(false);
PerformLayout();
@ -127,9 +195,15 @@
private Label labelCollection;
private Panel panelCollectionWarmlyLocomotive;
private PictureBox pictureBoxCollectionWarmlyLocomotive;
private Button buttonadd;
private Button buttonAdd;
private Button buttonRemove;
private Button buttonreFreshCollection;
private TextBox textBoxCollectionWarmlyLocomotive;
private TextBox maskedTextBoxNumber;
private Label labelGenericCollection;
private Panel panel1;
private Button buttonAddObject;
private ListBox listBoxStorages;
private TextBox textBoxStorageName;
private Button buttonDelObject;
}
}

View File

@ -1,28 +1,102 @@
using WarmlyLocomotive.DrawningObjects;
using WarmlyLocomotive.Generics;
using WarmlyLocomotive.Generics;
using WarmlyLocomotive.MovementStrategy;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WarmlyLocomotive
{
public partial class FormWarmlyLocomotiveCollection : Form
{
private readonly CarsGenericCollection<DrawningWarmlyLocomotive,
DrawningObjectCar> _warmlylocomotives;
/// <summary>
/// Набор объектов
/// </summary>
private readonly WarmlyLocomotivesGenericStorage _storage;
public FormWarmlyLocomotiveCollection()
{
InitializeComponent();
_warmlylocomotives = new CarsGenericCollection<DrawningWarmlyLocomotive, DrawningObjectCar>(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
_storage = new WarmlyLocomotivesGenericStorage(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
}
/// <summary>
/// Заполнение listBoxObjects
/// </summary>
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
>= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
/// <summary>
/// Выбор набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollectionWarmlyLocomotive.Image =
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowWarmlyLocomotives();
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?",
"Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
WarmlyLocomotiveForm form = new();
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
WarmlyLocomotiveForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_warmlylocomotives + form.SelectedCar != null)
if (obj + form.SelectedWarmlyLocomotive)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars();
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
}
else
{
@ -31,35 +105,73 @@ namespace WarmlyLocomotive
}
}
private void buttonreFreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars();
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonRemove_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos;
if (textBoxCollectionWarmlyLocomotive.Text == null || !int.TryParse(textBoxCollectionWarmlyLocomotive.Text, out pos))
{
MessageBox.Show("Введите номер парковочного места");
return;
}
if (_warmlylocomotives - pos != null)
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars();
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonreFreshCollection_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
}
/// <summary>
/// Добавление набора в коллекцию
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
}
}
}

View File

@ -12,7 +12,6 @@ namespace WarmlyLocomotive
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormWarmlyLocomotiveCollection());
Application.Run(new WarmlyLocomotiveForm());
}
}
}

View File

@ -4,95 +4,107 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive.Generics
namespace WarmlyLocomotive.Generics
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetGeneric<T>
where T : class
{
internal class SetGeneric<T>
where T : class
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Count;
/// <summary>
/// Максимальное количество объектов в списке
/// </summary>
private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetGeneric(int count)
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T?[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
///
public int startPointer = 0;
public SetGeneric(int count)
_maxCount = count;
_places = new List<T?>(count);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="warmlylocomotive">Добавляемый тепловоз</param>
/// <returns></returns>
public bool Insert(T warmlylocomotive)
{
if (_places.Count == _maxCount)
{
_places = new T?[count];
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <returns></returns>
public int Insert(T car)
{
if (_places[Count - 1] != null)
return -1;
return Insert(car, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T car, int position)
{
int nullIndex = -1, i;
if (position < 0 || position >= Count)
return -1;
for (i = position; i < Count; i++)
{
if (_places[i] == null)
{
nullIndex = i;
break;
}
}
if (nullIndex < 0)
return -1;
for (i = nullIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = car;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (position < Count && position >= 0)
{
_places[position] = null;
return true;
}
return false;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? Get(int position)
Insert(warmlylocomotive, 0);
return true;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="warmlylocomotive">Добавляемый тепловоз</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T warmlylocomotive, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) return false;
_places.Insert(position, warmlylocomotive);
return true;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (position < 0 || position >= Count) return false;
_places.RemoveAt(position);
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? this[int position]
{
get
{
if (position < Count && position >= 0) { return _places[position]; }
return null;
if (position < 0 || position >= Count) return null;
return _places[position];
}
set
{
if (!(position >= 0 && position < Count && _places.Count < _maxCount)) return;
_places.Insert(position, value);
return;
}
}
/// <summary>
/// Проход по списку
/// </summary>
/// <returns></returns>
public IEnumerable<T?> GetWarmlyLocomotives(int? maxWarmlyLocomotives = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxWarmlyLocomotives.HasValue && i == maxWarmlyLocomotives.Value)
{
yield break;
}
}
}
}
}

View File

@ -7,20 +7,18 @@ using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive
{
/// <summary>
/// Ôîđěŕ đŕáîňű ń îáúĺęňîě "Ńďîđňčâíűé ŕâňîěîáčëü"
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Òåïëîâîç ñ òðóáîé è ïðèöåïîì"
/// </summary>
public partial class WarmlyLocomotiveForm : Form
{
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
private AbstractStrategy? _abstractStrategy;
private AbstractStrategy? _strategy;
public DrawningWarmlyLocomotive? SelectedCar { get; private set; }
public DrawningWarmlyLocomotive? SelectedWarmlyLocomotive { get; private set; }
public WarmlyLocomotiveForm()
{
InitializeComponent();
_strategy = null;
SelectedCar = null;
SelectedWarmlyLocomotive = null;
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû
@ -99,32 +97,32 @@ namespace WarmlyLocomotive
}
if (comboBoxWarmlyLocomotive.Enabled)
{
_abstractStrategy = comboBoxWarmlyLocomotive.SelectedIndex
_strategy = comboBoxWarmlyLocomotive.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectCar(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width,
_strategy.SetData(new
DrawningObjectWarmlyLocomotive(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width,
pictureBoxWarmlyLocomotive.Height);
comboBoxWarmlyLocomotive.Enabled = false;
}
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_abstractStrategy.MakeStep();
_strategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
if (_strategy.GetStatus() == Status.Finish)
{
comboBoxWarmlyLocomotive.Enabled = true;
_abstractStrategy = null;
_strategy = null;
}
}
/// <summary>
@ -132,6 +130,37 @@ namespace WarmlyLocomotive
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_WarmlyLocomotivePro_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dopDialog = new();
if (dopDialog.ShowDialog() == DialogResult.OK)
{
dopColor = dopDialog.Color;
}
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotiveWithTrumpet(random.Next(100, 300),
random.Next(1000, 3000),
color,
dopColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void buttonSelectWarmlyLocomotive_Click(object sender, EventArgs e)
{
SelectedWarmlyLocomotive = _drawningWarmlyLocomotive;
DialogResult = DialogResult.OK;
}
private void buttonCreate_Pro_Click(object sender, EventArgs e)
{
Random random = new();
@ -158,11 +187,5 @@ namespace WarmlyLocomotive
100));
Draw();
}
private void buttonSelectCar_Click(object sender, EventArgs e)
{
SelectedCar = _drawningWarmlyLocomotive;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -2,7 +2,7 @@
using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive.Generics
{
internal class CarsGenericCollection<T, U>
internal class WarmlyLocomotivesGenericCollection<T, U>
where T : DrawningWarmlyLocomotive
where U : IMoveableObject
{
@ -31,7 +31,7 @@ namespace WarmlyLocomotive.Generics
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public CarsGenericCollection(int picWidth, int picHeight)
public WarmlyLocomotivesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
@ -45,14 +45,13 @@ namespace WarmlyLocomotive.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(CarsGenericCollection<T, U> collect, T?
obj)
public static bool operator +(WarmlyLocomotivesGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
return false;
}
return collect._collection.Insert(obj);
return (bool)collect?._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -60,15 +59,14 @@ namespace WarmlyLocomotive.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static bool operator -(CarsGenericCollection<T, U> collect, int
pos)
public static bool operator -(WarmlyLocomotivesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return true;
return false;
}
/// <summary>
/// Получение объекта IMoveableObject
@ -77,13 +75,13 @@ namespace WarmlyLocomotive.Generics
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
return (U?)_collection[pos]?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowCars()
public Bitmap ShowWarmlyLocomotives()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
@ -117,16 +115,16 @@ namespace WarmlyLocomotive.Generics
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
DrawningWarmlyLocomotive warmlylocomotive;
int i = 0;
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
foreach (var warmlylocomotive in _collection.GetWarmlyLocomotives())
{
warmlylocomotive = _collection.Get(i);
if (warmlylocomotive != null)
{
warmlylocomotive.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
warmlylocomotive.DrawTransport(g);
}
i++;
}
}
}

View File

@ -0,0 +1,40 @@
using WarmlyLocomotive.DrawningObjects;
using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive.Generics
{
internal class WarmlyLocomotivesGenericStorage
{
readonly Dictionary<string, WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>> _warmlylocomotiveStorages;
public List<string> Keys => _warmlylocomotiveStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public WarmlyLocomotivesGenericStorage(int pictureWidth, int pictureHeight)
{
_warmlylocomotiveStorages = new Dictionary<string,
WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
_warmlylocomotiveStorages.Add(name, new WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (!_warmlylocomotiveStorages.ContainsKey(name))
return;
_warmlylocomotiveStorages.Remove(name);
}
public WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>? this[string ind]
{
get
{
if (_warmlylocomotiveStorages.ContainsKey(ind))
return _warmlylocomotiveStorages[ind];
return null;
}
}
}
}

View File

@ -149,7 +149,7 @@
buttonSelectCar.TabIndex = 11;
buttonSelectCar.Text = "Выбор тепловоза";
buttonSelectCar.UseVisualStyleBackColor = true;
buttonSelectCar.Click += buttonSelectCar_Click;
buttonSelectCar.Click += buttonSelectWarmlyLocomotive_Click;
//
// WarmlyLocomotiveForm
//