Compare commits

...

11 Commits
main ... lab3

32 changed files with 1711 additions and 92 deletions

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
namespace ProjectElectricLocomotive.MovementStrategy
{
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; }
/// <param name="moveableObject">Перемещаемый объект</param>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
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(Direction.Left);
protected bool MoveRight() => MoveTo(Direction.Right);
protected bool MoveUp() => MoveTo(Direction.Up);
protected bool MoveDown() => MoveTo(Direction.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();
/// <param name="directionType">Направление</param>
private bool MoveTo(Direction directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View 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 Direction
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.Entities;
namespace ProjectElectricLocomotive.DrawingObjects
{
public class DrawingElectricLocomotive : DrawingLocomotive
{
public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor,
bool pantograph, bool compartment, int width, int height) : base(speed, weight, bodyColor, width, height, 80, 52)
{
if (EntityLocomotive != null)
{
EntityLocomotive = new EntityElectricLocomotive(speed, width, bodyColor, additionalColor, pantograph, compartment);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityLocomotive is not EntityElectricLocomotive electricLocomotive)
{
return;
}
Pen pen = new(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
Brush windows = new SolidBrush(Color.LightBlue);
Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor);
Brush bodyColor = new SolidBrush(electricLocomotive.BodyColor);
g.DrawRectangle(pen, _startPosX + 40, _startPosY + 24, 25, 11);
g.FillPolygon(additionalBrush, new Point[]
{
new Point(_startPosX + 61, _startPosY + 25),
new Point(_startPosX + 85, _startPosY + 25),
new Point(_startPosX + 85, _startPosY + 35),
new Point(_startPosX + 61, _startPosY + 35),
new Point(_startPosX + 61, _startPosY + 25),
}
);
g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5);
g.DrawLine(pen, _startPosX + 30, _startPosY + 15, _startPosX + 50, _startPosY + 2);
g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 60, _startPosY + 2);
base.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.Entities;
using ProjectElectricLocomotive.MovementStrategy;
using ProjectElectricLocomotive.Properties;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectElectricLocomotive.DrawingObjects
{
public class DrawingLocomotive
{
public EntityLocomotive? EntityLocomotive { get; protected set; }
protected int _pictureWidth;
protected int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _locomWidth = 80;
protected readonly int _locomHeight = 52;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _locomWidth;
public int GetHeight => _locomHeight;
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
{
if (width < _locomWidth || heigth < _locomHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = heigth;
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
protected DrawingLocomotive(int speed, double weight, Color bodyColor, int width,
int height, int locomWidth, int locomHeight)
{
if (width < _locomWidth || height < _locomHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_locomWidth = locomWidth;
_locomHeight = locomHeight;
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
public void SetPosition(int x, int y)
{
if (x < 0 || x + _locomWidth > _pictureWidth)
{
x = _pictureWidth - _locomWidth;
}
if (y < 0 || y + _locomHeight > _pictureHeight)
{
y = _pictureHeight - _locomHeight;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(Direction direction)
{
if (EntityLocomotive == null)
{
return;
}
switch (direction)
{
case Direction.Left:
if (_startPosX - EntityLocomotive.Step > 0)
{
_startPosX -= (int)EntityLocomotive.Step;
}
break;
case Direction.Up:
if (_startPosY - EntityLocomotive.Step > 0)
{
_startPosY -= (int)EntityLocomotive.Step;
}
break;
case Direction.Right:
if (_startPosX + EntityLocomotive.Step + _locomWidth < _pictureWidth)
{
_startPosX += (int)EntityLocomotive.Step;
}
break;
case Direction.Down:
if (_startPosY + EntityLocomotive.Step + _locomHeight < _pictureHeight)
{
_startPosY += (int)EntityLocomotive.Step;
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
{
if (EntityLocomotive == null) return;
}
Pen pen = new(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
Brush windows = new SolidBrush(Color.LightBlue);
Brush bodyColor = new SolidBrush(EntityLocomotive.BodyColor);
g.FillPolygon(bodyColor, new Point[]
{
new Point(_startPosX, _startPosY + 40),
new Point(_startPosX, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 20),
new Point(_startPosX + 70, _startPosY + 20),
new Point(_startPosX + 80, _startPosY + 20),
new Point(_startPosX + 80, _startPosY + 40),
new Point(_startPosX + 75, _startPosY + 45),
new Point(_startPosX + 5, _startPosY + 45),
new Point(_startPosX, _startPosY + 40),
}
);
g.DrawPolygon(pen, new Point[]
{
new Point(_startPosX, _startPosY + 40),
new Point(_startPosX, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 20),
new Point(_startPosX + 70, _startPosY + 20),
new Point(_startPosX + 80, _startPosY + 20),
new Point(_startPosX + 80, _startPosY + 40),
new Point(_startPosX + 75, _startPosY + 45),
new Point(_startPosX + 5, _startPosY + 45),
new Point(_startPosX, _startPosY + 40),
}
);
g.FillEllipse(windows, _startPosX + 10, _startPosY + 24, 10, 10);
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 25, 10, 10);
g.FillRectangle(windows, _startPosX + 25, _startPosY + 25, 10, 5);
g.DrawRectangle(pen, _startPosX + 25, _startPosY + 25, 10, 5);
g.FillEllipse(blackBrush, _startPosX + 10, _startPosY + 45, 10, 10);
g.FillEllipse(blackBrush, _startPosX + 25, _startPosY + 45, 10, 10);
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 45, 10, 10);
g.FillEllipse(blackBrush, _startPosX + 65, _startPosY + 45, 10, 10);
}
/// <param name="direction">Направление</param>
public bool CanMove(Direction direction)
{
if (EntityLocomotive == null)
{
return false;
}
return direction switch
{
//влево
Direction.Left => _startPosX - EntityLocomotive.Step > 0,
//вверх
Direction.Up => _startPosY - EntityLocomotive.Step > 0,
// вправо
Direction.Right => _startPosX + EntityLocomotive.Step < _pictureWidth,
//вниз
Direction.Down => _startPosY + EntityLocomotive.Step < _pictureHeight,
};
}
public IMoveableObject GetMoveableObject => new
DrawingObjectLocomotive(this);
}
}

View File

@ -0,0 +1,35 @@
using ProjectElectricLocomotive.DrawingObjects;
using ElectricLocomotive;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.MovementStrategy
{
public class DrawingObjectLocomotive : IMoveableObject
{
private readonly DrawingLocomotive? _drawingLocomotive = null;
public DrawingObjectLocomotive(DrawingLocomotive drawingLocomotive)
{
_drawingLocomotive = drawingLocomotive;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawingLocomotive == null || _drawingLocomotive.EntityLocomotive == null)
{
return null;
}
return new ObjectParameters(_drawingLocomotive.GetPosX,
_drawingLocomotive.GetPosY, _drawingLocomotive.GetWidth, _drawingLocomotive.GetHeight);
}
}
public int GetStep => (int)(_drawingLocomotive?.EntityLocomotive?.Step ?? 0);
public bool CheckCanMove(Direction direction) => _drawingLocomotive?.CanMove(direction) ?? false;
public void MoveObject(Direction direction) => _drawingLocomotive?.MoveTransport(direction);
}
}

View File

@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,27 @@
using ProjectElectricLocomotive.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.Entities
{
public class EntityElectricLocomotive : EntityLocomotive
{
public Color AdditionalColor { get; private set; }
public bool Pantograph { get; private set; }
public bool Compartment { get; private set; }
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pantograph">Признак наличия токоприемника</param>
/// <param name="compartment">Признак наличия отсеков под электрические батареи</param>
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph,
bool compartment) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Pantograph = pantograph;
Compartment = compartment;
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.Entities
{
public class EntityLocomotive
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
/// <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;
}
}
}

View File

@ -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
}
}

View File

@ -1,10 +0,0 @@
namespace ElectricLocomotive
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,211 @@
using System;
namespace ElectricLocomotive
{
partial class FormElectricLocomotive
{
/// <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()
{
pictureBoxElectricLocomotive = new PictureBox();
buttonCreateElectricLocomotive = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonDown = new Button();
comboBoxStrategy = new ComboBox();
buttonCreateLocomotive = new Button();
buttonStep = new Button();
button1 = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
SuspendLayout();
//
// pictureBoxElectricLocomotive
//
pictureBoxElectricLocomotive.Cursor = Cursors.No;
pictureBoxElectricLocomotive.Dock = DockStyle.Fill;
pictureBoxElectricLocomotive.Enabled = false;
pictureBoxElectricLocomotive.Location = new Point(0, 0);
pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive";
pictureBoxElectricLocomotive.Size = new Size(847, 441);
pictureBoxElectricLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxElectricLocomotive.TabIndex = 0;
pictureBoxElectricLocomotive.TabStop = false;
pictureBoxElectricLocomotive.Click += buttonMove_Click;
//
// buttonCreateElectricLocomotive
//
buttonCreateElectricLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateElectricLocomotive.Font = new Font("Calibri", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
buttonCreateElectricLocomotive.Location = new Point(11, 365);
buttonCreateElectricLocomotive.Margin = new Padding(2);
buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
buttonCreateElectricLocomotive.Size = new Size(134, 64);
buttonCreateElectricLocomotive.TabIndex = 1;
buttonCreateElectricLocomotive.Text = "Создать электролокомотив";
buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
buttonCreateElectricLocomotive.Click += buttonCreateElectricLocomotive_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_left_arrow_line_symbol_54321;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(733, 399);
buttonLeft.Margin = new Padding(2);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_up_arrow_angle_54817;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(767, 365);
buttonUp.Margin = new Padding(2);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_right_arrow_angle_54833;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(802, 399);
buttonRight.Margin = new Padding(2);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 4;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = ProjectElectricLocomotive.Properties.Resources.free_icon_down_arrow_54785;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(767, 399);
buttonDown.Margin = new Padding(2);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightEdge" });
comboBoxStrategy.Location = new Point(681, 7);
comboBoxStrategy.Margin = new Padding(2);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 23);
comboBoxStrategy.TabIndex = 6;
comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
//
// buttonCreateLocomotive
//
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateLocomotive.Font = new Font("Calibri", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
buttonCreateLocomotive.Location = new Point(149, 365);
buttonCreateLocomotive.Margin = new Padding(2);
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
buttonCreateLocomotive.Size = new Size(102, 65);
buttonCreateLocomotive.TabIndex = 7;
buttonCreateLocomotive.Text = "Создать локомотив";
buttonCreateLocomotive.UseVisualStyleBackColor = true;
buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
//
// buttonStep
//
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStep.Font = new Font("Calibri", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
buttonStep.Location = new Point(744, 34);
buttonStep.Margin = new Padding(2);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(88, 34);
buttonStep.TabIndex = 8;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStrategyStep_Click;
//
// button1
//
button1.Location = new Point(256, 365);
button1.Name = "button1";
button1.Size = new Size(206, 64);
button1.TabIndex = 9;
button1.Text = "Выбрать локомотив";
button1.UseVisualStyleBackColor = true;
button1.Click += ButtonSelectLocomotive_Click;
//
// FormElectricLocomotive
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(847, 441);
Controls.Add(button1);
Controls.Add(buttonStep);
Controls.Add(buttonCreateLocomotive);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonCreateElectricLocomotive);
Controls.Add(pictureBoxElectricLocomotive);
Margin = new Padding(2);
Name = "FormElectricLocomotive";
StartPosition = FormStartPosition.CenterScreen;
Text = "ElectricLocomotive";
Load += ElectricLocomotive_Load;
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox pictureBoxElectricLocomotive;
private Button buttonCreateElectricLocomotive;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
private ComboBox comboBoxStrategy;
private Button buttonCreateLocomotive;
private Button buttonStep;
private Button button1;
}
}

View File

@ -0,0 +1,143 @@
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
using ProjectElectricLocomotive;
using System;
namespace ElectricLocomotive
{
public partial class FormElectricLocomotive : Form
{
private DrawingLocomotive? _drawingLocomotive;
private AbstractStrategy? _abstractStrategy;
public DrawingLocomotive? SelectedLocomotive { get; private set; }
public FormElectricLocomotive()
{
InitializeComponent();
_abstractStrategy = null;
SelectedLocomotive = null;
}
private void Draw()
{
if (_drawingLocomotive == null)
{
return;
}
Bitmap bmp = new(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingLocomotive.DrawTransport(gr);
pictureBoxElectricLocomotive.Image = bmp;
}
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
{
Random random = new Random();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog colorDialog = new ColorDialog();
if (colorDialog.ShowDialog() == DialogResult.OK)
{
color = colorDialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
if (colorDialog.ShowDialog() == DialogResult.OK)
{
dopColor = colorDialog.Color;
}
_drawingLocomotive = new DrawingElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonCreateLocomotive_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;
}
_drawingLocomotive = new DrawingLocomotive(random.Next(100, 300),
random.Next(1000, 3000), color,
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingLocomotive == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingLocomotive.MoveTransport(Direction.Up);
break;
case "buttonDown":
_drawingLocomotive.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_drawingLocomotive.MoveTransport(Direction.Left);
break;
case "buttonRight":
_drawingLocomotive.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawingLocomotive == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToRightEdge(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawingObjectLocomotive(_drawingLocomotive), pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void pictureBoxElectricLocomotive_Click(object sender, EventArgs e)
{
}
private void ElectricLocomotive_Load(object sender, EventArgs e)
{
}
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
{
SelectedLocomotive = _drawingLocomotive;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,140 @@
namespace ProjectElectricLocomotive
{
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()
{
panelLocomotiveCollection = new Panel();
maskedTextBoxNumber = new MaskedTextBox();
ButtonRefreshCollection = new Button();
ButtonRemoveLocomotive = new Button();
ButtonAddLocomotive = new Button();
pictureBoxCollection = new PictureBox();
LabelOnPanel = new Label();
panelLocomotiveCollection.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// panelLocomotiveCollection
//
panelLocomotiveCollection.AccessibleDescription = "";
panelLocomotiveCollection.AccessibleName = "";
panelLocomotiveCollection.Controls.Add(LabelOnPanel);
panelLocomotiveCollection.Controls.Add(maskedTextBoxNumber);
panelLocomotiveCollection.Controls.Add(ButtonRefreshCollection);
panelLocomotiveCollection.Controls.Add(ButtonRemoveLocomotive);
panelLocomotiveCollection.Controls.Add(ButtonAddLocomotive);
panelLocomotiveCollection.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
panelLocomotiveCollection.Location = new Point(594, 2);
panelLocomotiveCollection.Name = "panelLocomotiveCollection";
panelLocomotiveCollection.Size = new Size(208, 448);
panelLocomotiveCollection.TabIndex = 0;
panelLocomotiveCollection.Tag = "Инструменты";
panelLocomotiveCollection.Paint += panelLocomotiveCollection_Paint;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(40, 74);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(123, 23);
maskedTextBoxNumber.TabIndex = 3;
//
// ButtonRefreshCollection
//
ButtonRefreshCollection.Location = new Point(3, 194);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(194, 43);
ButtonRefreshCollection.TabIndex = 2;
ButtonRefreshCollection.Text = " Обновить коллекцию";
ButtonRefreshCollection.UseVisualStyleBackColor = true;
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// ButtonRemoveLocomotive
//
ButtonRemoveLocomotive.Location = new Point(3, 138);
ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
ButtonRemoveLocomotive.Size = new Size(194, 39);
ButtonRemoveLocomotive.TabIndex = 1;
ButtonRemoveLocomotive.Text = "Удалить локомотив";
ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
ButtonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
//
// ButtonAddLocomotive
//
ButtonAddLocomotive.Location = new Point(3, 15);
ButtonAddLocomotive.Name = "ButtonAddLocomotive";
ButtonAddLocomotive.Size = new Size(194, 39);
ButtonAddLocomotive.TabIndex = 0;
ButtonAddLocomotive.Text = "Добавить локомотив";
ButtonAddLocomotive.UseVisualStyleBackColor = true;
ButtonAddLocomotive.Click += ButtonAddLocomotive_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(2, 2);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(589, 448);
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
//
// LabelOnPanel
//
LabelOnPanel.AutoSize = true;
LabelOnPanel.Location = new Point(3, -3);
LabelOnPanel.Name = "LabelOnPanel";
LabelOnPanel.Size = new Size(83, 15);
LabelOnPanel.TabIndex = 4;
LabelOnPanel.Text = "Инструменты";
LabelOnPanel.Click += LabelOnPanel_Click;
//
// FormLocomotiveCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(pictureBoxCollection);
Controls.Add(panelLocomotiveCollection);
Name = "FormLocomotiveCollection";
Text = "Набор локомотивов";
Load += FormLocomotiveCollection_Load;
panelLocomotiveCollection.ResumeLayout(false);
panelLocomotiveCollection.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panelLocomotiveCollection;
private Button ButtonAddLocomotive;
private Button ButtonRemoveLocomotive;
private Button ButtonRefreshCollection;
private PictureBox pictureBoxCollection;
private MaskedTextBox maskedTextBoxNumber;
private Label LabelOnPanel;
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.Generics;
using ProjectElectricLocomotive.MovementStrategy;
namespace ProjectElectricLocomotive
{
public partial class FormLocomotiveCollection : Form
{
private readonly LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
public FormLocomotiveCollection()
{
InitializeComponent();
_locomotives = new LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{
FormElectricLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_locomotives + form.SelectedLocomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_locomotives - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
}
private void FormLocomotiveCollection_Load(object sender, EventArgs e)
{
}
private void LabelOnPanel_Click(object sender, EventArgs e)
{
}
private void panelLocomotiveCollection_Paint(object sender, PaintEventArgs e)
{
}
}
}

View 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>

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
namespace ProjectElectricLocomotive.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
/// <param name="direction"></param>
bool CheckCanMove(Direction direction);
/// <param name="direction">Направление</param>
void MoveObject(Direction direction);
}
}

View File

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
namespace ProjectElectricLocomotive.Generics
{
internal class LocomotivesGenericCollection<T, U>
where T : DrawingLocomotive
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? locomotive)
{
if (locomotive == null)
{
return -1;
}
return collect?._collection.Insert(locomotive) ?? -1;
}
public static bool operator -(LocomotivesGenericCollection<T, U> collect, int pos)
{
T? locomotive = collect._collection.Get(pos);
if (locomotive != null)
return collect._collection.Remove(pos);
return false;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(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 HLoco = _pictureHeight / _placeSizeHeight;
int Wloco = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
{
T? type = _collection.Get(i);
if (type != null)
{
type.SetPosition(
(int)(i / HLoco * _placeSizeWidth),
(HLoco - 1) * _placeSizeHeight - (int)(i % HLoco * _placeSizeHeight)
);
type?.DrawTransport(g);
}
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.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();
}
}
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.MovementStrategy
{
public class MoveToRightEdge : 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();
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
/// <summary>
/// Верхняя граница
/// </summary>
public int TopBorder => _y;
/// <summary>
/// Правая граница
/// </summary>
public int RightBorder => _x + _width;
/// <summary>
/// Нижняя граница
/// </summary>
public int DownBorder => _y + _height;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleHorizontal => _x + _width / 2;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleVertical => _y + _height / 2;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -1,17 +1,15 @@
using ProjectElectricLocomotive;
using System.Drawing;
namespace ElectricLocomotive namespace ElectricLocomotive
{ {
internal static class Program internal static class Program
{ {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new FormLocomotiveCollection());
} }
} }
} }

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<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>

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectElectricLocomotive.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("ProjectElectricLocomotive.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;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap free_icon_down_arrow_54785 {
get {
object obj = ResourceManager.GetObject("free-icon-down-arrow-54785", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap free_icon_left_arrow_line_symbol_54321 {
get {
object obj = ResourceManager.GetObject("free-icon-left-arrow-line-symbol-54321", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap free_icon_right_arrow_angle_54833 {
get {
object obj = ResourceManager.GetObject("free-icon-right-arrow-angle-54833", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap free_icon_up_arrow_angle_54817 {
get {
object obj = ResourceManager.GetObject("free-icon-up-arrow-angle-54817", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?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.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="free-icon-left-arrow-line-symbol-54321" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\free-icon-left-arrow-line-symbol-54321.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="free-icon-down-arrow-54785" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\free-icon-down-arrow-54785.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="free-icon-up-arrow-angle-54817" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\free-icon-up-arrow-angle-54817.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="free-icon-right-arrow-angle-54833" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\free-icon-right-arrow-angle-54833.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View 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 T?[] _places;
public int Count => _places.Length;
public SetGeneric(int count)
{
_places = new T?[count];
}
public int Insert(T locomotive)
{
return Insert(locomotive, 0);
}
public int Insert(T locomotive, int position)
{
int Full = 0;
int temp = 0;
for (int i = position; i < Count; i++)
{
if (_places[i] != null) Full++;
}
if (Full == Count - position - 1)
return -1;
if (position < Count && position >= 0)
{
for (int j = position; j < Count; j++)
{
if (_places[j] == null)
{
temp = j;
break;
}
}
for (int i = temp; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = locomotive;
return position;
}
return -1;
}
public bool Remove(int position)
{
if (position >= Count || position < 0)
if (!(position >= 0 && position < Count) || _places[position] == null)
return false;
_places[position] = null;
return true;
}
public T Get(int position)
{
if (position < 0 || position >= Count) return null;
return _places[position];
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.MovementStrategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279 VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricLocomotive", "ElectricLocomotive\ElectricLocomotive.csproj", "{A7A62158-ECC2-48DA-81F7-565BB5CE1E0D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectElectricLocomotive", "ElectricLocomotive\ProjectElectricLocomotive.csproj", "{A7A62158-ECC2-48DA-81F7-565BB5CE1E0D}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution