diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/AbstractStrategy.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/AbstractStrategy.cs
index c31e043..85e6338 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/AbstractStrategy.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/AbstractStrategy.cs
@@ -9,9 +9,6 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectElectricLocomotive.MovementStrategy
{
- ///
- /// Абстрактный класс стратегии
- ///
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingElectricLocomotive.cs
index 92e2421..b730aca 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingElectricLocomotive.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingElectricLocomotive.cs
@@ -33,7 +33,7 @@ namespace ProjectElectricLocomotive.DrawingObjects
if (electricLocomotive.Horns)
{
//horns
- g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5);
+ g.FillRectangle(additionalBrush, _startPosX + 30, _startPosY + 15, 20, 5);
g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 10);
g.DrawLine(pen, _startPosX + 50, _startPosY + 10, _startPosX + 45, _startPosY);
g.DrawLine(pen, _startPosX + 45, _startPosY + 15, _startPosX + 50, _startPosY + 10);
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocomotive.cs
index fc1c21f..9106a51 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocomotive.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocomotive.cs
@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.Entities;
+using ProjectElectricLocomotive.MovementStrategy;
using ProjectElectricLocomotive.Properties;
namespace ProjectElectricLocomotive.DrawingObjects
@@ -29,6 +30,7 @@ namespace ProjectElectricLocomotive.DrawingObjects
public int GetWidth => _locoWidth;
public int GetHeight => _locoHeight;
+ public IMoveableObject GetMoveableObject => new DrawingObjectLocomotive(this);
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
{
if (width < _locoWidth || heigth < _locoHeight)
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
index afaeb3c..5b886c3 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
@@ -1,6 +1,6 @@
namespace ElectricLocomotive
{
- partial class ElectricLocomotive
+ partial class FormElectricLocomotive
{
///
/// Required designer variable.
@@ -37,6 +37,7 @@
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonCreateLocomotive = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
+ this.ButtonSelect_Locomotive = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxElectricLocomotive)).BeginInit();
this.SuspendLayout();
//
@@ -44,8 +45,9 @@
//
this.pictureBoxElectricLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxElectricLocomotive.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive";
- this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(1242, 512);
+ this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(994, 520);
this.pictureBoxElectricLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxElectricLocomotive.TabIndex = 0;
this.pictureBoxElectricLocomotive.TabStop = false;
@@ -54,9 +56,10 @@
//
this.buttonCreateElectricLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateElectricLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
- this.buttonCreateElectricLocomotive.Location = new System.Drawing.Point(16, 442);
+ this.buttonCreateElectricLocomotive.Location = new System.Drawing.Point(13, 442);
+ this.buttonCreateElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
- this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(272, 52);
+ this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateElectricLocomotive.TabIndex = 1;
this.buttonCreateElectricLocomotive.Text = "Создать электролокомотив";
this.buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
@@ -67,9 +70,10 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonLeft.Location = new System.Drawing.Point(1098, 464);
+ this.buttonLeft.Location = new System.Drawing.Point(878, 481);
+ this.buttonLeft.Margin = new System.Windows.Forms.Padding(2);
this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.Size = new System.Drawing.Size(24, 24);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
@@ -79,9 +83,10 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowUP;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonUp.Location = new System.Drawing.Point(1144, 415);
+ this.buttonUp.Location = new System.Drawing.Point(915, 442);
+ this.buttonUp.Margin = new System.Windows.Forms.Padding(2);
this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.Size = new System.Drawing.Size(24, 24);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
@@ -91,9 +96,10 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonRight.Location = new System.Drawing.Point(1188, 464);
+ this.buttonRight.Location = new System.Drawing.Point(950, 481);
+ this.buttonRight.Margin = new System.Windows.Forms.Padding(2);
this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.Size = new System.Drawing.Size(24, 24);
this.buttonRight.TabIndex = 4;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
@@ -103,9 +109,10 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonDown.Location = new System.Drawing.Point(1144, 464);
+ this.buttonDown.Location = new System.Drawing.Point(915, 481);
+ this.buttonDown.Margin = new System.Windows.Forms.Padding(2);
this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.Size = new System.Drawing.Size(24, 24);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
@@ -118,18 +125,20 @@
this.comboBoxStrategy.Items.AddRange(new object[] {
"MoveToCenter",
"MoveToRightCorner"});
- this.comboBoxStrategy.Location = new System.Drawing.Point(1058, 12);
+ this.comboBoxStrategy.Location = new System.Drawing.Point(846, 10);
+ this.comboBoxStrategy.Margin = new System.Windows.Forms.Padding(2);
this.comboBoxStrategy.Name = "comboBoxStrategy";
- this.comboBoxStrategy.Size = new System.Drawing.Size(160, 33);
+ this.comboBoxStrategy.Size = new System.Drawing.Size(129, 28);
this.comboBoxStrategy.TabIndex = 6;
//
// buttonCreateLocomotive
//
this.buttonCreateLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
- this.buttonCreateLocomotive.Location = new System.Drawing.Point(333, 442);
+ this.buttonCreateLocomotive.Location = new System.Drawing.Point(266, 442);
+ this.buttonCreateLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateLocomotive.Name = "buttonCreateLocomotive";
- this.buttonCreateLocomotive.Size = new System.Drawing.Size(272, 52);
+ this.buttonCreateLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateLocomotive.TabIndex = 7;
this.buttonCreateLocomotive.Text = "Создать локомотив";
this.buttonCreateLocomotive.UseVisualStyleBackColor = true;
@@ -139,19 +148,34 @@
//
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonStep.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
- this.buttonStep.Location = new System.Drawing.Point(1079, 65);
+ this.buttonStep.Location = new System.Drawing.Point(863, 52);
+ this.buttonStep.Margin = new System.Windows.Forms.Padding(2);
this.buttonStep.Name = "buttonStep";
- this.buttonStep.Size = new System.Drawing.Size(125, 56);
+ this.buttonStep.Size = new System.Drawing.Size(100, 45);
this.buttonStep.TabIndex = 8;
this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true;
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
//
- // ElectricLocomotive
+ // ButtonSelect_Locomotive
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.ButtonSelect_Locomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.ButtonSelect_Locomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.ButtonSelect_Locomotive.Location = new System.Drawing.Point(863, 113);
+ this.ButtonSelect_Locomotive.Margin = new System.Windows.Forms.Padding(2);
+ this.ButtonSelect_Locomotive.Name = "ButtonSelect_Locomotive";
+ this.ButtonSelect_Locomotive.Size = new System.Drawing.Size(100, 61);
+ this.ButtonSelect_Locomotive.TabIndex = 9;
+ this.ButtonSelect_Locomotive.Text = "Выбор локо";
+ this.ButtonSelect_Locomotive.UseVisualStyleBackColor = true;
+ this.ButtonSelect_Locomotive.Click += new System.EventHandler(this.ButtonSelect_Locomotive_Click);
+ //
+ // FormElectricLocomotive
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1242, 512);
+ this.ClientSize = new System.Drawing.Size(994, 520);
+ this.Controls.Add(this.ButtonSelect_Locomotive);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateLocomotive);
this.Controls.Add(this.comboBoxStrategy);
@@ -161,7 +185,8 @@
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonCreateElectricLocomotive);
this.Controls.Add(this.pictureBoxElectricLocomotive);
- this.Name = "ElectricLocomotive";
+ this.Margin = new System.Windows.Forms.Padding(2);
+ this.Name = "FormElectricLocomotive";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ElectricLocomotive";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxElectricLocomotive)).EndInit();
@@ -181,5 +206,6 @@
private ComboBox comboBoxStrategy;
private Button buttonCreateLocomotive;
private Button buttonStep;
+ private Button ButtonSelect_Locomotive;
}
}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs
index fd8841c..b94366e 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs
@@ -2,19 +2,23 @@ using ProjectElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
using System;
+using System.Windows.Forms;
namespace ElectricLocomotive
{
- public partial class ElectricLocomotive : Form
+ public partial class FormElectricLocomotive : Form
{
private DrawingLocomotive? _drawingLocomotive;
private AbstractStrategy? _abstractStrategy;
+ public DrawingLocomotive? SelectedLocomotive { get; private set; }
- public ElectricLocomotive()
+ public FormElectricLocomotive()
{
InitializeComponent();
+ _abstractStrategy = null;
+ SelectedLocomotive = null;
}
private void Draw()
@@ -32,9 +36,23 @@ namespace ElectricLocomotive
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
{
Random random = new Random();
- _drawingLocomotive = new DrawingElectricLocomotive(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)),
+
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+
+ ColorDialog colorDialog = new ColorDialog();
+
+ if(colorDialog.ShowDialog() == DialogResult.OK){
+ color = colorDialog.Color;
+ }
+
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+
+ if (colorDialog.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = colorDialog.Color;
+ }
+
+ _drawingLocomotive = new DrawingElectricLocomotive(random.Next(100, 300),random.Next(1000, 3000),color, dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
@@ -44,8 +62,13 @@ namespace ElectricLocomotive
private void buttonCreateLocomotive_Click(object sender, EventArgs e)
{
Random rnd = new Random();
- _drawingLocomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog colorDialog = new ColorDialog();
+ if (colorDialog.ShowDialog() == DialogResult.OK)
+ {
+ color = colorDialog.Color;
+ }
+ _drawingLocomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), color,
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
Draw();
@@ -94,15 +117,14 @@ namespace ElectricLocomotive
{
return;
}
- _abstractStrategy.SetData(new
- DrawingObjectLocomotive(_drawingLocomotive), pictureBoxElectricLocomotive.Width,
+ _abstractStrategy.SetData(_drawingLocomotive.GetMoveableObject, pictureBoxElectricLocomotive.Width,
pictureBoxElectricLocomotive.Height);
- comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
+ comboBoxStrategy.Enabled = false;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
@@ -111,5 +133,11 @@ namespace ElectricLocomotive
_abstractStrategy = null;
}
}
+
+ private void ButtonSelect_Locomotive_Click(object sender, EventArgs e)
+ {
+ SelectedLocomotive = _drawingLocomotive;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs
new file mode 100644
index 0000000..562433d
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs
@@ -0,0 +1,133 @@
+namespace ProjectElectricLocomotive
+{
+ partial class FormLocomotiveCollections
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.Instruments = new System.Windows.Forms.Panel();
+ this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
+ this.ButtonRefreshCollection = new System.Windows.Forms.Button();
+ this.ButtonRemoveLocomotive = new System.Windows.Forms.Button();
+ this.ButtonAddLocomotive = new System.Windows.Forms.Button();
+ this.pictureBoxCollections = new System.Windows.Forms.PictureBox();
+ this.Instruments.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).BeginInit();
+ this.SuspendLayout();
+ //
+ // Instruments
+ //
+ this.Instruments.Anchor = System.Windows.Forms.AnchorStyles.Right;
+ this.Instruments.AutoSize = true;
+ this.Instruments.Controls.Add(this.maskedTextBoxNumber);
+ this.Instruments.Controls.Add(this.ButtonRefreshCollection);
+ this.Instruments.Controls.Add(this.ButtonRemoveLocomotive);
+ this.Instruments.Controls.Add(this.ButtonAddLocomotive);
+ this.Instruments.Location = new System.Drawing.Point(435, -40);
+ this.Instruments.Name = "Instruments";
+ this.Instruments.Size = new System.Drawing.Size(191, 451);
+ this.Instruments.TabIndex = 0;
+ //
+ // maskedTextBoxNumber
+ //
+ this.maskedTextBoxNumber.Location = new System.Drawing.Point(42, 123);
+ this.maskedTextBoxNumber.Mask = "0";
+ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
+ this.maskedTextBoxNumber.TabIndex = 4;
+ //
+ // ButtonRefreshCollection
+ //
+ this.ButtonRefreshCollection.Anchor = System.Windows.Forms.AnchorStyles.Right;
+ this.ButtonRefreshCollection.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.ButtonRefreshCollection.Location = new System.Drawing.Point(29, 249);
+ this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
+ this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 36);
+ this.ButtonRefreshCollection.TabIndex = 2;
+ this.ButtonRefreshCollection.Text = "Обновить все";
+ this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
+ this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
+ //
+ // ButtonRemoveLocomotive
+ //
+ this.ButtonRemoveLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Right;
+ this.ButtonRemoveLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(29, 179);
+ this.ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
+ this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 36);
+ this.ButtonRemoveLocomotive.TabIndex = 1;
+ this.ButtonRemoveLocomotive.Text = "Удалить локо";
+ this.ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
+ this.ButtonRemoveLocomotive.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
+ //
+ // ButtonAddLocomotive
+ //
+ this.ButtonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.ButtonAddLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.ButtonAddLocomotive.Location = new System.Drawing.Point(29, 52);
+ this.ButtonAddLocomotive.Name = "ButtonAddLocomotive";
+ this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 36);
+ this.ButtonAddLocomotive.TabIndex = 0;
+ this.ButtonAddLocomotive.Text = "Добавить локо";
+ this.ButtonAddLocomotive.UseVisualStyleBackColor = true;
+ this.ButtonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
+ //
+ // pictureBoxCollections
+ //
+ this.pictureBoxCollections.Anchor = System.Windows.Forms.AnchorStyles.Left;
+ this.pictureBoxCollections.Location = new System.Drawing.Point(-3, -2);
+ this.pictureBoxCollections.Name = "pictureBoxCollections";
+ this.pictureBoxCollections.Size = new System.Drawing.Size(458, 373);
+ this.pictureBoxCollections.TabIndex = 1;
+ this.pictureBoxCollections.TabStop = false;
+ //
+ // FormLocomotiveCollections
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(626, 370);
+ this.Controls.Add(this.pictureBoxCollections);
+ this.Controls.Add(this.Instruments);
+ this.Name = "FormLocomotiveCollections";
+ this.Text = "Набор локомотивов";
+ this.Instruments.ResumeLayout(false);
+ this.Instruments.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Panel Instruments;
+ private Button ButtonRefreshCollection;
+ private Button ButtonRemoveLocomotive;
+ private Button ButtonAddLocomotive;
+ private PictureBox pictureBoxCollections;
+ private MaskedTextBox maskedTextBoxNumber;
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs
new file mode 100644
index 0000000..c5de85b
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs
@@ -0,0 +1,70 @@
+using ElectricLocomotive;
+using ProjectElectricLocomotive.DrawingObjects;
+using ProjectElectricLocomotive.Generics;
+using ProjectElectricLocomotive.MovementStrategy;
+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 FormLocomotiveCollections : Form
+ {
+ private readonly LocomotiveGenericCollection _locomotives;
+ public FormLocomotiveCollections()
+ {
+ InitializeComponent();
+ _locomotives = new LocomotiveGenericCollection(pictureBoxCollections.Width,
+ pictureBoxCollections.Height);
+ }
+
+ private void ButtonAddLocomotive_Click(object sender, EventArgs e)
+ {
+ if (_locomotives == null) return;
+ FormElectricLocomotive form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ //проверяем, удалось ли нам загрузить объект
+ if (_locomotives + form.SelectedLocomotive != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollections.Image = _locomotives.ShowLocomotives();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+
+ 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("Объект удален");
+ pictureBoxCollections.Image = _locomotives.ShowLocomotives();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void ButtonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollections.Image = _locomotives.ShowLocomotives();
+ }
+ }
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/IMoveableObject.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/IMoveableObject.cs
index bd4bd2f..36e747e 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/IMoveableObject.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/IMoveableObject.cs
@@ -11,9 +11,7 @@ namespace ProjectElectricLocomotive.MovementStrategy
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
-
int GetStep { get; }
-
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs
new file mode 100644
index 0000000..67d182e
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs
@@ -0,0 +1,97 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectElectricLocomotive.DrawingObjects;
+using ProjectElectricLocomotive.MovementStrategy;
+
+namespace ProjectElectricLocomotive.Generics
+{
+ internal class LocomotiveGenericCollection where T : DrawingLocomotive where U : IMoveableObject
+ {
+ //ширина/высота окна
+ private readonly int _pictureWidth;
+ private readonly int _pictureHeight;
+ //ширина/высота занимаемого места
+ private readonly int _placeSizeWidth = 85;
+ private readonly int _placeSizeHeight = 50;
+
+ /// Набор объектов
+ private readonly SetGeneric _collection;
+
+ public LocomotiveGenericCollection(int picWidth, int picHeight)
+ {
+ // немного странная логика, что-то я пока ее не особо понимаю, зачем нам ААААА дошло...
+ // высчитываем размер массива для setgeneric
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = new SetGeneric(width * height);
+ }
+
+ /// Перегрузка оператора сложения
+ public static int operator +(LocomotiveGenericCollection collect, T loco)
+ {
+ if (loco == null)
+ {
+ return -1;
+ }
+ return collect._collection.Insert(loco);
+ }
+
+ /// Перегрузка оператора вычитания
+ public static T operator -(LocomotiveGenericCollection collect, int pos)
+ {
+ return collect._collection.Remove(pos);
+ }
+
+ // получение объекта imoveableObj
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+
+ /// Вывод всего набора объектов
+ public Bitmap ShowLocomotives()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+ 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);
+ }
+ }
+
+ private void DrawObjects(Graphics g)
+ {
+ int HeightObjCount = _pictureHeight / _placeSizeHeight;
+ int WidthObjCount = _pictureWidth / _placeSizeWidth;
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ T? type = _collection.Get(i);
+ if (type != null)
+ {
+ type.SetPosition(
+ (int)(i / HeightObjCount * _placeSizeWidth),
+ (HeightObjCount - 1) * _placeSizeHeight - (int)(i % HeightObjCount * _placeSizeHeight)
+ );
+ type?.DrawTransport(g);
+ }
+ }
+ }
+ }
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
index cfc9721..0dccc49 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
@@ -1,3 +1,5 @@
+using ProjectElectricLocomotive;
+
namespace ElectricLocomotive
{
internal static class Program
@@ -11,7 +13,7 @@ namespace ElectricLocomotive
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new ElectricLocomotive());
+ Application.Run(new FormLocomotiveCollections());
}
}
}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs
new file mode 100644
index 0000000..3b43fb2
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.Generics
+{
+ internal class SetGeneric where T : class
+ {
+ private readonly T[] _places;
+ public int Count => _places.Length;
+ public SetGeneric(int count)
+ {
+ _places = new T[count];
+ }
+
+ /// Добавление объекта в набор
+ public int Insert(T loco)
+ {
+ return Insert(loco, 0);
+ }
+
+ public int Insert(T loco, int position)
+ {
+ int NoEmpty = 0, temp = 0;
+ for (int i = position; i < Count; i++)
+ {
+ if (_places[i] != null) NoEmpty++;
+ }
+ if (NoEmpty == Count - position - 1) return -1;
+
+ if (position < Count && position >= 0)
+ {
+ for (int j = position; j < Count; j++)
+ {
+ if (_places[j] == null)
+ {
+ temp = j;
+ break;
+ }
+ }
+ // shift right
+ for (int i = temp; i > position; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[position] = loco;
+ return position;
+ }
+ return -1;
+ // TODO проверка позиции
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ // проверка, что после вставляемого элемента в массиве есть пустой элемент //
+ }
+
+ public T Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ if (position >= Count || position < 0)
+ return null;
+
+ T tmp = _places[position];
+ _places[position] = null;
+ return tmp;
+ }
+ //Получение объекта из набора по позиции
+ public T Get(int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position >= Count) return null;
+ return _places[position];
+ }
+ }
+}