pochti vse

This commit is contained in:
Baryshev Dmitry 2024-03-20 13:21:28 +04:00
parent 1a0b56c637
commit ceca79942a
6 changed files with 69 additions and 112 deletions

View File

@ -21,14 +21,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObject<T>
{ {
if (value > 0) if (value > 0)
{ {
if (_collection.Length > 0) if (_collection.Length > 0) Array.Resize(ref _collection, value);
{
Array.Resize(ref _collection, value); else _collection = new T?[value];
}
else
{
_collection = new T?[value];
}
} }
} }
} }

View File

@ -28,35 +28,22 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
buttonCreateDumpTruck = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
buttonRight = new Button(); buttonRight = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonCreateTruck = new Button();
comboBoxStrategy = new ComboBox(); comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button(); buttonStrategyStep = new Button();
pictureBoxDumpTruck1 = new PictureBox(); pictureBoxDumpTruck = new PictureBox();
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck1).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// buttonCreateDumpTruck
//
buttonCreateDumpTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateDumpTruck.Location = new Point(12, 486);
buttonCreateDumpTruck.Name = "buttonCreateDumpTruck";
buttonCreateDumpTruck.Size = new Size(188, 29);
buttonCreateDumpTruck.TabIndex = 1;
buttonCreateDumpTruck.Text = "Создать самосвал";
buttonCreateDumpTruck.UseVisualStyleBackColor = true;
buttonCreateDumpTruck.Click += ButtonCreateDumpTruck_Click;
//
// buttonLeft // buttonLeft
// //
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.влево; buttonLeft.BackgroundImage = Properties.Resources.влево;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(852, 469); buttonLeft.Location = new Point(850, 469);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(40, 40); buttonLeft.Size = new Size(40, 40);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
@ -68,7 +55,7 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.вправо; buttonRight.BackgroundImage = Properties.Resources.вправо;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(944, 469); buttonRight.Location = new Point(942, 469);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(40, 40); buttonRight.Size = new Size(40, 40);
buttonRight.TabIndex = 3; buttonRight.TabIndex = 3;
@ -80,7 +67,7 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.вверх; buttonUp.BackgroundImage = Properties.Resources.вверх;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(898, 423); buttonUp.Location = new Point(896, 423);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(40, 40); buttonUp.Size = new Size(40, 40);
buttonUp.TabIndex = 4; buttonUp.TabIndex = 4;
@ -92,37 +79,27 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.вниз; buttonDown.BackgroundImage = Properties.Resources.вниз;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(898, 469); buttonDown.Location = new Point(896, 469);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(40, 40); buttonDown.Size = new Size(40, 40);
buttonDown.TabIndex = 5; buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click; buttonDown.Click += ButtonMove_Click;
// //
// buttonCreateTruck
//
buttonCreateTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateTruck.Location = new Point(206, 486);
buttonCreateTruck.Name = "buttonCreateTruck";
buttonCreateTruck.Size = new Size(188, 29);
buttonCreateTruck.TabIndex = 6;
buttonCreateTruck.Text = "Создать грузовик";
buttonCreateTruck.UseVisualStyleBackColor = true;
buttonCreateTruck.Click += ButtonCreateTruck_Click;
//
// comboBoxStrategy // comboBoxStrategy
// //
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(833, 21); comboBoxStrategy.Location = new Point(831, 21);
comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28); comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 7; comboBoxStrategy.TabIndex = 7;
// //
// buttonStrategyStep // buttonStrategyStep
// //
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStrategyStep.Location = new Point(890, 55); buttonStrategyStep.Location = new Point(890, 55);
buttonStrategyStep.Name = "buttonStrategyStep"; buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(94, 29); buttonStrategyStep.Size = new Size(94, 29);
@ -131,46 +108,40 @@
buttonStrategyStep.UseVisualStyleBackColor = true; buttonStrategyStep.UseVisualStyleBackColor = true;
buttonStrategyStep.Click += ButtonStrategyStep_Click; buttonStrategyStep.Click += ButtonStrategyStep_Click;
// //
// pictureBoxDumpTruck1 // pictureBoxDumpTruck
// //
pictureBoxDumpTruck1.Dock = DockStyle.Fill; pictureBoxDumpTruck.Dock = DockStyle.Fill;
pictureBoxDumpTruck1.Location = new Point(0, 0); pictureBoxDumpTruck.Location = new Point(0, 0);
pictureBoxDumpTruck1.Name = "pictureBoxDumpTruck1"; pictureBoxDumpTruck.Name = "pictureBoxDumpTruck";
pictureBoxDumpTruck1.Size = new Size(1006, 527); pictureBoxDumpTruck.Size = new Size(1004, 527);
pictureBoxDumpTruck1.TabIndex = 10; pictureBoxDumpTruck.TabIndex = 10;
pictureBoxDumpTruck1.TabStop = false; pictureBoxDumpTruck.TabStop = false;
// //
// FormDumpTruck // FormDumpTruck
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1006, 527); ClientSize = new Size(1004, 527);
Controls.Add(buttonStrategyStep); Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy); Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateTruck);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreateDumpTruck); Controls.Add(pictureBoxDumpTruck);
Controls.Add(pictureBoxDumpTruck1);
Name = "FormDumpTruck"; Name = "FormDumpTruck";
Text = "Самосвал"; Text = "Самосвал";
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck1).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private PictureBox pictureBoxDumpTruck;
private Button buttonCreateDumpTruck;
private Button buttonLeft; private Button buttonLeft;
private Button buttonRight; private Button buttonRight;
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;
private Button buttonCreateTruck;
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonStrategyStep; private Button buttonStrategyStep;
private PictureBox pictureBoxDumpTruck1; private PictureBox pictureBoxDumpTruck;
} }
} }

View File

@ -14,6 +14,18 @@ public partial class FormDumpTruck : Form
/// </summary> /// </summary>
private AbstractStrategy? _strategy; private AbstractStrategy? _strategy;
public DrawningTruck SetTruck
{
set
{
_drawningTruck = value;
_drawningTruck.SetPictureSize(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
public FormDumpTruck() public FormDumpTruck()
{ {
InitializeComponent(); InitializeComponent();
@ -24,61 +36,14 @@ public partial class FormDumpTruck : Form
{ {
if (_drawningTruck == null) return; if (_drawningTruck == null) return;
Bitmap bmp = new(pictureBoxDumpTruck1.Width, Bitmap bmp = new(pictureBoxDumpTruck.Width,
pictureBoxDumpTruck1.Height); pictureBoxDumpTruck.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawningTruck.DrawTransport(gr); _drawningTruck.DrawTransport(gr);
pictureBoxDumpTruck1.Image = bmp; pictureBoxDumpTruck.Image = bmp;
} }
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningTruck):
_drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
break;
case nameof(DrawningDumpTruck):
_drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawningTruck.SetPictureSize(pictureBoxDumpTruck1.Width, pictureBoxDumpTruck1.Height);
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
//comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Обработка нажатия кнокпки "Создать самосвал"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck));
/// <summary>
/// Обработка нажатия кнокпки "Создать грузовик"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck));
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawningTruck == null) return; if (_drawningTruck == null) return;
@ -122,7 +87,7 @@ public partial class FormDumpTruck : Form
if (_strategy == null) return; if (_strategy == null) return;
_strategy.SetData(new MoveableTruck(_drawningTruck), pictureBoxDumpTruck1.Width, pictureBoxDumpTruck1.Height); _strategy.SetData(new MoveableTruck(_drawningTruck), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
} }
if (_strategy == null) return; if (_strategy == null) return;

View File

@ -86,7 +86,7 @@
buttonRemoveTruck.TabIndex = 4; buttonRemoveTruck.TabIndex = 4;
buttonRemoveTruck.Text = "Удаление\r\n"; buttonRemoveTruck.Text = "Удаление\r\n";
buttonRemoveTruck.UseVisualStyleBackColor = true; buttonRemoveTruck.UseVisualStyleBackColor = true;
buttonRemoveTruck.Click += buttonRemoveTruck_Click; buttonRemoveTruck.Click += ButtonRemoveTruck_Click;
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //

View File

@ -12,9 +12,14 @@ using System.Windows.Forms;
namespace ProjectDumpTruck; namespace ProjectDumpTruck;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormTruckCollection : Form public partial class FormTruckCollection : Form
{ {
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null; private AbstractCompany? _company = null;
/// <summary> /// <summary>
@ -25,6 +30,11 @@ public partial class FormTruckCollection : Form
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{ {
switch (comboBoxSelectorCompany.Text) switch (comboBoxSelectorCompany.Text)
@ -89,10 +99,9 @@ public partial class FormTruckCollection : Form
private void ButtonAddTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck)); private void ButtonAddTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck));
private void ButtonAddDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck)); private void ButtonAddDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck));
private void buttonRemoveTruck_Click(object sender, EventArgs e) private void ButtonRemoveTruck_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) return; if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) return;
@ -124,6 +133,23 @@ public partial class FormTruckCollection : Form
{ {
if (_company == null) return; if (_company == null) return;
int counter = 100;
DrawningTruck? truck = null;
while (truck == null)
{
truck = _company.GetRandomObject();
counter--;
if (counter <= 0) break;
}
if (truck == null) return;
FormDumpTruck form = new()
{
SetTruck = truck
};
form.ShowDialog();
} }
} }

View File

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