LabWork06

This commit is contained in:
Osyagina_Anna 2024-05-01 21:30:32 +04:00
parent 058d31a0f7
commit 7e69a5b27b
9 changed files with 16 additions and 111 deletions

View File

@ -10,16 +10,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class where T : class
{ {
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _collection; private readonly List<T?> _collection;
public CollectionType GetCollectionType => CollectionType.List; public CollectionType GetCollectionType => CollectionType.List;
/// <summary>
/// Максимально допустимое число объектов в списке
/// </summary>
private int _maxCount; private int _maxCount;
public int Count => _collection.Count; public int Count => _collection.Count;
@ -39,9 +33,6 @@ where T : class
} }
} }
/// <summary>
/// Конструктор
/// </summary>
public ListGenericObjects() public ListGenericObjects()
{ {
_collection = new(); _collection = new();
@ -49,15 +40,12 @@ where T : class
public T? Get(int position) public T? Get(int position)
{ {
// TODO проверка позиции
if (position >= Count || position < 0) return null; if (position >= Count || position < 0) return null;
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj)
{ {
// TODO проверка, что не превышено максимальное количество элементов
// TODO вставка в конец набора
if (Count + 1 > _maxCount) return -1; if (Count + 1 > _maxCount) return -1;
_collection.Add(obj); _collection.Add(obj);
return Count; return Count;
@ -65,9 +53,6 @@ where T : class
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
// TODO проверка, что не превышено максимальное количество элементов
// TODO проверка позиции
// TODO вставка по позиции
if (Count + 1 > _maxCount) return -1; if (Count + 1 > _maxCount) return -1;
if (position < 0 || position > Count) return -1; if (position < 0 || position > Count) return -1;
_collection.Insert(position, obj); _collection.Insert(position, obj);
@ -76,8 +61,6 @@ where T : class
public T? Remove(int position) public T? Remove(int position)
{ {
// TODO проверка позиции
// TODO удаление объекта из списка
if (position < 0 || position > Count) return null; if (position < 0 || position > Count) return null;
T? pos = _collection[position]; T? pos = _collection[position];
_collection.RemoveAt(position); _collection.RemoveAt(position);

View File

@ -23,8 +23,7 @@ public class StorageCollection<T>
public void AddCollection(string name, CollectionType collectionType) public void AddCollection(string name, CollectionType collectionType)
{ {
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления
if (name == null || _storages.ContainsKey(name)) { return; } if (name == null || _storages.ContainsKey(name)) { return; }
switch (collectionType) switch (collectionType)
@ -43,7 +42,7 @@ public class StorageCollection<T>
public void DelCollection(string name) public void DelCollection(string name)
{ {
// TODO Прописать логику для удаления коллекции
if (_storages.ContainsKey(name)) if (_storages.ContainsKey(name))
_storages.Remove(name); _storages.Remove(name);
} }
@ -53,7 +52,7 @@ public class StorageCollection<T>
{ {
get get
{ {
// TODO Продумать логику получения объекта
if (name == null || !_storages.ContainsKey(name)) { return null; } if (name == null || !_storages.ContainsKey(name)) { return null; }
return _storages[name]; return _storages[name];
} }
@ -65,11 +64,7 @@ public class StorageCollection<T>
private readonly string _separatorItems = ";"; private readonly string _separatorItems = ";";
/// <summary>
/// Сохранение информации в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename) public bool SaveData(string filename)
{ {
if (_storages.Count == 0) if (_storages.Count == 0)
@ -118,11 +113,7 @@ public class StorageCollection<T>
return true; return true;
} }
/// <summary>
/// Загрузка информации в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename) public bool LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))

View File

@ -114,28 +114,28 @@ public class DrawningBoat
} }
switch (direction) switch (direction)
{ {
//влево
case DirectionType.Left: case DirectionType.Left:
if (_startPosX.Value - EntityBoat.Step > 0) if (_startPosX.Value - EntityBoat.Step > 0)
{ {
_startPosX -= (int)EntityBoat.Step; _startPosX -= (int)EntityBoat.Step;
} }
return true; return true;
//вверх
case DirectionType.Up: case DirectionType.Up:
if (_startPosY.Value - EntityBoat.Step > 0) if (_startPosY.Value - EntityBoat.Step > 0)
{ {
_startPosY -= (int)EntityBoat.Step; _startPosY -= (int)EntityBoat.Step;
} }
return true; return true;
// вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX.Value + EntityBoat.Step + _drawningBoatWidth < _pictureWidth) if (_startPosX.Value + EntityBoat.Step + _drawningBoatWidth < _pictureWidth)
{ {
_startPosX += (int)EntityBoat.Step; _startPosX += (int)EntityBoat.Step;
} }
return true; return true;
//вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY.Value + EntityBoat.Step + _drawningBoatHeight < _pictureHeight) if (_startPosY.Value + EntityBoat.Step + _drawningBoatHeight < _pictureHeight)
{ {
@ -155,7 +155,7 @@ public class DrawningBoat
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush mainBrush = new SolidBrush(EntityBoat.BodyColor); Brush mainBrush = new SolidBrush(EntityBoat.BodyColor);
// корпус
Point[] hull = new Point[] Point[] hull = new Point[]
{ {
new Point(_startPosX.Value + 5, _startPosY.Value + 0), new Point(_startPosX.Value + 5, _startPosY.Value + 0),
@ -167,7 +167,6 @@ public class DrawningBoat
g.FillPolygon(mainBrush, hull); g.FillPolygon(mainBrush, hull);
g.DrawPolygon(pen, hull); g.DrawPolygon(pen, hull);
// основная часть
Brush blockBrush = new SolidBrush(EntityBoat.BodyColor); Brush blockBrush = new SolidBrush(EntityBoat.BodyColor);
g.FillRectangle(blockBrush, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40); g.FillRectangle(blockBrush, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40);
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40); g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 15, 80, 40);

View File

@ -27,14 +27,14 @@ public class DrawningMotorboat : DrawningBoat
base.DrawTransport(g); base.DrawTransport(g);
// стекло впереди
if (motorboat.Glass) if (motorboat.Glass)
{ {
Brush glassBrush = new SolidBrush(Color.LightBlue); Brush glassBrush = new SolidBrush(Color.LightBlue);
g.FillEllipse(glassBrush, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40); g.FillEllipse(glassBrush, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40); g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 15, 100, 40);
} }
// двигатель
if (motorboat.Motor) if (motorboat.Motor)
{ {
Brush engineBrush = new Brush engineBrush = new

View File

@ -8,16 +8,7 @@ using System.Threading.Tasks;
namespace ProjectMotorboat.Drownings; namespace ProjectMotorboat.Drownings;
public static class ExtentionDrawningBoat public static class ExtentionDrawningBoat
{ {
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separatorForObject = ":"; private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static DrawningBoat? CreateDrawningBoat(this string info) public static DrawningBoat? CreateDrawningBoat(this string info)
{ {
string[] strs = info.Split(_separatorForObject); string[] strs = info.Split(_separatorForObject);
@ -34,12 +25,6 @@ public static class ExtentionDrawningBoat
} }
return null; return null;
} }
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawingWarship"></param>
/// <returns></returns>
public static string GetDataForSave(this DrawningBoat drawningBoat) public static string GetDataForSave(this DrawningBoat drawningBoat)
{ {
string[]? array = drawningBoat?.EntityBoat?.GetStringRepresentation(); string[]? array = drawningBoat?.EntityBoat?.GetStringRepresentation();

View File

@ -30,12 +30,6 @@ public class EntityBoat
{ {
return new[] { nameof(EntityBoat), Speed.ToString(), Weight.ToString(), BodyColor.Name }; return new[] { nameof(EntityBoat), Speed.ToString(), Weight.ToString(), BodyColor.Name };
} }
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityBoat? CreateEntityBoat(string[] strs) public static EntityBoat? CreateEntityBoat(string[] strs)
{ {
if (strs.Length != 4 || strs[0] != nameof(EntityBoat)) if (strs.Length != 4 || strs[0] != nameof(EntityBoat))

View File

@ -3,47 +3,24 @@ using ProjectMotorboat.Drownings;
using System.Windows.Forms; using System.Windows.Forms;
namespace ProjectMotorboat; namespace ProjectMotorboat;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormBoatCollection : Form public partial class FormBoatCollection : Form
{ {
private readonly StorageCollection<DrawningBoat> _storageCollection; private readonly StorageCollection<DrawningBoat> _storageCollection;
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null; private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormBoatCollection() public FormBoatCollection()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new(); _storageCollection = new();
} }
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{ {
panelCompanyTools.Enabled = false; panelCompanyTools.Enabled = false;
} }
/// <summary>
/// Добавление обычного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBoat_Click(object sender, EventArgs e) private void ButtonAddBoat_Click(object sender, EventArgs e)
{ {
FormBoatConfig form = new(); FormBoatConfig form = new();
// TODO передать метод
form.AddEvent(SetBoat); form.AddEvent(SetBoat);
form.Show(); form.Show();
@ -67,18 +44,6 @@ public partial class FormBoatCollection : Form
} }
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveBoat_Click(object sender, EventArgs e) private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
@ -103,11 +68,6 @@ public partial class FormBoatCollection : Form
} }
} }
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e) private void ButtonGoToCheck_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)
@ -139,11 +99,6 @@ public partial class FormBoatCollection : Form
form.ShowDialog(); form.ShowDialog();
} }
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e) private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)

View File

@ -81,11 +81,11 @@ namespace ProjectMotorboat
private void Panel_MouseDown(object? sender, MouseEventArgs e) private void Panel_MouseDown(object? sender, MouseEventArgs e)
{ {
// TODO отправка цвета в Drag&Drop
(sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); (sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
} }
// Логика смены цветов: основного и дополнительного (для продвинутого объекта)
private void LabelBodyColor_DragEnter(object sender, DragEventArgs e) private void LabelBodyColor_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data?.GetDataPresent(typeof(Color)) ?? false) if (e.Data?.GetDataPresent(typeof(Color)) ?? false)

View File

@ -2,9 +2,7 @@ namespace ProjectMotorboat
{ {
internal static class Program internal static class Program
{ {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {