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 (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
if (_collection.Length > 0) Array.Resize(ref _collection, value);
else _collection = new T?[value];
}
}
}

View File

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

View File

@ -14,6 +14,18 @@ public partial class FormDumpTruck : Form
/// </summary>
private AbstractStrategy? _strategy;
public DrawningTruck SetTruck
{
set
{
_drawningTruck = value;
_drawningTruck.SetPictureSize(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
public FormDumpTruck()
{
InitializeComponent();
@ -24,61 +36,14 @@ public partial class FormDumpTruck : Form
{
if (_drawningTruck == null) return;
Bitmap bmp = new(pictureBoxDumpTruck1.Width,
pictureBoxDumpTruck1.Height);
Bitmap bmp = new(pictureBoxDumpTruck.Width,
pictureBoxDumpTruck.Height);
Graphics gr = Graphics.FromImage(bmp);
_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)
{
if (_drawningTruck == null) return;
@ -122,7 +87,7 @@ public partial class FormDumpTruck : Form
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;

View File

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

View File

@ -12,9 +12,14 @@ using System.Windows.Forms;
namespace ProjectDumpTruck;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormTruckCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
@ -25,6 +30,11 @@ public partial class FormTruckCollection : Form
InitializeComponent();
}
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
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 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;
@ -124,6 +133,23 @@ public partial class FormTruckCollection : Form
{
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,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormDumpTruck());
Application.Run(new FormTruckCollection());
}
}
}