Compare commits
11 Commits
main
...
ISBd_21.Go
Author | SHA1 | Date | |
---|---|---|---|
f7bd75416a | |||
790766694c | |||
c0d6680106 | |||
bf4f0f9881 | |||
bd6f7fb3f3 | |||
c0b10d25c2 | |||
57e4fd46b7 | |||
8a64878aad | |||
b9ea3213ee | |||
d1f9a5eead | |||
025bd88523 |
87
ElectricLocomotive/ElectricLocomotive/AbstractStrategy.cs
Normal file
87
ElectricLocomotive/ElectricLocomotive/AbstractStrategy.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ElectricLocomotive;
|
||||
using ElectricLocomotive.MovementStrategy;
|
||||
|
||||
namespace ProjectElectricLocomotive.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Абстрактный класс стратегии
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
16
ElectricLocomotive/ElectricLocomotive/DirectionType.cs
Normal file
16
ElectricLocomotive/ElectricLocomotive/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 ElectricLocomotive
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using ElectricLocomotive.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public class DrawningElectricLocomotive : DrawningLocomotive
|
||||
{
|
||||
public DrawningElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool Horns_1,bool Horns_2, int width, int height)
|
||||
: base (speed, weight, bodyColor, width , height)
|
||||
{
|
||||
if (EntityLocomotive != null)
|
||||
{
|
||||
EntityLocomotive = new EntityElectroLocomotive(speed, weight, bodyColor,
|
||||
additionalColor, Horns_1,Horns_2);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityLocomotive is not EntityElectroLocomotive electroLocomotive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(electroLocomotive.BodyColor) ;
|
||||
Brush brush = new SolidBrush(electroLocomotive.AdditionalColor);
|
||||
// обвесы
|
||||
if (electroLocomotive.Horns_1)
|
||||
{
|
||||
g.FillRectangle(brush, _startPosX + 25, _startPosY + 5, 15, 5);
|
||||
|
||||
Point[] horns =
|
||||
{
|
||||
new Point(_startPosX+25, _startPosY+10),
|
||||
new Point(_startPosX+25, _startPosY+5),
|
||||
new Point(_startPosX+33,_startPosY+5),
|
||||
new Point(_startPosX+50, _startPosY),
|
||||
new Point(_startPosX+33,_startPosY+5),
|
||||
new Point(_startPosX+40,_startPosY+5),
|
||||
new Point(_startPosX+40,_startPosY+10)
|
||||
};
|
||||
g.DrawPolygon(pen, horns);
|
||||
}
|
||||
if (electroLocomotive.Horns_2)
|
||||
{
|
||||
g.FillRectangle(brush, _startPosX + 65, _startPosY + 5, 15, 5);
|
||||
Point[] horns2 =
|
||||
{
|
||||
new Point(_startPosX+65, _startPosY+10),
|
||||
new Point(_startPosX+65, _startPosY+5),
|
||||
new Point(_startPosX+73,_startPosY+5),
|
||||
new Point(_startPosX+90, _startPosY),
|
||||
new Point(_startPosX+73,_startPosY+5),
|
||||
new Point(_startPosX+80,_startPosY+5),
|
||||
new Point(_startPosX+80,_startPosY+10)
|
||||
};
|
||||
g.DrawPolygon(pen, horns2);
|
||||
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
}
|
||||
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
(EntityLocomotive as EntityElectroLocomotive).SetAdditionalColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
218
ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
Normal file
218
ElectricLocomotive/ElectricLocomotive/DrawningLocomotive.cs
Normal file
@ -0,0 +1,218 @@
|
||||
using ElectricLocomotive.Entities;
|
||||
using ElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive.DrawningObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningLocomotive
|
||||
{
|
||||
public EntityLocomotive? EntityLocomotive { get; protected set; }
|
||||
|
||||
public int _pictureWidth;
|
||||
|
||||
public int _pictureHeight;
|
||||
|
||||
protected int _startPosX;
|
||||
|
||||
protected int _startPosY;
|
||||
|
||||
protected readonly int _locoWidth = 95;
|
||||
|
||||
protected readonly int _locoHeight = 50;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _locoWidth;
|
||||
public int GetHeight => _locoHeight;
|
||||
|
||||
public DrawningLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
|
||||
{
|
||||
if (width < _locoWidth || heigth < _locoHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = heigth;
|
||||
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawningLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, int width,
|
||||
int height, int locoWidth, int locoHeight)
|
||||
{
|
||||
if (width < _locoWidth || height < _locoHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_locoWidth = locoWidth;
|
||||
_locoHeight = locoHeight;
|
||||
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _locoWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth - _locoWidth;
|
||||
}
|
||||
if (y < 0 || y + _locoHeight > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight - _locoHeight;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityLocomotive.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityLocomotive.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityLocomotive.Step + _locoWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityLocomotive.Step + _locoHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityLocomotive.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brush = new SolidBrush(EntityLocomotive.BodyColor);
|
||||
///ВЛ60к-1595
|
||||
|
||||
///ходовая
|
||||
g.FillRectangle(brush, new Rectangle(_startPosX + 20, _startPosY + 45, 15, 5));
|
||||
g.FillRectangle(brush, new Rectangle(_startPosX + 65, _startPosY + 45, 15, 5));
|
||||
|
||||
g.FillEllipse(brush, _startPosX + 15, _startPosY + 45, 10, 10);
|
||||
g.FillEllipse(brush, _startPosX + 30, _startPosY + 45, 10, 10);
|
||||
g.FillEllipse(brush, _startPosX + 60, _startPosY + 45, 10, 10);
|
||||
g.FillEllipse(brush, _startPosX + 75, _startPosY + 45, 10, 10);
|
||||
PointF[] chassis =
|
||||
{
|
||||
new Point(_startPosX+10, _startPosY+50),
|
||||
new Point(_startPosX, _startPosY+50),
|
||||
new Point(_startPosX+10, _startPosY +40),
|
||||
new Point(_startPosX + 90, _startPosY+40),
|
||||
new Point(_startPosX+100, _startPosY+50),
|
||||
new Point(_startPosX+90,_startPosY+ 50),
|
||||
new Point(_startPosX+85, _startPosY+45),
|
||||
new Point(_startPosX+15, _startPosY+45),
|
||||
};
|
||||
g.FillPolygon(brush, chassis);
|
||||
|
||||
///обводка ходовой
|
||||
Point[] chassisCont =
|
||||
{
|
||||
new Point(_startPosX+10, _startPosY+50),
|
||||
new Point(_startPosX, _startPosY+50),
|
||||
new Point(_startPosX+10, _startPosY +40),
|
||||
new Point(_startPosX + 90, _startPosY+40),
|
||||
new Point(_startPosX+100, _startPosY+50),
|
||||
new Point(_startPosX+90,_startPosY+ 50),
|
||||
new Point(_startPosX+85, _startPosY+45),
|
||||
new Point(_startPosX+15, _startPosY+45),
|
||||
};
|
||||
g.DrawPolygon(pen, chassisCont);
|
||||
|
||||
///кабина
|
||||
Point[] cabin =
|
||||
{
|
||||
new Point(_startPosX+20, _startPosY+10),
|
||||
new Point(_startPosX+90,_startPosY+10),
|
||||
new Point(_startPosX+90,_startPosY + 40),
|
||||
new Point(_startPosX+10,_startPosY+40),
|
||||
new Point(_startPosX+10,_startPosY+25)
|
||||
};
|
||||
g.DrawPolygon(pen, cabin);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 25, _startPosX + 90, _startPosY + 25);
|
||||
|
||||
///окна
|
||||
g.FillRectangle(brush, _startPosX + 20, _startPosY + 15, 10, 10);
|
||||
g.FillRectangle(brush, _startPosX + 35, _startPosY + 15, 10, 10);
|
||||
|
||||
g.FillRectangle(brush, _startPosX + 75, _startPosY + 15, 10, 10);
|
||||
|
||||
///дверь
|
||||
g.FillRectangle(brush, _startPosX + 50, _startPosY + 15, 10, 25);
|
||||
|
||||
///Батарея
|
||||
g.FillRectangle(brush, _startPosX + 45, _startPosY + 5, 15, 5);
|
||||
|
||||
}
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityLocomotive == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityLocomotive.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityLocomotive.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityLocomotive.Step < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + EntityLocomotive.Step < _pictureHeight,
|
||||
};
|
||||
}
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectLocomotive(this);
|
||||
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
EntityLocomotive?.SetBodyColor(color);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using ElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public class DrawningObjectLocomotive : IMoveableObject
|
||||
{
|
||||
private readonly DrawningLocomotive? _drawningLocomotive = null;
|
||||
public DrawningObjectLocomotive(DrawningLocomotive drawningLocomotive)
|
||||
{
|
||||
_drawningLocomotive = drawningLocomotive;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningLocomotive == null || _drawningLocomotive.EntityLocomotive == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningLocomotive.GetPosX,_drawningLocomotive.GetPosY, _drawningLocomotive.GetWidth, _drawningLocomotive.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningLocomotive?.EntityLocomotive?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>_drawningLocomotive?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>_drawningLocomotive?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
|
196
ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.Designer.cs
generated
Normal file
196
ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.Designer.cs
generated
Normal file
@ -0,0 +1,196 @@
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
partial class ElectricLocomotive
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ElectricLocomotive));
|
||||
pictureBoxElectroLocomotiv = new PictureBox();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonCreateElectricLocomotive = new Button();
|
||||
buttonCreateLocomotive = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonChoiceLocomotive = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectroLocomotiv).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxElectroLocomotiv
|
||||
//
|
||||
pictureBoxElectroLocomotiv.AccessibleRole = AccessibleRole.Client;
|
||||
pictureBoxElectroLocomotiv.Dock = DockStyle.Fill;
|
||||
pictureBoxElectroLocomotiv.Location = new Point(0, 0);
|
||||
pictureBoxElectroLocomotiv.Name = "pictureBoxElectroLocomotiv";
|
||||
pictureBoxElectroLocomotiv.Size = new Size(854, 467);
|
||||
pictureBoxElectroLocomotiv.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxElectroLocomotiv.TabIndex = 5;
|
||||
pictureBoxElectroLocomotiv.TabStop = false;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(777, 389);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 10;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(813, 425);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 9;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(777, 425);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 8;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(741, 425);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 7;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreateElectricLocomotive
|
||||
//
|
||||
buttonCreateElectricLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateElectricLocomotive.Location = new Point(13, 425);
|
||||
buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
|
||||
buttonCreateElectricLocomotive.Size = new Size(208, 34);
|
||||
buttonCreateElectricLocomotive.TabIndex = 6;
|
||||
buttonCreateElectricLocomotive.Text = "Нарисовать Электролокомотив";
|
||||
buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonCreateElectricLocomotive.Click += PaintElectricLocoButton_click;
|
||||
//
|
||||
// buttonCreateLocomotive
|
||||
//
|
||||
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateLocomotive.Location = new Point(227, 425);
|
||||
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
||||
buttonCreateLocomotive.Size = new Size(197, 34);
|
||||
buttonCreateLocomotive.TabIndex = 11;
|
||||
buttonCreateLocomotive.Text = "Нарисовать локомотив";
|
||||
buttonCreateLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonCreateLocomotive.Click += PaintLocoButton_click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightCorner" });
|
||||
comboBoxStrategy.Location = new Point(730, 11);
|
||||
comboBoxStrategy.Margin = new Padding(2);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(113, 23);
|
||||
comboBoxStrategy.TabIndex = 12;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStep.Font = new Font("Candara Light", 10F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonStep.Location = new Point(741, 49);
|
||||
buttonStep.Margin = new Padding(2);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(88, 34);
|
||||
buttonStep.TabIndex = 13;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// buttonChoiceLocomotive
|
||||
//
|
||||
buttonChoiceLocomotive.Location = new Point(430, 425);
|
||||
buttonChoiceLocomotive.Name = "buttonChoiceLocomotive";
|
||||
buttonChoiceLocomotive.Size = new Size(206, 34);
|
||||
buttonChoiceLocomotive.TabIndex = 14;
|
||||
buttonChoiceLocomotive.Text = "Выбрать локомотив";
|
||||
buttonChoiceLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonChoiceLocomotive.Click += ButtonSelectLocomotive_Click;
|
||||
//
|
||||
// ElectricLocomotive
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(854, 467);
|
||||
Controls.Add(buttonChoiceLocomotive);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateLocomotive);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateElectricLocomotive);
|
||||
Controls.Add(pictureBoxElectroLocomotiv);
|
||||
Name = "ElectricLocomotive";
|
||||
Text = "ElectricLocomotive";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectroLocomotiv).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxElectroLocomotiv;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreateElectricLocomotive;
|
||||
private Button buttonCreateLocomotive;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonChoiceLocomotive;
|
||||
}
|
||||
}
|
133
ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
Normal file
133
ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using ElectricLocomotive.MovementStrategy;
|
||||
using ProjectElectricLocomotive;
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public partial class ElectricLocomotive : Form
|
||||
{
|
||||
|
||||
private DrawningLocomotive? _drawningLocomotive;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningLocomotive? SelectedLocomotive { get; private set; }
|
||||
|
||||
public ElectricLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedLocomotive = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningLocomotive.DrawTransport(gr);
|
||||
pictureBoxElectroLocomotiv.Image = bmp;
|
||||
}
|
||||
|
||||
private void PaintLocoButton_click(object sender, EventArgs e)
|
||||
{
|
||||
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;
|
||||
_drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
|
||||
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void PaintElectricLocoButton_click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
bool Horns_1 = Convert.ToBoolean(random.Next(0, 2));
|
||||
bool Horns_2 = Convert.ToBoolean(random.Next(0, 2));
|
||||
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
color = dialog.Color;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
dopColor = dialog.Color;
|
||||
_drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Horns_1,Horns_2, pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
|
||||
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningLocomotive.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningLocomotive.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningLocomotive.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningLocomotive.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToRightCorner(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectLocomotive(_drawningLocomotive), pictureBoxElectroLocomotiv.Width,
|
||||
pictureBoxElectroLocomotiv.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedLocomotive = _drawningLocomotive;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,4 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
234
ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.resx
Normal file
234
ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.resx
Normal file
@ -0,0 +1,234 @@
|
||||
<?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>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAAX1JREFUaEPt
|
||||
2T0rhXEcxvHjqbwGg+IVyMxIJpOyGEweFpPYZbBQMpmYFEViZGWR1yJi8Ox71bnr390lHbq5f/l/61P6
|
||||
36dzX4fOGZxGLpfL5epaL+Ywix4dRGocd3hvusEYQjSJJxTjC4+YQK2bwjPK4wsvmEYtm8cr3PDUGxZQ
|
||||
q5bhxn5GL2IRtajV8ak1/FltWIcb1oot6Ll+Nd1QN3aDvmMb7fiVOrALN+Qn9tCJStMNDuEGFM7NWeHM
|
||||
nKX03PoFVdZXb9hTdJfOUrp2UjorW0JlXcLdVA7QBeWui9Jj9uGuywUq6xjupnpPpH969xgp0mN34B5z
|
||||
hMoaxAPSG+rTqPwJkl5PpemTbBPp9XsMoNL6sQrdfFQHpnRUyjWCDaygTwd1yI2XMLnxEiY3XsLkxkuY
|
||||
3HgJkxsvYXLjJUxuvITJjZcwufESJjdewuTGS5jceAmTGy9hcv9e1FmYrlF+AVcI0zBuUYzXz0MIlb7U
|
||||
mGkK9wVHLpfL/YsajQ+TA0YtgOqCtwAAAABJRU5ErkJggg==
|
||||
</value>
|
||||
</data>
|
||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
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
|
||||
Lfof8qiDQ1mFN78AAAAASUVORK5CYII=
|
||||
</value>
|
||||
</data>
|
||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
|
||||
DAAACwwBP0AiyAAAASRJREFUaEPtmL0KwjAURiv4AK6Co6KCoDgr/ryKvoSb7+Tk4mu46CIiooKDOut3
|
||||
ay+EklQXexO5Bw4kaYac0hYxUhR/qcJNIo2DYwafiTQOjjnkABoHhwZIowHSaIA0GiCNBkijAdJogDQa
|
||||
II0GSKMB0miANBogjQb8khKcwkY8s/NtQBlOYCWe5cQC0sHucEALFr4JqMM9pD1rWsiLFeTDuSI+BTTh
|
||||
AfKeHcwN+r+f7xxpi8gKaMEj5Os32IO5UoNmxAOOIeMKaMMT5GsUP4QiZEXYAjrwDM39YodnXBHpgC68
|
||||
GGu0bwS9IB1Bj8XSmNNX62rM6ZnvQ69IR7j06s6n+RTh9eEZV0QQh2dsL3Ywh2coYgvpy+P6ueE9BVh8
|
||||
D5V/JIpe+j/GQF3wLqYAAAAASUVORK5CYII=
|
||||
</value>
|
||||
</data>
|
||||
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAAMNJREFUaEPt
|
||||
1T0OAVEUhuGbWAYW4GcBGksgbIZSSWxKBDugwgZmBWh4T6K4ubmmUMg98T3J20wyyXeamSAiIiIi/6VN
|
||||
ezpR1x54YuMv9Hy3JjfS8Q8akgu58RNyoUWux59J438tN35KLrge36R4vLWheSHNqE8fbSkeX2IVNShr
|
||||
R7mXSqr2APthXSl+4UCrQlpQj2qlf907jcgVHVEKHVGK3BFjcsWOiD+xNxqQK+kRS3LHjrA/9pE69kBE
|
||||
RERE5AshvACI8cWowOkNEgAAAABJRU5ErkJggg==
|
||||
</value>
|
||||
</data>
|
||||
</root>
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ElectricLocomotive.Entities;
|
||||
|
||||
namespace ElectricLocomotive.Entities
|
||||
{
|
||||
public class EntityElectroLocomotive : EntityLocomotive
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public bool Horns_1 { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) roga
|
||||
/// </summary>
|
||||
///
|
||||
public bool Horns_2 { get; private set; }
|
||||
|
||||
public EntityElectroLocomotive(int Speed, double weight, Color bodyColor, Color additionalColor, bool horns_1, bool horns_2) : base(Speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Horns_1 = horns_1;
|
||||
Horns_2 = horns_2;
|
||||
}
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
44
ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
Normal file
44
ElectricLocomotive/ElectricLocomotive/EntityLocomotive.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive.Entities
|
||||
{
|
||||
public class EntityLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityLocomotive(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
66
ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs
Normal file
66
ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using ElectricLocomotive;
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using ElectricLocomotive.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.DrawingObjects
|
||||
{
|
||||
public static class ExtentionLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningLocomotive? CreateDrawningLocomotive(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningLocomotive(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawningElectricLocomotive(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningCar">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningLocomotive drawningCar, char separatorForObject)
|
||||
{
|
||||
var loco = drawningCar.EntityLocomotive;
|
||||
if (loco == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str =
|
||||
$"{loco.Speed}{separatorForObject}{loco.Weight}{separatorForObject}{loco.BodyColor.Name}";
|
||||
if (loco is not EntityElectroLocomotive electricLocomotive)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{electricLocomotive.AdditionalColor.Name}{separatorForObject}{electricLocomotive.Horns_1}{separatorForObject}{electricLocomotive.Horns_2}";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
250
ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
250
ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
@ -0,0 +1,250 @@
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
partial class FormLocomotiveCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLocomotiveCollection));
|
||||
CollectionPictureBox = new PictureBox();
|
||||
ToolsBox = new GroupBox();
|
||||
NaborGroupBox = new GroupBox();
|
||||
ButtomRemoveNabor = new Button();
|
||||
listBoxStorage = new ListBox();
|
||||
AddNabor = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
Input = new TextBox();
|
||||
RefreshCollection = new Button();
|
||||
DelLocomotive = new Button();
|
||||
AddLocomotive = new Button();
|
||||
menuStrip = new MenuStrip();
|
||||
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)CollectionPictureBox).BeginInit();
|
||||
ToolsBox.SuspendLayout();
|
||||
NaborGroupBox.SuspendLayout();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// CollectionPictureBox
|
||||
//
|
||||
CollectionPictureBox.Location = new Point(3, 34);
|
||||
CollectionPictureBox.Name = "CollectionPictureBox";
|
||||
CollectionPictureBox.Size = new Size(696, 496);
|
||||
CollectionPictureBox.TabIndex = 0;
|
||||
CollectionPictureBox.TabStop = false;
|
||||
//
|
||||
// ToolsBox
|
||||
//
|
||||
ToolsBox.Controls.Add(NaborGroupBox);
|
||||
ToolsBox.Controls.Add(Input);
|
||||
ToolsBox.Controls.Add(RefreshCollection);
|
||||
ToolsBox.Controls.Add(DelLocomotive);
|
||||
ToolsBox.Controls.Add(AddLocomotive);
|
||||
ToolsBox.Location = new Point(705, 34);
|
||||
ToolsBox.Name = "ToolsBox";
|
||||
ToolsBox.Size = new Size(200, 496);
|
||||
ToolsBox.TabIndex = 1;
|
||||
ToolsBox.TabStop = false;
|
||||
ToolsBox.Text = "Инструменты";
|
||||
//
|
||||
// NaborGroupBox
|
||||
//
|
||||
NaborGroupBox.Controls.Add(ButtomRemoveNabor);
|
||||
NaborGroupBox.Controls.Add(listBoxStorage);
|
||||
NaborGroupBox.Controls.Add(AddNabor);
|
||||
NaborGroupBox.Controls.Add(textBoxStorageName);
|
||||
NaborGroupBox.Location = new Point(7, 22);
|
||||
NaborGroupBox.Name = "NaborGroupBox";
|
||||
NaborGroupBox.Size = new Size(185, 280);
|
||||
NaborGroupBox.TabIndex = 4;
|
||||
NaborGroupBox.TabStop = false;
|
||||
NaborGroupBox.Text = "Наборы";
|
||||
//
|
||||
// ButtomRemoveNabor
|
||||
//
|
||||
ButtomRemoveNabor.Location = new Point(6, 221);
|
||||
ButtomRemoveNabor.Name = "ButtomRemoveNabor";
|
||||
ButtomRemoveNabor.Size = new Size(173, 48);
|
||||
ButtomRemoveNabor.TabIndex = 3;
|
||||
ButtomRemoveNabor.Text = "Удалить набор";
|
||||
ButtomRemoveNabor.UseVisualStyleBackColor = true;
|
||||
ButtomRemoveNabor.Click += ButtonRemoveObject_Click;
|
||||
//
|
||||
// listBoxStorage
|
||||
//
|
||||
listBoxStorage.FormattingEnabled = true;
|
||||
listBoxStorage.ItemHeight = 15;
|
||||
listBoxStorage.Location = new Point(6, 112);
|
||||
listBoxStorage.Name = "listBoxStorage";
|
||||
listBoxStorage.Size = new Size(173, 94);
|
||||
listBoxStorage.TabIndex = 2;
|
||||
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||
//
|
||||
// AddNabor
|
||||
//
|
||||
AddNabor.Location = new Point(6, 63);
|
||||
AddNabor.Name = "AddNabor";
|
||||
AddNabor.Size = new Size(173, 43);
|
||||
AddNabor.TabIndex = 1;
|
||||
AddNabor.Text = "Добавить набор";
|
||||
AddNabor.UseVisualStyleBackColor = true;
|
||||
AddNabor.Click += ButtonAddObject_Click;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(6, 34);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(173, 23);
|
||||
textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// Input
|
||||
//
|
||||
Input.Location = new Point(7, 360);
|
||||
Input.Name = "Input";
|
||||
Input.Size = new Size(186, 23);
|
||||
Input.TabIndex = 3;
|
||||
//
|
||||
// RefreshCollection
|
||||
//
|
||||
RefreshCollection.Location = new Point(7, 441);
|
||||
RefreshCollection.Name = "RefreshCollection";
|
||||
RefreshCollection.Size = new Size(187, 46);
|
||||
RefreshCollection.TabIndex = 2;
|
||||
RefreshCollection.Text = "Обновить все";
|
||||
RefreshCollection.UseVisualStyleBackColor = true;
|
||||
RefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// DelLocomotive
|
||||
//
|
||||
DelLocomotive.Location = new Point(7, 389);
|
||||
DelLocomotive.Name = "DelLocomotive";
|
||||
DelLocomotive.Size = new Size(187, 46);
|
||||
DelLocomotive.TabIndex = 1;
|
||||
DelLocomotive.Text = "Удалить локомотив";
|
||||
DelLocomotive.UseVisualStyleBackColor = true;
|
||||
DelLocomotive.Click += ButtonRemoveLocomotive_Click;
|
||||
//
|
||||
// AddLocomotive
|
||||
//
|
||||
AddLocomotive.Location = new Point(7, 308);
|
||||
AddLocomotive.Name = "AddLocomotive";
|
||||
AddLocomotive.Size = new Size(187, 46);
|
||||
AddLocomotive.TabIndex = 0;
|
||||
AddLocomotive.Text = "Добавить локомотив";
|
||||
AddLocomotive.UseVisualStyleBackColor = true;
|
||||
AddLocomotive.Click += ButtonAddLocomotive_Click;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.BackColor = SystemColors.ButtonFace;
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(914, 24);
|
||||
menuStrip.TabIndex = 3;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { LoadToolStripMenuItem, SaveToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(48, 20);
|
||||
файлToolStripMenuItem.Text = "&Файл";
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Image = (Image)resources.GetObject("LoadToolStripMenuItem.Image");
|
||||
LoadToolStripMenuItem.ImageTransparentColor = Color.Magenta;
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(141, 22);
|
||||
LoadToolStripMenuItem.Text = "Загрузка";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Image = (Image)resources.GetObject("SaveToolStripMenuItem.Image");
|
||||
SaveToolStripMenuItem.ImageTransparentColor = Color.Magenta;
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(141, 22);
|
||||
SaveToolStripMenuItem.Text = "Сохранение";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog1";
|
||||
//
|
||||
// FormLocomotiveCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 537);
|
||||
Controls.Add(menuStrip);
|
||||
Controls.Add(ToolsBox);
|
||||
Controls.Add(CollectionPictureBox);
|
||||
Name = "FormLocomotiveCollection";
|
||||
Text = "Коллекция";
|
||||
MainMenuStrip = menuStrip;
|
||||
((System.ComponentModel.ISupportInitialize)CollectionPictureBox).EndInit();
|
||||
ToolsBox.ResumeLayout(false);
|
||||
ToolsBox.PerformLayout();
|
||||
NaborGroupBox.ResumeLayout(false);
|
||||
NaborGroupBox.PerformLayout();
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox CollectionPictureBox;
|
||||
private GroupBox ToolsBox;
|
||||
private TextBox Input;
|
||||
private Button RefreshCollection;
|
||||
private Button DelLocomotive;
|
||||
private Button AddLocomotive;
|
||||
private GroupBox NaborGroupBox;
|
||||
private Button AddNabor;
|
||||
private TextBox textBoxStorageName;
|
||||
private Button ButtomRemoveNabor;
|
||||
private ListBox listBoxStorage;
|
||||
private MenuStrip menuStrip;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private GroupBox groupBoxMenu;
|
||||
}
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using ElectricLocomotive.Generics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public partial class FormLocomotiveCollection : Form
|
||||
{
|
||||
|
||||
private readonly LocomotiveGenericStorage _storage;
|
||||
public FormLocomotiveCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new LocomotiveGenericStorage(CollectionPictureBox.Width, CollectionPictureBox.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorage.SelectedIndex;
|
||||
|
||||
listBoxStorage.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorage.Items.Count > 0 && (index == -1 || index >= listBoxStorage.Items.Count))
|
||||
{
|
||||
listBoxStorage.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorage.Items.Count > 0 && index > -1 && index < listBoxStorage.Items.Count)
|
||||
{
|
||||
listBoxStorage.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
private void listBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
CollectionPictureBox.Image = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowLocomotives();
|
||||
}
|
||||
|
||||
private void ButtonRemoveObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorage.SelectedItem.ToString() ?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formLocomotiveConfig = new FormLocomotiveConfig();
|
||||
formLocomotiveConfig.AddEvent(NAddLocomotive);
|
||||
formLocomotiveConfig.Show();
|
||||
}
|
||||
public void NAddLocomotive(DrawningLocomotive loco)
|
||||
{
|
||||
loco._pictureWidth = CollectionPictureBox.Width;
|
||||
loco._pictureHeight = CollectionPictureBox.Height;
|
||||
|
||||
if (listBoxStorage.SelectedIndex == -1) return;
|
||||
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//проверяем, удалось ли нам загрузить объект
|
||||
if (obj + loco > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
CollectionPictureBox.Image = obj.ShowLocomotives();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1) return;
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(Input.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
CollectionPictureBox.Image = obj.ShowLocomotives();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorage.SelectedIndex == -1) return;
|
||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CollectionPictureBox.Image = obj.ShowLocomotives();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно!",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Ошибка сохранения!", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Загрузка завершена!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Ошибка загрузки!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
<?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>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>19, 13</value>
|
||||
</metadata>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="LoadToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFUSURBVDhPlZK9SgNBFIXnCcQnkLyA4CPkHayFdBY22mqj
|
||||
paVlxCKCoBaClUQLESNRC4OE4EKQrAbcYBKy62Z/ynHOzUwcMzuyDhzYGc795tw7y2ZXFEVLSZI8p2la
|
||||
kkf5lywO1vZr/MH54LkhwlgQKsZxvC4AfHHjjM+tHOaDiKIKiqDqk0s6rbUJoCDCsy3t5kJh+bJFZrZ8
|
||||
YGhh9ZjgSIeUUgVZPgHot2HfGwbTNu4aTf75UuW+50wVhSMAKwRwugO6aevokYohfQbDzj1/vdj8pffb
|
||||
PfJREpUAEPSOvXoFBdSFBIDgmxIgTr3lEkRPYZMOwDwYDtzrXToATPVp06B9QwB8o4YAipjVr02dqx0T
|
||||
gOHMGm3qNc8nL6EAX33XMP2l8cj7mQEOvMaJYbKpWy/zMAzf6BVE9ADF6CnLnCXMCn8mAUSMEiCYwX/k
|
||||
+/48Y4x9AwxhsnXBwZZBAAAAAElFTkSuQmCC
|
||||
</value>
|
||||
</data>
|
||||
<data name="SaveToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABzSURBVDhPY/j69WvDt2/f/pODQXoZQIyYCfv+MwTPIQmD
|
||||
9ID0gg3ApoAYjGHAh/cficLD2QBS8SA1AJufkTGyWtoagM5HFwdhmAEfkPMCukJkzcjiIAw24MuXLwbI
|
||||
hqArRNaMLA7CYANAAGYISIA0/O0/AID67ECmnhNDAAAAAElFTkSuQmCC
|
||||
</value>
|
||||
</data>
|
||||
</root>
|
369
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
369
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs
generated
Normal file
@ -0,0 +1,369 @@
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
partial class FormLocomotiveConfig
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxConfig = new GroupBox();
|
||||
labelAdvancedObject = new Label();
|
||||
labelSimpleObject = new Label();
|
||||
groupBoxColors = new GroupBox();
|
||||
panelColorPurple = new Panel();
|
||||
panelColorBlack = new Panel();
|
||||
panelColorGray = new Panel();
|
||||
panelColorWhite = new Panel();
|
||||
panelColorYellow = new Panel();
|
||||
panelColorBlue = new Panel();
|
||||
panelColorGreen = new Panel();
|
||||
panelColorRed = new Panel();
|
||||
checkBoxPantograph_1 = new CheckBox();
|
||||
numericUpDownWeight = new NumericUpDown();
|
||||
numericUpDownSpeed = new NumericUpDown();
|
||||
labelWeight = new Label();
|
||||
labelSpeed = new Label();
|
||||
pictureBoxLoco = new PictureBox();
|
||||
panelWithPictureBox = new Panel();
|
||||
labelAdvancedColor = new Label();
|
||||
labelSimpleColor = new Label();
|
||||
buttonAddObject = new Button();
|
||||
buttonCancelObject = new Button();
|
||||
checkBoxPantograph_2 = new CheckBox();
|
||||
groupBoxConfig.SuspendLayout();
|
||||
groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxLoco).BeginInit();
|
||||
panelWithPictureBox.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxConfig
|
||||
//
|
||||
groupBoxConfig.Controls.Add(checkBoxPantograph_2);
|
||||
groupBoxConfig.Controls.Add(labelAdvancedObject);
|
||||
groupBoxConfig.Controls.Add(labelSimpleObject);
|
||||
groupBoxConfig.Controls.Add(groupBoxColors);
|
||||
groupBoxConfig.Controls.Add(checkBoxPantograph_1);
|
||||
groupBoxConfig.Controls.Add(numericUpDownWeight);
|
||||
groupBoxConfig.Controls.Add(numericUpDownSpeed);
|
||||
groupBoxConfig.Controls.Add(labelWeight);
|
||||
groupBoxConfig.Controls.Add(labelSpeed);
|
||||
groupBoxConfig.Location = new Point(2, 4);
|
||||
groupBoxConfig.Name = "groupBoxConfig";
|
||||
groupBoxConfig.Size = new Size(474, 255);
|
||||
groupBoxConfig.TabIndex = 0;
|
||||
groupBoxConfig.TabStop = false;
|
||||
groupBoxConfig.Text = "Параметры";
|
||||
//
|
||||
// labelAdvancedObject
|
||||
//
|
||||
labelAdvancedObject.AllowDrop = true;
|
||||
labelAdvancedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdvancedObject.Location = new Point(324, 175);
|
||||
labelAdvancedObject.Name = "labelAdvancedObject";
|
||||
labelAdvancedObject.Size = new Size(119, 51);
|
||||
labelAdvancedObject.TabIndex = 9;
|
||||
labelAdvancedObject.Text = "Продвинутый";
|
||||
labelAdvancedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAdvancedObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
labelSimpleObject.AllowDrop = true;
|
||||
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimpleObject.Location = new Point(181, 174);
|
||||
labelSimpleObject.Name = "labelSimpleObject";
|
||||
labelSimpleObject.Size = new Size(119, 51);
|
||||
labelSimpleObject.TabIndex = 8;
|
||||
labelSimpleObject.Text = "Простой";
|
||||
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
groupBoxColors.Controls.Add(panelColorPurple);
|
||||
groupBoxColors.Controls.Add(panelColorBlack);
|
||||
groupBoxColors.Controls.Add(panelColorGray);
|
||||
groupBoxColors.Controls.Add(panelColorWhite);
|
||||
groupBoxColors.Controls.Add(panelColorYellow);
|
||||
groupBoxColors.Controls.Add(panelColorBlue);
|
||||
groupBoxColors.Controls.Add(panelColorGreen);
|
||||
groupBoxColors.Controls.Add(panelColorRed);
|
||||
groupBoxColors.Location = new Point(181, 18);
|
||||
groupBoxColors.Name = "groupBoxColors";
|
||||
groupBoxColors.Size = new Size(287, 150);
|
||||
groupBoxColors.TabIndex = 7;
|
||||
groupBoxColors.TabStop = false;
|
||||
groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelColorPurple
|
||||
//
|
||||
panelColorPurple.AllowDrop = true;
|
||||
panelColorPurple.BackColor = Color.Purple;
|
||||
panelColorPurple.Location = new Point(199, 84);
|
||||
panelColorPurple.Name = "panelColorPurple";
|
||||
panelColorPurple.Size = new Size(50, 50);
|
||||
panelColorPurple.TabIndex = 7;
|
||||
//
|
||||
// panelColorBlack
|
||||
//
|
||||
panelColorBlack.AllowDrop = true;
|
||||
panelColorBlack.BackColor = Color.Black;
|
||||
panelColorBlack.Location = new Point(143, 84);
|
||||
panelColorBlack.Name = "panelColorBlack";
|
||||
panelColorBlack.Size = new Size(50, 50);
|
||||
panelColorBlack.TabIndex = 6;
|
||||
//
|
||||
// panelColorGray
|
||||
//
|
||||
panelColorGray.AllowDrop = true;
|
||||
panelColorGray.BackColor = Color.Silver;
|
||||
panelColorGray.Location = new Point(87, 84);
|
||||
panelColorGray.Name = "panelColorGray";
|
||||
panelColorGray.Size = new Size(50, 50);
|
||||
panelColorGray.TabIndex = 5;
|
||||
//
|
||||
// panelColorWhite
|
||||
//
|
||||
panelColorWhite.AllowDrop = true;
|
||||
panelColorWhite.BackColor = Color.White;
|
||||
panelColorWhite.Location = new Point(31, 84);
|
||||
panelColorWhite.Name = "panelColorWhite";
|
||||
panelColorWhite.Size = new Size(50, 50);
|
||||
panelColorWhite.TabIndex = 4;
|
||||
//
|
||||
// panelColorYellow
|
||||
//
|
||||
panelColorYellow.AllowDrop = true;
|
||||
panelColorYellow.BackColor = Color.Yellow;
|
||||
panelColorYellow.Location = new Point(199, 28);
|
||||
panelColorYellow.Name = "panelColorYellow";
|
||||
panelColorYellow.Size = new Size(50, 50);
|
||||
panelColorYellow.TabIndex = 3;
|
||||
//
|
||||
// panelColorBlue
|
||||
//
|
||||
panelColorBlue.AllowDrop = true;
|
||||
panelColorBlue.BackColor = Color.Blue;
|
||||
panelColorBlue.Location = new Point(143, 28);
|
||||
panelColorBlue.Name = "panelColorBlue";
|
||||
panelColorBlue.Size = new Size(50, 50);
|
||||
panelColorBlue.TabIndex = 2;
|
||||
//
|
||||
// panelColorGreen
|
||||
//
|
||||
panelColorGreen.AllowDrop = true;
|
||||
panelColorGreen.BackColor = Color.FromArgb(0, 192, 0);
|
||||
panelColorGreen.Location = new Point(87, 28);
|
||||
panelColorGreen.Name = "panelColorGreen";
|
||||
panelColorGreen.Size = new Size(50, 50);
|
||||
panelColorGreen.TabIndex = 1;
|
||||
//
|
||||
// panelColorRed
|
||||
//
|
||||
panelColorRed.AllowDrop = true;
|
||||
panelColorRed.BackColor = Color.Red;
|
||||
panelColorRed.Location = new Point(31, 28);
|
||||
panelColorRed.Name = "panelColorRed";
|
||||
panelColorRed.Size = new Size(50, 50);
|
||||
panelColorRed.TabIndex = 0;
|
||||
panelColorRed.MouseDown += PanelColor_MouseDown;
|
||||
//
|
||||
// checkBoxPantograph_1
|
||||
//
|
||||
checkBoxPantograph_1.AutoSize = true;
|
||||
checkBoxPantograph_1.Location = new Point(10, 124);
|
||||
checkBoxPantograph_1.Name = "checkBoxPantograph_1";
|
||||
checkBoxPantograph_1.Size = new Size(154, 19);
|
||||
checkBoxPantograph_1.TabIndex = 4;
|
||||
checkBoxPantograph_1.Text = "Первый токоприемник";
|
||||
checkBoxPantograph_1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(10, 95);
|
||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(120, 23);
|
||||
numericUpDownWeight.TabIndex = 3;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(10, 51);
|
||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(120, 23);
|
||||
numericUpDownSpeed.TabIndex = 2;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
labelWeight.AutoSize = true;
|
||||
labelWeight.Location = new Point(10, 77);
|
||||
labelWeight.Name = "labelWeight";
|
||||
labelWeight.Size = new Size(26, 15);
|
||||
labelWeight.TabIndex = 1;
|
||||
labelWeight.Text = "Вес";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
labelSpeed.AutoSize = true;
|
||||
labelSpeed.Location = new Point(10, 33);
|
||||
labelSpeed.Name = "labelSpeed";
|
||||
labelSpeed.Size = new Size(59, 15);
|
||||
labelSpeed.TabIndex = 0;
|
||||
labelSpeed.Text = "Скорость";
|
||||
//
|
||||
// pictureBoxLoco
|
||||
//
|
||||
pictureBoxLoco.Location = new Point(14, 38);
|
||||
pictureBoxLoco.Name = "pictureBoxLoco";
|
||||
pictureBoxLoco.Size = new Size(284, 147);
|
||||
pictureBoxLoco.TabIndex = 1;
|
||||
pictureBoxLoco.TabStop = false;
|
||||
//
|
||||
// panelWithPictureBox
|
||||
//
|
||||
panelWithPictureBox.AllowDrop = true;
|
||||
panelWithPictureBox.Controls.Add(labelAdvancedColor);
|
||||
panelWithPictureBox.Controls.Add(labelSimpleColor);
|
||||
panelWithPictureBox.Controls.Add(pictureBoxLoco);
|
||||
panelWithPictureBox.Location = new Point(482, 12);
|
||||
panelWithPictureBox.Name = "panelWithPictureBox";
|
||||
panelWithPictureBox.Size = new Size(316, 195);
|
||||
panelWithPictureBox.TabIndex = 1;
|
||||
panelWithPictureBox.DragDrop += PanelObject_DragDrop;
|
||||
panelWithPictureBox.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// labelAdvancedColor
|
||||
//
|
||||
labelAdvancedColor.AllowDrop = true;
|
||||
labelAdvancedColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdvancedColor.Location = new Point(159, 10);
|
||||
labelAdvancedColor.Name = "labelAdvancedColor";
|
||||
labelAdvancedColor.Size = new Size(139, 23);
|
||||
labelAdvancedColor.TabIndex = 3;
|
||||
labelAdvancedColor.Text = "Доп. Цвет";
|
||||
labelAdvancedColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAdvancedColor.DragDrop += LabelColor_DragDrop;
|
||||
labelAdvancedColor.DragEnter += LabelColor_DragDrop;
|
||||
//
|
||||
// labelSimpleColor
|
||||
//
|
||||
labelSimpleColor.AllowDrop = true;
|
||||
labelSimpleColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimpleColor.Location = new Point(14, 10);
|
||||
labelSimpleColor.Name = "labelSimpleColor";
|
||||
labelSimpleColor.Size = new Size(139, 23);
|
||||
labelSimpleColor.TabIndex = 2;
|
||||
labelSimpleColor.Text = "Цвет";
|
||||
labelSimpleColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelSimpleColor.DragDrop += LabelColor_DragDrop;
|
||||
labelSimpleColor.DragEnter += LabelColor_DragDrop;
|
||||
//
|
||||
// buttonAddObject
|
||||
//
|
||||
buttonAddObject.Location = new Point(496, 213);
|
||||
buttonAddObject.Name = "buttonAddObject";
|
||||
buttonAddObject.Size = new Size(139, 41);
|
||||
buttonAddObject.TabIndex = 3;
|
||||
buttonAddObject.Text = "Добавить";
|
||||
buttonAddObject.UseVisualStyleBackColor = true;
|
||||
buttonAddObject.Click += buttonAddObject_Click;
|
||||
//
|
||||
// buttonCancelObject
|
||||
//
|
||||
buttonCancelObject.Location = new Point(641, 213);
|
||||
buttonCancelObject.Name = "buttonCancelObject";
|
||||
buttonCancelObject.Size = new Size(139, 41);
|
||||
buttonCancelObject.TabIndex = 4;
|
||||
buttonCancelObject.Text = "Отмена";
|
||||
buttonCancelObject.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxPantograph_2
|
||||
//
|
||||
checkBoxPantograph_2.AutoSize = true;
|
||||
checkBoxPantograph_2.Location = new Point(10, 149);
|
||||
checkBoxPantograph_2.Name = "checkBoxPantograph_2";
|
||||
checkBoxPantograph_2.Size = new Size(150, 19);
|
||||
checkBoxPantograph_2.TabIndex = 10;
|
||||
checkBoxPantograph_2.Text = "Второй токоприемник";
|
||||
checkBoxPantograph_2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormLocomotiveConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 266);
|
||||
Controls.Add(buttonCancelObject);
|
||||
Controls.Add(buttonAddObject);
|
||||
Controls.Add(panelWithPictureBox);
|
||||
Controls.Add(groupBoxConfig);
|
||||
Name = "FormLocomotiveConfig";
|
||||
Text = "FormLocomotiveConfig";
|
||||
groupBoxConfig.ResumeLayout(false);
|
||||
groupBoxConfig.PerformLayout();
|
||||
groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxLoco).EndInit();
|
||||
panelWithPictureBox.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxConfig;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private CheckBox checkBox3;
|
||||
private CheckBox checkBox2;
|
||||
private CheckBox checkBoxPantograph_1;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private GroupBox groupBoxColors;
|
||||
private Panel panelColorYellow;
|
||||
private Panel panelColorBlue;
|
||||
private Panel panelColorGreen;
|
||||
private Panel panelColorRed;
|
||||
private Panel panelColorPurple;
|
||||
private Panel panelColorBlack;
|
||||
private Panel panelColorGray;
|
||||
private Panel panelColorWhite;
|
||||
private Label labelAdvancedObject;
|
||||
private Label labelSimpleObject;
|
||||
private PictureBox pictureBoxLoco;
|
||||
private Panel panelWithPictureBox;
|
||||
private Label labelAdvancedColor;
|
||||
private Label labelSimpleColor;
|
||||
private Button buttonAddObject;
|
||||
private Button buttonCancelObject;
|
||||
private CheckBox checkBoxPantograph_2;
|
||||
}
|
||||
}
|
130
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
Normal file
130
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using Microsoft.VisualBasic.Devices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public partial class FormLocomotiveConfig : Form
|
||||
{
|
||||
DrawningLocomotive? _locomotive = null;
|
||||
private event Action<DrawningLocomotive>? EventAddLocomotive;
|
||||
|
||||
public FormLocomotiveConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelColorBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelColorPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelColorGray.MouseDown += PanelColor_MouseDown;
|
||||
panelColorGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelColorRed.MouseDown += PanelColor_MouseDown;
|
||||
panelColorWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelColorYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelColorBlue.MouseDown += PanelColor_MouseDown;
|
||||
|
||||
buttonCancelObject.Click += (s, e) => Close();
|
||||
|
||||
}
|
||||
public void AddEvent(Action<DrawningLocomotive> ev)
|
||||
{
|
||||
if (EventAddLocomotive == null)
|
||||
{
|
||||
EventAddLocomotive = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddLocomotive += ev;
|
||||
}
|
||||
}
|
||||
private void DrawLocomotive()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxLoco.Width, pictureBoxLoco.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_locomotive?.SetPosition(5, 5);
|
||||
_locomotive?.DrawTransport(gr);
|
||||
pictureBoxLoco.Image = bmp;
|
||||
}
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_locomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.Blue, pictureBoxLoco.Width,
|
||||
pictureBoxLoco.Height);
|
||||
break;
|
||||
case "labelAdvancedObject":
|
||||
_locomotive = new DrawningElectricLocomotive((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.Blue, Color.Red, checkBoxPantograph_1.Checked, checkBoxPantograph_2.Checked,
|
||||
pictureBoxLoco.Width, pictureBoxLoco.Height);
|
||||
break;
|
||||
}
|
||||
DrawLocomotive();
|
||||
}
|
||||
|
||||
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddLocomotive?.Invoke(_locomotive);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_locomotive == null)
|
||||
return;
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelSimpleColor":
|
||||
_locomotive.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAdvancedColor":
|
||||
if (!(_locomotive is DrawningElectricLocomotive))
|
||||
{
|
||||
return;
|
||||
}
|
||||
(_locomotive as DrawningElectricLocomotive).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawLocomotive();
|
||||
}
|
||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if ((e.Data?.GetDataPresent(typeof(Color)) ?? false))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.resx
Normal file
120
ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.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>
|
18
ElectricLocomotive/ElectricLocomotive/IMoveableObject.cs
Normal file
18
ElectricLocomotive/ElectricLocomotive/IMoveableObject.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
int GetStep { get; }
|
||||
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
@ -0,0 +1,191 @@
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using ProjectElectricLocomotive.DrawingObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive.Generics
|
||||
{
|
||||
internal class LocomotiveGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, LocomotivesGenericCollection<DrawningLocomotive, DrawningObjectLocomotive>> _locomotivesStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _locomotivesStorage.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public LocomotiveGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_locomotivesStorage = new Dictionary<string, LocomotivesGenericCollection<DrawningLocomotive, DrawningObjectLocomotive>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (!_locomotivesStorage.ContainsKey(name))
|
||||
{
|
||||
_locomotivesStorage.Add(name, new LocomotivesGenericCollection<DrawningLocomotive, DrawningObjectLocomotive>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_locomotivesStorage.ContainsKey(name))
|
||||
{
|
||||
_locomotivesStorage.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public LocomotivesGenericCollection<DrawningLocomotive, DrawningObjectLocomotive>?
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
if (_locomotivesStorage.ContainsKey(ind))
|
||||
{
|
||||
return _locomotivesStorage[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, LocomotivesGenericCollection<DrawningLocomotive, DrawningObjectLocomotive>> record in _locomotivesStorage)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningLocomotive? elem in record.Value.GetLocomotives)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using StreamWriter fs = new StreamWriter(filename);
|
||||
{
|
||||
fs.WriteLine($"LocomotiveStorage{Environment.NewLine}");
|
||||
fs.WriteLine(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по автомобилям в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
{
|
||||
|
||||
string str = fs.ReadLine();
|
||||
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!str.StartsWith("LocomotiveStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
}
|
||||
|
||||
_locomotivesStorage.Clear();
|
||||
string strs = "";
|
||||
|
||||
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
{
|
||||
|
||||
if (strs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
LocomotivesGenericCollection<DrawningLocomotive, DrawningObjectLocomotive> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawningLocomotive? loco = elem?.CreateDrawningLocomotive(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (loco != null)
|
||||
{
|
||||
if ((collection + loco) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_locomotivesStorage.Add(record[0], collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ElectricLocomotive.DrawningObject;
|
||||
using ElectricLocomotive.MovementStrategy;
|
||||
using ProjectElectricLocomotive.Generics;
|
||||
|
||||
namespace ElectricLocomotive.Generics
|
||||
{
|
||||
internal class LocomotivesGenericCollection<T, U>
|
||||
where T : DrawningLocomotive
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 200;
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public LocomotivesGenericCollection(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 +(LocomotivesGenericCollection<T, U> collect, T? loco)
|
||||
{
|
||||
if (loco == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(loco);
|
||||
}
|
||||
|
||||
|
||||
/// Перегрузка оператора вычитания
|
||||
public static T? operator -(LocomotivesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowLocomotives()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int HeightObjCount = _pictureHeight / _placeSizeHeight;
|
||||
int WidthObjCount = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
T? type = _collection[i];
|
||||
if (type != null)
|
||||
{
|
||||
type.SetPosition(
|
||||
(int)(i / HeightObjCount * _placeSizeWidth),
|
||||
(HeightObjCount - 1) * _placeSizeHeight - (int)(i % HeightObjCount * _placeSizeHeight));
|
||||
type?.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetLocomotives => _collection.GetLocomotives();
|
||||
}
|
||||
}
|
57
ElectricLocomotive/ElectricLocomotive/MoveToCenter.cs
Normal file
57
ElectricLocomotive/ElectricLocomotive/MoveToCenter.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using ElectricLocomotive.MovementStrategy;
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive.MovementStrategy
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
ElectricLocomotive/ElectricLocomotive/MoveToRightCorner.cs
Normal file
30
ElectricLocomotive/ElectricLocomotive/MoveToRightCorner.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive.MovementStrategy
|
||||
{
|
||||
public class MoveToRightCorner : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null) return false;
|
||||
|
||||
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null) return;
|
||||
|
||||
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
|
||||
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
27
ElectricLocomotive/ElectricLocomotive/ObjectParameters.cs
Normal file
27
ElectricLocomotive/ElectricLocomotive/ObjectParameters.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using ProjectElectricLocomotive;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,7 +13,7 @@ namespace ElectricLocomotive
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormLocomotiveCollection());
|
||||
}
|
||||
}
|
||||
}
|
63
ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs
generated
Normal file
63
ElectricLocomotive/ElectricLocomotive/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ElectricLocomotive.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ElectricLocomotive.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
65
ElectricLocomotive/ElectricLocomotive/SetGeneric.cs
Normal file
65
ElectricLocomotive/ElectricLocomotive/SetGeneric.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Generics
|
||||
{
|
||||
internal class SetGeneric<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 loco)
|
||||
{
|
||||
return Insert(loco, 0);
|
||||
}
|
||||
|
||||
public int Insert(T loco, int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount) return -1;
|
||||
_places.Insert(position, loco);
|
||||
return position;
|
||||
}
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
return null;
|
||||
|
||||
T? tmp = _places[position];
|
||||
_places[position] = null;
|
||||
return tmp;
|
||||
}
|
||||
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?> GetLocomotives(int? maxLocos = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxLocos.HasValue && i == maxLocos.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
ElectricLocomotive/ElectricLocomotive/Status.cs
Normal file
15
ElectricLocomotive/ElectricLocomotive/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 ElectricLocomotive.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user