PIbd22_Kuznetsov_A.V._lab4 #5
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34024.191
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excavator", "Excavator/Excavator.csproj", "{2AA7FB83-8FC3-451D-B277-158CCA4DAE44}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excavator", "Excavator\Excavator.csproj", "{2AA7FB83-8FC3-451D-B277-158CCA4DAE44}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
48
Excavator/Drawing/DrawingExcavator.cs
Normal file
48
Excavator/Drawing/DrawingExcavator.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Excavator.Entities;
|
||||
|
||||
namespace Excavator.Drawing
|
||||
{
|
||||
public class DrawingExcavator : DrawingMash
|
||||
{
|
||||
public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports, int width, int height) : base(speed, weight, bodyColor, width, height, 180, 110)
|
||||
{
|
||||
if (EntityMash != null)
|
||||
{
|
||||
EntityMash = new EntityExcavator(speed, weight, bodyColor, additionalColor, bucket, supports);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityMash is not EntityExcavator Excavator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Pen additionalPen = new(Excavator.AddColor);
|
||||
Brush additionalBrush = new SolidBrush(Excavator.AddColor);
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (Excavator.Bucket)
|
||||
{
|
||||
Brush additionalBrush2 = new
|
||||
SolidBrush(EntityMash.BodyColor);
|
||||
|
||||
g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 42, 20, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX+ 5, _startPosY + 37, 10, 50);
|
||||
}
|
||||
|
||||
if (Excavator.Supports)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 170, _startPosY + 47, 25, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 27, 15, 45);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 175, _startPosY + 72, 25, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
140
Excavator/Drawing/DrawingMash.cs
Normal file
140
Excavator/Drawing/DrawingMash.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Excavator.Entities;
|
||||
using Excavator.Move_Strategy;
|
||||
|
||||
namespace Excavator.Drawing
|
||||
{
|
||||
public class DrawingMash
|
||||
{
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectmash(this);
|
||||
public EntityMash? EntityMash { get; protected set; }
|
||||
public int _pictureWidth;
|
||||
public int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected readonly int _mashWidth = 175;
|
||||
protected readonly int _mashHeight = 115;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _mashWidth;
|
||||
public int GetHeight => _mashHeight;
|
||||
public DrawingMash(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _mashWidth || height < _mashHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityMash = new EntityMash(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawingMash(int speed, double weight, Color bodyColor, int width, int height, int mashWidth, int mashHeight)
|
||||
{
|
||||
if (width < _mashWidth || height < _mashHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_mashWidth = mashWidth;
|
||||
_mashHeight = mashHeight;
|
||||
EntityMash = new EntityMash(speed, weight, bodyColor);
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x > _pictureWidth || y > _pictureHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityMash == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityMash.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityMash.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityMash.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityMash.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _mashWidth + EntityMash.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityMash.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _mashHeight + EntityMash.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityMash.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntityMash.BodyColor);
|
||||
|
||||
g.FillRectangle(additionalBrush, _startPosX + 30, _startPosY + 31, 140, 35);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 60, _startPosY + 2, 15, 35);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 125, _startPosY + 2, 40, 40);
|
||||
|
||||
Brush additionalBrush1 = new
|
||||
SolidBrush(EntityMash.BodyColor);
|
||||
|
||||
Brush gr = new SolidBrush(Color.Gray);
|
||||
|
||||
g.FillEllipse(additionalBrush1, _startPosX + 20, _startPosY + 72, 25, 25);
|
||||
g.FillEllipse(additionalBrush1, _startPosX + 145, _startPosY + 72, 25, 25);
|
||||
|
||||
g.FillEllipse(gr, _startPosX + 55, _startPosY + 81, 17, 17);
|
||||
g.FillEllipse(gr, _startPosX + 85, _startPosY + 81, 17, 17);
|
||||
g.FillEllipse(gr, _startPosX + 110, _startPosY + 81, 17, 17);
|
||||
|
||||
g.FillEllipse(gr, _startPosX + 68, _startPosY + 72, 8, 8);
|
||||
g.FillEllipse(gr, _startPosX + 95, _startPosY + 72, 8, 8);
|
||||
|
||||
Pen blackPen = new Pen(Color.Black, 3);
|
||||
Rectangle rect1 = new Rectangle(_startPosX + 15, _startPosY + 69, 30, 30);
|
||||
g.DrawArc(blackPen, rect1, 90, 180);
|
||||
Rectangle rect2 = new Rectangle(_startPosX + 145, _startPosY + 69, 30, 30);
|
||||
g.DrawArc(blackPen, rect2, -90, 180);
|
||||
g.DrawLine(blackPen, _startPosX + 27, _startPosY + 69, _startPosX + 165, _startPosY + 69);
|
||||
g.DrawLine(blackPen, _startPosX + 27, _startPosY + 99, _startPosX + 165, _startPosY + 99);
|
||||
}
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityMash == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
DirectionType.Left => _startPosX - EntityMash.Step > 0,
|
||||
DirectionType.Up => _startPosY - EntityMash.Step > 0,
|
||||
DirectionType.Right => _startPosX + _mashWidth + EntityMash.Step < _pictureWidth,
|
||||
DirectionType.Down => _startPosY + _mashHeight + EntityMash.Step < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
16
Excavator/Entities/DirectionType.cs
Normal file
16
Excavator/Entities/DirectionType.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Entities
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
}
|
||||
}
|
22
Excavator/Entities/EntityExcavator.cs
Normal file
22
Excavator/Entities/EntityExcavator.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Excavator.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Entities
|
||||
{
|
||||
public class EntityExcavator : EntityMash
|
||||
{
|
||||
public Color AddColor { get; private set; }
|
||||
public bool Bucket { get; private set; }
|
||||
public bool Supports { get; private set; }
|
||||
public EntityExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AddColor = additionalColor;
|
||||
Bucket = bucket;
|
||||
Supports = supports;
|
||||
}
|
||||
}
|
||||
}
|
22
Excavator/Entities/EntityMash.cs
Normal file
22
Excavator/Entities/EntityMash.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Entities
|
||||
{
|
||||
public class EntityMash
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public EntityMash(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
8
Excavator/FormExcavator.Designer.cs
generated
8
Excavator/FormExcavator.Designer.cs
generated
@ -57,7 +57,6 @@
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
//this.buttonUp.BackgroundImage = global::Excavator.Properties.Resources.ArrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(811, 377);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
@ -68,9 +67,8 @@
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
//this.buttonLeft.BackgroundImage = global::Excavator.Properties.Resources.ArrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(775, 413);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(776, 413);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
@ -79,7 +77,6 @@
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
//this.buttonDown.BackgroundImage = global::Excavator.Properties.Resources.ArrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(811, 413);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
@ -90,7 +87,6 @@
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
//this.buttonRight.BackgroundImage = global::Excavator.Properties.Resources.ArrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(848, 413);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
@ -128,7 +124,7 @@
|
||||
this.buttonCreateMash.Name = "buttonCreateMash";
|
||||
this.buttonCreateMash.Size = new System.Drawing.Size(120, 74);
|
||||
this.buttonCreateMash.TabIndex = 13;
|
||||
this.buttonCreateMash.Text = "Создать Гусеничную машину";
|
||||
this.buttonCreateMash.Text = "Создать Гусеничную Машину";
|
||||
this.buttonCreateMash.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateMash.Click += new System.EventHandler(this.buttonCreateMash_Click);
|
||||
//
|
||||
|
@ -1,29 +1,33 @@
|
||||
using Excavator.DrawingObjects;
|
||||
using Excavator.MovementStrategy;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Entities;
|
||||
using Excavator.Move_Strategy;
|
||||
|
||||
namespace Excavator
|
||||
{
|
||||
|
||||
public partial class FormExcavator : Form
|
||||
{
|
||||
private DrawingMash? _drawingMash;
|
||||
private DrawingMash? _DrawingMash;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingMash? SelectedMash { get; private set; }
|
||||
public DrawingMash? Selectedmash { get; private set; }
|
||||
|
||||
public FormExcavator()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedMash = null;
|
||||
Selectedmash = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingMash == null)
|
||||
if (_DrawingMash == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingMash.DrawTransport(gr);
|
||||
_DrawingMash.DrawTransport(gr);
|
||||
pictureBoxExcavator.Image = bmp;
|
||||
|
||||
}
|
||||
private void buttonCreateExcavator_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -33,16 +37,19 @@ namespace Excavator
|
||||
Color color1 = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
ColorDialog dialog1 = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK && dialog1.ShowDialog() == DialogResult.OK)
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
ColorDialog dialog1 = new();
|
||||
if (dialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color1 = dialog1.Color;
|
||||
}
|
||||
_drawingMash = new DrawingExcavator(random.Next(100, 300),
|
||||
_DrawingMash = new DrawingExcavator(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color, color1, true, true,
|
||||
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
_drawingMash.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
_DrawingMash.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
@ -56,15 +63,15 @@ namespace Excavator
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingMash = new DrawingMash(random.Next(100, 300),
|
||||
_DrawingMash = new DrawingMash(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
_drawingMash.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_DrawingMash.SetPosition(random.Next(10, 100), random.Next(10,100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingMash == null)
|
||||
if (_DrawingMash == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -72,23 +79,23 @@ namespace Excavator
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingMash.MoveTransport(DirectionType.Up);
|
||||
_DrawingMash.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingMash.MoveTransport(DirectionType.Down);
|
||||
_DrawingMash.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingMash.MoveTransport(DirectionType.Left);
|
||||
_DrawingMash.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingMash.MoveTransport(DirectionType.Right);
|
||||
_DrawingMash.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingMash == null)
|
||||
if (_DrawingMash == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -105,7 +112,7 @@ namespace Excavator
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawingObjectMash(_drawingMash), pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
_abstractStrategy.SetData(new DrawingObjectmash(_DrawingMash), pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
@ -120,9 +127,10 @@ namespace Excavator
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedMash = _drawingMash;
|
||||
Selectedmash = _DrawingMash;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
|
192
Excavator/FormExcavatorCollection.Designer.cs
generated
Normal file
192
Excavator/FormExcavatorCollection.Designer.cs
generated
Normal file
@ -0,0 +1,192 @@
|
||||
namespace Excavator
|
||||
{
|
||||
partial class FormExcavatorCollection
|
||||
{
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
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()
|
||||
{
|
||||
this.buttonAddmash = new System.Windows.Forms.Button();
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.labelInstruments = new System.Windows.Forms.Label();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonDeletemash = new System.Windows.Forms.Button();
|
||||
this.colorDialog = new System.Windows.Forms.ColorDialog();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.buttonAddStorage = new System.Windows.Forms.Button();
|
||||
this.buttonDeleteStorage = new System.Windows.Forms.Button();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonAddmash
|
||||
//
|
||||
this.buttonAddmash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonAddmash.Location = new System.Drawing.Point(761, 441);
|
||||
this.buttonAddmash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddmash.Name = "buttonAddmash";
|
||||
this.buttonAddmash.Size = new System.Drawing.Size(135, 37);
|
||||
this.buttonAddmash.TabIndex = 0;
|
||||
this.buttonAddmash.Text = "Добавить автобус";
|
||||
this.buttonAddmash.UseVisualStyleBackColor = true;
|
||||
this.buttonAddmash.Click += new System.EventHandler(this.buttonAddmash_Click);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(3, 0);
|
||||
this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(730, 581);
|
||||
this.pictureBoxCollection.TabIndex = 1;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// labelInstruments
|
||||
//
|
||||
this.labelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.labelInstruments.AutoSize = true;
|
||||
this.labelInstruments.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.labelInstruments.Location = new System.Drawing.Point(761, 0);
|
||||
this.labelInstruments.Name = "labelInstruments";
|
||||
this.labelInstruments.Size = new System.Drawing.Size(136, 28);
|
||||
this.labelInstruments.TabIndex = 2;
|
||||
this.labelInstruments.Text = "Инструменты";
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(752, 173);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(150, 33);
|
||||
this.buttonUpdate.TabIndex = 3;
|
||||
this.buttonUpdate.Text = "Обновить набор";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||
//
|
||||
// buttonDeletemash
|
||||
//
|
||||
this.buttonDeletemash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDeletemash.Location = new System.Drawing.Point(761, 525);
|
||||
this.buttonDeletemash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDeletemash.Name = "buttonDeletemash";
|
||||
this.buttonDeletemash.Size = new System.Drawing.Size(135, 37);
|
||||
this.buttonDeletemash.TabIndex = 4;
|
||||
this.buttonDeletemash.Text = "Удалить объект";
|
||||
this.buttonDeletemash.UseVisualStyleBackColor = true;
|
||||
this.buttonDeletemash.Click += new System.EventHandler(this.buttonDeletemash_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(752, 487);
|
||||
this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.maskedTextBoxNumber.Mask = "00";
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(157, 27);
|
||||
this.maskedTextBoxNumber.TabIndex = 5;
|
||||
this.maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(752, 51);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(66, 20);
|
||||
this.label1.TabIndex = 7;
|
||||
this.label1.Text = "Наборы";
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 20;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(751, 212);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(150, 144);
|
||||
this.listBoxStorages.TabIndex = 8;
|
||||
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddStorage
|
||||
//
|
||||
this.buttonAddStorage.Location = new System.Drawing.Point(751, 135);
|
||||
this.buttonAddStorage.Name = "buttonAddStorage";
|
||||
this.buttonAddStorage.Size = new System.Drawing.Size(150, 33);
|
||||
this.buttonAddStorage.TabIndex = 9;
|
||||
this.buttonAddStorage.Text = "Добавить набор";
|
||||
this.buttonAddStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonAddStorage.Click += new System.EventHandler(this.buttonAddStorage_Click);
|
||||
//
|
||||
// buttonDeleteStorage
|
||||
//
|
||||
this.buttonDeleteStorage.Location = new System.Drawing.Point(751, 363);
|
||||
this.buttonDeleteStorage.Name = "buttonDeleteStorage";
|
||||
this.buttonDeleteStorage.Size = new System.Drawing.Size(150, 33);
|
||||
this.buttonDeleteStorage.TabIndex = 10;
|
||||
this.buttonDeleteStorage.Text = "Удалить набор";
|
||||
this.buttonDeleteStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteStorage.Click += new System.EventHandler(this.buttonDeleteStorage_Click);
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(751, 101);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(150, 27);
|
||||
this.textBoxStorageName.TabIndex = 11;
|
||||
//
|
||||
// FormExcavatorCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(926, 591);
|
||||
this.Controls.Add(this.textBoxStorageName);
|
||||
this.Controls.Add(this.buttonDeleteStorage);
|
||||
this.Controls.Add(this.buttonAddStorage);
|
||||
this.Controls.Add(this.listBoxStorages);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.buttonAddmash);
|
||||
this.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.Controls.Add(this.buttonDeletemash);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.labelInstruments);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormExcavatorCollection";
|
||||
this.Text = "Набор объектов";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAddmash;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Label labelInstruments;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDeletemash;
|
||||
private ColorDialog colorDialog;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Label label1;
|
||||
private ListBox listBoxStorages;
|
||||
private Button buttonAddStorage;
|
||||
private Button buttonDeleteStorage;
|
||||
private TextBox textBoxStorageName;
|
||||
}
|
||||
}
|
143
Excavator/FormExcavatorCollection.cs
Normal file
143
Excavator/FormExcavatorCollection.cs
Normal file
@ -0,0 +1,143 @@
|
||||
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 Excavator.Generic;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Move_Strategy;
|
||||
|
||||
namespace Excavator
|
||||
{
|
||||
public partial class FormExcavatorCollection : Form
|
||||
{
|
||||
private readonly MashsGenericStorage _storage;
|
||||
public FormExcavatorCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new MashsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void buttonAddStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.Showmash();
|
||||
}
|
||||
private void buttonDeleteStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
private void buttonAddmash_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Не выбран набор");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormExcavator form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (obj + form.Selectedmash != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.Showmash();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonDeletemash_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = 0;
|
||||
try
|
||||
{
|
||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (obj - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.Showmash();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.Showmash();
|
||||
}
|
||||
}
|
||||
}
|
66
Excavator/FormExcavatorCollection.resx
Normal file
66
Excavator/FormExcavatorCollection.resx
Normal file
@ -0,0 +1,66 @@
|
||||
<root>
|
||||
<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>
|
||||
<metadata name="colorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>36</value>
|
||||
</metadata>
|
||||
</root>
|
93
Excavator/Generic/MashGenericCollection.cs
Normal file
93
Excavator/Generic/MashGenericCollection.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Move_Strategy;
|
||||
|
||||
namespace Excavator.Generic
|
||||
{
|
||||
internal class MashGenericCollection<T, U>
|
||||
where T : DrawingMash
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 200;
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public MashGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
public static int operator +(MashGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public static bool operator -(MashGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
if (collect._collection.Getmash(pos) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Remove(pos) ?? false;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
public int ReturnLength()
|
||||
{
|
||||
return _collection.Count;
|
||||
}
|
||||
public Bitmap Showmash()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
private void DrawBackground(Graphics gr)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int x = _pictureWidth / _placeSizeWidth - 1;
|
||||
int y = 0;
|
||||
foreach (var mash in _collection.Getmash())
|
||||
{
|
||||
if (mash != null)
|
||||
{
|
||||
if (x < 0)
|
||||
{
|
||||
x = _pictureWidth / _placeSizeWidth - 1;
|
||||
++y;
|
||||
}
|
||||
mash.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
|
||||
mash.DrawTransport(g);
|
||||
--x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
Excavator/Generic/MashsGenericStorage.cs
Normal file
56
Excavator/Generic/MashsGenericStorage.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Move_Strategy;
|
||||
|
||||
namespace Excavator.Generic
|
||||
{
|
||||
internal class MashsGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, MashGenericCollection<DrawingMash, DrawingObjectmash>> _mashStorages;
|
||||
public List<string> Keys => _mashStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public MashsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mashStorages = new Dictionary<string, MashGenericCollection<DrawingMash, DrawingObjectmash>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
foreach (string nameStorage in Keys)
|
||||
{
|
||||
if (nameStorage == name)
|
||||
{
|
||||
MessageBox.Show("Набор с заданным именем уже есть", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_mashStorages.Add(name, new MashGenericCollection<DrawingMash, DrawingObjectmash>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_mashStorages.ContainsKey(name))
|
||||
{
|
||||
_mashStorages.Remove(name);
|
||||
}
|
||||
|
||||
}
|
||||
public MashGenericCollection<DrawingMash, DrawingObjectmash>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mashStorages.ContainsKey(ind))
|
||||
{
|
||||
return _mashStorages[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
Excavator/Generic/SetGeneric.cs
Normal file
74
Excavator/Generic/SetGeneric.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Generic
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly List<T?> _places;
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
public int Insert(T mash)
|
||||
{
|
||||
_places.Insert(0, mash);
|
||||
return 0;
|
||||
}
|
||||
public bool Insert(T mash, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count || Count >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.Insert(position, mash);
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position > Count || Count >= _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
public IEnumerable<T?> Getmash(int? maxmash = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxmash.HasValue && i == maxmash.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
72
Excavator/Move_Strategy/AbstractStrategy.cs
Normal file
72
Excavator/Move_Strategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Excavator.Entities;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
private IMoveableObject? _moveableObject;
|
||||
private Status _state = Status.NotInit;
|
||||
protected int FieldWidth { get; private set; }
|
||||
protected int FieldHeight { get; private set; }
|
||||
public Status GetStatus() { return _state; }
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
35
Excavator/Move_Strategy/DrawingObjectBus.cs
Normal file
35
Excavator/Move_Strategy/DrawingObjectBus.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Excavator.Entities;
|
||||
using Excavator.Drawing;
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
public class DrawingObjectmash : IMoveableObject
|
||||
{
|
||||
private readonly DrawingMash? _DrawingMash = null;
|
||||
public DrawingObjectmash(DrawingMash DrawingMash)
|
||||
{
|
||||
_DrawingMash = DrawingMash;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DrawingMash == null || _DrawingMash.EntityMash == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_DrawingMash.GetPosX, _DrawingMash.GetPosY, _DrawingMash.GetWidth, _DrawingMash.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_DrawingMash?.EntityMash?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) => _DrawingMash?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) => _DrawingMash?.MoveTransport(direction);
|
||||
}
|
||||
}
|
19
Excavator/Move_Strategy/IMoveableObject.cs
Normal file
19
Excavator/Move_Strategy/IMoveableObject.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Entities;
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
int GetStep { get; }
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
56
Excavator/Move_Strategy/MoveToBorder.cs
Normal file
56
Excavator/Move_Strategy/MoveToBorder.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
Excavator/Move_Strategy/MoveToCenter.cs
Normal file
57
Excavator/Move_Strategy/MoveToCenter.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
Excavator/Move_Strategy/ObjectParameters.cs
Normal file
29
Excavator/Move_Strategy/ObjectParameters.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
public int LeftBorder => _x;
|
||||
public int TopBorder => _y;
|
||||
public int RightBorder => _x + _width;
|
||||
public int DownBorder => _y + _height;
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
15
Excavator/Move_Strategy/Status.cs
Normal file
15
Excavator/Move_Strategy/Status.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace Excavator
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMashCollection());
|
||||
Application.Run(new FormExcavatorCollection());
|
||||
}
|
||||
}
|
||||
}
|
@ -118,16 +118,16 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user