Добавление родителей и ввод конструкторов
This commit is contained in:
parent
e9c9a9caff
commit
d1bfd8cebe
@ -1,4 +1,4 @@
|
||||
namespace ProjectContainerShip;
|
||||
namespace ProjectContainerShip.Drawings;
|
||||
|
||||
public enum DirectionType
|
||||
{
|
@ -0,0 +1,67 @@
|
||||
using ProjectContainerShip.Entities;
|
||||
|
||||
namespace ProjectContainerShip.Drawings;
|
||||
|
||||
public class DrawningContainerShip : DrawningShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodycolor">Основной цвет</param>
|
||||
/// <param name="additionalcolor">Дополнительный цвет</param>
|
||||
/// <param name="crane">Признак наличия крана</param>
|
||||
/// <param name="container">Признак наличия контейнеров</param>
|
||||
public DrawningContainerShip(int speed, double weight, Color bodycolor, Color additionalcolor, bool crane, bool container) : base(120,40)
|
||||
{
|
||||
EntityShip = new EntityContainerShip(speed, weight, bodycolor, additionalcolor, crane, container);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityShip == null || EntityShip is not EntityContainerShip containerShip || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(containerShip.AdditionalColor);
|
||||
|
||||
if (containerShip.Container)
|
||||
|
||||
{
|
||||
// Верхний маленький контейнер
|
||||
Point[] container =
|
||||
{
|
||||
new Point((int)_startPosX + 30, (int)_startPosY + 10),
|
||||
new Point((int)_startPosX + 30, (int)_startPosY ),
|
||||
new Point((int)_startPosX + 55, (int)_startPosY),
|
||||
new Point((int)_startPosX + 55, (int)_startPosY + 10)
|
||||
};
|
||||
|
||||
g.FillPolygon(additionalBrush, container);
|
||||
g.DrawPolygon(pen, container);
|
||||
|
||||
//Контейнер под маленьким контейнером
|
||||
g.FillRectangle(additionalBrush, (int)_startPosX + 20, (int)_startPosY + 10, 27, 10);
|
||||
g.DrawRectangle(pen, (int)_startPosX + 20, (int)_startPosY + 10, 27, 10);
|
||||
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (containerShip.Crane)
|
||||
{
|
||||
g.DrawLine(pen, (int)_startPosX + 70, (int)_startPosY + 10, (int)_startPosX + 70, (int)_startPosY);
|
||||
g.DrawLine(pen, (int)_startPosX + 70, (int)_startPosY, (int)_startPosX + 110, (int)_startPosY);
|
||||
g.DrawLine(pen, (int)_startPosX + 70, (int)_startPosY, (int)_startPosX + 110, (int)_startPosY + 5);
|
||||
g.DrawLine(pen, (int)_startPosX + 110, (int)_startPosY, (int)_startPosX + 110, (int)_startPosY + 30);
|
||||
|
||||
//Хваталка контейнера
|
||||
g.DrawLine(pen, (int)(_startPosX + 100), (int)(_startPosY + 30), (int)_startPosX + 120, (int)(_startPosY + 30));
|
||||
g.DrawLine(pen, (int)(_startPosX + 100), (int)(_startPosY + 30), (int)_startPosX + 100, (int)(_startPosY + 35));
|
||||
g.DrawLine(pen, (int)(_startPosX + 120), (int)(_startPosY + 30), (int)_startPosX + 120, (int)(_startPosY + 35));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,18 @@
|
||||
namespace ProjectContainerShip;
|
||||
using ProjectContainerShip.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class DrawningContainerShip
|
||||
namespace ProjectContainerShip.Drawings;
|
||||
|
||||
public class DrawningShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityContainerShip? EntityContainerShip { get; private set; }
|
||||
public EntityShip? EntityShip { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@ -20,42 +27,56 @@ public class DrawningContainerShip
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки контейнеровоза
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координата прорисовки контейнеровоза
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки контейнеровоза
|
||||
/// </summary>
|
||||
private readonly int _drawningContainerShipWidth = 120;
|
||||
private readonly int _drawningContainerShipWidth = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки контейнеровоза
|
||||
/// </summary>
|
||||
private readonly int _drawningContainerShipHeight = 40;
|
||||
private readonly int _drawningContainerShipHeight = 30;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodycolor">Основной цвет</param>
|
||||
/// <param name="additionalcolor">Дополнительный цвет</param>
|
||||
/// <param name="crane">Признак наличия крана</param>
|
||||
/// <param name="container">Признак наличия контейнеров</param>
|
||||
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, bool crane, bool container)
|
||||
private DrawningShip()
|
||||
{
|
||||
EntityContainerShip = new EntityContainerShip();
|
||||
EntityContainerShip.Init(speed,weight,bodycolor,additionalcolor,crane,container);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodycolor">Основной цвет</param>
|
||||
public DrawningShip(int speed, double weight, Color bodycolor) : this()
|
||||
{
|
||||
EntityShip = new EntityShip(speed, weight, bodycolor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningContainerShipWidth">Ширина прорисовки корабля</param>
|
||||
/// <param name="drawningContainerShipHeight">Высота прорисовки корабля</param>
|
||||
protected DrawningShip(int drawningContainerShipWidth, int drawningContainerShipHeight) : this()
|
||||
{
|
||||
_drawningContainerShipWidth = drawningContainerShipWidth;
|
||||
_drawningContainerShipHeight = drawningContainerShipHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -64,7 +85,7 @@ public class DrawningContainerShip
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawningContainerShipWidth > width || _drawningContainerShipHeight> height)
|
||||
if (_drawningContainerShipWidth > width || _drawningContainerShipHeight > height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -121,7 +142,7 @@ public class DrawningContainerShip
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityContainerShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -130,30 +151,30 @@ public class DrawningContainerShip
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityContainerShip.Step > 0)
|
||||
if (_startPosX.Value - EntityShip.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityContainerShip.Step;
|
||||
_startPosX -= (int)EntityShip.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityContainerShip.Step > 0)
|
||||
if (_startPosY.Value - EntityShip.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityContainerShip.Step;
|
||||
_startPosY -= (int)EntityShip.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningContainerShipWidth + EntityContainerShip.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningContainerShipWidth + EntityShip.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityContainerShip.Step;
|
||||
_startPosX += (int)EntityShip.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningContainerShipHeight + EntityContainerShip.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawningContainerShipHeight + EntityShip.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityContainerShip.Step;
|
||||
_startPosY += (int)EntityShip.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -165,15 +186,14 @@ public class DrawningContainerShip
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityContainerShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityContainerShip.AdditionalColor);
|
||||
|
||||
//Корпус контейнеровоза
|
||||
g.DrawPolygon(pen, new Point[]
|
||||
@ -184,8 +204,7 @@ public class DrawningContainerShip
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Brush br = new SolidBrush(EntityContainerShip.BodyColor);
|
||||
Brush br = new SolidBrush(EntityShip.BodyColor);
|
||||
g.FillPolygon(br, new Point[]
|
||||
{
|
||||
new Point((int)_startPosX+10,(int)_startPosY+20),new Point((int)_startPosX+100,(int)_startPosY+20),
|
||||
@ -200,44 +219,7 @@ public class DrawningContainerShip
|
||||
g.DrawLine(pen, (int)_startPosX + 26, (int)_startPosY + 31, (int)_startPosX + 30, (int)_startPosY + 31);
|
||||
|
||||
//Длинный контейнер справа
|
||||
g.DrawRectangle(pen,(int)_startPosX+40,(int)_startPosY+10,57,10);
|
||||
g.DrawRectangle(pen, (int)_startPosX + 40, (int)_startPosY + 10, 57, 10);
|
||||
g.FillRectangle(br, (int)_startPosX + 40, (int)_startPosY + 10, 57, 10);
|
||||
|
||||
//Кран
|
||||
if (EntityContainerShip.Crane)
|
||||
{
|
||||
g.DrawLine(pen, (int)_startPosX + 70, (int)_startPosY + 10, (int)_startPosX + 70, (int)_startPosY);
|
||||
g.DrawLine(pen, (int)_startPosX + 70, (int)_startPosY, (int)_startPosX + 110, (int)_startPosY);
|
||||
g.DrawLine(pen, (int)_startPosX + 70, (int)_startPosY, (int)_startPosX + 110, (int)_startPosY + 5);
|
||||
g.DrawLine(pen, (int)_startPosX + 110, (int)_startPosY, (int)_startPosX + 110, (int)_startPosY + 30);
|
||||
|
||||
//Хваталка контейнера
|
||||
g.DrawLine(pen,(int)(_startPosX + 100),(int)(_startPosY + 30), (int)_startPosX + 120, (int)(_startPosY + 30));
|
||||
g.DrawLine(pen, (int)(_startPosX + 100), (int)(_startPosY + 30), (int)_startPosX + 100, (int)(_startPosY + 35));
|
||||
g.DrawLine(pen, (int)(_startPosX + 120), (int)(_startPosY + 30), (int)_startPosX + 120, (int)(_startPosY + 35));
|
||||
}
|
||||
|
||||
//Контейнер
|
||||
if (EntityContainerShip.Container)
|
||||
|
||||
{
|
||||
// Верхний маленький контейнер
|
||||
Point[] container =
|
||||
{
|
||||
new Point((int)_startPosX + 30, (int)_startPosY + 10),
|
||||
new Point((int)_startPosX + 30, (int)_startPosY ),
|
||||
new Point((int)_startPosX + 55, (int)_startPosY),
|
||||
new Point((int)_startPosX + 55, (int)_startPosY + 10)
|
||||
};
|
||||
|
||||
g.FillPolygon(additionalBrush, container);
|
||||
g.DrawPolygon(pen, container);
|
||||
|
||||
//Контейнер под маленьким контейнером
|
||||
g.FillRectangle(additionalBrush, (int)_startPosX + 20, (int)_startPosY + 10, 27, 10);
|
||||
g.DrawRectangle(pen, (int)_startPosX + 20, (int)_startPosY + 10, 27, 10);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
namespace ProjectContainerShip.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность Контейнеровоз
|
||||
/// </summary>
|
||||
public class EntityContainerShip : EntityShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия крана
|
||||
/// </summary>
|
||||
public bool Crane { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия контейнеров
|
||||
/// </summary>
|
||||
public bool Container { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес контейнеровоза</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="crane">Признак наличия крана</param>
|
||||
/// <param name="container">Признак наличия контейнеров</param>
|
||||
public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container) : base(speed,weight,bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Crane = crane;
|
||||
Container = container;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
namespace ProjectContainerShip.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Корабль"
|
||||
/// </summary>
|
||||
public class EntityShip
|
||||
{
|
||||
/// <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 EntityShip(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
namespace ProjectContainerShip;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность Контейнеровоз
|
||||
/// </summary>
|
||||
public class EntityContainerShip
|
||||
{
|
||||
/// <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 Crane { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия контейнеров
|
||||
/// </summary>
|
||||
public bool Container { 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="crane">Признак наличия крана</param>
|
||||
/// <param name="container">Признак наличия контейнеров</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Crane = crane;
|
||||
Container = container;
|
||||
}
|
||||
|
||||
}
|
@ -34,6 +34,7 @@
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateShip = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxContainerShip).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -51,9 +52,9 @@
|
||||
buttonCreateContainerShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateContainerShip.Location = new Point(12, 457);
|
||||
buttonCreateContainerShip.Name = "buttonCreateContainerShip";
|
||||
buttonCreateContainerShip.Size = new Size(150, 46);
|
||||
buttonCreateContainerShip.Size = new Size(316, 46);
|
||||
buttonCreateContainerShip.TabIndex = 1;
|
||||
buttonCreateContainerShip.Text = "Создать";
|
||||
buttonCreateContainerShip.Text = "Создать контейнеровоз";
|
||||
buttonCreateContainerShip.UseVisualStyleBackColor = true;
|
||||
buttonCreateContainerShip.Click += ButtonCreateContainerShip_Click;
|
||||
//
|
||||
@ -105,11 +106,23 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateShip
|
||||
//
|
||||
buttonCreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateShip.Location = new Point(358, 457);
|
||||
buttonCreateShip.Name = "buttonCreateShip";
|
||||
buttonCreateShip.Size = new Size(316, 46);
|
||||
buttonCreateShip.TabIndex = 6;
|
||||
buttonCreateShip.Text = "Создать корабль";
|
||||
buttonCreateShip.UseVisualStyleBackColor = true;
|
||||
buttonCreateShip.Click += ButtonCreateShip_Click;
|
||||
//
|
||||
// FormContainerShip
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1256, 529);
|
||||
Controls.Add(buttonCreateShip);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
@ -132,5 +145,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateShip;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ProjectContainerShip.Drawings;
|
||||
|
||||
namespace ProjectContainerShip;
|
||||
|
||||
@ -10,7 +11,7 @@ public partial class FormContainerShip : Form
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningContainerShip? _drawningContainerShip;
|
||||
private DrawningShip? _drawningShip;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@ -25,34 +26,54 @@ public partial class FormContainerShip : Form
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningContainerShip == null)
|
||||
if (_drawningShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningContainerShip.DrawTransport(gr);
|
||||
_drawningShip.DrawTransport(gr);
|
||||
pictureBoxContainerShip.Image = bmp;
|
||||
}
|
||||
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningShip):
|
||||
_drawningShip = new DrawningShip(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(DrawningContainerShip):
|
||||
_drawningShip = new DrawningContainerShip(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;
|
||||
}
|
||||
|
||||
_drawningShip.SetPictureSize(pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Обработка нажатия кнопки "Создать контейнеровоз"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateContainerShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningContainerShip = new DrawningContainerShip();
|
||||
_drawningContainerShip.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)));
|
||||
_drawningContainerShip.SetPictureSize(pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||
_drawningContainerShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateContainerShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningContainerShip));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать корабль"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningShip));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@ -61,7 +82,7 @@ public partial class FormContainerShip : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningContainerShip == null)
|
||||
if (_drawningShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -71,16 +92,16 @@ public partial class FormContainerShip : Form
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningContainerShip.MoveTransport(DirectionType.Up);
|
||||
result = _drawningShip.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningContainerShip.MoveTransport(DirectionType.Down);
|
||||
result = _drawningShip.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningContainerShip.MoveTransport(DirectionType.Left);
|
||||
result = _drawningShip.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningContainerShip.MoveTransport(DirectionType.Right);
|
||||
result = _drawningShip.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user