ready lab2

This commit is contained in:
LivelyPuer 2024-02-28 23:06:50 +04:00
parent 095509189a
commit 6a08c454c5
30 changed files with 1134 additions and 548 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1", "Lab1\Lab1.csproj", "{5FE81003-1286-435E-8F6F-C2D1ADCA4B2C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectElectroTrans", "ProjectElectroTrans\ProjectElectroTrans.csproj", "{5FE81003-1286-435E-8F6F-C2D1ADCA4B2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace Lab1
{
internal class Config
{
public static Size screenSize = new Size(923, 597);
}
}

View File

@ -1,244 +0,0 @@
using System.Drawing;
namespace Lab1;
public class DrawingElectroTrans
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityElectroTrans? EntityElectroTrans { get; private set; }
/// <summary>
/// Ширина окна
/// </summary>
private int? _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки автомобиля
/// </summary>
private int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary>
private int? _startPosY;
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _drawningTransWidth = 80;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _drawningTransHeight = 60;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="horns">Признак активности усов</param>
/// <param name="wheels">Признак колличества колес</param>
/// <param name="battery">Признак наличия бптпрей</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool horns, int wheels, bool battery)
{
EntityElectroTrans = new EntityElectroTrans();
EntityElectroTrans.Init(speed, weight, bodyColor, additionalColor, horns, wheels, battery);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
if (width >= _drawningTransWidth || height >= _drawningTransWidth)
{
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX.HasValue && _startPosY.HasValue){
SetPosition(_startPosX.Value, _startPosY.Value);
}
return true;
}
return false;
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x < 0)
{
x = 0;
}else if (x > _pictureWidth - _drawningTransWidth)
{
x = _pictureWidth.Value - _drawningTransWidth;
}
if (y < 0)
{
y = 0;
}
else if (y > _pictureHeight - _drawningTransHeight)
{
y = _pictureHeight.Value - _drawningTransHeight;
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityElectroTrans == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return false;
}
if (_startPosX.Value < 0 || _startPosY.Value < 0 || _startPosX > _pictureWidth - _drawningTransWidth || _startPosY > _pictureHeight - _drawningTransHeight)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityElectroTrans.Step > 0)
{
_startPosX -= (int)EntityElectroTrans.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityElectroTrans.Step > 0)
{
_startPosY -= (int)EntityElectroTrans.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + EntityElectroTrans.Step < _pictureWidth - _drawningTransWidth)
{
_startPosX += (int)EntityElectroTrans.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityElectroTrans.Step < _pictureHeight - _drawningTransHeight)
{
_startPosY += (int)EntityElectroTrans.Step;
}
return true;
default:
return false;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntityElectroTrans == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return;
}
Pen pen = new(EntityElectroTrans.BodyColor);
Pen additionalPen = new(EntityElectroTrans.AdditionalColor);
Brush brush = new SolidBrush(EntityElectroTrans.BodyColor);
Brush additionalBrush = new SolidBrush(EntityElectroTrans.AdditionalColor);
int _centerPosX = _startPosX.Value + _drawningTransWidth / 2;
int _centerPosY = _startPosY.Value + _drawningTransHeight / 2;
g.DrawPolygon(pen, new Point[] {
new Point(_centerPosX - 40, _centerPosY),
new Point(_centerPosX - 30, _centerPosY - 20),
new Point(_centerPosX + 30, _centerPosY - 20),
new Point(_centerPosX + 40, _centerPosY),
new Point(_centerPosX + 40, _centerPosY + 20),
new Point(_centerPosX - 40, _centerPosY + 20),
});
for (int i = 0; i < EntityElectroTrans.Wheels; i++)
{
g.FillEllipse(additionalBrush, new Rectangle((_centerPosX - 40) + (70 / EntityElectroTrans.Wheels) * (i + 1) + -4, _centerPosY + 16, 8, 8));
}
g.FillPolygon(additionalBrush, new Point[] {
new Point(_centerPosX - 38, _centerPosY),
new Point(_centerPosX - 30, _centerPosY - 17),
new Point(_centerPosX + 30, _centerPosY - 17),
new Point(_centerPosX + 38, _centerPosY),
});
if (EntityElectroTrans.Horns)
{
g.DrawPolygon(additionalPen, new Point[] {
new Point(_centerPosX, _centerPosY - 20),
new Point(_centerPosX - 20, _centerPosY - 30),
new Point(_centerPosX + 20, _centerPosY - 30),
});
}
else
{
g.DrawPolygon(additionalPen, new Point[] {
new Point(_centerPosX, _centerPosY - 20),
new Point(_centerPosX - 20, _centerPosY - 23),
new Point(_centerPosX + 20, _centerPosY - 23),
});
}
if (EntityElectroTrans.Battery){
g.FillPolygon(additionalBrush, new Point[] {
new Point(_centerPosX - 15, _centerPosY + 2),
new Point(_centerPosX - 15, _centerPosY + 6),
new Point(_centerPosX - 18, _centerPosY + 6),
new Point(_centerPosX - 18, _centerPosY + 10),
new Point(_centerPosX - 15, _centerPosY + 10),
new Point(_centerPosX - 15, _centerPosY + 16),
new Point(_centerPosX + 18, _centerPosY + 16),
new Point(_centerPosX + 18, _centerPosY + 2),
});
}
}
}

View File

@ -1,68 +0,0 @@
using System.Drawing;
namespace Lab1;
public class EntityElectroTrans
{
/// <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 Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) подняты ли рога
/// </summary>
public bool Horns { get; private set; }
/// <summary>
/// Признак (опция) кол-во колес
/// </summary>
public int Wheels { get; private set; }
/// <summary>
/// Признак (опция) налиция батерей
/// </summary>
public bool Battery { get; private set; }
/// <summary>
/// Шаг перемещения электропоезда
/// </summary>
public double Step => Speed * 100 / Weight; // lambda выражение
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="horns">Признак активности усов</param>
/// <param name="wheels">Признак колличества колес</param>
/// <param name="battery">Признак наличия батарей</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool horns, int wheels, bool battery)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Horns = horns;
Wheels = wheels;
Battery = battery;
}
}

134
Lab1/Form1.Designer.cs generated
View File

@ -1,134 +0,0 @@
namespace Lab1
{
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()
{
pictureBoxSportCar = new PictureBox();
buttonCreateSportCar = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).BeginInit();
SuspendLayout();
//
// pictureBoxSportCar
//
pictureBoxSportCar.Dock = DockStyle.Fill;
pictureBoxSportCar.Location = new Point(0, 0);
pictureBoxSportCar.Name = "pictureBoxSportCar";
pictureBoxSportCar.Size = Config.screenSize;
pictureBoxSportCar.TabIndex = 0;
pictureBoxSportCar.TabStop = false;
//
// buttonCreateSportCar
//
buttonCreateSportCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateSportCar.Location = new Point(12, 562);
buttonCreateSportCar.Name = "buttonCreateSportCar";
buttonCreateSportCar.Size = new Size(75, 23);
buttonCreateSportCar.TabIndex = 1;
buttonCreateSportCar.Text = "Create";
buttonCreateSportCar.UseVisualStyleBackColor = true;
buttonCreateSportCar.Click += ButtonCreateElectroTrans_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(787, 550);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(828, 509);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(828, 550);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(869, 550);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// FormElectroTrans
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = Config.screenSize;
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonCreateSportCar);
Controls.Add(pictureBoxSportCar);
Name = "FormElectroTrans";
Text = "ElectroTrans";
((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxSportCar;
private Button buttonCreateSportCar;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
}
}

View File

@ -1,79 +0,0 @@
namespace Lab1
{
public partial class Form1 : Form
{
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawingElectroTrans _drawningElectroTrans;
public Form1()
{
InitializeComponent();
_drawningElectroTrans = new DrawingElectroTrans();
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû
/// </summary>
private void Draw()
{
if (_drawningElectroTrans == null)
{
return;
}
Bitmap bmp = new(pictureBoxSportCar.Width, pictureBoxSportCar.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningElectroTrans.DrawTransport(gr);
pictureBoxSportCar.Image = bmp;
}
private void ButtonCreateElectroTrans_Click(object sender, EventArgs e)
{
Random random = new();
_drawningElectroTrans.Init(random.Next(500, 1500), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), random.Next(3, 8), Convert.ToBoolean(random.Next(0, 2)));
_drawningElectroTrans.SetPictureSize(pictureBoxSportCar.Size.Width, pictureBoxSportCar.Size.Height);
_drawningElectroTrans.SetPosition(random.Next(0, 5), random.Next(0, 5));
Draw();
}
/// <summary>
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningElectroTrans == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _drawningElectroTrans.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningElectroTrans.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningElectroTrans.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningElectroTrans.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
}
}

View File

@ -0,0 +1,32 @@
namespace ProjectSportCar.Drawnings;
/// <summary>
/// Направление перемещения
/// </summary>
public enum DirectionType
{
/// <summary>
/// Неизвестное направление
/// </summary>
Unknow = -1,
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}

View File

@ -0,0 +1,71 @@
using ProjectElectroTrans.Entities;
namespace ProjectElectroTrans.Drawnings;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingElectroTrans : DrawingTrans
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public DrawingElectroTrans(int speed, double weight, Color bodyColor, Color
additionalColor, bool horns, bool battery) : base(110, 60)
{
EntityTrans = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, horns, battery);
}
public override void DrawTransport(Graphics g)
{
if (EntityTrans == null || EntityTrans is not EntityElectroTrans electroTrans ||
!_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(electroTrans.BodyColor);
Brush additionalBrush= new SolidBrush(electroTrans.AdditionalColor);
base.DrawTransport(g);
if (electroTrans.Horns)
{
g.DrawPolygon(pen, new Point[] {
new Point(_startPosX.Value + 40, _startPosY.Value + 10),
new Point(_startPosX.Value + 20, _startPosY.Value),
new Point(_startPosX.Value + 60, _startPosY.Value),
});
}
else
{
g.DrawPolygon(pen, new Point[] {
new Point(_startPosX.Value + 40, _startPosY.Value + 7),
new Point(_startPosX.Value + 20, _startPosY.Value + 7),
new Point(_startPosX.Value + 60, _startPosY.Value + 7),
});
}
if (electroTrans.Battery)
{
g.FillPolygon(additionalBrush, new Point[] {
new Point(_startPosX.Value + 25, _startPosY.Value + 32),
new Point(_startPosX.Value + 25, _startPosY.Value + 36),
new Point(_startPosX.Value + 22, _startPosY.Value + 36),
new Point(_startPosX.Value + 22, _startPosY.Value + 40),
new Point(_startPosX.Value + 25, _startPosY.Value + 40),
new Point(_startPosX.Value + 25, _startPosY.Value + 46),
new Point(_startPosX.Value + 58, _startPosY.Value + 46),
new Point(_startPosX.Value + 58, _startPosY.Value + 32),
});
}
}
}

View File

@ -0,0 +1,226 @@
using ProjectElectroTrans.Entities;
using ProjectSportCar.Drawnings;
namespace ProjectElectroTrans.Drawnings;
public class DrawingTrans
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityTrans? EntityTrans { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
private int? _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки автомобиля
/// </summary>
protected int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary>
protected int? _startPosY;
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _drawningTransWidth = 80;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _drawningTransHeight = 60;
/// <summary>
/// Координата X объекта
/// </summary>
public int? GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int? GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _drawningTransWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _drawningTransHeight;
/// <summary>
/// Пустой конструктор
/// </summary>
private DrawingTrans()
{
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawingTrans(int speed, double weight, Color bodyColor) : this()
{
EntityTrans = new EntityTrans(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
protected DrawingTrans(int drawningCarWidth, int drawningCarHeight) : this()
{
_drawningTransWidth = drawningCarWidth;
_pictureHeight = drawningCarHeight;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
if (width >= _drawningTransWidth || height >= _drawningTransWidth)
{
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX.HasValue && _startPosY.HasValue)
{
SetPosition(_startPosX.Value, _startPosY.Value);
}
return true;
}
return false;
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x < 0)
{
x = 0;
}
else if (x > _pictureWidth - _drawningTransWidth)
{
x = _pictureWidth.Value - _drawningTransWidth;
}
if (y < 0)
{
y = 0;
}
else if (y > _pictureHeight - _drawningTransHeight)
{
y = _pictureHeight.Value - _drawningTransHeight;
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещене выполнено, false - перемещениеневозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityTrans == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityTrans.Step > 0)
{
_startPosX -= (int)EntityTrans.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityTrans.Step > 0)
{
_startPosY -= (int)EntityTrans.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + EntityTrans.Step < _pictureWidth - _drawningTransWidth)
{
_startPosX += (int)EntityTrans.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityTrans.Step < _pictureHeight - _drawningTransHeight)
{
_startPosY += (int)EntityTrans.Step;
}
return true;
default:
return false;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (EntityTrans == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return;
}
Pen pen = new(EntityTrans.BodyColor);
// Тело
g.DrawPolygon(pen, new Point[] {
new Point(_startPosX.Value, _startPosY.Value + 30),
new Point(_startPosX.Value + 10, _startPosY.Value + 10),
new Point(_startPosX.Value + 70, _startPosY.Value + 10),
new Point(_startPosX.Value + 80, _startPosY.Value + 30),
new Point(_startPosX.Value + 80, _startPosY.Value + 50),
new Point(_startPosX.Value, _startPosY.Value + 50),
});
// Колеса
for (int i = 0; i < 4; i++)
{
g.DrawEllipse(pen, new Rectangle((_startPosX.Value) + (70 / 4) * (i + 1) + -4, _startPosY.Value + 46, 8, 8));
}
// Стекла
g.DrawPolygon(pen, new Point[] {
new Point(_startPosX.Value + 2, _startPosY.Value + 30),
new Point(_startPosX.Value + 10, _startPosY.Value + 13),
new Point(_startPosX.Value + 70, _startPosY.Value + 13),
new Point(_startPosX.Value + 78, _startPosY.Value + 30),
});
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectroTrans.Entities;
internal class EntityElectroTrans : EntityTrans
{
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) подняты ли рога
/// </summary>
public bool Horns { get; private set; }
/// <summary>
/// Признак (опция) налиция батерей
/// </summary>
public bool Battery { get; private set; }
/// <summary>
/// Конструктор сущности
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="horns">Признак активности усов</param>
/// <param name="battery">Признак наличия батарей</param>
public EntityElectroTrans(int speed, double weight, Color bodyColor, Color
additionalColor, bool horns, bool battery) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Horns = horns;
Battery = battery;
}
}

View File

@ -0,0 +1,37 @@
namespace ProjectElectroTrans.Entities;
/// <summary>
/// Класс-сущность "Поезд"
/// </summary>
public class EntityTrans
{
/// <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 => Speed * 100 / Weight;
/// <summary>
/// Конструктор сущности
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityTrans(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@ -0,0 +1,178 @@
using static System.Net.Mime.MediaTypeNames;
using System.Windows.Forms;
using System.Xml.Linq;
namespace ProjectElectroTrans
{
partial class FormElectroTrans
{
/// <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()
{
pictureBoxElectroTrans = new PictureBox();
buttonCreateElectroTrans = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonCreateCar = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectroTrans).BeginInit();
SuspendLayout();
//
// pictureBoxElectroTrans
//
pictureBoxElectroTrans.Dock = DockStyle.Fill;
pictureBoxElectroTrans.Location = new Point(0, 0);
pictureBoxElectroTrans.Name = "pictureBoxElectroTrans";
pictureBoxElectroTrans.Size = new Size(923, 597);
pictureBoxElectroTrans.TabIndex = 0;
pictureBoxElectroTrans.TabStop = false;
//
// buttonCreateElectroTrans
//
buttonCreateElectroTrans.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateElectroTrans.Location = new Point(12, 562);
buttonCreateElectroTrans.Name = "buttonCreateElectroTrans";
buttonCreateElectroTrans.Size = new Size(223, 23);
buttonCreateElectroTrans.TabIndex = 1;
buttonCreateElectroTrans.Text = "Создать электропоезд";
buttonCreateElectroTrans.UseVisualStyleBackColor = true;
buttonCreateElectroTrans.Click += ButtonCreateElectroTrans_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(787, 550);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(828, 509);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(828, 550);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(869, 550);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonCreateCar
//
buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateCar.Location = new Point(250, 562);
buttonCreateCar.Name = "buttonCreateTrans";
buttonCreateCar.Size = new Size(223, 23);
buttonCreateCar.TabIndex = 6;
buttonCreateCar.Text = "Создать поезд";
buttonCreateCar.UseVisualStyleBackColor = true;
buttonCreateCar.Click += ButtonCreateTrans_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(790, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.TabIndex = 7;
//
// buttonStrategyStep
//
buttonStrategyStep.Location = new Point(836, 41);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(75, 23);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
buttonStrategyStep.Click += ButtonStrategyStep_Click;
//
// FormElectroTrans
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(923, 597);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateCar);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonCreateElectroTrans);
Controls.Add(pictureBoxElectroTrans);
Name = "FormElectroTrans";
Text = "Электропоезд";
((System.ComponentModel.ISupportInitialize)pictureBoxElectroTrans).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxElectroTrans;
private Button buttonCreateElectroTrans;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateCar;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
}

View File

@ -0,0 +1,156 @@
using ProjectElectroTrans.Drawnings;
using ProjectElectroTrans.MovementStrategy;
using ProjectSportCar.Drawnings;
using ProjectSportCar.MovementStrategy;
namespace ProjectElectroTrans;
public partial class FormElectroTrans : Form
{
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawingTrans? _drawingTrans;
/// <summary>
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
/// </summary>
private AbstractStrategy? _strategy;
public FormElectroTrans()
{
InitializeComponent();
_strategy = null;
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû
/// </summary>
private void Draw()
{
if (_drawingTrans == null)
{
return;
}
Bitmap bmp = new(pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingTrans.DrawTransport(gr);
pictureBoxElectroTrans.Image = bmp;
}
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawingTrans):
_drawingTrans = new DrawingTrans(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
break;
case nameof(DrawingElectroTrans):
_drawingTrans = new DrawingElectroTrans(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawingTrans.SetPictureSize(pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
_drawingTrans.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü ñïîðòèâíûé àâòîìîáèëü"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateElectroTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingElectroTrans));
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü àâòîìîáèëü"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTrans));
/// <summary>
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingTrans == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _drawingTrans.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawingTrans.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawingTrans.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawingTrans.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawingTrans == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(new MoveableTrans(_drawingTrans), pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
}
if (_strategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == StrategyStatus.Finish)
{
comboBoxStrategy.Enabled = true;
_strategy = null;
}
}
}

View File

@ -0,0 +1,123 @@

namespace ProjectElectroTrans.MovementStrategy;
/// <summary>
/// Класс-стратегия перемещения объекта
/// </summary>
public abstract class AbstractStrategy
{
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject? _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private StrategyStatus _state = StrategyStatus.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth { get; private set; }
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight { get; private set; }
/// <summary>
/// Статус перемещения
/// </summary>
public StrategyStatus GetStatus() { return _state; }
/// <summary>
/// Установка данных
/// </summary>
/// <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 = StrategyStatus.NotInit;
return;
}
_state = StrategyStatus.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = StrategyStatus.Finish;
return;
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
/// <summary>
/// Перемещение вправо
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveRight() => MoveTo(MovementDirection.Right);
/// <summary>
/// Перемещение вверх
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveUp() => MoveTo(MovementDirection.Up);
/// <summary>
/// Перемещение вниз
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveDown() => MoveTo(MovementDirection.Down);
/// <summary>
/// Параметры объекта
/// </summary>
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
/// <summary>
/// Шаг объекта
/// </summary>
/// <returns></returns>
protected int? GetStep()
{
if (_state != StrategyStatus.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract bool IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="movementDirection">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(MovementDirection movementDirection)
{
if (_state != StrategyStatus.InProgress)
{
return false;
}
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
}
}

View File

@ -0,0 +1,22 @@

namespace ProjectElectroTrans.MovementStrategy;
public interface IMoveableObject
{
/// <summary>
/// Получение координаты объекта
/// </summary>
ObjectParameters? GetObjectPosition { get; }
/// <summary>
/// Шаг объекта
/// </summary>
int GetStep { get; }
/// <summary>
/// Попытка переместить объект в указанном направлении
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
bool TryMoveObject(MovementDirection direction);
}

View File

@ -0,0 +1,52 @@
using ProjectElectroTrans.MovementStrategy;
namespace ProjectSportCar.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth &&
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
int diffY = objParams.ObjectMiddleVertical - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,50 @@

namespace ProjectElectroTrans.MovementStrategy;
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,61 @@
using ProjectElectroTrans.Drawnings;
using ProjectSportCar.Drawnings;
namespace ProjectElectroTrans.MovementStrategy;
public class MoveableTrans : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawningTrans или его наследника
/// </summary>
private readonly DrawingTrans? _trans = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="trans">Объект класса DrawningTrans</param>
public MoveableTrans(DrawingTrans trans)
{
_trans = trans;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_trans == null || _trans.EntityTrans == null ||
!_trans.GetPosX.HasValue || !_trans.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_trans.GetPosX.Value,
_trans.GetPosY.Value, _trans.GetWidth, _trans.GetHeight);
}
}
public int GetStep => (int)(_trans?.EntityTrans?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_trans == null || _trans.EntityTrans == null)
{
return false;
}
return _trans.MoveTransport(GetDirectionType(direction));
}
/// <summary>
/// Конвертация из MovementDirection в DirectionType
/// </summary>
/// <param name="direction">MovementDirection</param>
/// <returns>DirectionType</returns>
private static DirectionType GetDirectionType(MovementDirection direction)
{
return direction switch
{
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
MovementDirection.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
_ => DirectionType.Unknow,
};
}
}

View File

@ -1,6 +1,6 @@
namespace Lab1;
namespace ProjectElectroTrans.MovementStrategy;
public enum DirectionType
public enum MovementDirection
{
/// <summary>
/// Вверх
@ -18,5 +18,4 @@ public enum DirectionType
/// Вправо
/// </summary>
Right = 4
}
}

View File

@ -0,0 +1,60 @@
namespace ProjectElectroTrans.MovementStrategy;
public class ObjectParameters
{
/// <summary>
/// Координата X
/// </summary>
private readonly int _x;
/// <summary>
/// Координата Y
/// </summary>
private readonly int _y;
/// <summary>
/// Ширина объекта
/// </summary>
private readonly int _width;
/// <summary>
/// Высота объекта
/// </summary>
private readonly int _height;
/// <summary>
/// Левая граница
/// </summary>
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

@ -0,0 +1,17 @@
namespace ProjectElectroTrans.MovementStrategy;
public enum StrategyStatus
{
/// <summary>
/// Все готово к началу
/// </summary>
NotInit,
/// <summary>
/// Выполняется
/// </summary>
InProgress,
/// <summary>
/// Завершено
/// </summary>
Finish
}

View File

@ -1,4 +1,4 @@
namespace Lab1
namespace ProjectElectroTrans
{
internal static class Program
{
@ -11,7 +11,7 @@ namespace Lab1
// 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 FormElectroTrans());
}
}
}

View File

@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace Lab1.Properties {
namespace ProjectElectroTrans.Properties {
using System;
@ -39,7 +39,7 @@ namespace Lab1.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lab1.Properties.Resources", typeof(Resources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectElectroTrans.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View File

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View File

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View File

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB