Laba3-90%
This commit is contained in:
parent
f618a7936b
commit
e573f439b5
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DumpTruck.Entities;
|
using DumpTruck.Entities;
|
||||||
|
using DumpTruck.MovementStrategy;
|
||||||
|
|
||||||
namespace DumpTruck.DrawningObjects
|
namespace DumpTruck.DrawningObjects
|
||||||
{
|
{
|
||||||
@ -19,6 +20,11 @@ namespace DumpTruck.DrawningObjects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectTruck(this);
|
||||||
|
/// <summary>
|
||||||
public int _pictureWidth;
|
public int _pictureWidth;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота окна
|
/// Высота окна
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<SupportedOSPlatformVersion>10.0.22621.0</SupportedOSPlatformVersion>
|
||||||
|
<UseWPF>True</UseWPF>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
215
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
215
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
@ -27,134 +27,152 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.pictureBoxDumpTruck = new System.Windows.Forms.PictureBox();
|
pictureBoxDumpTruck = new PictureBox();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
buttonUp = new Button();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
buttonLeft = new Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
buttonRight = new Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
buttonDown = new Button();
|
||||||
this.Create_Truck_Button = new System.Windows.Forms.Button();
|
Create_Truck_Button = new Button();
|
||||||
this.CreateDumpTruckButton = new System.Windows.Forms.Button();
|
CreateDumpTruckButton = new Button();
|
||||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
this.Step_Button = new System.Windows.Forms.Button();
|
Step_Button = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxDumpTruck)).BeginInit();
|
buttonSelectTruck = new Button();
|
||||||
this.SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxDumpTruck
|
// pictureBoxDumpTruck
|
||||||
//
|
//
|
||||||
this.pictureBoxDumpTruck.Dock = System.Windows.Forms.DockStyle.Fill;
|
pictureBoxDumpTruck.Dock = DockStyle.Fill;
|
||||||
this.pictureBoxDumpTruck.Location = new System.Drawing.Point(0, 0);
|
pictureBoxDumpTruck.Location = new Point(0, 0);
|
||||||
this.pictureBoxDumpTruck.Name = "pictureBoxDumpTruck";
|
pictureBoxDumpTruck.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.pictureBoxDumpTruck.Size = new System.Drawing.Size(884, 461);
|
pictureBoxDumpTruck.Name = "pictureBoxDumpTruck";
|
||||||
this.pictureBoxDumpTruck.TabIndex = 0;
|
pictureBoxDumpTruck.Size = new Size(1010, 615);
|
||||||
this.pictureBoxDumpTruck.TabStop = false;
|
pictureBoxDumpTruck.TabIndex = 0;
|
||||||
|
pictureBoxDumpTruck.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
this.buttonUp.Location = new System.Drawing.Point(795, 374);
|
buttonUp.Location = new Point(909, 499);
|
||||||
this.buttonUp.Name = "buttonUp";
|
buttonUp.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonUp.Size = new System.Drawing.Size(24, 26);
|
buttonUp.Name = "buttonUp";
|
||||||
this.buttonUp.TabIndex = 2;
|
buttonUp.Size = new Size(27, 35);
|
||||||
this.buttonUp.Text = "1";
|
buttonUp.TabIndex = 2;
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.Text = "1";
|
||||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
this.buttonLeft.BackColor = System.Drawing.SystemColors.ControlDark;
|
buttonLeft.BackColor = SystemColors.ControlDark;
|
||||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
this.buttonLeft.Location = new System.Drawing.Point(765, 406);
|
buttonLeft.Location = new Point(874, 541);
|
||||||
this.buttonLeft.Name = "buttonLeft";
|
buttonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonLeft.Size = new System.Drawing.Size(24, 26);
|
buttonLeft.Name = "buttonLeft";
|
||||||
this.buttonLeft.TabIndex = 3;
|
buttonLeft.Size = new Size(27, 35);
|
||||||
this.buttonLeft.Text = "3";
|
buttonLeft.TabIndex = 3;
|
||||||
this.buttonLeft.UseVisualStyleBackColor = false;
|
buttonLeft.Text = "3";
|
||||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
buttonLeft.UseVisualStyleBackColor = false;
|
||||||
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
this.buttonRight.Location = new System.Drawing.Point(825, 407);
|
buttonRight.Location = new Point(943, 543);
|
||||||
this.buttonRight.Name = "buttonRight";
|
buttonRight.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonRight.Size = new System.Drawing.Size(24, 26);
|
buttonRight.Name = "buttonRight";
|
||||||
this.buttonRight.TabIndex = 4;
|
buttonRight.Size = new Size(27, 35);
|
||||||
this.buttonRight.Text = "4";
|
buttonRight.TabIndex = 4;
|
||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.Text = "4";
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
this.buttonDown.Location = new System.Drawing.Point(795, 406);
|
buttonDown.Location = new Point(909, 541);
|
||||||
this.buttonDown.Name = "buttonDown";
|
buttonDown.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonDown.Size = new System.Drawing.Size(24, 26);
|
buttonDown.Name = "buttonDown";
|
||||||
this.buttonDown.TabIndex = 5;
|
buttonDown.Size = new Size(27, 35);
|
||||||
this.buttonDown.Text = "2";
|
buttonDown.TabIndex = 5;
|
||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.Text = "2";
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// Create_Truck_Button
|
// Create_Truck_Button
|
||||||
//
|
//
|
||||||
this.Create_Truck_Button.Location = new System.Drawing.Point(12, 392);
|
Create_Truck_Button.Location = new Point(14, 523);
|
||||||
this.Create_Truck_Button.Name = "Create_Truck_Button";
|
Create_Truck_Button.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Create_Truck_Button.Size = new System.Drawing.Size(123, 23);
|
Create_Truck_Button.Name = "Create_Truck_Button";
|
||||||
this.Create_Truck_Button.TabIndex = 6;
|
Create_Truck_Button.Size = new Size(141, 31);
|
||||||
this.Create_Truck_Button.Text = "Create Truck";
|
Create_Truck_Button.TabIndex = 6;
|
||||||
this.Create_Truck_Button.UseVisualStyleBackColor = true;
|
Create_Truck_Button.Text = "Create Truck";
|
||||||
this.Create_Truck_Button.Click += new System.EventHandler(this.Create_Truck_Button_Click);
|
Create_Truck_Button.UseVisualStyleBackColor = true;
|
||||||
|
Create_Truck_Button.Click += Create_Truck_Button_Click;
|
||||||
//
|
//
|
||||||
// CreateDumpTruckButton
|
// CreateDumpTruckButton
|
||||||
//
|
//
|
||||||
this.CreateDumpTruckButton.Location = new System.Drawing.Point(166, 392);
|
CreateDumpTruckButton.Location = new Point(190, 523);
|
||||||
this.CreateDumpTruckButton.Name = "CreateDumpTruckButton";
|
CreateDumpTruckButton.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.CreateDumpTruckButton.Size = new System.Drawing.Size(168, 23);
|
CreateDumpTruckButton.Name = "CreateDumpTruckButton";
|
||||||
this.CreateDumpTruckButton.TabIndex = 7;
|
CreateDumpTruckButton.Size = new Size(192, 31);
|
||||||
this.CreateDumpTruckButton.Text = "Create DumpTruck";
|
CreateDumpTruckButton.TabIndex = 7;
|
||||||
this.CreateDumpTruckButton.UseVisualStyleBackColor = true;
|
CreateDumpTruckButton.Text = "Create DumpTruck";
|
||||||
this.CreateDumpTruckButton.Click += new System.EventHandler(this.CreateDumpTruckButton_Click);
|
CreateDumpTruckButton.UseVisualStyleBackColor = true;
|
||||||
|
CreateDumpTruckButton.Click += CreateDumpTruckButton_Click;
|
||||||
//
|
//
|
||||||
// comboBoxStrategy
|
// comboBoxStrategy
|
||||||
//
|
//
|
||||||
this.comboBoxStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
this.comboBoxStrategy.FormattingEnabled = true;
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||||
"MoveToCenter",
|
comboBoxStrategy.Location = new Point(858, 16);
|
||||||
"MoveToBorder"});
|
comboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.comboBoxStrategy.Location = new System.Drawing.Point(751, 12);
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
comboBoxStrategy.Size = new Size(138, 28);
|
||||||
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
|
comboBoxStrategy.TabIndex = 8;
|
||||||
this.comboBoxStrategy.TabIndex = 8;
|
|
||||||
//
|
//
|
||||||
// Step_Button
|
// Step_Button
|
||||||
//
|
//
|
||||||
this.Step_Button.Location = new System.Drawing.Point(797, 41);
|
Step_Button.Location = new Point(911, 55);
|
||||||
this.Step_Button.Name = "Step_Button";
|
Step_Button.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Step_Button.Size = new System.Drawing.Size(75, 23);
|
Step_Button.Name = "Step_Button";
|
||||||
this.Step_Button.TabIndex = 9;
|
Step_Button.Size = new Size(86, 31);
|
||||||
this.Step_Button.Text = "Step";
|
Step_Button.TabIndex = 9;
|
||||||
this.Step_Button.UseVisualStyleBackColor = true;
|
Step_Button.Text = "Step";
|
||||||
this.Step_Button.Click += new System.EventHandler(this.Step_Button_Click);
|
Step_Button.UseVisualStyleBackColor = true;
|
||||||
|
Step_Button.Click += Step_Button_Click;
|
||||||
|
//
|
||||||
|
// buttonSelectTruck
|
||||||
|
//
|
||||||
|
buttonSelectTruck.Location = new Point(443, 523);
|
||||||
|
buttonSelectTruck.Name = "buttonSelectTruck";
|
||||||
|
buttonSelectTruck.Size = new Size(94, 29);
|
||||||
|
buttonSelectTruck.TabIndex = 10;
|
||||||
|
buttonSelectTruck.Text = "SelectTruck";
|
||||||
|
buttonSelectTruck.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// FormDumpTruck
|
// FormDumpTruck
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
ClientSize = new Size(1010, 615);
|
||||||
this.Controls.Add(this.Step_Button);
|
Controls.Add(buttonSelectTruck);
|
||||||
this.Controls.Add(this.comboBoxStrategy);
|
Controls.Add(Step_Button);
|
||||||
this.Controls.Add(this.CreateDumpTruckButton);
|
Controls.Add(comboBoxStrategy);
|
||||||
this.Controls.Add(this.Create_Truck_Button);
|
Controls.Add(CreateDumpTruckButton);
|
||||||
this.Controls.Add(this.buttonDown);
|
Controls.Add(Create_Truck_Button);
|
||||||
this.Controls.Add(this.buttonRight);
|
Controls.Add(buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
Controls.Add(buttonRight);
|
||||||
this.Controls.Add(this.buttonUp);
|
Controls.Add(buttonLeft);
|
||||||
this.Controls.Add(this.pictureBoxDumpTruck);
|
Controls.Add(buttonUp);
|
||||||
this.Name = "FormDumpTruck";
|
Controls.Add(pictureBoxDumpTruck);
|
||||||
this.Text = "FormDumpTruck";
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxDumpTruck)).EndInit();
|
Name = "FormDumpTruck";
|
||||||
this.ResumeLayout(false);
|
Text = "FormDumpTruck";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -168,5 +186,6 @@
|
|||||||
private Button CreateDumpTruckButton;
|
private Button CreateDumpTruckButton;
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button Step_Button;
|
private Button Step_Button;
|
||||||
|
private Button buttonSelectTruck;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,10 +19,21 @@ namespace DumpTruck
|
|||||||
|
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
|
||||||
|
/// Выбранный автомобиль
|
||||||
|
/// </summary>
|
||||||
|
public DrawningTruck? selectedTruck { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация формы
|
||||||
|
/// </summary>
|
||||||
public FormDumpTruck()
|
public FormDumpTruck()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
selectedTruck = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningTruck == null)
|
if (_drawningTruck == null)
|
||||||
@ -38,9 +49,14 @@ namespace DumpTruck
|
|||||||
private void Create_Truck_Button_Click(object sender, EventArgs e)
|
private void Create_Truck_Button_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
|
Color color = 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;
|
||||||
|
}
|
||||||
_drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000),
|
_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)),
|
color,color,
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
||||||
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
@ -48,9 +64,14 @@ namespace DumpTruck
|
|||||||
private void CreateDumpTruckButton_Click(object sender, EventArgs e)
|
private void CreateDumpTruckButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
|
Color color = 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;
|
||||||
|
}
|
||||||
_drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000),
|
_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,color,
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(1), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
Convert.ToBoolean(1), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
||||||
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
@ -121,5 +142,10 @@ namespace DumpTruck
|
|||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void buttonSelectTruck_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
selectedTruck = _drawningTruck;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,64 @@
|
|||||||
<root>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<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:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
123
DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
generated
Normal file
123
DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
namespace DumpTruck
|
||||||
|
{
|
||||||
|
partial class FormTruckCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
buttonRefreshCollection = new Button();
|
||||||
|
buttonRemoveTruck = new Button();
|
||||||
|
buttonAddTruck = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBox1.Controls.Add(buttonRefreshCollection);
|
||||||
|
groupBox1.Controls.Add(buttonRemoveTruck);
|
||||||
|
groupBox1.Controls.Add(buttonAddTruck);
|
||||||
|
groupBox1.Location = new Point(588, 12);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(200, 426);
|
||||||
|
groupBox1.TabIndex = 0;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(52, 101);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(100, 23);
|
||||||
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// buttonRefreshCollection
|
||||||
|
//
|
||||||
|
buttonRefreshCollection.Location = new Point(6, 224);
|
||||||
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
|
buttonRefreshCollection.Size = new Size(188, 33);
|
||||||
|
buttonRefreshCollection.TabIndex = 3;
|
||||||
|
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// buttonRemoveTruck
|
||||||
|
//
|
||||||
|
buttonRemoveTruck.Location = new Point(6, 130);
|
||||||
|
buttonRemoveTruck.Name = "buttonRemoveTruck";
|
||||||
|
buttonRemoveTruck.Size = new Size(188, 34);
|
||||||
|
buttonRemoveTruck.TabIndex = 2;
|
||||||
|
buttonRemoveTruck.Text = "Удалить грузовик";
|
||||||
|
buttonRemoveTruck.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveTruck.Click += buttonRemoveTruck_Click;
|
||||||
|
//
|
||||||
|
// buttonAddTruck
|
||||||
|
//
|
||||||
|
buttonAddTruck.Location = new Point(6, 22);
|
||||||
|
buttonAddTruck.Name = "buttonAddTruck";
|
||||||
|
buttonAddTruck.Size = new Size(188, 31);
|
||||||
|
buttonAddTruck.TabIndex = 1;
|
||||||
|
buttonAddTruck.Text = "Добавить грузовик";
|
||||||
|
buttonAddTruck.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddTruck.Click += buttonAddTruck_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(12, 12);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(570, 426);
|
||||||
|
pictureBoxCollection.TabIndex = 1;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormTruckCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Name = "FormTruckCollection";
|
||||||
|
Text = "Набор грузовиков";
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private Button buttonAddTruck;
|
||||||
|
private Button buttonRemoveTruck;
|
||||||
|
private Button buttonRefreshCollection;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
}
|
||||||
|
}
|
72
DumpTruck/DumpTruck/FormTruckCollection.cs
Normal file
72
DumpTruck/DumpTruck/FormTruckCollection.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
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;
|
||||||
|
using DumpTruck.DrawningObjects;
|
||||||
|
using DumpTruck.Generics;
|
||||||
|
using DumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
namespace DumpTruck
|
||||||
|
{
|
||||||
|
public partial class FormTruckCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly TrucksGenericCollection<DrawningTruck, DrawningObjectTruck> _trucks;
|
||||||
|
|
||||||
|
public FormTruckCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_trucks = new TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAddTruck_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormDumpTruck form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_trucks + form.selectedTruck != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _trucks.ShowTrucks();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (_trucks - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _trucks.ShowTrucks();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _trucks.ShowTrucks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
DumpTruck/DumpTruck/FormTruckCollection.resx
Normal file
120
DumpTruck/DumpTruck/FormTruckCollection.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<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>
|
||||||
|
</root>
|
@ -1,3 +1,5 @@
|
|||||||
|
using DumpTruck;
|
||||||
|
|
||||||
namespace DumpTruck
|
namespace DumpTruck
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -11,7 +13,7 @@ namespace DumpTruck
|
|||||||
// 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
110
DumpTruck/DumpTruck/SetGeneric.cs
Normal file
110
DumpTruck/DumpTruck/SetGeneric.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DumpTruck.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly T?[] _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Length;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="truck">Добавляемый автомобиль</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T truck)
|
||||||
|
{
|
||||||
|
return Insert(truck, 0);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="truck">Добавляемый автомобиль</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T truck, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0 || position > Count)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
int nullIndex = -1;
|
||||||
|
for (int i = position + 1; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
nullIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Если пустого элемента нет, то выходим
|
||||||
|
if (nullIndex < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
|
int j = nullIndex - 1;
|
||||||
|
while (j >= position)
|
||||||
|
{
|
||||||
|
_places[j + 1] = _places[j];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO вставка по позиции
|
||||||
|
_places[position] = truck;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if ((position < 0) || (position > Count)) return false;
|
||||||
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if ((position < 0) || (position > Count)) return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
140
DumpTruck/DumpTruck/TrucksGenericCollection.cs
Normal file
140
DumpTruck/DumpTruck/TrucksGenericCollection.cs
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
using DumpTruck.DrawningObjects;
|
||||||
|
using DumpTruck.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DumpTruck.Generics
|
||||||
|
{
|
||||||
|
internal class TrucksGenericCollection<T, U>
|
||||||
|
where T : DrawningTruck
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 110;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 70;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public TrucksGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(TrucksGenericCollection<T, U> collect, T?
|
||||||
|
obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(TrucksGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowTrucks()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
// TODO получение объекта
|
||||||
|
// TODO установка позиции
|
||||||
|
// TODO прорисовка объекта
|
||||||
|
DrawningTruck? truck = _collection.Get(i);
|
||||||
|
if (truck == null)
|
||||||
|
continue;
|
||||||
|
truck.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
|
||||||
|
truck.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user