лаба 3 с нареканиями
This commit is contained in:
parent
d9e4d18651
commit
e3253aeb74
121
laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
Normal file
121
laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using MotorBoat.Drawning;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 150;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция катеров
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningB>? _collection = null;
|
||||
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth">Ширина окна</param>
|
||||
/// <param name="picHeight">Высота окна</param>
|
||||
/// <param name="collection">Коллекция автомобилей</param>
|
||||
public AbstractCompany(int picWidth, int picHeight,
|
||||
ICollectionGenericObjects<DrawningB> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="car">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawningB B)
|
||||
{
|
||||
return company._collection?.Insert(B) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningB? GetRandomObject()
|
||||
{
|
||||
Random rnd = new();
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackground(graphics);
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningB? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
protected abstract void DrawBackground(Graphics g);
|
||||
|
||||
/// <summary>
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
||||
|
55
laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs
Normal file
55
laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.Drawning;
|
||||
|
||||
namespace MotorBoat.CollectionGenericObjects;
|
||||
|
||||
public class BoatHarbor : AbstractCompany
|
||||
{
|
||||
public BoatHarbor(int picWidth, int picHeight, ICollectionGenericObjects<DrawningB> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
Pen black = new Pen(Color.Black);
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
for (int i = _pictureHeight - 1; i >= 0; i -= _placeSizeHeight)
|
||||
{
|
||||
g.DrawLine(black, _pictureWidth - ((int)(_pictureWidth / _placeSizeWidth) * _placeSizeWidth), i, _pictureWidth, i);
|
||||
|
||||
for (int j = _pictureWidth - 1; j >= 0; j -= _placeSizeWidth)
|
||||
{
|
||||
g.DrawLine(black, j, i, j, i - _placeSizeHeight + 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
{
|
||||
int posX = -1;
|
||||
int posY = 0;
|
||||
for (int i = 0; i < _collection?.Count; i++)
|
||||
{
|
||||
if (_collection.Get(i) != null)
|
||||
{
|
||||
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i)?.SetPosition(posX * _placeSizeWidth +200, posY * _placeSizeHeight + 15);
|
||||
}
|
||||
|
||||
posX++;
|
||||
if (posX >= _pictureWidth / _placeSizeWidth - 1)
|
||||
{
|
||||
posY++;
|
||||
posX = -1;
|
||||
}
|
||||
if (posY >= _pictureHeight / _placeSizeHeight-1) { return; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Количество объектов в коллекции
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка неудалась</returns>
|
||||
bool Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка неудалась</returns>
|
||||
bool Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
bool Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.CollectionGenericObjects;
|
||||
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T?[] _collection;
|
||||
|
||||
public int Count => _collection.Length;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _collection.Length) return null;
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
for (int i = 0; i < _collection.Length; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
|
||||
if (position < 0 || position >= _collection.Length) { return false; }
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = position + 1; i < _collection.Length; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = position - 1; i >= 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _collection.Length) { return false; }
|
||||
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace laba_0.Drawning;
|
||||
namespace MotorBoat.Drawning;
|
||||
|
||||
/// <summary>
|
||||
/// направление перемещения
|
||||
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using laba_0.Entities;
|
||||
using MotorBoat.Entities;
|
||||
|
||||
namespace laba_0.Drawning;
|
||||
namespace MotorBoat.Drawning;
|
||||
|
||||
public class DrawningB
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using laba_0.Entities;
|
||||
using MotorBoat.Entities;
|
||||
|
||||
namespace laba_0.Drawning;
|
||||
namespace MotorBoat.Drawning;
|
||||
|
||||
/// <summary>
|
||||
/// класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace laba_0.Entities;
|
||||
namespace MotorBoat.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Катер"
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace laba_0.Entities;
|
||||
namespace MotorBoat.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Катер"
|
||||
|
30
laba 0/laba 0/FormBoat.Designer.cs
generated
30
laba 0/laba 0/FormBoat.Designer.cs
generated
@ -1,4 +1,4 @@
|
||||
namespace laba_0;
|
||||
namespace MotorBoat;
|
||||
|
||||
partial class FormBoat
|
||||
{
|
||||
@ -30,12 +30,10 @@ partial class FormBoat
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBoat));
|
||||
pictureBoxBoat = new PictureBox();
|
||||
buttonCreateBoat = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
ButtonCreateB = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit();
|
||||
@ -53,17 +51,6 @@ partial class FormBoat
|
||||
pictureBoxBoat.TabStop = false;
|
||||
pictureBoxBoat.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBoat
|
||||
//
|
||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBoat.Location = new Point(12, 327);
|
||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
||||
buttonCreateBoat.Size = new Size(153, 23);
|
||||
buttonCreateBoat.TabIndex = 1;
|
||||
buttonCreateBoat.Text = "Создать катер";
|
||||
buttonCreateBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateBoat.Click += ButtonCreateBoat_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -112,17 +99,6 @@ partial class FormBoat
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonCreateB
|
||||
//
|
||||
ButtonCreateB.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonCreateB.Location = new Point(171, 327);
|
||||
ButtonCreateB.Name = "ButtonCreateB";
|
||||
ButtonCreateB.Size = new Size(147, 23);
|
||||
ButtonCreateB.TabIndex = 6;
|
||||
ButtonCreateB.Text = "Создать простой катер";
|
||||
ButtonCreateB.UseVisualStyleBackColor = true;
|
||||
ButtonCreateB.Click += ButtonCreateB_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
@ -150,12 +126,10 @@ partial class FormBoat
|
||||
ClientSize = new Size(640, 359);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(ButtonCreateB);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonCreateBoat);
|
||||
Controls.Add(pictureBoxBoat);
|
||||
Name = "FormBoat";
|
||||
Text = "FormBoat";
|
||||
@ -167,12 +141,10 @@ partial class FormBoat
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxBoat;
|
||||
private Button buttonCreateBoat;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button ButtonCreateB;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
@ -7,10 +7,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using laba_0.Drawning;
|
||||
using laba_0.MovementStrategy;
|
||||
using MotorBoat.Drawning;
|
||||
using MotorBoat.MovementStrategy;
|
||||
|
||||
namespace laba_0;
|
||||
namespace MotorBoat;
|
||||
|
||||
public partial class FormBoat : Form
|
||||
{
|
||||
@ -24,6 +24,18 @@ public partial class FormBoat : Form
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawningB SetB
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningB = value;
|
||||
_drawningB.SetPictureSize(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// конструктор формы
|
||||
/// </summary>
|
||||
@ -49,56 +61,6 @@ public partial class FormBoat : Form
|
||||
pictureBoxBoat.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningB):
|
||||
_drawningB = new DrawningB(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningBoat):
|
||||
_drawningB = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningB.SetPictureSize(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||||
_drawningB.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка создания кнопки "создать катер"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningBoat));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка создания кнопки "создать простой катер"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateB_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningB));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
|
173
laba 0/laba 0/FormBoatCollection.Designer.cs
generated
Normal file
173
laba 0/laba 0/FormBoatCollection.Designer.cs
generated
Normal file
@ -0,0 +1,173 @@
|
||||
namespace MotorBoat
|
||||
{
|
||||
partial class FormBoatCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveBoat = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddMotorBoat = new Button();
|
||||
buttonAddBoat = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonRemoveBoat);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddMotorBoat);
|
||||
groupBoxTools.Controls.Add(buttonAddBoat);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(489, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(194, 411);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(3, 320);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(185, 27);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить ";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += buttonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(3, 260);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(185, 27);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты ";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||
//
|
||||
// buttonRemoveBoat
|
||||
//
|
||||
buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveBoat.Location = new Point(3, 206);
|
||||
buttonRemoveBoat.Name = "buttonRemoveBoat";
|
||||
buttonRemoveBoat.Size = new Size(185, 27);
|
||||
buttonRemoveBoat.TabIndex = 4;
|
||||
buttonRemoveBoat.Text = "Удалить катер\r\n ";
|
||||
buttonRemoveBoat.UseVisualStyleBackColor = true;
|
||||
buttonRemoveBoat.Click += buttonRemoveBoat_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(3, 177);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(185, 23);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddMotorBoat
|
||||
//
|
||||
buttonAddMotorBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMotorBoat.Location = new Point(3, 113);
|
||||
buttonAddMotorBoat.Name = "buttonAddMotorBoat";
|
||||
buttonAddMotorBoat.Size = new Size(185, 38);
|
||||
buttonAddMotorBoat.TabIndex = 2;
|
||||
buttonAddMotorBoat.Text = "Добавление моторного катера";
|
||||
buttonAddMotorBoat.UseVisualStyleBackColor = true;
|
||||
buttonAddMotorBoat.Click += buttonAddMotorBoat_Click;
|
||||
//
|
||||
// buttonAddBoat
|
||||
//
|
||||
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddBoat.Location = new Point(3, 69);
|
||||
buttonAddBoat.Name = "buttonAddBoat";
|
||||
buttonAddBoat.Size = new Size(185, 38);
|
||||
buttonAddBoat.TabIndex = 1;
|
||||
buttonAddBoat.Text = "Добавление катера";
|
||||
buttonAddBoat.UseVisualStyleBackColor = true;
|
||||
buttonAddBoat.Click += buttonBoat_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(3, 22);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(185, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(489, 411);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(683, 411);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormBoatCollection";
|
||||
Text = "Коллекция катеров";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddMotorBoat;
|
||||
private Button buttonAddBoat;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRemoveBoat;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
}
|
||||
}
|
161
laba 0/laba 0/FormBoatCollection.cs
Normal file
161
laba 0/laba 0/FormBoatCollection.cs
Normal file
@ -0,0 +1,161 @@
|
||||
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;
|
||||
using MotorBoat.CollectionGenericObjects;
|
||||
using MotorBoat.Drawning;
|
||||
|
||||
namespace MotorBoat;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormBoatCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormBoatCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new BoatHarbor(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningB>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null) return;
|
||||
|
||||
Random random = new();
|
||||
DrawningB drawningB;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningB):
|
||||
drawningB = new DrawningB(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
drawningB.SetPictureSize(pictureBox.Width, pictureBox.Height);
|
||||
break;
|
||||
case nameof(DrawningBoat):
|
||||
drawningB = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random), GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
drawningB.SetPictureSize(pictureBox.Width, pictureBox.Height);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningB)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Объект не удалось добавить");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение цвета
|
||||
/// </summary>
|
||||
/// <param name="rnd"></param>
|
||||
/// <returns></returns>
|
||||
private static Color GetColor(Random rnd)
|
||||
{
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
private void buttonBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningB));
|
||||
|
||||
private void buttonAddMotorBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
|
||||
|
||||
private void buttonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null || string.IsNullOrEmpty(maskedTextBox.Text)) return;
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удалён");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningB? B = null;
|
||||
int counter = 100;
|
||||
while (B == null)
|
||||
{
|
||||
B = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (B == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormBoat form = new()
|
||||
{
|
||||
SetB = B
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null) return;
|
||||
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
120
laba 0/laba 0/FormBoatCollection.resx
Normal file
120
laba 0/laba 0/FormBoatCollection.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<RootNamespace>laba_0</RootNamespace>
|
||||
<RootNamespace>MotorBoat</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using laba_0.Drawning;
|
||||
using MotorBoat.Drawning;
|
||||
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-реализация IMoveableObject с использованием DrawningB
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
public enum MovementDirection
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
public class ObjectParameters
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace laba_0.MovementStrategy;
|
||||
namespace MotorBoat.MovementStrategy;
|
||||
|
||||
public enum StrategyStatus
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace laba_0
|
||||
namespace MotorBoat
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
@ -11,7 +11,7 @@ namespace laba_0
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormBoat());
|
||||
Application.Run(new FormBoatCollection());
|
||||
}
|
||||
}
|
||||
}
|
4
laba 0/laba 0/Properties/Resources.Designer.cs
generated
4
laba 0/laba 0/Properties/Resources.Designer.cs
generated
@ -8,7 +8,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace laba_0.Properties {
|
||||
namespace MotorBoat.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ namespace laba_0.Properties {
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("laba_0.Properties.Resources", typeof(Resources).Assembly);
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MotorBoat.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
|
Loading…
Reference in New Issue
Block a user