Боровков М В ПИбд-22 3 лабораторная работа #4
@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectElectricLocomotive.Entities;
|
||||
using ProjectElectricLocomotive.Entities;
|
||||
using ProjectElectricLocomotive;
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
|
||||
namespace ProjectElectricLocomotive.DrawningObjects
|
||||
{
|
||||
@ -59,6 +55,12 @@ namespace ProjectElectricLocomotive.DrawningObjects
|
||||
/// </summary>
|
||||
public int GetHeight => _locomotiveHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectLocomotive(this);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
|
@ -37,6 +37,7 @@
|
||||
buttonCreateElectricLocomotive = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonSelectLocomotive = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -71,7 +72,7 @@
|
||||
// buttonCreateLocomotive
|
||||
//
|
||||
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCreateLocomotive.Location = new Point(816, 562);
|
||||
buttonCreateLocomotive.Location = new Point(816, 514);
|
||||
buttonCreateLocomotive.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
||||
buttonCreateLocomotive.Size = new Size(182, 40);
|
||||
@ -122,7 +123,7 @@
|
||||
// buttonCreateElectricLocomotive
|
||||
//
|
||||
buttonCreateElectricLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCreateElectricLocomotive.Location = new Point(816, 514);
|
||||
buttonCreateElectricLocomotive.Location = new Point(816, 466);
|
||||
buttonCreateElectricLocomotive.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
|
||||
buttonCreateElectricLocomotive.Size = new Size(182, 40);
|
||||
@ -154,11 +155,24 @@
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// buttonSelectLocomotive
|
||||
//
|
||||
buttonSelectLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonSelectLocomotive.Location = new Point(816, 562);
|
||||
buttonSelectLocomotive.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSelectLocomotive.Name = "buttonSelectLocomotive";
|
||||
buttonSelectLocomotive.Size = new Size(182, 40);
|
||||
buttonSelectLocomotive.TabIndex = 9;
|
||||
buttonSelectLocomotive.Text = "выбрать";
|
||||
buttonSelectLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonSelectLocomotive.Click += buttonSelectLocomotive_Click;
|
||||
//
|
||||
// FormLocomotive
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1010, 615);
|
||||
Controls.Add(buttonSelectLocomotive);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateElectricLocomotive);
|
||||
@ -188,5 +202,7 @@
|
||||
private Button buttonCreateElectricLocomotive;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button button1;
|
||||
private Button buttonSelectLocomotive;
|
||||
}
|
||||
}
|
@ -34,12 +34,17 @@ namespace ProjectElectricLocomotive
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonStep_Click(sender, e);
|
||||
ButtonnStartegyStep_Click(sender, e);
|
||||
}
|
||||
|
||||
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonCreateElectricLocomotive_Click(sender, e);
|
||||
}
|
||||
|
||||
private void buttonSelectLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonSelectLocomotive_Click(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
153
ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
153
ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
@ -0,0 +1,153 @@
|
||||
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()
|
||||
{
|
||||
tableLayoutPanel1 = new TableLayoutPanel();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
groupBox1 = new GroupBox();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemoveLocomotive = new Button();
|
||||
buttonAddLocomotive = new Button();
|
||||
tableLayoutPanel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
groupBox1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// tableLayoutPanel1
|
||||
//
|
||||
tableLayoutPanel1.AutoSize = true;
|
||||
tableLayoutPanel1.ColumnCount = 2;
|
||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
|
||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle());
|
||||
tableLayoutPanel1.Controls.Add(pictureBoxCollection, 0, 0);
|
||||
tableLayoutPanel1.Controls.Add(groupBox1, 1, 0);
|
||||
tableLayoutPanel1.Dock = DockStyle.Fill;
|
||||
tableLayoutPanel1.Location = new Point(0, 0);
|
||||
tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||
tableLayoutPanel1.RowCount = 1;
|
||||
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
||||
tableLayoutPanel1.Size = new Size(885, 449);
|
||||
tableLayoutPanel1.TabIndex = 0;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||
pictureBoxCollection.Location = new Point(3, 3);
|
||||
pictureBoxCollection.MinimumSize = new Size(100, 100);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(673, 444);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
groupBox1.AutoSize = true;
|
||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||
groupBox1.Controls.Add(buttonRefreshCollection);
|
||||
groupBox1.Controls.Add(buttonRemoveLocomotive);
|
||||
groupBox1.Controls.Add(buttonAddLocomotive);
|
||||
groupBox1.Location = new Point(682, 3);
|
||||
groupBox1.MaximumSize = new Size(200, 1000000);
|
||||
groupBox1.MinimumSize = new Size(200, 200);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(200, 220);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(6, 97);
|
||||
maskedTextBoxNumber.Mask = "00000";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(184, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(6, 165);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(184, 29);
|
||||
buttonRefreshCollection.TabIndex = 3;
|
||||
buttonRefreshCollection.Text = "Обновить колекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||
//
|
||||
// buttonRemoveLocomotive
|
||||
//
|
||||
buttonRemoveLocomotive.Location = new Point(6, 130);
|
||||
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
||||
buttonRemoveLocomotive.Size = new Size(184, 29);
|
||||
buttonRemoveLocomotive.TabIndex = 2;
|
||||
buttonRemoveLocomotive.Text = "Удалить локомотив";
|
||||
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonRemoveLocomotive.Click += buttonRemoveLocomotive_Click;
|
||||
//
|
||||
// buttonAddLocomotive
|
||||
//
|
||||
buttonAddLocomotive.Location = new Point(6, 26);
|
||||
buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||
buttonAddLocomotive.Size = new Size(184, 29);
|
||||
buttonAddLocomotive.TabIndex = 0;
|
||||
buttonAddLocomotive.Text = "Добавить локомотив";
|
||||
buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonAddLocomotive.Click += buttonAddLocomotive_Click;
|
||||
//
|
||||
// FormLocomotiveCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(885, 449);
|
||||
Controls.Add(tableLayoutPanel1);
|
||||
MinimumSize = new Size(700, 400);
|
||||
Name = "FormLocomotiveCollection";
|
||||
Text = "FormLocomotiveCollection";
|
||||
tableLayoutPanel1.ResumeLayout(false);
|
||||
tableLayoutPanel1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TableLayoutPanel tableLayoutPanel1;
|
||||
private GroupBox groupBox1;
|
||||
private Button buttonAddLocomotive;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Button buttonRemoveLocomotive;
|
||||
private Button buttonRefreshCollection;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
}
|
||||
}
|
30
ElectricLocomotive/FormLocomotiveCollection.cs
Normal file
30
ElectricLocomotive/FormLocomotiveCollection.cs
Normal file
@ -0,0 +1,30 @@
|
||||
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
|
||||
{
|
||||
public partial class FormLocomotiveCollection
|
||||
{
|
||||
private void buttonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonAddLocomotive_Click(sender, e);
|
||||
}
|
||||
|
||||
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonRemoveLocomotive_Click(sender, e);
|
||||
}
|
||||
|
||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonRefreshCollection_Click(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
120
ElectricLocomotive/FormLocomotiveCollection.resx
Normal file
120
ElectricLocomotive/FormLocomotiveCollection.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>
|
147
ElectricLocomotive/Generics/LocomotivesGenericCollection.cs
Normal file
147
ElectricLocomotive/Generics/LocomotivesGenericCollection.cs
Normal file
@ -0,0 +1,147 @@
|
||||
using ProjectElectricLocomotive.DrawningObjects;
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный класс для набора объектов DrawningLocomotive
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class LocomotivesGenericCollection<T, U>
|
||||
where T : DrawningLocomotive
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public LocomotivesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(LocomotivesGenericCollection<T, U> collect, T?
|
||||
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static T? operator -(LocomotivesGenericCollection<T, U> collect, int
|
||||
eegov
commented
Требовалось поменять тип возвращаемого значения Требовалось поменять тип возвращаемого значения
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowCars()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private 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 +
|
||||
1; ++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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningLocomotive drawningLocomotive = _collection.Get(i);
|
||||
if (drawningLocomotive == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int widthCount = _pictureHeight / _placeSizeHeight;
|
||||
drawningLocomotive.SetPosition((i / widthCount) * _placeSizeWidth, (i % widthCount) * _placeSizeHeight);
|
||||
drawningLocomotive.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
141
ElectricLocomotive/Generics/SetGeneric.cs
Normal file
141
ElectricLocomotive/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T?[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// обмен двух элементов
|
||||
/// </summary>
|
||||
/// <param name="first">Первый элемент</param>
|
||||
/// <param name="second">Второй элемент</param>
|
||||
/// <returns></returns>
|
||||
private void swap(ref T first, ref T second)
|
||||
{
|
||||
T temp = first;
|
||||
first = second;
|
||||
second = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="locomotive">Добавляемый локомотив</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T locomotive)
|
||||
{
|
||||
int end = _places.Length;
|
||||
eegov
commented
Правильнее было вызвать Insert(T obj, 0); Правильнее было вызвать Insert(T obj, 0);
|
||||
for (int i = 0; i < _places.Length; ++i)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end == _places.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = end; i >= 1; --i)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[0] = locomotive;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="locomotive">Добавляемый поезд</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T locomotive, int position)
|
||||
{
|
||||
if (position >= _places.Length || position < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = locomotive;
|
||||
return true;
|
||||
}
|
||||
int end = _places.Length;
|
||||
for (int i = position; i < _places.Length; ++i)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end == _places.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[end] = locomotive;
|
||||
for (int i = position; i < end; ++i)
|
||||
{
|
||||
swap(ref _places[i], ref _places[end]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position >= _places.Length || position < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_places[position] = null;
|
||||
return true;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position >= _places.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -20,16 +21,22 @@ namespace ProjectElectricLocomotive
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// Выбранный электровоз
|
||||
/// </summary>
|
||||
public DrawningLocomotive? SelectedLocomotive { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация формы
|
||||
/// </summary>
|
||||
public FormLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
SelectedLocomotive = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки машины
|
||||
/// Метод прорисовки локомотива
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
@ -51,11 +58,30 @@ namespace ProjectElectricLocomotive
|
||||
private void ButtonCreateElectricLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color bodyColor = Color.FromArgb(
|
||||
random.Next(0, 256),
|
||||
random.Next(0, 256),
|
||||
random.Next(0, 256));
|
||||
Color additionalColor = Color.FromArgb(
|
||||
random.Next(0, 256),
|
||||
random.Next(0, 256),
|
||||
random.Next(0, 256));
|
||||
ColorDialog dialog;
|
||||
dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodyColor = dialog.Color;
|
||||
}
|
||||
dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
additionalColor = dialog.Color;
|
||||
}
|
||||
_drawningLocomotive = 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)),
|
||||
bodyColor,
|
||||
additionalColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||
@ -71,10 +97,19 @@ namespace ProjectElectricLocomotive
|
||||
private void ButtonCreateLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
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;
|
||||
}
|
||||
_drawningLocomotive = new DrawningLocomotive(
|
||||
random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
color,
|
||||
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
@ -89,9 +124,9 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
Size size = ((PictureBox)sender)?.Size ?? Size.Empty;
|
||||
|
||||
if (_abstractStrategy != null)
|
||||
if (_strategy != null)
|
||||
{
|
||||
_abstractStrategy.SetFieldSize(size);
|
||||
_strategy.SetFieldSize(size);
|
||||
}
|
||||
if (_drawningLocomotive != null)
|
||||
{
|
||||
@ -130,11 +165,11 @@ namespace ProjectElectricLocomotive
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// Шаг стратегии перемещения
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
private void ButtonnStartegyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningLocomotive == null)
|
||||
{
|
||||
@ -142,35 +177,45 @@ namespace ProjectElectricLocomotive
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectLocomotive(_drawningLocomotive), pictureBoxElectricLocomotive.Width,
|
||||
pictureBoxElectricLocomotive.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.SetData(
|
||||
_drawningLocomotive.GetMoveableObject,
|
||||
pictureBoxElectricLocomotive.Width,
|
||||
pictureBoxElectricLocomotive.Height
|
||||
);
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Выбор локомотива
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedLocomotive = _drawningLocomotive;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
89
ElectricLocomotive/LogicFormLocomotiveCollection.cs
Normal file
89
ElectricLocomotive/LogicFormLocomotiveCollection.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectElectricLocomotive.DrawningObjects;
|
||||
using ProjectElectricLocomotive.Generics;
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
|
||||
namespace ProjectElectricLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма для работы с набором объектов класса DrawningLocomotive
|
||||
/// </summary>
|
||||
|
||||
public partial class FormLocomotiveCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly LocomotivesGenericCollection<
|
||||
DrawningLocomotive, DrawningObjectLocomotive> _locomotives;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormLocomotiveCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_locomotives = new LocomotivesGenericCollection<DrawningLocomotive, DrawningObjectLocomotive>(
|
||||
pictureBoxCollection.Width, pictureBoxCollection.Height
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormLocomotive form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_locomotives + form.SelectedLocomotive)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _locomotives.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show(
|
||||
"Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_locomotives - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _locomotives.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _locomotives.ShowCars();
|
||||
}
|
||||
}
|
||||
}
|
@ -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 FormLocomotive());
|
||||
Application.Run(new FormLocomotiveCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Требовалось поменять тип возвращаемого значения