Добавление конструкторов и классов-родителей
This commit is contained in:
parent
ff7a87438e
commit
5d72860a96
@ -1,24 +0,0 @@
|
||||
namespace LocomotiveProject;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
namespace LocomativeProject.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right
|
||||
}
|
||||
}
|
@ -1,64 +1,75 @@
|
||||
namespace LocomotiveProject
|
||||
using LocomativeProject.Entities;
|
||||
|
||||
namespace LocomativeProject.Drawnings
|
||||
{
|
||||
public class DrawningLocomotive
|
||||
public class DrawningBaseLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityLocomotive? EntityLocomotive { get; private set; }
|
||||
public EntityBaseLocomotive? _EntityLocomotive { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
protected int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
protected int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки тепловоза
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки тепловоза
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки тепловоза
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveWidth = 120;
|
||||
private readonly int _drawningBaseLocomotiveWidth = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки тепловоза
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveHeight = 60;
|
||||
private readonly int _drawningBaseLocomotiveHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="exehaustPipe">Признак наличия трубы</param>
|
||||
/// <param name="fuelCompartment">Признак наличия отсека для топлива</param>
|
||||
/// <param name="wheelCount">Признак количества колес</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool exehaustPipe, bool fuelCompartment, int wheelCount)
|
||||
private DrawningBaseLocomotive()
|
||||
{
|
||||
EntityLocomotive = new EntityLocomotive();
|
||||
EntityLocomotive.Init(speed, weight, bodyColor, additionalColor,
|
||||
exehaustPipe, fuelCompartment, wheelCount);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор базового поезда
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBaseLocomotive(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
_EntityLocomotive = new EntityBaseLocomotive(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningLocomotiveWidth">ширина</param>
|
||||
/// <param name="drawningLocomotiveHeight">высота</param>
|
||||
protected DrawningBaseLocomotive(int Width, int Height) : this()
|
||||
{
|
||||
_drawningBaseLocomotiveWidth = Width;
|
||||
_drawningBaseLocomotiveHeight = Height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
@ -67,15 +78,15 @@
|
||||
///разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (width > _drawningLocomotiveWidth || height > _drawningLocomotiveHeight) // если ширина и высота окна больше чем объект
|
||||
if (width > _drawningBaseLocomotiveWidth || height > _drawningBaseLocomotiveHeight) // если ширина и высота окна больше чем объект
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX + _drawningLocomotiveWidth > width || _startPosX < 0) // если координаты выходят за пределы, корректируем
|
||||
if (_startPosX + _drawningBaseLocomotiveWidth > width || _startPosX < 0) // если координаты выходят за пределы, корректируем
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY + _drawningLocomotiveHeight > height || _startPosY < 0)
|
||||
if (_startPosY + _drawningBaseLocomotiveHeight > height || _startPosY < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
@ -96,20 +107,20 @@
|
||||
}
|
||||
|
||||
// если все нормально
|
||||
if (x > 0 || x + _drawningLocomotiveWidth < _pictureWidth)
|
||||
if (x > 0 || x + _drawningBaseLocomotiveWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX = x;
|
||||
}
|
||||
if (y > 0 || y + _drawningLocomotiveHeight < _pictureHeight)
|
||||
if (y > 0 || y + _drawningBaseLocomotiveHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY = y;
|
||||
}
|
||||
// если не лезет, но мог бы влезть
|
||||
if (x < 0 || x + _drawningLocomotiveWidth > _pictureWidth)
|
||||
if (x < 0 || x + _drawningBaseLocomotiveWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (y < 0 || y + _drawningLocomotiveHeight > _pictureHeight)
|
||||
if (y < 0 || y + _drawningBaseLocomotiveHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
@ -123,7 +134,7 @@
|
||||
/// невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityLocomotive == null || !_startPosX.HasValue ||
|
||||
if (_EntityLocomotive == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
@ -132,30 +143,30 @@
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityLocomotive.Step > 0)
|
||||
if (_startPosX.Value - _EntityLocomotive.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityLocomotive.Step;
|
||||
_startPosX -= (int)_EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityLocomotive.Step > 0) // 10 – высота трубы
|
||||
if (_startPosY.Value - _EntityLocomotive.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityLocomotive.Step;
|
||||
_startPosY -= (int)_EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningLocomotiveWidth + EntityLocomotive.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningBaseLocomotiveWidth + _EntityLocomotive.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityLocomotive.Step;
|
||||
_startPosX += (int)_EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningLocomotiveHeight + EntityLocomotive.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawningBaseLocomotiveHeight + _EntityLocomotive.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityLocomotive.Step;
|
||||
_startPosY += (int)_EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -189,15 +200,14 @@
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (_EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityLocomotive.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityLocomotive.BodyColor);
|
||||
Brush bodyBrush = new SolidBrush(_EntityLocomotive.BodyColor);
|
||||
Brush blackBrush = new SolidBrush(Color.Black);
|
||||
Brush whiteBrush = new SolidBrush(Color.White);
|
||||
//границы тепловоза
|
||||
@ -207,7 +217,6 @@
|
||||
_startPosX.Value + 115, _startPosY.Value + 20 + 10,
|
||||
_startPosX.Value + 5, _startPosY.Value + 20 + 10
|
||||
);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + +10 + 20, 110, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20 + 10, 110, 20);
|
||||
g.FillRectangle(blackBrush, _startPosX.Value, _startPosY.Value + 5 + 10, 5, 30);
|
||||
//шасси
|
||||
@ -240,20 +249,6 @@
|
||||
g.DrawRectangle(pen, _startPosX.Value + 85, _startPosY.Value + 5 + 10, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 5 + 10, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 5 + 10, 10, 10);
|
||||
//труба
|
||||
if (EntityLocomotive.ExehaustPipe)
|
||||
{
|
||||
Brush greyBrush = new SolidBrush(Color.Gray);
|
||||
g.FillRectangle(greyBrush, _startPosX.Value + 80, _startPosY.Value, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value, 5, 10);
|
||||
}
|
||||
// отсек для топлива
|
||||
if (EntityLocomotive.FuelCompartment)
|
||||
{
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 25, _startPosY.Value + 10 + 10, 10, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 10 + 10, 10, 20);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomotiveProject.Entities;
|
||||
|
||||
namespace LocomotiveProject.Drawnings
|
||||
{
|
||||
public class DrawningLocomotive : DrawningBaseLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес тепловоза</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="exehaustPipe">Признак наличия трубы</param>
|
||||
/// <param name="fuelCompartment">Признак наличия топливного отсека</param>
|
||||
public DrawningLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool exehaustPipe, bool fuelCompartment) : base(120, 60)
|
||||
{
|
||||
_EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor, additionalColor, exehaustPipe, fuelCompartment);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_EntityLocomotive == null || _EntityLocomotive is not EntityLocomotive entityLocomotive || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(entityLocomotive.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(entityLocomotive.BodyColor);
|
||||
//Brush blackBrush = new SolidBrush(Color.Black);
|
||||
//Brush whiteBrush = new SolidBrush(Color.White);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + +10 + 20, 110, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20 + 10, 110, 20);
|
||||
base.DrawTransport(g);
|
||||
if (entityLocomotive.ExehaustPipe)
|
||||
{
|
||||
Brush greyBrush = new SolidBrush(Color.Gray);
|
||||
g.FillRectangle(greyBrush, _startPosX.Value + 80, _startPosY.Value, 5, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value, 5, 10);
|
||||
}
|
||||
// отсек для топлива
|
||||
if (entityLocomotive.FuelCompartment)
|
||||
{
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 25, _startPosY.Value + 10 + 10, 10, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 10 + 10, 10, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
namespace LocomativeProject.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность базовый тепловоз
|
||||
/// </summary>
|
||||
public class EntityBaseLocomotive
|
||||
{
|
||||
/// <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 EntityBaseLocomotive(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using LocomativeProject.Entities;
|
||||
|
||||
namespace LocomotiveProject.Entities
|
||||
{
|
||||
public class EntityLocomotive : EntityBaseLocomotive
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие трубы
|
||||
/// </summary>
|
||||
public bool ExehaustPipe { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие топливного отсека
|
||||
/// </summary>
|
||||
public bool FuelCompartment { get; private set; }
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес тепловоза</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="exehaustPipe">Признак наличия трубы</param>
|
||||
/// <param name="fuelCompartment">Признак наличия топливного отсека</param>
|
||||
public EntityLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool exehaustPipe, bool fuelCompartment) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
ExehaustPipe = exehaustPipe;
|
||||
FuelCompartment = fuelCompartment;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
namespace LocomotiveProject
|
||||
{
|
||||
public class EntityLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие трубы
|
||||
/// </summary>
|
||||
public bool ExehaustPipe { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие топливного отсека
|
||||
/// </summary>
|
||||
public bool FuelCompartment { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак количество колес
|
||||
/// </summary>
|
||||
public int WheelCount { 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>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="exehaustPipe">Признак наличия трубы</param>
|
||||
/// <param name="fuelCompartment">Признак наличия топливного отсека</param>
|
||||
/// <param name="wheelCount">Признак количества колес</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool exehaustPipe, bool fuelCompartment, int wheelCount)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
ExehaustPipe = exehaustPipe;
|
||||
FuelCompartment = fuelCompartment;
|
||||
WheelCount = wheelCount;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -29,120 +29,136 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LocomotiveProject));
|
||||
pictureBox1 = new PictureBox();
|
||||
pictureBoxLocomotive = new PictureBox();
|
||||
create = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonRight = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit();
|
||||
SuspendLayout();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreateBaseLocomotive = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonCreateLocomotive = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
pictureBox1.Location = new Point(0, 0);
|
||||
pictureBox1.Name = "pictureBox1";
|
||||
pictureBox1.Size = new Size(100, 50);
|
||||
pictureBox1.TabIndex = 0;
|
||||
pictureBox1.TabStop = false;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
|
||||
this.pictureBox1.TabIndex = 0;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// pictureBoxLocomotive
|
||||
//
|
||||
pictureBoxLocomotive.Dock = DockStyle.Fill;
|
||||
pictureBoxLocomotive.Location = new Point(0, 0);
|
||||
pictureBoxLocomotive.Name = "pictureBoxLocomotive";
|
||||
pictureBoxLocomotive.Size = new Size(800, 450);
|
||||
pictureBoxLocomotive.TabIndex = 1;
|
||||
pictureBoxLocomotive.TabStop = false;
|
||||
this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxLocomotive.Name = "pictureBoxLocomotive";
|
||||
this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBoxLocomotive.TabIndex = 1;
|
||||
this.pictureBoxLocomotive.TabStop = false;
|
||||
//
|
||||
// create
|
||||
// buttonCreateBaseLocomotive
|
||||
//
|
||||
create.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
create.Location = new Point(12, 415);
|
||||
create.Name = "create";
|
||||
create.Size = new Size(75, 23);
|
||||
create.TabIndex = 2;
|
||||
create.Text = "создать";
|
||||
create.UseVisualStyleBackColor = true;
|
||||
create.Click += create_Click;
|
||||
this.buttonCreateBaseLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateBaseLocomotive.Location = new System.Drawing.Point(12, 415);
|
||||
this.buttonCreateBaseLocomotive.Name = "buttonCreateBaseLocomotive";
|
||||
this.buttonCreateBaseLocomotive.Size = new System.Drawing.Size(171, 23);
|
||||
this.buttonCreateBaseLocomotive.TabIndex = 2;
|
||||
this.buttonCreateBaseLocomotive.Text = "создать обычный поезд";
|
||||
this.buttonCreateBaseLocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateBaseLocomotive.Click += new System.EventHandler(this.ButtonCreateBaseLocomotive_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(691, 362);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(691, 362);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonUp.TabIndex = 3;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(691, 403);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(691, 403);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonDown.TabIndex = 4;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(650, 403);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 5;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(650, 403);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonLeft.TabIndex = 5;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(732, 403);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 6;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(732, 403);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonRight.TabIndex = 6;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateLocomotive
|
||||
//
|
||||
this.buttonCreateLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateLocomotive.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
|
||||
this.buttonCreateLocomotive.Location = new System.Drawing.Point(189, 415);
|
||||
this.buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
||||
this.buttonCreateLocomotive.Size = new System.Drawing.Size(173, 23);
|
||||
this.buttonCreateLocomotive.TabIndex = 7;
|
||||
this.buttonCreateLocomotive.Text = "создать продвинутый поезд";
|
||||
this.buttonCreateLocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateLocomotive.Click += new System.EventHandler(this.ButtonCreateLocomotive_Click);
|
||||
//
|
||||
// LocomotiveProject
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(create);
|
||||
Controls.Add(pictureBoxLocomotive);
|
||||
Controls.Add(pictureBox1);
|
||||
Name = "LocomotiveProject";
|
||||
Text = "Тепловоз";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).EndInit();
|
||||
ResumeLayout(false);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonCreateLocomotive);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreateBaseLocomotive);
|
||||
this.Controls.Add(this.pictureBoxLocomotive);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Name = "LocomotiveProject";
|
||||
this.Text = "Тепловоз";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBox1;
|
||||
private PictureBox pictureBoxLocomotive;
|
||||
private Button create;
|
||||
private Button buttonCreateBaseLocomotive;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateLocomotive;
|
||||
}
|
||||
}
|
@ -8,12 +8,15 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using LocomotiveProject.Entities;
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomotiveProject.Drawnings;
|
||||
|
||||
namespace LocomativeProject
|
||||
{
|
||||
public partial class LocomotiveProject : Form
|
||||
{
|
||||
private DrawningLocomotive? _drawningLocomotive;
|
||||
private DrawningBaseLocomotive? _drawningLocomotive;
|
||||
|
||||
public LocomotiveProject()
|
||||
{
|
||||
@ -32,30 +35,50 @@ namespace LocomativeProject
|
||||
pictureBoxLocomotive.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void create_Click(object sender, EventArgs e)
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningLocomotive = new DrawningLocomotive();
|
||||
_drawningLocomotive.Init
|
||||
(
|
||||
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)),
|
||||
random.Next(2, 6)
|
||||
);
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBaseLocomotive):
|
||||
_drawningLocomotive = new DrawningBaseLocomotive(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(DrawningLocomotive):
|
||||
_drawningLocomotive = new DrawningLocomotive(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;
|
||||
}
|
||||
|
||||
_drawningLocomotive.SetPictureSize(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать базовый поезд"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBaseLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBaseLocomotive));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать продвинутый поезд"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
|
||||
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningLocomotive == null)
|
||||
@ -84,6 +107,5 @@ namespace LocomativeProject
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,4 @@
|
||||
<?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.
|
||||
-->
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
@ -528,7 +468,7 @@
|
||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||
vQAADr0BR/uQrQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABq4SURBVHhe7d1X
|
||||
vAAADrwBlbxySQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABq4SURBVHhe7d1X
|
||||
0F1lvcfxAOMMioCAQbBhL9jBgqKCXcCC0WgsGFSMElIgBEgU4+g4OuOV114w44W3inKBBSxYsEdFRQWj
|
||||
YAkaFYMFQcjyeZKlIcmTt+z3v/deaz2fz8z3cI5Jdlkvx/9vHI9nUQMAVMcAAIAKGQAAUCEDAAAqZAAA
|
||||
QIUMAACokAEAABUyAACgQgYAAFTIAACAChkAAFAhAwAAKmQAAECFDAAAqJABAAAVMgAAoEIGAABUyAAA
|
||||
|
Loading…
Reference in New Issue
Block a user