Создание родительского класса для entity liner
This commit is contained in:
parent
bd746e9288
commit
6c4691699b
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectLiner;
|
namespace ProjectLiner.Drawnings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
@ -1,14 +1,17 @@
|
|||||||
namespace ProjectLiner;
|
using ProjectLiner.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
/// <summary>
|
namespace ProjectLiner.Drawnings;
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
public class DrawningCommonLiner
|
||||||
/// </summary>
|
|
||||||
public class DrawningLiner
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityLiner? EntityLiner { get; private set; }
|
public EntityCommonLiner? EntityCommonLiner { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -23,12 +26,12 @@ public class DrawningLiner
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки лайнера
|
/// Левая координата прорисовки лайнера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки лайнера
|
/// Верхняя кооридната прорисовки лайнера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки лайнера
|
/// Ширина прорисовки лайнера
|
||||||
@ -38,27 +41,44 @@ public class DrawningLiner
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки лайнера
|
/// Высота прорисовки лайнера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningLinerHeight = 125;
|
private readonly int _drawningLinerHeight = 90;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Пустой конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
public DrawningCommonLiner()
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="anchor">Признак наличия якоря</param>
|
|
||||||
/// <param name="boats">Признак наличия шлюпок</param>
|
|
||||||
/// <param name="pipe">Признак наличия трубы</param>
|
|
||||||
public void Init(EntityLiner liner)
|
|
||||||
{
|
{
|
||||||
EntityLiner = liner;
|
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
|
||||||
|
public DrawningCommonLiner(int speed, double weight, Color bodycolor) : this()
|
||||||
|
{
|
||||||
|
EntityCommonLiner = new EntityCommonLiner(speed, weight, bodycolor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningLinerHeight">Высота</param>
|
||||||
|
/// <param name="drawningLinerWight">Длина</param>
|
||||||
|
|
||||||
|
protected DrawningCommonLiner(int drawningLinerWight, int drawningLinerHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningLinerHeight = drawningLinerHeight;
|
||||||
|
_drawningLinerWidth = drawningLinerWight;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -129,7 +149,7 @@ public class DrawningLiner
|
|||||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityCommonLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -138,30 +158,30 @@ public class DrawningLiner
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityLiner.Step > 0)
|
if (_startPosX.Value - EntityCommonLiner.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityLiner.Step;
|
_startPosX -= (int)EntityCommonLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityLiner.Step > 0)
|
if (_startPosY.Value - EntityCommonLiner.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityLiner.Step;
|
_startPosY -= (int)EntityCommonLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + EntityLiner.Step < _pictureWidth-_drawningLinerWidth)
|
if (_startPosX.Value + EntityCommonLiner.Step < _pictureWidth - _drawningLinerWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityLiner.Step;
|
_startPosX += (int)EntityCommonLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY.Value + EntityLiner.Step < _pictureHeight-_drawningLinerHeight)
|
if (_startPosY.Value + EntityCommonLiner.Step < _pictureHeight - _drawningLinerHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityLiner.Step;
|
_startPosY += (int)EntityCommonLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -173,61 +193,33 @@ public class DrawningLiner
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityCommonLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new SolidBrush(EntityLiner.AdditionalColor);
|
Brush br = new SolidBrush(EntityCommonLiner.BodyColor);
|
||||||
Brush br = new SolidBrush(EntityLiner.BodyColor);
|
|
||||||
|
|
||||||
// якорь
|
|
||||||
if (EntityLiner.Anchor)
|
|
||||||
{
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 85, _startPosX.Value + 45, _startPosY.Value + 115);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 95, _startPosX.Value + 60, _startPosY.Value + 95);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 100, _startPosX.Value + 45, _startPosY.Value + 115);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 115, _startPosX.Value + 65, _startPosY.Value + 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// кузов лайнера
|
// кузов лайнера
|
||||||
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 80);
|
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 40);
|
||||||
Point point2 = new Point(_startPosX.Value + 50, _startPosY.Value + 130);
|
Point point2 = new Point(_startPosX.Value + 50, _startPosY.Value + 90);
|
||||||
Point point3 = new Point(_startPosX.Value + 135, _startPosY.Value + 130);
|
Point point3 = new Point(_startPosX.Value + 135, _startPosY.Value + 90);
|
||||||
Point point4 = new Point(_startPosX.Value + 155, _startPosY.Value + 80);
|
Point point4 = new Point(_startPosX.Value + 155, _startPosY.Value + 40);
|
||||||
Point[] curvePoints = { point1, point2, point3, point4 };
|
Point[] curvePoints = { point1, point2, point3, point4 };
|
||||||
g.FillPolygon(br, curvePoints);
|
g.FillPolygon(br, curvePoints);
|
||||||
|
|
||||||
|
|
||||||
// борт лайнера
|
// борт лайнера
|
||||||
Point point5 = new Point(_startPosX.Value+40, _startPosY.Value + 40);
|
Point point5 = new Point(_startPosX.Value + 40, _startPosY.Value);
|
||||||
Point point6 = new Point(_startPosX.Value + 140, _startPosY.Value + 40);
|
Point point6 = new Point(_startPosX.Value + 140, _startPosY.Value);
|
||||||
Point point7 = new Point(_startPosX.Value + 140, _startPosY.Value + 80);
|
Point point7 = new Point(_startPosX.Value + 140, _startPosY.Value + 40);
|
||||||
Point point8 = new Point(_startPosX.Value + 40, _startPosY.Value + 80);
|
Point point8 = new Point(_startPosX.Value + 40, _startPosY.Value + 40);
|
||||||
Point[] curvePoints2 = { point5, point6, point7, point8 };
|
Point[] curvePoints2 = { point5, point6, point7, point8 };
|
||||||
g.FillPolygon(additionalBrush, curvePoints2);
|
g.FillPolygon(br, curvePoints2);
|
||||||
|
|
||||||
// шлюпки
|
|
||||||
if (EntityLiner.Boats)
|
|
||||||
{
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 85, 30, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 85, 30, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 85, 30, 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
// труба
|
|
||||||
if (EntityLiner.Pipe)
|
|
||||||
{
|
|
||||||
|
|
||||||
Point point9 = new Point(_startPosX.Value + 90, _startPosY.Value + 10);
|
|
||||||
Point point10 = new Point(_startPosX.Value + 90, _startPosY.Value + 40);
|
|
||||||
Point point11 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
|
|
||||||
Point point12 = new Point(_startPosX.Value + 115, _startPosY.Value + 10);
|
|
||||||
Point[] curvePoints3 = { point9, point10, point11, point12 };
|
|
||||||
g.FillPolygon(br, curvePoints3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
72
ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
Normal file
72
ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using ProjectLiner.Entities;
|
||||||
|
|
||||||
|
namespace ProjectLiner.Drawnings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningLiner : DrawningCommonLiner
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="anchor">Признак наличия якоря</param>
|
||||||
|
/// <param name="boats">Признак наличия шлюпок</param>
|
||||||
|
/// <param name="pipe">Признак наличия трубы</param>
|
||||||
|
public DrawningLiner(int speed, double weight, Color bodycolor, Color additionalColor, bool anchor, bool boats, bool pipe) : base(150, 125)
|
||||||
|
{
|
||||||
|
EntityCommonLiner = new EntityLiner(speed, weight, bodycolor, additionalColor, anchor, boats, pipe);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityCommonLiner == null || EntityCommonLiner is not EntityLiner liner || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(liner.AdditionalColor);
|
||||||
|
Brush br = new SolidBrush(liner.BodyColor);
|
||||||
|
|
||||||
|
_startPosY += 40;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosY -= 40;
|
||||||
|
|
||||||
|
|
||||||
|
// якорь
|
||||||
|
if (liner.Anchor)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 85, _startPosX.Value + 45, _startPosY.Value + 115);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 95, _startPosX.Value + 60, _startPosY.Value + 95);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 100, _startPosX.Value + 45, _startPosY.Value + 115);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 115, _startPosX.Value + 65, _startPosY.Value + 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// шлюпки
|
||||||
|
if (liner.Boats)
|
||||||
|
{
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 85, 30, 15);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 85, 30, 15);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 85, 30, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
// труба
|
||||||
|
if (liner.Pipe)
|
||||||
|
{
|
||||||
|
|
||||||
|
Point point9 = new Point(_startPosX.Value + 90, _startPosY.Value + 10);
|
||||||
|
Point point10 = new Point(_startPosX.Value + 90, _startPosY.Value + 40);
|
||||||
|
Point point11 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
|
||||||
|
Point point12 = new Point(_startPosX.Value + 115, _startPosY.Value + 10);
|
||||||
|
Point[] curvePoints3 = { point9, point10, point11, point12 };
|
||||||
|
g.FillPolygon(br, curvePoints3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
ProjectLiner/ProjectLiner/Entities/EntityCommonLiner.cs
Normal file
50
ProjectLiner/ProjectLiner/Entities/EntityCommonLiner.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность обычного "Лайнера"
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
namespace ProjectLiner.Entities
|
||||||
|
{
|
||||||
|
public class EntityCommonLiner
|
||||||
|
{
|
||||||
|
/// <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 EntityCommonLiner(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +1,10 @@
|
|||||||
namespace ProjectLiner;
|
namespace ProjectLiner.Entities;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Лайнер"
|
/// Класс-сущность "Лайнер"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityLiner
|
public class EntityLiner: EntityCommonLiner
|
||||||
{
|
{
|
||||||
/// <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>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
@ -40,26 +26,17 @@ public class EntityLiner
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Pipe { get; private set; }
|
public bool Pipe { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения автомобиля
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// <param name="anchor">Признак наличия якоря</param>
|
/// <param name="anchor">Признак наличия якоря</param>
|
||||||
/// <param name="boats">Признак наличия шлюпок</param>
|
/// <param name="boats">Признак наличия шлюпок</param>
|
||||||
/// <param name="pipe">Признак наличия трубы</param>
|
/// <param name="pipe">Признак наличия трубы</param>
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool anchor, bool boats, bool pipe)
|
public EntityLiner(int speed, double weight, Color bodyColor, Color additionalColor, bool anchor, bool boats, bool pipe) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
new EntityCommonLiner(speed, weight, bodyColor);
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Anchor = anchor;
|
Anchor = anchor;
|
||||||
Boats = boats;
|
Boats = boats;
|
20
ProjectLiner/ProjectLiner/FormLiner.Designer.cs
generated
20
ProjectLiner/ProjectLiner/FormLiner.Designer.cs
generated
@ -34,6 +34,7 @@
|
|||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
|
buttonCreateCommonLiner = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -50,11 +51,11 @@
|
|||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
//
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Location = new Point(12, 520);
|
buttonCreate.Location = new Point(12, 544);
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreate.Name = "buttonCreate";
|
||||||
buttonCreate.Size = new Size(150, 82);
|
buttonCreate.Size = new Size(203, 58);
|
||||||
buttonCreate.TabIndex = 1;
|
buttonCreate.TabIndex = 1;
|
||||||
buttonCreate.Text = "Создать";
|
buttonCreate.Text = "Создать Лайнер";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
buttonCreate.Click += buttonCreate_Click;
|
buttonCreate.Click += buttonCreate_Click;
|
||||||
//
|
//
|
||||||
@ -106,11 +107,23 @@
|
|||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateCommonLiner
|
||||||
|
//
|
||||||
|
buttonCreateCommonLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateCommonLiner.Location = new Point(221, 544);
|
||||||
|
buttonCreateCommonLiner.Name = "buttonCreateCommonLiner";
|
||||||
|
buttonCreateCommonLiner.Size = new Size(240, 58);
|
||||||
|
buttonCreateCommonLiner.TabIndex = 6;
|
||||||
|
buttonCreateCommonLiner.Text = "Создать Обычный Лайнер";
|
||||||
|
buttonCreateCommonLiner.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateCommonLiner.Click += buttonCreateCommonLiner_Click;
|
||||||
|
//
|
||||||
// FormLiner
|
// FormLiner
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(11F, 25F);
|
AutoScaleDimensions = new SizeF(11F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(948, 614);
|
ClientSize = new Size(948, 614);
|
||||||
|
Controls.Add(buttonCreateCommonLiner);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
@ -131,5 +144,6 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreateCommonLiner;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,12 +7,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using ProjectLiner.Drawnings;
|
||||||
|
|
||||||
namespace ProjectLiner
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
public partial class FormLiner : Form
|
public partial class FormLiner : Form
|
||||||
{
|
{
|
||||||
private DrawningLiner? _drawningLiner;
|
private DrawningCommonLiner? _drawningCommonLiner;
|
||||||
public FormLiner()
|
public FormLiner()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -23,35 +24,66 @@ namespace ProjectLiner
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningLiner == null)
|
if (_drawningCommonLiner == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningLiner.DrawTransport(gr);
|
_drawningCommonLiner.DrawTransport(gr);
|
||||||
pictureBoxLiner.Image = bmp;
|
pictureBoxLiner.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningCommonLiner):
|
||||||
|
_drawningCommonLiner = new DrawningCommonLiner(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(DrawningLiner):
|
||||||
|
_drawningCommonLiner = new DrawningLiner(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)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
|
_drawningCommonLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать Лайнер"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
CreateObject(nameof(DrawningLiner));
|
||||||
EntityLiner liner = new EntityLiner();
|
}
|
||||||
liner.Init(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
/// <summary>
|
||||||
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)), Convert.ToBoolean(random.Next(0, 2)));
|
/// </summary>
|
||||||
_drawningLiner = new DrawningLiner();
|
/// <param name="sender"></param>
|
||||||
_drawningLiner.Init(liner);
|
/// <param name="e"></param>
|
||||||
_drawningLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
|
||||||
_drawningLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
private void buttonCreateCommonLiner_Click(object sender, EventArgs e)
|
||||||
Draw();
|
{
|
||||||
|
CreateObject(nameof(DrawningCommonLiner));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -61,7 +93,7 @@ namespace ProjectLiner
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningLiner == null)
|
if (_drawningCommonLiner == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -71,16 +103,16 @@ namespace ProjectLiner
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawningLiner.MoveTransport(DirectionType.Up);
|
result = _drawningCommonLiner.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawningLiner.MoveTransport(DirectionType.Down);
|
result = _drawningCommonLiner.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawningLiner.MoveTransport(DirectionType.Left);
|
result = _drawningCommonLiner.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawningLiner.MoveTransport(DirectionType.Right);
|
result = _drawningCommonLiner.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,5 +121,6 @@ namespace ProjectLiner
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user