доработка кода, добавление комментариев, доработка формы

This commit is contained in:
Мельников Игорь 2022-11-24 18:25:49 +04:00
parent e198915d98
commit 19a298716d
12 changed files with 148 additions and 866 deletions

View File

@ -1,13 +1,34 @@
namespace WarmlyLocomotove namespace WarmlyLocomotove
{ {
/// <summary>
/// Параметризованный класс с параметрами типа сущности и интерфейса отрисовки дополнительных частей
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class AdvancedObjectGeneric<T, U> internal class AdvancedObjectGeneric<T, U>
where T : EntityLocomotive where T : EntityLocomotive
where U : class, IDrawningAdditionalElements where U : class, IDrawningAdditionalElements
{ {
T[] Entities = new T[10]; /// <summary>
public int CurrentEntityIndex = 0; /// Массив сущностей
public U[] AdditionalElementsSetups = new U[10]; /// </summary>
public int CurrentAdditionalElementSetupIndex = 0; private T[] Entities = new T[10];
/// <summary>
/// Текущая выбранная сущность(индекс для заполнения)
/// </summary>
private int CurrentEntityIndex = 0;
/// <summary>
/// Массив конфигураций(набора параметров для доп. отрисовки)
/// </summary>
private U[] AdditionalElementsSetups = new U[10];
/// <summary>
/// Текущая выбранная конфигурация
/// </summary>
int CurrentAdditionalElementSetupIndex = 0;
/// <summary>
/// Добавление новой сущности в массив сущностей
/// </summary>
/// <param name="NewEntity">Добавляемая сущность</param>
public void AddEntity(T NewEntity) public void AddEntity(T NewEntity)
{ {
if (CurrentEntityIndex >= 9) if (CurrentEntityIndex >= 9)
@ -17,6 +38,10 @@
Entities[CurrentEntityIndex] = NewEntity; Entities[CurrentEntityIndex] = NewEntity;
CurrentEntityIndex++; CurrentEntityIndex++;
} }
/// <summary>
/// Добавление новой конфигурации в массив конфигураций
/// </summary>
/// <param name="NewAdditionalElementSetup">Добавляемая конфигурация</param>
public void AddAdditionalElementSetup(U NewAdditionalElementSetup) public void AddAdditionalElementSetup(U NewAdditionalElementSetup)
{ {
if (CurrentAdditionalElementSetupIndex >= 9) if (CurrentAdditionalElementSetupIndex >= 9)
@ -26,26 +51,24 @@
AdditionalElementsSetups[CurrentAdditionalElementSetupIndex] = NewAdditionalElementSetup; AdditionalElementsSetups[CurrentAdditionalElementSetupIndex] = NewAdditionalElementSetup;
CurrentAdditionalElementSetupIndex++; CurrentAdditionalElementSetupIndex++;
} }
/// <summary>
/// Генерация нового объекта от класса отрисовки на основе случайно выбранной сущности и набора конфигураций
/// </summary>
/// <returns></returns>
public DrawningLocomotive GeneratedObject() public DrawningLocomotive GeneratedObject()
{ {
Random rnd = new(); Random rnd = new();
int SelectedEntityIndex = rnd.Next(0, 9); int SelectedEntityIndex = rnd.Next(0, 9);
int SelectedAdditionalElementSetupIndex = rnd.Next(0, 9); int SelectedAdditionalElementSetupIndex = rnd.Next(0, 9);
DrawningLocomotive Object; DrawningLocomotive Object = null;
if (Entities[SelectedEntityIndex] is EntityLocomotive) if (Entities[SelectedEntityIndex] is EntityWarmlyLocomotive entitywarmlylocomotive)
{ {
Object = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); Object = new DrawningWarmlyLocomotive(entitywarmlylocomotive.Speed, entitywarmlylocomotive.Weight, entitywarmlylocomotive.BodyColor, 160, 115, entitywarmlylocomotive.AdditionalColor, entitywarmlylocomotive.HasPipe, entitywarmlylocomotive.HasFuelTank);
Object.Locomotive = Entities[SelectedEntityIndex];
Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex]; Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex];
} }
else else if (Entities[SelectedEntityIndex] is EntityLocomotive entitylocomotive)
{ {
Object = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Object = new DrawningLocomotive(entitylocomotive.Speed, entitylocomotive.Weight, entitylocomotive.BodyColor);
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
160, 115,
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)),
Convert.ToBoolean(rnd.Next(0, 2)));
Object.Locomotive = Entities[SelectedEntityIndex]; Object.Locomotive = Entities[SelectedEntityIndex];
Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex]; Object.AdditionalElements = AdditionalElementsSetups[SelectedAdditionalElementSetupIndex];
} }

View File

@ -1,63 +0,0 @@
<root>
<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>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -29,13 +29,6 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox(); this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button(); this.buttonCreate = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
@ -45,9 +38,16 @@
this.labelWheelsNumber = new System.Windows.Forms.Label(); this.labelWheelsNumber = new System.Windows.Forms.Label();
this.buttonCreateModif = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectLocomotive = new System.Windows.Forms.Button(); this.buttonSelectLocomotive = new System.Windows.Forms.Button();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip = new System.Windows.Forms.StatusStrip();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// pictureBoxLocomotive // pictureBoxLocomotive
@ -62,57 +62,6 @@
this.pictureBoxLocomotive.TabStop = false; this.pictureBoxLocomotive.TabStop = false;
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize); this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
// //
// statusStrip
//
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor,
this.toolStripStatusLabelAdditionalColor,
this.toolStripStatusLabelHasPipe,
this.toolStripStatusLabelHasFuelTank});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 1;
this.statusStrip.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
this.toolStripStatusLabelWeight.Text = "Вес: ";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
//
// toolStripStatusLabelAdditionalColor
//
this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor";
this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17);
this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: ";
//
// toolStripStatusLabelHasPipe
//
this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe";
this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17);
this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: ";
//
// toolStripStatusLabelHasFuelTank
//
this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank";
this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17);
this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: ";
//
// buttonCreate // buttonCreate
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
@ -228,7 +177,58 @@
this.buttonSelectLocomotive.UseVisualStyleBackColor = true; this.buttonSelectLocomotive.UseVisualStyleBackColor = true;
this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click); this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
// //
// FormLocomotiveAdditional // toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
this.toolStripStatusLabelWeight.Text = "Вес: ";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
//
// toolStripStatusLabelAdditionalColor
//
this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor";
this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17);
this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: ";
//
// toolStripStatusLabelHasPipe
//
this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe";
this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17);
this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: ";
//
// toolStripStatusLabelHasFuelTank
//
this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank";
this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17);
this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: ";
//
// statusStrip
//
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor,
this.toolStripStatusLabelAdditionalColor,
this.toolStripStatusLabelHasPipe,
this.toolStripStatusLabelHasFuelTank});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 1;
this.statusStrip.Text = "statusStrip1";
//
// FormLocomotive
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -244,12 +244,12 @@
this.Controls.Add(this.buttonCreate); this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStrip); this.Controls.Add(this.statusStrip);
this.Controls.Add(this.pictureBoxLocomotive); this.Controls.Add(this.pictureBoxLocomotive);
this.Name = "FormLocomotiveAdditional"; this.Name = "FormLocomotive";
this.Text = "Локомотив"; this.Text = "Локомотив";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit();
this.statusStrip.ResumeLayout(false); this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout(); this.statusStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -258,10 +258,6 @@
#endregion #endregion
private PictureBox pictureBoxLocomotive; private PictureBox pictureBoxLocomotive;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate; private Button buttonCreate;
private Button buttonRight; private Button buttonRight;
private Button buttonLeft; private Button buttonLeft;
@ -270,9 +266,13 @@
private NumericUpDown numericUpDownWheelsNumber; private NumericUpDown numericUpDownWheelsNumber;
private Label labelWheelsNumber; private Label labelWheelsNumber;
private Button buttonCreateModif; private Button buttonCreateModif;
private Button buttonSelectLocomotive;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private ToolStripStatusLabel toolStripStatusLabelAdditionalColor; private ToolStripStatusLabel toolStripStatusLabelAdditionalColor;
private ToolStripStatusLabel toolStripStatusLabelHasPipe; private ToolStripStatusLabel toolStripStatusLabelHasPipe;
private ToolStripStatusLabel toolStripStatusLabelHasFuelTank; private ToolStripStatusLabel toolStripStatusLabelHasFuelTank;
private Button buttonSelectLocomotive; private StatusStrip statusStrip;
} }
} }

View File

@ -29,27 +29,16 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox(); this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown(); this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown();
this.labelWheelsNumber = new System.Windows.Forms.Label(); this.labelWheelsNumber = new System.Windows.Forms.Label();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectLocomotive = new System.Windows.Forms.Button();
this.buttonGenerateEntities = new System.Windows.Forms.Button(); this.buttonGenerateEntities = new System.Windows.Forms.Button();
this.buttonGenerateAdditionalElementsSetup = new System.Windows.Forms.Button(); this.buttonGenerateAdditionalElementsSetup = new System.Windows.Forms.Button();
this.buttonShowGeneratedObject = new System.Windows.Forms.Button(); this.buttonShowGeneratedObject = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -65,74 +54,12 @@
this.pictureBoxLocomotive.TabStop = false; this.pictureBoxLocomotive.TabStop = false;
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize); this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize);
// //
// statusStrip
//
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor,
this.toolStripStatusLabelAdditionalColor,
this.toolStripStatusLabelHasPipe,
this.toolStripStatusLabelHasFuelTank});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 1;
this.statusStrip.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
this.toolStripStatusLabelWeight.Text = "Вес: ";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
//
// toolStripStatusLabelAdditionalColor
//
this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor";
this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17);
this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: ";
//
// toolStripStatusLabelHasPipe
//
this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe";
this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17);
this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: ";
//
// toolStripStatusLabelHasFuelTank
//
this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank";
this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17);
this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: ";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 395);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(90, 30);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonRight // buttonRight
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight; this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(758, 395); this.buttonRight.Location = new System.Drawing.Point(761, 406);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3; this.buttonRight.TabIndex = 3;
@ -144,7 +71,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowLeft; this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(686, 395); this.buttonLeft.Location = new System.Drawing.Point(689, 406);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4; this.buttonLeft.TabIndex = 4;
@ -156,7 +83,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowDown; this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 395); this.buttonDown.Location = new System.Drawing.Point(725, 406);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5; this.buttonDown.TabIndex = 5;
@ -168,7 +95,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp; this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 359); this.buttonUp.Location = new System.Drawing.Point(725, 370);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 6; this.buttonUp.TabIndex = 6;
@ -178,7 +105,7 @@
// numericUpDownWheelsNumber // numericUpDownWheelsNumber
// //
this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(651, 402); this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(651, 413);
this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] { this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] {
4, 4,
0, 0,
@ -203,61 +130,39 @@
// //
this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.labelWheelsNumber.AutoSize = true; this.labelWheelsNumber.AutoSize = true;
this.labelWheelsNumber.Location = new System.Drawing.Point(565, 404); this.labelWheelsNumber.Location = new System.Drawing.Point(565, 415);
this.labelWheelsNumber.Name = "labelWheelsNumber"; this.labelWheelsNumber.Name = "labelWheelsNumber";
this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15); this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15);
this.labelWheelsNumber.TabIndex = 8; this.labelWheelsNumber.TabIndex = 8;
this.labelWheelsNumber.Text = "Число колёс:"; this.labelWheelsNumber.Text = "Число колёс:";
// //
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.Location = new System.Drawing.Point(108, 395);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(98, 30);
this.buttonCreateModif.TabIndex = 9;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// buttonSelectLocomotive
//
this.buttonSelectLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonSelectLocomotive.Location = new System.Drawing.Point(461, 396);
this.buttonSelectLocomotive.Name = "buttonSelectLocomotive";
this.buttonSelectLocomotive.Size = new System.Drawing.Size(98, 30);
this.buttonSelectLocomotive.TabIndex = 10;
this.buttonSelectLocomotive.Text = "Выбрать";
this.buttonSelectLocomotive.UseVisualStyleBackColor = true;
this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
//
// buttonGenerateEntities // buttonGenerateEntities
// //
this.buttonGenerateEntities.Location = new System.Drawing.Point(12, 294); this.buttonGenerateEntities.Location = new System.Drawing.Point(12, 406);
this.buttonGenerateEntities.Name = "buttonGenerateEntities"; this.buttonGenerateEntities.Name = "buttonGenerateEntities";
this.buttonGenerateEntities.Size = new System.Drawing.Size(90, 32); this.buttonGenerateEntities.Size = new System.Drawing.Size(156, 32);
this.buttonGenerateEntities.TabIndex = 11; this.buttonGenerateEntities.TabIndex = 11;
this.buttonGenerateEntities.Text = "button1"; this.buttonGenerateEntities.Text = "Сгенерировать сущности";
this.buttonGenerateEntities.UseVisualStyleBackColor = true; this.buttonGenerateEntities.UseVisualStyleBackColor = true;
this.buttonGenerateEntities.Click += new System.EventHandler(this.ButtonGenerateEntities_Click_1); this.buttonGenerateEntities.Click += new System.EventHandler(this.ButtonGenerateEntities_Click);
// //
// buttonGenerateAdditionalElementsSetup // buttonGenerateAdditionalElementsSetup
// //
this.buttonGenerateAdditionalElementsSetup.Location = new System.Drawing.Point(188, 294); this.buttonGenerateAdditionalElementsSetup.Location = new System.Drawing.Point(375, 406);
this.buttonGenerateAdditionalElementsSetup.Name = "buttonGenerateAdditionalElementsSetup"; this.buttonGenerateAdditionalElementsSetup.Name = "buttonGenerateAdditionalElementsSetup";
this.buttonGenerateAdditionalElementsSetup.Size = new System.Drawing.Size(90, 32); this.buttonGenerateAdditionalElementsSetup.Size = new System.Drawing.Size(184, 32);
this.buttonGenerateAdditionalElementsSetup.TabIndex = 12; this.buttonGenerateAdditionalElementsSetup.TabIndex = 12;
this.buttonGenerateAdditionalElementsSetup.Text = "button1"; this.buttonGenerateAdditionalElementsSetup.Text = "Сгенерировать доп. отрисовку";
this.buttonGenerateAdditionalElementsSetup.UseVisualStyleBackColor = true; this.buttonGenerateAdditionalElementsSetup.UseVisualStyleBackColor = true;
this.buttonGenerateAdditionalElementsSetup.Click += new System.EventHandler(this.ButtonGenerateAdditionalElementsSetup_Click); this.buttonGenerateAdditionalElementsSetup.Click += new System.EventHandler(this.ButtonGenerateAdditionalElementsSetup_Click);
// //
// buttonShowGeneratedObject // buttonShowGeneratedObject
// //
this.buttonShowGeneratedObject.Location = new System.Drawing.Point(98, 216); this.buttonShowGeneratedObject.Location = new System.Drawing.Point(204, 406);
this.buttonShowGeneratedObject.Name = "buttonShowGeneratedObject"; this.buttonShowGeneratedObject.Name = "buttonShowGeneratedObject";
this.buttonShowGeneratedObject.Size = new System.Drawing.Size(90, 32); this.buttonShowGeneratedObject.Size = new System.Drawing.Size(139, 32);
this.buttonShowGeneratedObject.TabIndex = 13; this.buttonShowGeneratedObject.TabIndex = 13;
this.buttonShowGeneratedObject.Text = "button1"; this.buttonShowGeneratedObject.Text = "Сгенерировать объект";
this.buttonShowGeneratedObject.UseVisualStyleBackColor = true; this.buttonShowGeneratedObject.UseVisualStyleBackColor = true;
this.buttonShowGeneratedObject.Click += new System.EventHandler(this.ButtonShowGeneratedObject_Click); this.buttonShowGeneratedObject.Click += new System.EventHandler(this.ButtonShowGeneratedObject_Click);
// //
@ -269,22 +174,16 @@
this.Controls.Add(this.buttonShowGeneratedObject); this.Controls.Add(this.buttonShowGeneratedObject);
this.Controls.Add(this.buttonGenerateAdditionalElementsSetup); this.Controls.Add(this.buttonGenerateAdditionalElementsSetup);
this.Controls.Add(this.buttonGenerateEntities); this.Controls.Add(this.buttonGenerateEntities);
this.Controls.Add(this.buttonSelectLocomotive);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.labelWheelsNumber); this.Controls.Add(this.labelWheelsNumber);
this.Controls.Add(this.numericUpDownWheelsNumber); this.Controls.Add(this.numericUpDownWheelsNumber);
this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStrip);
this.Controls.Add(this.pictureBoxLocomotive); this.Controls.Add(this.pictureBoxLocomotive);
this.Name = "FormLocomotiveAdditional"; this.Name = "FormLocomotiveAdditional";
this.Text = "Локомотив"; this.Text = "Локомотив";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -294,22 +193,12 @@
#endregion #endregion
private PictureBox pictureBoxLocomotive; private PictureBox pictureBoxLocomotive;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonRight; private Button buttonRight;
private Button buttonLeft; private Button buttonLeft;
private Button buttonDown; private Button buttonDown;
private Button buttonUp; private Button buttonUp;
private NumericUpDown numericUpDownWheelsNumber; private NumericUpDown numericUpDownWheelsNumber;
private Label labelWheelsNumber; private Label labelWheelsNumber;
private Button buttonCreateModif;
private ToolStripStatusLabel toolStripStatusLabelAdditionalColor;
private ToolStripStatusLabel toolStripStatusLabelHasPipe;
private ToolStripStatusLabel toolStripStatusLabelHasFuelTank;
private Button buttonSelectLocomotive;
private Button buttonGenerateEntities; private Button buttonGenerateEntities;
private Button buttonGenerateAdditionalElementsSetup; private Button buttonGenerateAdditionalElementsSetup;
private Button buttonShowGeneratedObject; private Button buttonShowGeneratedObject;

View File

@ -7,12 +7,12 @@
/// </summary> /// </summary>
private DrawningLocomotive _locomotive; private DrawningLocomotive _locomotive;
/// <summary> /// <summary>
/// Выбранный объект /// Объект от параметризованного класса с параметрами типа сущности и интерфейса отрисовки дополнительных частей
/// </summary> /// </summary>
public DrawningLocomotive SelectedLocomotive { get; private set; }
private AdvancedObjectGeneric<EntityLocomotive,IDrawningAdditionalElements> AdvancedObject = new AdvancedObjectGeneric<EntityLocomotive, IDrawningAdditionalElements>(); private AdvancedObjectGeneric<EntityLocomotive,IDrawningAdditionalElements> AdvancedObject = new AdvancedObjectGeneric<EntityLocomotive, IDrawningAdditionalElements>();
/// <summary>
/// Конструктор
/// </summary>
public FormLocomotiveAdditional() public FormLocomotiveAdditional()
{ {
InitializeComponent(); InitializeComponent();
@ -28,48 +28,6 @@
pictureBoxLocomotive.Image = bmp; pictureBoxLocomotive.Image = bmp;
} }
/// <summary> /// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="locomotive">Объект от класса отрисовки или его наследника</param>
private void SetData(DrawningLocomotive locomotive)
{
Random rnd = new();
toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д";
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д";
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д";
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
}
/// <summary>
/// Заполнение дополнительной информации по объекту (только для усложнённого объекта)
/// </summary>
/// <param name="warmlylocomotive">Объект от наследника класса отрисовки</param>
private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive)
{
if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
{
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}";
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}";
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}";
}
}
/// <summary>
/// Метод обработки нажатия на кнопку "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
SetData(_locomotive);
_locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
Draw();
}
/// <summary>
/// Метод обработки нажатия на кнопки перемещения /// Метод обработки нажатия на кнопки перемещения
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
@ -106,39 +64,13 @@
Draw(); Draw();
} }
/// <summary> /// <summary>
/// Метод обработки нажатия на кнопку "Модификация" /// Метод обработки нажатия на кнопку "Сгенерировать сущности"
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e) private void ButtonGenerateEntities_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
160, 115,
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)),
Convert.ToBoolean(rnd.Next(0, 2)));
SetData(_locomotive);
SetAdditionalData((DrawningWarmlyLocomotive)_locomotive);
_locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
Draw();
}
/// <summary>
/// Метод обработки нажатия на кнопку "Выбрать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
{
SelectedLocomotive = _locomotive;
DialogResult = DialogResult.OK;
}
private void ButtonGenerateEntities_Click_1(object sender, EventArgs e)
{
Random rnd = new();
AdvancedObject.CurrentEntityIndex = 0;
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
bool IsAdvancedEntity = Convert.ToBoolean(rnd.Next(0, 2)); bool IsAdvancedEntity = Convert.ToBoolean(rnd.Next(0, 2));
@ -158,13 +90,17 @@
AdvancedObject.AddEntity(Entity); AdvancedObject.AddEntity(Entity);
} }
} }
/// <summary>
/// Метод обработки нажатия на кнопку "Сгенерировать доп. элементы"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGenerateAdditionalElementsSetup_Click(object sender, EventArgs e) private void ButtonGenerateAdditionalElementsSetup_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
int AdditionalElementSetupType = rnd.Next(0, 2); int AdditionalElementSetupType = rnd.Next(0, 3);
switch (AdditionalElementSetupType) switch (AdditionalElementSetupType)
{ {
case 0: case 0:
@ -179,13 +115,16 @@
} }
} }
} }
/// <summary>
/// Метод обработки нажатия на кнопку "Сгенерировать объект"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowGeneratedObject_Click(object sender, EventArgs e) private void ButtonShowGeneratedObject_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_locomotive = AdvancedObject.GeneratedObject(); _locomotive = AdvancedObject.GeneratedObject();
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
SetData(_locomotive);
_locomotive.AdditionalElements.WheelsNum = 2; _locomotive.AdditionalElements.WheelsNum = 2;
_locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value; _locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
Draw(); Draw();

View File

@ -57,7 +57,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>

View File

@ -1,327 +0,0 @@
namespace WarmlyLocomotove
{
partial class FormMap
{
/// <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()
{
this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.labelWheelsNumber = new System.Windows.Forms.Label();
this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown();
this.radioButtonNoOrnament = new System.Windows.Forms.RadioButton();
this.radioButtonRectOrnament = new System.Windows.Forms.RadioButton();
this.radioButtonEllipseOrnament = new System.Windows.Forms.RadioButton();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
this.SuspendLayout();
//
// pictureBoxLocomotive
//
this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0);
this.pictureBoxLocomotive.MinimumSize = new System.Drawing.Size(1, 1);
this.pictureBoxLocomotive.Name = "pictureBoxLocomotive";
this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 450);
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxLocomotive.TabIndex = 0;
this.pictureBoxLocomotive.TabStop = false;
//
// statusStrip
//
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor,
this.toolStripStatusLabelAdditionalColor,
this.toolStripStatusLabelHasPipe,
this.toolStripStatusLabelHasFuelTank});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 1;
this.statusStrip.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
this.toolStripStatusLabelWeight.Text = "Вес: ";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
//
// toolStripStatusLabelAdditionalColor
//
this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor";
this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17);
this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: ";
//
// toolStripStatusLabelHasPipe
//
this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe";
this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17);
this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: ";
//
// toolStripStatusLabelHasFuelTank
//
this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank";
this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17);
this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: ";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 395);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(90, 30);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(758, 395);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(686, 395);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 395);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 359);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Карта с крестом",
"Карта с дорожками"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(141, 23);
this.comboBoxSelectorMap.TabIndex = 7;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.Location = new System.Drawing.Point(108, 395);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(109, 30);
this.buttonCreateModif.TabIndex = 8;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// labelWheelsNumber
//
this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.labelWheelsNumber.AutoSize = true;
this.labelWheelsNumber.Location = new System.Drawing.Point(560, 403);
this.labelWheelsNumber.Name = "labelWheelsNumber";
this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15);
this.labelWheelsNumber.TabIndex = 10;
this.labelWheelsNumber.Text = "Число колёс:";
//
// numericUpDownWheelsNumber
//
this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(646, 401);
this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] {
4,
0,
0,
0});
this.numericUpDownWheelsNumber.Minimum = new decimal(new int[] {
2,
0,
0,
0});
this.numericUpDownWheelsNumber.Name = "numericUpDownWheelsNumber";
this.numericUpDownWheelsNumber.ReadOnly = true;
this.numericUpDownWheelsNumber.Size = new System.Drawing.Size(29, 23);
this.numericUpDownWheelsNumber.TabIndex = 9;
this.numericUpDownWheelsNumber.Value = new decimal(new int[] {
2,
0,
0,
0});
//
// radioButtonNoOrnament
//
this.radioButtonNoOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.radioButtonNoOrnament.AutoSize = true;
this.radioButtonNoOrnament.Checked = true;
this.radioButtonNoOrnament.Location = new System.Drawing.Point(223, 399);
this.radioButtonNoOrnament.Name = "radioButtonNoOrnament";
this.radioButtonNoOrnament.Size = new System.Drawing.Size(108, 19);
this.radioButtonNoOrnament.TabIndex = 11;
this.radioButtonNoOrnament.TabStop = true;
this.radioButtonNoOrnament.Text = "Нет орнамента";
this.radioButtonNoOrnament.UseVisualStyleBackColor = true;
this.radioButtonNoOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged);
//
// radioButtonRectOrnament
//
this.radioButtonRectOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.radioButtonRectOrnament.AutoSize = true;
this.radioButtonRectOrnament.Location = new System.Drawing.Point(337, 399);
this.radioButtonRectOrnament.Name = "radioButtonRectOrnament";
this.radioButtonRectOrnament.Size = new System.Drawing.Size(91, 19);
this.radioButtonRectOrnament.TabIndex = 12;
this.radioButtonRectOrnament.Text = "Квадратный";
this.radioButtonRectOrnament.UseVisualStyleBackColor = true;
this.radioButtonRectOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged);
//
// radioButtonEllipseOrnament
//
this.radioButtonEllipseOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.radioButtonEllipseOrnament.AutoSize = true;
this.radioButtonEllipseOrnament.Location = new System.Drawing.Point(437, 399);
this.radioButtonEllipseOrnament.Name = "radioButtonEllipseOrnament";
this.radioButtonEllipseOrnament.Size = new System.Drawing.Size(73, 19);
this.radioButtonEllipseOrnament.TabIndex = 13;
this.radioButtonEllipseOrnament.Text = "Круглый";
this.radioButtonEllipseOrnament.UseVisualStyleBackColor = true;
this.radioButtonEllipseOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.radioButtonEllipseOrnament);
this.Controls.Add(this.radioButtonRectOrnament);
this.Controls.Add(this.radioButtonNoOrnament);
this.Controls.Add(this.labelWheelsNumber);
this.Controls.Add(this.numericUpDownWheelsNumber);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStrip);
this.Controls.Add(this.pictureBoxLocomotive);
this.Name = "FormMap";
this.Text = "Локомотив";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxLocomotive;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonRight;
private Button buttonLeft;
private Button buttonDown;
private Button buttonUp;
private ComboBox comboBoxSelectorMap;
private Button buttonCreateModif;
private ToolStripStatusLabel toolStripStatusLabelAdditionalColor;
private ToolStripStatusLabel toolStripStatusLabelHasPipe;
private ToolStripStatusLabel toolStripStatusLabelHasFuelTank;
private Label labelWheelsNumber;
private NumericUpDown numericUpDownWheelsNumber;
private RadioButton radioButtonNoOrnament;
private RadioButton radioButtonRectOrnament;
private RadioButton radioButtonEllipseOrnament;
}
}

View File

@ -1,151 +0,0 @@
namespace WarmlyLocomotove
{
public partial class FormMap : Form
{
/// <summary>
/// Создание объекта от абстрактного класса карты
/// </summary>
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="locomotive">Объект от класса отрисовки или его наследника</param>
private void SetData(DrawningLocomotive locomotive)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д";
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д";
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д";
pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height,
new DrawningObjectLocomotive(locomotive));
}
/// <summary>
/// Заполнение дополнительной информации по объекту (только для усложнённого объекта)
/// </summary>
/// <param name="warmlylocomotive">Объект от наследника класса отрисовки</param>
private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive)
{
if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
{
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}";
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}";
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}";
}
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetOrnament(locomotive);
locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
SetData(locomotive);
}
/// <summary>
/// Перемещение объекта по форме
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
var locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
160, 85,
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)),
Convert.ToBoolean(rnd.Next(0, 2)));
SetOrnament(locomotive);
locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
SetData(locomotive);
SetAdditionalData(locomotive);
}
/// <summary>
/// Смена карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Карта с крестом":
_abstractMap = new CrossMap();
break;
case "Карта с дорожками":
_abstractMap = new RoadsMap();
break;
default:
break;
}
}
string CurrentOrnament = "";
private void RadioButtonOrnament_CheckedChanged(object sender, EventArgs e)
{
if (((RadioButton)sender).Checked)
{
CurrentOrnament = ((RadioButton)sender).Name;
}
}
private void SetOrnament(DrawningLocomotive locomotive)
{
switch (CurrentOrnament)
{
case "radioButtonNoOrnament":
locomotive.AdditionalElements = new DrawningWheels();
break;
case "radioButtonRectOrnament":
locomotive.AdditionalElements = new DrawningRectOrnament();
break;
case "radioButtonEllipseOrnament":
locomotive.AdditionalElements = new DrawningEllipseOrnament();
break;
}
}
}
}

View File

@ -90,7 +90,7 @@
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if ((_mapCarsCollectionGeneric - pos) > -1) if ((_mapCarsCollectionGeneric - pos) != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet();

View File

@ -51,7 +51,7 @@
/// <returns></returns> /// <returns></returns>
public static int operator +(MapWithSetLocomotivesGeneric<T, U> map, T locomotive) public static int operator +(MapWithSetLocomotivesGeneric<T, U> map, T locomotive)
{ {
return map._setLocomotives.Insert(locomotive); return map._setLocomotives.Insert(locomotive, 0);
} }
/// <summary> /// <summary>
/// Перегрузка оператора вычитания /// Перегрузка оператора вычитания
@ -59,7 +59,7 @@
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public static int operator -(MapWithSetLocomotivesGeneric<T, U> map, int position) public static T operator -(MapWithSetLocomotivesGeneric<T, U> map, int position)
{ {
return map._setLocomotives.Remove(position); return map._setLocomotives.Remove(position);
} }

View File

@ -20,32 +20,6 @@
_places = new T[count]; _places = new T[count];
} }
/// <summary> /// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="locomotive">Добавляемый локомотив</param>
/// <returns></returns>
public int Insert(T locomotive)
{
T testLocomotive = _places[0];
for (int i = 0; i < Count; i++)
{
if (_places[i] == null)
{
testLocomotive = _places[i];
}
}
if (testLocomotive != null)
{
return -1;
}
for (int i = Count - 2; i >= 0; i--)
{
_places[i + 1] = _places[i];
}
_places[0] = locomotive;
return 0;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию /// Добавление объекта в набор на конкретную позицию
/// </summary> /// </summary>
/// <param name="locomotive">Добавляемый локомотив</param> /// <param name="locomotive">Добавляемый локомотив</param>
@ -55,14 +29,14 @@
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
{ {
return position; return -1;
} }
int ClosestNullElementIndex = position; int ClosestNullElementIndex = position;
while (_places[ClosestNullElementIndex] != null) while (_places[ClosestNullElementIndex] != null)
{ {
if (ClosestNullElementIndex == Count) if (ClosestNullElementIndex == Count)
{ {
return position; return -1;
} }
ClosestNullElementIndex++; ClosestNullElementIndex++;
} }
@ -79,14 +53,15 @@
/// </summary> /// </summary>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public int Remove(int position) public T Remove(int position)
{ {
if (_places[position] == null) if (_places[position] == null)
{ {
return -1; return null;
} }
var result = _places[position];
_places[position] = null; _places[position] = null;
return position; return result;
} }
/// <summary> /// <summary>
/// Получение объекта из набора по позиции /// Получение объекта из набора по позиции

View File

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Update="FormLocomotive - Копировать.cs"> <Compile Update="FormLocomotiveAdditional.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">