Лаба завершена на 99%

This commit is contained in:
Tonb73 2024-03-14 13:26:53 +03:00
parent 906af6a7e9
commit 9e098ea128
11 changed files with 730 additions and 78 deletions

View File

@ -0,0 +1,119 @@
using ProjectElectricLocomotive.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящий коллекцию Локомотивов
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 140;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция Локомотивов
/// </summary>
protected ICollectionGenericObjects<DrawningLocomotive>? _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<DrawningLocomotive> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="Locomotive">Добавляемый объект</param>
/// <returns></returns>
public static bool operator +(AbstractCompany company, DrawningLocomotive locomotive)
{
return company._collection?.Insert(locomotive) ?? 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 DrawningLocomotive? 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(_collection);
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningLocomotive? obj = _collection?.Get(i);
if (obj != null)
{
obj.SetPictureSize(_pictureWidth, _pictureWidth);
}
obj?.DrawTransport(graphics);
}
return bitmap;
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
protected abstract void DrawBackgound(Graphics g);
/// <summary>
/// Расстановка объектов
/// </summary>
protected abstract void SetObjectsPosition(ICollectionGenericObjects<DrawningLocomotive> collection);
}

View File

@ -50,5 +50,3 @@ bool Remove(int position);
/// <returns>Объект</returns>
T? Get(int position);
}
}

View File

@ -0,0 +1,52 @@
using ProjectElectricLocomotive.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.CollectionGenericObjects;
public class LocomotiveDepo : AbstractCompany
{
public LocomotiveDepo(int picWidth, int picHeight, ICollectionGenericObjects<DrawningLocomotive> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
Pen steel = new Pen(Color.Gray);
Pen wood = new Pen(Color.Brown);
g.DrawRectangle(steel,0, _pictureHeight - 50,_pictureWidth,40 );
for(int i = 0; i < _pictureWidth; i += 20)
{
g.DrawLine(wood, i, _pictureHeight - 50, i + 10, _pictureHeight - 10);
g.DrawLine(wood, i, _pictureHeight - 190, i + 10, _pictureHeight - 150);
g.DrawLine(wood, i, _pictureHeight - 325, i + 10, _pictureHeight - 285);
}
g.DrawRectangle(steel, 0, _pictureHeight - 190, _pictureWidth, 40);
g.DrawRectangle(steel, 0, _pictureHeight - 325, _pictureWidth, 40);
//g.DrawRectangle(steel, 0, _pictureHeight - 40, _pictureWidth, 1000);
}
protected override void SetObjectsPosition(ICollectionGenericObjects<DrawningLocomotive> collection)
{
int index = 0;
for(int i = _pictureHeight - _placeSizeHeight; i >= 0; i-= _placeSizeHeight)
{
for(int j = 0; j <= _pictureWidth - _placeSizeWidth; j += _placeSizeWidth)
{
if (collection.Get(index) != null)
{
collection.Get(index).SetPosition(j + 10, i + 10);
index++;
}
}
}
}
}

View File

@ -40,17 +40,55 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
}
public T? Get(int position)
{
// TODO проверка позиции
return _collection[position];
//TODO проверка позиции
if(position < 0)
{
return null;
}
return _collection[position];
}
public bool Insert(T obj)
{
// TODO вставка в свободное место набора
if(obj == null){ return false; }
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(obj == null || position < 0)
{
return false;
}
if (_collection[position] != null)
{
for(int i = position; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
for(int i = position; i > 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
}
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
@ -60,6 +98,15 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
}
public bool Remove(int position)
{
if(position < 0)
{
return false;
}
else
{
_collection[position] = null;
}
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
return true;

View File

@ -35,10 +35,10 @@ public class DrawningLocomotive
/// Ширина прорисовки Локомотива
/// </summary>
public readonly int _drawningLocomotiveWidth = 155;
/// <summary>
/// Высота прорисовки локомотива
/// </summary>
public readonly int _drawningLocomotiveHeight = 90;
/// <summary>
/// Высота прорисовки локомотива
/// </summary>
public readonly int _drawningLocomotiveHeight = 115;
/// <summary>
/// Координата X объекта

View File

@ -0,0 +1,168 @@
namespace ProjectElectricLocomotive
{
partial class FormLocomotiveCollection
{
/// <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();
buttonDelLocomotive = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddElectricLocomotive = new Button();
buttonAddLocomotive = 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(buttonDelLocomotive);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddElectricLocomotive);
groupBoxTools.Controls.Add(buttonAddLocomotive);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(574, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(226, 450);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Location = new Point(21, 358);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(193, 39);
buttonRefresh.TabIndex = 7;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(21, 313);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(193, 39);
buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += buttonGoToCheck_Click;
//
// buttonDelLocomotive
//
buttonDelLocomotive.Location = new Point(21, 244);
buttonDelLocomotive.Name = "buttonDelLocomotive";
buttonDelLocomotive.Size = new Size(193, 63);
buttonDelLocomotive.TabIndex = 5;
buttonDelLocomotive.Text = "Удаление Локомотива";
buttonDelLocomotive.UseVisualStyleBackColor = true;
buttonDelLocomotive.Click += buttonDelLocomotive_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(21, 207);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(193, 31);
maskedTextBox.TabIndex = 4;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddElectricLocomotive
//
buttonAddElectricLocomotive.Location = new Point(21, 138);
buttonAddElectricLocomotive.Name = "buttonAddElectricLocomotive";
buttonAddElectricLocomotive.Size = new Size(193, 63);
buttonAddElectricLocomotive.TabIndex = 2;
buttonAddElectricLocomotive.Text = "Добавление Электро - Локомотива";
buttonAddElectricLocomotive.UseVisualStyleBackColor = true;
buttonAddElectricLocomotive.Click += buttonAddElectricLocomotive_Click;
//
// buttonAddLocomotive
//
buttonAddLocomotive.Location = new Point(21, 69);
buttonAddLocomotive.Name = "buttonAddLocomotive";
buttonAddLocomotive.Size = new Size(193, 63);
buttonAddLocomotive.TabIndex = 1;
buttonAddLocomotive.Text = "Добавление Локомотива";
buttonAddLocomotive.UseVisualStyleBackColor = true;
buttonAddLocomotive.Click += buttonAddLocomotive_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(21, 30);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(193, 33);
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(574, 450);
pictureBox.TabIndex = 3;
pictureBox.TabStop = false;
//
// FormLocomotiveCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormLocomotiveCollection";
Text = "Коллекция Локомотивов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddElectricLocomotive;
private Button buttonAddLocomotive;
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;
private Button buttonDelLocomotive;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,202 @@
using ProjectElectricLocomotive.CollectionGenericObjects;
using ProjectElectricLocomotive.Drawnings;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProjectElectricLocomotive;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormLocomotiveCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormLocomotiveCollection()
{
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 LocomotiveDepo(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningLocomotive>());
break;
}
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
Random random = new();
DrawningLocomotive drawningLocomotive;
switch (type)
{
case nameof(DrawningLocomotive):
drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random));
break;
case nameof(DrawningElectricLocomotive):
drawningLocomotive = new DrawningElectricLocomotive(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 + drawningLocomotive)
{
pictureBox.Image = _company.Show();
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();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
return color;
}
/// <summary>
/// Добавление локомотива
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddLocomotive_Click(object sender, EventArgs e) =>
CreateObject(nameof(DrawningLocomotive));
/// <summary>
/// Добавление электро локомотива
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddElectricLocomotive_Click(object sender, EventArgs e) =>
CreateObject(nameof(DrawningElectricLocomotive));
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonDelLocomotive_Click(object sender, EventArgs e)
{
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company ==
null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos)
{
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;
}
DrawningLocomotive? locomotive = null;
int counter = 100;
while (locomotive == null)
{
locomotive = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (locomotive == null)
{
return;
}
FormlectricLocomotive form = new()
{
SetLocomotive = locomotive
};
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()
{
pictureBoxElectricLocomotive = new PictureBox();
buttonCreate = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonDown = new Button();
buttonCreateLocomotive = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
@ -50,17 +48,6 @@
pictureBoxElectricLocomotive.TabIndex = 0;
pictureBoxElectricLocomotive.TabStop = false;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 353);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(263, 34);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать ЭлектроЛокомотив";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -109,17 +96,6 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// buttonCreateLocomotive
//
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateLocomotive.Location = new Point(281, 353);
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
buttonCreateLocomotive.Size = new Size(263, 34);
buttonCreateLocomotive.TabIndex = 6;
buttonCreateLocomotive.Text = "Создать Локомотив";
buttonCreateLocomotive.UseVisualStyleBackColor = true;
buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -147,12 +123,10 @@
ClientSize = new Size(788, 399);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateLocomotive);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxElectricLocomotive);
Name = "FormlectricLocomotive";
Text = "ЭлектроВоз";
@ -163,12 +137,10 @@
#endregion
private PictureBox pictureBoxElectricLocomotive;
private Button buttonCreate;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
private Button buttonCreateLocomotive;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -20,7 +20,19 @@ namespace ProjectElectricLocomotive
/// </summary>
private AbstractStrategy? _strategy;
public FormlectricLocomotive()
public DrawningLocomotive SetLocomotive
{
set
{
_drawnningLocomotive = value;
_drawnningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
public FormlectricLocomotive()
{
InitializeComponent();
_strategy = null;
@ -39,47 +51,9 @@ namespace ProjectElectricLocomotive
pictureBoxElectricLocomotive.Image = bmp;
}
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningLocomotive):
_drawnningLocomotive = new DrawningLocomotive(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(DrawningElectricLocomotive):
_drawnningLocomotive = new DrawningElectricLocomotive(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;
}
_drawnningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawnningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
private DrawningLocomotive? _drawnningLocomotive;
/// <summary>
/// Обработка кнопки создать "ЭлектроЛокомотив"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectricLocomotive));
/// <summary>
/// Обработка нажатия кнопки создать "Локомотив"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawnningLocomotive == null)
@ -114,7 +88,7 @@ namespace ProjectElectricLocomotive
}
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawnningLocomotive == null)

View File

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