From 57e4fd46b79a1f70ebf44843a76e559f4cffe196 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?=
=?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com>
Date: Thu, 16 Nov 2023 21:47:58 +0400
Subject: [PATCH 1/2] GOTOVO
---
.../ElectricLocomotive/DrawningLocomotive.cs | 3 +
.../ElectricLocomotive.Designer.cs | 22 +++-
.../ElectricLocomotive/ElectricLocomotive.cs | 47 ++++---
.../FormLocomotiveCollection.Designer.cs | 123 ++++++++++++++++++
.../FormLocomotiveCollection.cs | 65 +++++++++
.../FormLocomotiveCollection.resx | 120 +++++++++++++++++
.../LocomotivesGenericCollection.cs | 90 +++++++++++++
.../ElectricLocomotive/Program.cs | 4 +-
.../ElectricLocomotive/SetGeneric.cs | 65 +++++++++
9 files changed, 517 insertions(+), 22 deletions(-)
create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
create mode 100644 ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx
create mode 100644 ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs
create mode 100644 ElectricLocomotive/ElectricLocomotive/SetGeneric.cs
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
index 9422635..9e06681 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
@@ -1,4 +1,5 @@
using ElectricLocomotive.Entities;
+using ElectricLocomotive.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -206,5 +207,7 @@ namespace ElectricLocomotive.DrawningObject
DirectionType.Down => _startPosY + EntityLocomotive.Step < _pictureHeight,
};
}
+
+ public IMoveableObject GetMoveableObject => new DrawningObjectLocomotive(this);
}
}
diff --git a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.Designer.cs b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.Designer.cs
index 38e688c..b2480cc 100644
--- a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.Designer.cs
+++ b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.Designer.cs
@@ -38,6 +38,7 @@
buttonCreateLocomotive = new Button();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
+ buttonChoiceLocomotive = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectroLocomotiv).BeginInit();
SuspendLayout();
//
@@ -51,7 +52,6 @@
pictureBoxElectroLocomotiv.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxElectroLocomotiv.TabIndex = 5;
pictureBoxElectroLocomotiv.TabStop = false;
-
//
// buttonUp
//
@@ -108,9 +108,9 @@
buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
buttonCreateElectricLocomotive.Size = new Size(208, 34);
buttonCreateElectricLocomotive.TabIndex = 6;
- buttonCreateElectricLocomotive.Text = "Создать Электролокомотив";
+ buttonCreateElectricLocomotive.Text = "Нарисовать Электролокомотив";
buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
- buttonCreateElectricLocomotive.Click += buttonCreateElectricLocomotive_Click;
+ buttonCreateElectricLocomotive.Click += PaintElectricLocoButton_click;
//
// buttonCreateLocomotive
//
@@ -119,9 +119,9 @@
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
buttonCreateLocomotive.Size = new Size(197, 34);
buttonCreateLocomotive.TabIndex = 11;
- buttonCreateLocomotive.Text = "Создать локомотив";
+ buttonCreateLocomotive.Text = "Нарисовать локомотив";
buttonCreateLocomotive.UseVisualStyleBackColor = true;
- buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
+ buttonCreateLocomotive.Click += PaintLocoButton_click;
//
// comboBoxStrategy
//
@@ -148,11 +148,22 @@
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click;
//
+ // buttonChoiceLocomotive
+ //
+ buttonChoiceLocomotive.Location = new Point(430, 425);
+ buttonChoiceLocomotive.Name = "buttonChoiceLocomotive";
+ buttonChoiceLocomotive.Size = new Size(206, 34);
+ buttonChoiceLocomotive.TabIndex = 14;
+ buttonChoiceLocomotive.Text = "Выбрать локомотив";
+ buttonChoiceLocomotive.UseVisualStyleBackColor = true;
+ buttonChoiceLocomotive.Click += ButtonSelectLocomotive_Click;
+ //
// ElectricLocomotive
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(854, 467);
+ Controls.Add(buttonChoiceLocomotive);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateLocomotive);
@@ -180,5 +191,6 @@
private Button buttonCreateLocomotive;
private ComboBox comboBoxStrategy;
private Button buttonStep;
+ private Button buttonChoiceLocomotive;
}
}
\ No newline at end of file
diff --git a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
index 01fadb1..fd5cab7 100644
--- a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
@@ -10,12 +10,14 @@ namespace ElectricLocomotive
{
private DrawningLocomotive? _drawningLocomotive;
-
private AbstractStrategy? _abstractStrategy;
+ public DrawningLocomotive? SelectedLocomotive { get; private set; }
public ElectricLocomotive()
{
InitializeComponent();
+ _abstractStrategy = null;
+ SelectedLocomotive = null;
}
private void Draw()
@@ -30,26 +32,35 @@ namespace ElectricLocomotive
pictureBoxElectroLocomotiv.Image = bmp;
}
- private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
+ private void PaintLocoButton_click(object sender, EventArgs e)
{
- Random random = new Random();
- _drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
-
+ Random random = new();
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ color = dialog.Color;
+ _drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
+
Draw();
}
- private void buttonCreateLocomotive_Click(object sender, EventArgs e)
+ private void PaintElectricLocoButton_click(object sender, EventArgs e)
{
- Random rnd = new Random();
- _drawningLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
- _drawningLocomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
+ Random random = new();
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ Color batteryColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ bool Horns = Convert.ToBoolean(random.Next(0, 2));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ color = dialog.Color;
+ if (dialog.ShowDialog() == DialogResult.OK)
+ dopColor = dialog.Color;
+
+ _drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Horns, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
+ _drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
@@ -114,6 +125,10 @@ namespace ElectricLocomotive
}
}
-
+ private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
+ {
+ SelectedLocomotive = _drawningLocomotive;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
new file mode 100644
index 0000000..0035c81
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
@@ -0,0 +1,123 @@
+namespace ElectricLocomotive
+{
+ partial class FormLocomotiveCollection
+ {
+ ///
+ /// 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()
+ {
+ CollectionPictureBox = new PictureBox();
+ ToolsBox = new GroupBox();
+ Input = new TextBox();
+ RefreshCollection = new Button();
+ DelLocomotive = new Button();
+ AddLocomotive = new Button();
+ ((System.ComponentModel.ISupportInitialize)CollectionPictureBox).BeginInit();
+ ToolsBox.SuspendLayout();
+ SuspendLayout();
+ //
+ // CollectionPictureBox
+ //
+ CollectionPictureBox.Location = new Point(3, 0);
+ CollectionPictureBox.Name = "CollectionPictureBox";
+ CollectionPictureBox.Size = new Size(634, 457);
+ CollectionPictureBox.TabIndex = 0;
+ CollectionPictureBox.TabStop = false;
+ //
+ // ToolsBox
+ //
+ ToolsBox.Controls.Add(Input);
+ ToolsBox.Controls.Add(RefreshCollection);
+ ToolsBox.Controls.Add(DelLocomotive);
+ ToolsBox.Controls.Add(AddLocomotive);
+ ToolsBox.Location = new Point(643, 0);
+ ToolsBox.Name = "ToolsBox";
+ ToolsBox.Size = new Size(200, 457);
+ ToolsBox.TabIndex = 1;
+ ToolsBox.TabStop = false;
+ ToolsBox.Text = "Инструменты";
+ //
+ // Input
+ //
+ Input.Location = new Point(7, 91);
+ Input.Name = "Input";
+ Input.Size = new Size(186, 23);
+ Input.TabIndex = 3;
+ //
+ // RefreshCollection
+ //
+ RefreshCollection.Location = new Point(7, 240);
+ RefreshCollection.Name = "RefreshCollection";
+ RefreshCollection.Size = new Size(187, 46);
+ RefreshCollection.TabIndex = 2;
+ RefreshCollection.Text = "Обновить коллекцию";
+ RefreshCollection.UseVisualStyleBackColor = true;
+ RefreshCollection.Click += refreshCollection_Click;
+ //
+ // DelLocomotive
+ //
+ DelLocomotive.Location = new Point(7, 134);
+ DelLocomotive.Name = "DelLocomotive";
+ DelLocomotive.Size = new Size(187, 46);
+ DelLocomotive.TabIndex = 1;
+ DelLocomotive.Text = "Удалить локомотив";
+ DelLocomotive.UseVisualStyleBackColor = true;
+ DelLocomotive.Click += deleteLoco_Click;
+ //
+ // AddLocomotive
+ //
+ AddLocomotive.Location = new Point(6, 22);
+ AddLocomotive.Name = "AddLocomotive";
+ AddLocomotive.Size = new Size(187, 46);
+ AddLocomotive.TabIndex = 0;
+ AddLocomotive.Text = "Добавить локомотив";
+ AddLocomotive.UseVisualStyleBackColor = true;
+ AddLocomotive.Click += addLocomotiv_Click;
+ //
+ // FormLocomotiveCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(848, 469);
+ Controls.Add(ToolsBox);
+ Controls.Add(CollectionPictureBox);
+ Name = "FormLocomotiveCollection";
+ Text = "Коллекция";
+ ((System.ComponentModel.ISupportInitialize)CollectionPictureBox).EndInit();
+ ToolsBox.ResumeLayout(false);
+ ToolsBox.PerformLayout();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private PictureBox CollectionPictureBox;
+ private GroupBox ToolsBox;
+ private TextBox Input;
+ private Button RefreshCollection;
+ private Button DelLocomotive;
+ private Button AddLocomotive;
+ }
+}
\ No newline at end of file
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
new file mode 100644
index 0000000..08b0892
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs
@@ -0,0 +1,65 @@
+using ElectricLocomotive.DrawningObject;
+using ElectricLocomotive.Generics;
+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 ElectricLocomotive
+{
+ public partial class FormLocomotiveCollection : Form
+ {
+ private readonly LocomotivesGenericCollection _locos;
+ public FormLocomotiveCollection()
+ {
+ InitializeComponent();
+ _locos = new(CollectionPictureBox.Width, CollectionPictureBox.Height);
+ }
+
+ private void addLocomotiv_Click(object sender, EventArgs e)
+ {
+ ElectricLocomotive form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_locos + form.SelectedLocomotive != null)
+ {
+ MessageBox.Show("Объект добавлен");
+ CollectionPictureBox.Image = _locos.ShowLocomotives();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+
+ private void deleteLoco_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(Input.Text);
+ if (_locos - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ CollectionPictureBox.Image = _locos.ShowLocomotives();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void refreshCollection_Click(object sender, EventArgs e)
+ {
+ CollectionPictureBox.Image = _locos.ShowLocomotives();
+
+ }
+ }
+}
diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.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/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs
new file mode 100644
index 0000000..edc48ae
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ElectricLocomotive.DrawningObject;
+using ElectricLocomotive.MovementStrategy;
+using ProjectElectricLocomotive.Generics;
+
+namespace ElectricLocomotive.Generics
+{
+ internal class LocomotivesGenericCollection
+ where T : DrawningLocomotive
+ where U : IMoveableObject
+ {
+ private readonly int _pictureWidth;
+ private readonly int _pictureHeight;
+ private readonly int _placeSizeWidth = 200;
+ private readonly int _placeSizeHeight = 90;
+ private readonly SetGeneric _collection;
+ public LocomotivesGenericCollection(int picWidth, int picHeight)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = new SetGeneric(width * height);
+ }
+ public static int operator +(LocomotivesGenericCollection collect, T? locomotive)
+ {
+ if (locomotive == null)
+ {
+ return -1;
+ }
+ return collect?._collection.Insert(locomotive) ?? -1;
+ }
+ public static bool operator -(LocomotivesGenericCollection collect, int pos)
+ {
+ T? locomotive = collect._collection.Get(pos);
+ if (locomotive != null)
+ return collect._collection.Remove(pos);
+ return false;
+ }
+ 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 HLoco = _pictureHeight / _placeSizeHeight;
+ int Wloco = _pictureWidth / _placeSizeWidth;
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ T? type = _collection.Get(i);
+ if (type != null)
+ {
+ type.SetPosition(
+ (int)(i / HLoco * _placeSizeWidth),
+ (HLoco - 1) * _placeSizeHeight - (int)(i % HLoco * _placeSizeHeight)
+ );
+ type?.DrawTransport(g);
+ }
+ }
+ }
+ }
+}
diff --git a/ElectricLocomotive/ElectricLocomotive/Program.cs b/ElectricLocomotive/ElectricLocomotive/Program.cs
index cfc9721..ead2f34 100644
--- a/ElectricLocomotive/ElectricLocomotive/Program.cs
+++ b/ElectricLocomotive/ElectricLocomotive/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 FormLocomotiveCollection());
}
}
}
\ No newline at end of file
diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs
new file mode 100644
index 0000000..60c65ce
--- /dev/null
+++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs
@@ -0,0 +1,65 @@
+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 locomotive)
+ {
+ return Insert(locomotive, 0);
+ }
+ public int Insert(T locomotive, int position)
+ {
+ int Full = 0;
+ int temp = 0;
+ for (int i = position; i < Count; i++)
+ {
+ if (_places[i] != null) Full++;
+ }
+ if (Full == Count - position - 1)
+ return -1;
+ if (position < Count && position >= 0)
+ {
+ for (int j = position; j < Count; j++)
+ {
+ if (_places[j] == null)
+ {
+ temp = j;
+ break;
+ }
+ }
+ for (int i = temp; i > position; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[position] = locomotive;
+ return position;
+ }
+ return -1;
+ }
+ public bool Remove(int position)
+ {
+ if (position >= Count || position < 0)
+ if (!(position >= 0 && position < Count) || _places[position] == null)
+ return false;
+ _places[position] = null;
+ return true;
+ }
+ public T Get(int position)
+ {
+ if (position < 0 || position >= Count) return null;
+ return _places[position];
+ }
+ }
+}
--
2.25.1
From c0b10d25c29a0ba06afc8621b9727eca2f674322 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?=
=?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com>
Date: Fri, 17 Nov 2023 12:37:16 +0400
Subject: [PATCH 2/2] Sdano
---
.../ElectricLocomotive/DrawningElectricLocomotive.cs | 2 +-
.../ElectricLocomotive/DrawningLocomotive.cs | 10 +++++-----
.../ElectricLocomotive/ElectricLocomotive.cs | 5 +----
.../ElectricLocomotive/EntityElectricLocomotive.cs | 5 ++++-
.../ElectricLocomotive/EntityLocomotive.cs | 7 +------
5 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
index a9aa508..17d3263 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs
@@ -11,7 +11,7 @@ namespace ElectricLocomotive
public class DrawningElectricLocomotive : DrawningLocomotive
{
public DrawningElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool Horns, int width, int height)
- : base (speed, weight, bodyColor, additionalColor, width , height)
+ : base (speed, weight, bodyColor, width , height)
{
if (EntityLocomotive != null)
{
diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
index 9e06681..ef15a0e 100644
--- a/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
@@ -31,7 +31,7 @@ namespace ElectricLocomotive.DrawningObject
public int GetWidth => _locoWidth;
public int GetHeight => _locoHeight;
- public DrawningLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, int width, int heigth)
+ public DrawningLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
{
if (width < _locoWidth || heigth < _locoHeight)
{
@@ -39,7 +39,7 @@ namespace ElectricLocomotive.DrawningObject
}
_pictureWidth = width;
_pictureHeight = heigth;
- EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor, additionalColor);
+ EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
protected DrawningLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, int width,
@@ -53,7 +53,7 @@ namespace ElectricLocomotive.DrawningObject
_pictureHeight = height;
_locoWidth = locoWidth;
_locoHeight = locoHeight;
- EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor, additionalColor);
+ EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
///
/// Установка позиции
@@ -124,8 +124,8 @@ namespace ElectricLocomotive.DrawningObject
{
return;
}
- Pen pen = new(EntityLocomotive.BodyColor);
- Brush brush = new SolidBrush(EntityLocomotive.AdditionalColor);
+ Pen pen = new(Color.Black);
+ Brush brush = new SolidBrush(EntityLocomotive.BodyColor);
///ВЛ60к-1595
///ходовая
diff --git a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
index fd5cab7..108187d 100644
--- a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
@@ -36,11 +36,10 @@ namespace ElectricLocomotive
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
color = dialog.Color;
- _drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
+ _drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@@ -51,14 +50,12 @@ namespace ElectricLocomotive
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- Color batteryColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
bool Horns = Convert.ToBoolean(random.Next(0, 2));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
color = dialog.Color;
if (dialog.ShowDialog() == DialogResult.OK)
dopColor = dialog.Color;
-
_drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Horns, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
index a340c0f..df3aeb2 100644
--- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs
@@ -9,12 +9,15 @@ namespace ElectricLocomotive.Entities
{
public class EntityElectroLocomotive : EntityLocomotive
{
+ public Color AdditionalColor { get; private set; }
+
public bool Horns { get; private set; }
///
/// Признак (опция) roga
///
- public EntityElectroLocomotive(int Speed, double weight, Color bodyColor, Color additionalColor, bool horns) : base(Speed,weight,bodyColor, additionalColor)
+ public EntityElectroLocomotive(int Speed, double weight, Color bodyColor, Color additionalColor, bool horns) : base(Speed,weight,bodyColor)
{
+ AdditionalColor = additionalColor;
Horns = horns;
}
}
diff --git a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
index 550fa55..9e45f19 100644
--- a/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
+++ b/ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
@@ -21,10 +21,6 @@ namespace ElectricLocomotive.Entities
///
public Color BodyColor { get; private set; }
///
- /// Дополнительный цвет (для опциональных элементов)
- ///
- public Color AdditionalColor { get; private set; }
- ///
/// Признак (опция) наличия обвеса
///
public double Step => (double)Speed * 100 / Weight;
@@ -34,12 +30,11 @@ namespace ElectricLocomotive.Entities
/// Скорость
/// Вес автомобиля
/// Основной цвет
- public EntityLocomotive(int speed, double weight, Color bodyColor, Color additionalColor)
+ public EntityLocomotive(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
- AdditionalColor = additionalColor;
}
}
}
--
2.25.1