PIbd-11 Tarasov V.D. LabWork_3 Simple #3

Closed
ENDORFIT wants to merge 3 commits from LabWork_3 into LabWork_2
9 changed files with 634 additions and 83 deletions
Showing only changes of commit 27d06f5bbc - Show all commits

View File

@ -33,8 +33,6 @@
buttonMove_Left = new Button();
buttonMove_Up = new Button();
pictureBoxMonorail = new PictureBox();
buttonCreateModernMonorail = new Button();
buttonCreateMonorail = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit();
@ -98,28 +96,6 @@
pictureBoxMonorail.TabIndex = 4;
pictureBoxMonorail.TabStop = false;
//
// buttonCreateModernMonorail
//
buttonCreateModernMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateModernMonorail.Location = new Point(12, 439);
buttonCreateModernMonorail.Name = "buttonCreateModernMonorail";
buttonCreateModernMonorail.Size = new Size(220, 23);
buttonCreateModernMonorail.TabIndex = 5;
buttonCreateModernMonorail.Text = "Создать современный монорельс";
buttonCreateModernMonorail.UseVisualStyleBackColor = true;
buttonCreateModernMonorail.Click += ButtonCreateModernMonorail_Click;
//
// buttonCreateMonorail
//
buttonCreateMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateMonorail.Location = new Point(238, 439);
buttonCreateMonorail.Name = "buttonCreateMonorail";
buttonCreateMonorail.Size = new Size(194, 23);
buttonCreateMonorail.TabIndex = 6;
buttonCreateMonorail.Text = "Создать монорельс";
buttonCreateMonorail.UseVisualStyleBackColor = true;
buttonCreateMonorail.Click += buttonCreateMonorail_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -147,8 +123,6 @@
ClientSize = new Size(813, 474);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateMonorail);
Controls.Add(buttonCreateModernMonorail);
Controls.Add(buttonMove_Up);
Controls.Add(buttonMove_Left);
Controls.Add(buttonMove_Down);
@ -167,8 +141,6 @@
private Button buttonMove_Left;
private Button buttonMove_Up;
private PictureBox pictureBoxMonorail;
private Button buttonCreateModernMonorail;
private Button buttonCreateMonorail;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -18,6 +18,20 @@ namespace ProjectMonorail
/// </summary>
private AbstractStrategy? _strategy;
public DrawingMonorail SetMonorail
{
set
{
_drawningMonorail = value;
_drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
Random random = new Random();
_drawningMonorail.SetPosition(random.Next(0, 100), random.Next(0, 100));
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// Конструктор формы
/// </summary>
@ -68,58 +82,6 @@ namespace ProjectMonorail
if (result) Draw();
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создоваемого объекта</param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawingMonorail):
_drawningMonorail = new DrawingMonorail(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(DrawingModernMonorail):
bool randomTrack = Convert.ToBoolean(random.Next(0, 2));
_drawningMonorail = new DrawingModernMonorail(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)),
randomTrack,
(randomTrack ? Convert.ToBoolean(random.Next(0, 2)) : true));
break;
default:
return;
}
_drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать современный монорельс"
/// </summary>
private void ButtonCreateModernMonorail_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingModernMonorail));
}
/// <summary>
/// Обработка нажатия кнопки "Создать монорельс"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateMonorail_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingMonorail));
}
/// <summary>
///
/// </summary>

View File

@ -0,0 +1,173 @@
namespace ProjectMonorail
{
partial class FormMonorailCollection
{
/// <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();
buttonRemoveMonorail = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddModernMonorail = new Button();
buttonAddMonorail = 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(buttonRemoveMonorail);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddModernMonorail);
groupBoxTools.Controls.Add(buttonAddMonorail);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(970, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(241, 662);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 581);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(229, 48);
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(6, 527);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(229, 48);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveMonorail
//
buttonRemoveMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveMonorail.Location = new Point(6, 350);
buttonRemoveMonorail.Name = "buttonRemoveMonorail";
buttonRemoveMonorail.Size = new Size(229, 48);
buttonRemoveMonorail.TabIndex = 4;
buttonRemoveMonorail.Text = "Удалить монорельс";
buttonRemoveMonorail.UseVisualStyleBackColor = true;
buttonRemoveMonorail.Click += buttonRemoveMonorail_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(6, 321);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(223, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddModernMonorail
//
buttonAddModernMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddModernMonorail.Location = new Point(6, 161);
buttonAddModernMonorail.Name = "buttonAddModernMonorail";
buttonAddModernMonorail.Size = new Size(229, 48);
buttonAddModernMonorail.TabIndex = 2;
buttonAddModernMonorail.Text = "Добавление современного монорельса";
buttonAddModernMonorail.UseVisualStyleBackColor = true;
buttonAddModernMonorail.Click += ButtonAddModernMonorail_Click;
//
// buttonAddMonorail
//
buttonAddMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddMonorail.Location = new Point(6, 107);
buttonAddMonorail.Name = "buttonAddMonorail";
buttonAddMonorail.Size = new Size(229, 48);
buttonAddMonorail.TabIndex = 1;
buttonAddMonorail.Text = "Добавление монорельса";
buttonAddMonorail.UseVisualStyleBackColor = true;
buttonAddMonorail.Click += ButtonAddMonorail_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(6, 46);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(229, 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(970, 662);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormMonorailCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1211, 662);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormMonorailCollection";
Text = "Коллекция монорельсов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonRemoveMonorail;
private MaskedTextBox maskedTextBox;
private Button buttonAddModernMonorail;
private Button buttonAddMonorail;
private PictureBox pictureBox;
private Button buttonGoToCheck;
private Button buttonRefresh;
}
}

View File

@ -0,0 +1,148 @@
using ProjectMonorail.Scripts.Monorail.CollectionGenericObjects;
using ProjectMonorail.Scripts.Monorail.Drawnings;
namespace ProjectMonorail
{
/// <summary>
///
/// </summary>
public partial class FormMonorailCollection : Form
{
/// <summary>
///
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormMonorailCollection()
{
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 MonorailSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingMonorail>());
break;
}
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создоваемого объекта</param>
private void CreateObject(string type)
{
if (_company == null) return;
Random random = new();
DrawingMonorail drawningMonorail;
switch (type)
{
case nameof(DrawingMonorail):
drawningMonorail = new DrawingMonorail(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random));
break;
case nameof(DrawingModernMonorail):
bool randomTrack = Convert.ToBoolean(random.Next(0, 2));
drawningMonorail = new DrawingModernMonorail(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), randomTrack, (randomTrack ? Convert.ToBoolean(random.Next(0, 2)) : true));
break;
default:
return;
}
if (_company + drawningMonorail)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чесел</param>
/// <returns></returns>
private static Color GetColor(Random random)
{
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
return color;
}
private void ButtonAddMonorail_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingMonorail));
}
private void ButtonAddModernMonorail_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingModernMonorail));
}
private void buttonRemoveMonorail_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
int position = Convert.ToInt32(maskedTextBox.Text);
if (_company - position)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null) return;
DrawingMonorail? monorail = null;
int coutner = 100;
while (monorail == null && coutner-- > 0)
{
monorail = _company.GetRandomObject();
}
if (monorail == null) return;
FormMonorail form = new FormMonorail()
{
SetMonorail = monorail
};
form.ShowDialog();
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null) return;
pictureBox.Image = _company.Show();
}
}
}

View 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>

View File

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

View File

@ -0,0 +1,115 @@
using ProjectMonorail.Scripts.Monorail.Drawnings;
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
{
/// <summary>
/// Абстракция компании, хранящий коллекцию монорельсов
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 80;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция монорельсов
/// </summary>
protected ICollectionGenericObjects<DrawingMonorail>? _collection = null;
/// <summary>
/// Вычисление максимального количества элементов, который можно разместить в окне
/// </summary>
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth">Ширина окна</param>
/// <param name="pictureHeight">Высота окна</param>
/// <param name="collection">Коллекция монорельсов</param>
public AbstractCompany(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingMonorail> collection)
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="monorail">Добавляемый объект</param>
/// <returns></returns>
public static bool operator +(AbstractCompany company, DrawingMonorail monorail)
{
return company._collection?.Insert(monorail) ?? 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 DrawingMonorail? 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);
DrawBackgound(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawingMonorail? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
return bitmap;
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
protected abstract void DrawBackgound(Graphics g);
/// <summary>
/// Расстановка объектов
/// </summary>
protected abstract void SetObjectsPosition();
}
}

View File

@ -1,4 +1,7 @@
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
using ProjectMonorail.Scripts.Monorail.Drawnings;
using System.Diagnostics;
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
{
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
@ -40,6 +43,7 @@
public T? Get(int position)
{
// TODO проверка позиции
if (_collection[position] == null) return null;
return _collection[position];
}
@ -48,7 +52,7 @@
// TODO вставка в свободное место набора
Review

Правильнее было вызвать Insert(T obj, 0);

Правильнее было вызвать Insert(T obj, 0);
for (int i = 0; i < Count; i++)
{
if (InsertingElementCollection(i, obj)) return true;
if (InsertingElementCollection(i, obj)) return true;
}
return false;

View File

@ -0,0 +1,57 @@
using ProjectMonorail.Scripts.Monorail.Drawnings;
using System.Diagnostics;
using System.Drawing;
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
{
public class MonorailSharingService : AbstractCompany
{
public MonorailSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingMonorail> collection) : base(pictureWidth, pictureHeight, collection) {}
private int maxCountX;
private int maxCountY;
private int offsetX = 30;
protected override void DrawBackgound(Graphics g)
{
Pen pen = new Pen(Color.Black, 4);
int maxCountX = _pictureWidth / _placeSizeWidth;
int maxCountY = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < maxCountX; i++)
{
for (int j = 0; j < maxCountY; j++)
{
g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth + i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight);
g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight, i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight, _placeSizeWidth + i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int maxCountX = _pictureWidth / _placeSizeWidth;
int maxCountY = _pictureHeight / _placeSizeHeight;
int boarderOffsetX = 20;
int boarderOffsetY = 20;
int currentIndex = -1;
for (int j = 0; j < maxCountY; j++)
{
for (int i = 0; i < maxCountX; i++)
{
currentIndex++;
if (_collection.Get(currentIndex) == null) continue;
_collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(currentIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * offsetX, boarderOffsetY + j * _placeSizeHeight);
}
}
}
}
}