Компания

This commit is contained in:
Geo7312 2024-03-17 18:32:46 +04:00
parent ac90203a34
commit 8e091196c7
12 changed files with 727 additions and 110 deletions

View File

@ -0,0 +1,103 @@
using ProjectTrolleybus.Drawnings;
namespace ProjectTrolleybus.CollectionGenericObjects;
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (Ширина)
/// </summary>
protected readonly int _placeSizeWidth = 225;
/// <summary>
/// Размер места (Высота)
/// </summary>
protected readonly int _placeSizeHeight = 55;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция автобусов
/// </summary>
protected ICollectionGenericObjects<DrawningTrolleyB>? _collection = null;
/// <summary>
/// Вычисление максимального кол-ва объектов которое можно разместить в окне
/// </summary>
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth);
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth">Ширина окна</param>
/// <param name="picHeight">Высота окна</param>
/// <param name="collection">Коллекция автобусов</param>
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrolleyB> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер добавляемого объекта</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningTrolleyB trolleyB)
{
return company._collection.Insert(trolleyB);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningTrolleyB operator -(AbstractCompany company, int position)
{
return company._collection.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningTrolleyB? GetRandomObject()
{
Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount));
}
public Bitmap? Show()
{
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackground(graphics);
SetObjectPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningTrolleyB? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
return bitmap;
}
protected abstract void DrawBackground(Graphics g);
protected abstract void SetObjectPosition();
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTrolleybus.CollectionGenericObjects;
namespace ProjectTrolleybus.CollectionGenericObjects;
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
@ -23,19 +17,26 @@ public interface ICollectionGenericObjects<T>
/// </summary>
int SetMaxCount { set; }
/// <summary>
/// Добавление объекта в коллецию
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
int Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj, int position);
int Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
bool Remove(int position);
T? Remove(int position);
/// <summary>
/// Получение объекта и з позиции

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTrolleybus.CollectionGenericObjects;
namespace ProjectTrolleybus.CollectionGenericObjects;
/// <summary>
/// Параметризированный набор объектов
@ -33,29 +27,80 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position)
{
// TODO проверка позиции
if (position >= _collection.Length || position < 0)
{
return null;
}
return _collection[position];
}
public bool Insert(T obj)
public int Insert(T obj)
{
// TODO вставка в свободное место набора
return false;
int index = 0;
while (index < _collection.Length)
{
if (_collection[index] == null)
{
_collection[index] = obj;
return index;
}
index++;
}
return -1;
}
public bool Insert(T obj, int position)
public int Insert(T obj, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идёт вставка туда
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
return false;
if (position >= _collection.Length || position < 0)
return -1;
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
if (_collection[position] != null)
{
// проверка, что после вставляемого элемента в массиве есть пустой элемент
int nullIndex = -1;
for (int i = position + 1; i < Count; i++)
{
if (_collection[i] == null)
{
nullIndex = i;
break;
}
}
// Если пустого элемента нет, то выходим
if (nullIndex < 0)
{
return -1;
}
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
int j = nullIndex - 1;
while (j >= position)
{
_collection[j + 1] = _collection[j];
j--;
}
}
// TODO вставка по позиции
_collection[position] = obj;
return position;
}
public bool Remove(int position)
public T? Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
return true;
if (position >= _collection.Length || position < 0)
{
return null;
}
T temp = _collection[position];
_collection[position] = null;
return temp;
}
}

View File

@ -0,0 +1,55 @@
using ProjectTrolleybus.Drawnings;
namespace ProjectTrolleybus.CollectionGenericObjects;
public class TrolleyBCarSharingService : AbstractCompany
{
public TrolleyBCarSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrolleyB> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j <= _pictureHeight / _placeSizeHeight; j++)
{
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
protected override void SetObjectPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int posWidth = width;
int posHeight = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection?.Get(i) != null)
{
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(_placeSizeWidth * posWidth + 4, posHeight * _placeSizeHeight + 4, width, height);
}
if (posWidth > 0)
posWidth--;
else
{
posWidth = width;
posHeight++;
}
if (posHeight > height)
{
return;
}
}
}
}

View File

@ -1,9 +1,4 @@
using ProjectTrolleybus.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTrolleybus.Drawnings;

View File

@ -1,5 +1,4 @@
using ProjectTrolleybus.Entities;
using System.Drawing;
namespace ProjectTrolleybus.Drawnings;

View File

@ -0,0 +1,174 @@
namespace ProjectTrolleybus
{
partial class FormTrolleyBCollection
{
/// <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();
buttonRemoveTrolleyB = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddTrolleybus = new Button();
buttonAddTrolleyB = 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(buttonRemoveTrolleyB);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddTrolleybus);
groupBoxTools.Controls.Add(buttonAddTrolleyB);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(861, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(201, 645);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 544);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(189, 41);
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, 362);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(189, 41);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveTrolleyB
//
buttonRemoveTrolleyB.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveTrolleyB.Location = new Point(6, 257);
buttonRemoveTrolleyB.Name = "buttonRemoveTrolleyB";
buttonRemoveTrolleyB.Size = new Size(189, 41);
buttonRemoveTrolleyB.TabIndex = 4;
buttonRemoveTrolleyB.Text = "Удалить троллейбус";
buttonRemoveTrolleyB.UseVisualStyleBackColor = true;
buttonRemoveTrolleyB.Click += ButtonRemoveTrolleyB_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.Location = new Point(6, 228);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(189, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddTrolleybus
//
buttonAddTrolleybus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTrolleybus.Location = new Point(6, 153);
buttonAddTrolleybus.Name = "buttonAddTrolleybus";
buttonAddTrolleybus.Size = new Size(189, 41);
buttonAddTrolleybus.TabIndex = 2;
buttonAddTrolleybus.Text = "Добавление улучшенного троллейбуса";
buttonAddTrolleybus.UseVisualStyleBackColor = true;
buttonAddTrolleybus.Click += ButtonAddTrolleybus_Click;
//
// buttonAddTrolleyB
//
buttonAddTrolleyB.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTrolleyB.Location = new Point(6, 106);
buttonAddTrolleyB.Name = "buttonAddTrolleyB";
buttonAddTrolleyB.Size = new Size(189, 41);
buttonAddTrolleyB.TabIndex = 1;
buttonAddTrolleyB.Text = "Добавление троллейбуса";
buttonAddTrolleyB.UseVisualStyleBackColor = true;
buttonAddTrolleyB.Click += ButtonAddTrolleyB_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, 22);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(189, 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(861, 645);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormTrolleyBCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1062, 645);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormTrolleyBCollection";
Text = "Коллекция троллейбусов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddTrolleybus;
private Button buttonAddTrolleyB;
private PictureBox pictureBox;
private Button buttonRemoveTrolleyB;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,193 @@
using ProjectTrolleybus.CollectionGenericObjects;
using ProjectTrolleybus.Drawnings;
namespace ProjectTrolleybus;
/// <summary>
///
/// </summary>
public partial class FormTrolleyBCollection : Form
{
/// <summary>
///
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormTrolleyBCollection()
{
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 TrolleyBCarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningTrolleyB>());
break;
}
}
/// <summary>
/// Добавление троллейбуса
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddTrolleyB_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrolleyB));
/// <summary>
/// Добавление улучшенного троллейбуса
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddTrolleybus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrolleybus));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создания объекта</param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningTrolleyB drawningTrolleyB;
switch (type)
{
case nameof(DrawningTrolleyB):
drawningTrolleyB = new DrawningTrolleyB(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningTrolleybus):
drawningTrolleyB = new DrawningTrolleybus(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random),
GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningTrolleyB != -1)
{
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, 255), random.Next(0, 255), random.Next(0, 255));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
return color;
}
/// <summary>
/// Удаление троллейбуса с места
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveTrolleyB_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удалён");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Отправление на тесты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningTrolleyB? trolleyB = null;
int counter = 100;
while (trolleyB == null)
{
trolleyB = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (trolleyB == null)
{
return;
}
FormTrolleybus form = new()
{
SetTrolleyB = trolleyB,
};
form.ShowDialog();
}
/// <summary>
/// Обновление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxTrolleybus = new PictureBox();
buttonCreateTrolleybus = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonCreateTrolleyB = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit();
@ -49,17 +47,6 @@
pictureBoxTrolleybus.TabIndex = 0;
pictureBoxTrolleybus.TabStop = false;
//
// buttonCreateTrolleybus
//
buttonCreateTrolleybus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateTrolleybus.Location = new Point(22, 406);
buttonCreateTrolleybus.Name = "buttonCreateTrolleybus";
buttonCreateTrolleybus.Size = new Size(204, 23);
buttonCreateTrolleybus.TabIndex = 1;
buttonCreateTrolleybus.Text = "Создать улучшенный троллейбус";
buttonCreateTrolleybus.UseVisualStyleBackColor = true;
buttonCreateTrolleybus.Click += ButtonCreateTrolleybus_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -108,17 +95,6 @@
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonCreateTrolleyB
//
buttonCreateTrolleyB.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateTrolleyB.Location = new Point(246, 406);
buttonCreateTrolleyB.Name = "buttonCreateTrolleyB";
buttonCreateTrolleyB.Size = new Size(130, 23);
buttonCreateTrolleyB.TabIndex = 6;
buttonCreateTrolleyB.Text = "Создать троллейбус";
buttonCreateTrolleyB.UseVisualStyleBackColor = true;
buttonCreateTrolleyB.Click += ButtonCreateTrolleyB_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -146,12 +122,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateTrolleyB);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonCreateTrolleybus);
Controls.Add(pictureBoxTrolleybus);
Name = "FormTrolleybus";
Text = "Троллейбус";
@ -162,12 +136,10 @@
#endregion
private PictureBox pictureBoxTrolleybus;
private Button buttonCreateTrolleybus;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreateTrolleyB;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -19,6 +19,18 @@ public partial class FormTrolleybus : Form
/// </summary>
private AbstractStrategy? _strategy;
public DrawningTrolleyB SetTrolleyB
{
set
{
_drawningTrolleyB = value;
_drawningTrolleyB.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// Конструктор формы
/// </summary>
@ -39,58 +51,6 @@ public partial class FormTrolleybus : Form
pictureBoxTrolleybus.Image = bmp;
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создания объекта</param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningTrolleyB):
_drawningTrolleyB = new DrawningTrolleyB(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(DrawningTrolleybus):
_drawningTrolleyB = new DrawningTrolleybus(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;
}
_drawningTrolleyB.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
_drawningTrolleyB.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Обработка нажатия создать улучшеный троллейбус
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateTrolleybus_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningTrolleybus));
}
/// <summary>
/// Обработка нажатия создать троллейбус
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateTrolleyB_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningTrolleyB));
}
/// <summary>
/// Перемещение объекта по кнопке (нажатие кнопок навигации)
/// </summary>

View File

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