Добавление родителей и ввод конструкторов
This commit is contained in:
parent
8b930c99d4
commit
fdeb174e90
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectSeaplane;
|
namespace ProjectSeaplane.Drawnings;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
@ -1,13 +1,18 @@
|
|||||||
namespace ProjectSeaplane;
|
using ProjectSeaplane.Entities;
|
||||||
/// <summary>
|
using System;
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
using System.Collections.Generic;
|
||||||
/// </summary>
|
using System.Linq;
|
||||||
public class DrawningSeaplane
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane.Drawnings;
|
||||||
|
|
||||||
|
public class DrawningPlane
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntitySeaplane? EntitySeaplane { get; private set; }
|
public EntityPlane? EntityPlane { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -22,42 +27,56 @@ public class DrawningSeaplane
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки гидросамолёта
|
/// Левая координата прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки гидросамолёта
|
/// Верхняя кооридната прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки гидросамолёта
|
/// Ширина прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningSeaplaneWidth = 130;
|
private readonly int _drawningPlaneWidth = 130;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки гидросамолёта
|
/// Высота прорисовки гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningSeaplaneHeight = 50;
|
private readonly int _drawningPlaneHeight = 45;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Пустой конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
private DrawningPlane()
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="floats">Признак наличия поплавков</param>
|
|
||||||
/// <param name="boat">Признак наличия лодки</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat)
|
|
||||||
{
|
{
|
||||||
EntitySeaplane = new EntitySeaplane();
|
|
||||||
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, floats, boat);
|
|
||||||
_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 DrawningPlane(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningPlaneWidth">Ширина прорисовки гидросамолёта</param>
|
||||||
|
/// <param name="drawningPlaneHeight">Высота прорисовки гидросамолёта</param>
|
||||||
|
protected DrawningPlane(int _drawningPlaneWidth, int _drawningPlaneHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningPlaneWidth = drawningPlaneWidth;
|
||||||
|
_pictureHeight = drawningPlaneHeight;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -66,7 +85,7 @@ public class DrawningSeaplane
|
|||||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||||
public bool SetPictureSize(int width, int height)
|
public bool SetPictureSize(int width, int height)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (height < _drawningSeaplaneHeight || width < _drawningSeaplaneWidth)
|
if (height < _drawningSeaplaneHeight || width < _drawningSeaplaneWidth)
|
||||||
{
|
{
|
||||||
@ -121,7 +140,7 @@ public class DrawningSeaplane
|
|||||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -130,31 +149,31 @@ public class DrawningSeaplane
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntitySeaplane.Step > 0)
|
if (_startPosX.Value - EntityPlane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntitySeaplane.Step;
|
_startPosX -= (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntitySeaplane.Step > 0)
|
if (_startPosY.Value - EntityPlane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntitySeaplane.Step;
|
_startPosY -= (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + _drawningSeaplaneWidth + EntitySeaplane.Step < _pictureWidth)
|
if (_startPosX.Value + _drawningSeaplaneWidth + EntityPlane.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntitySeaplane.Step;
|
_startPosX += (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
|
|
||||||
if (_startPosY.Value + _drawningSeaplaneHeight + EntitySeaplane.Step < _pictureHeight)
|
if (_startPosY.Value + _drawningSeaplaneHeight + EntityPlane.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntitySeaplane.Step;
|
_startPosY += (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -165,19 +184,16 @@ public class DrawningSeaplane
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black, 2);
|
Pen pen = new(Color.Black, 2);
|
||||||
Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Отрисовка основных частей самолёта
|
//Отрисовка основных частей самолёта
|
||||||
Brush br = new SolidBrush(EntitySeaplane.BodyColor);
|
Brush br = new SolidBrush(EntityPlane.BodyColor);
|
||||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 20, 20);
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 20, 20);
|
||||||
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 20, 20);
|
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 20, 20);
|
||||||
Point point1 = new Point(_startPosX.Value + 10, _startPosY.Value);
|
Point point1 = new Point(_startPosX.Value + 10, _startPosY.Value);
|
||||||
@ -192,7 +208,7 @@ public class DrawningSeaplane
|
|||||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 40, _startPosY.Value + 20);
|
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 40, _startPosY.Value + 20);
|
||||||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 40);
|
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 40);
|
||||||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 30, _startPosX.Value + 130, _startPosY.Value + 30);
|
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 30, _startPosX.Value + 130, _startPosY.Value + 30);
|
||||||
|
|
||||||
//Крылья
|
//Крылья
|
||||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 25, 5);
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 25, 5);
|
||||||
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 25, 5);
|
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 25, 5);
|
||||||
@ -212,26 +228,5 @@ public class DrawningSeaplane
|
|||||||
g.FillEllipse(br, _startPosX.Value + 35, _startPosY.Value + 45, 5, 5);
|
g.FillEllipse(br, _startPosX.Value + 35, _startPosY.Value + 45, 5, 5);
|
||||||
g.FillEllipse(br, _startPosX.Value + 42, _startPosY.Value + 45, 5, 5);
|
g.FillEllipse(br, _startPosX.Value + 42, _startPosY.Value + 45, 5, 5);
|
||||||
g.FillEllipse(br, _startPosX.Value + 87, _startPosY.Value + 45, 5, 5);
|
g.FillEllipse(br, _startPosX.Value + 87, _startPosY.Value + 45, 5, 5);
|
||||||
|
|
||||||
|
|
||||||
//Надувнвя лодка
|
|
||||||
if (EntitySeaplane.Boat)
|
|
||||||
{
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Поплавки
|
|
||||||
if (EntitySeaplane.Floats)
|
|
||||||
{
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
using ProjectSeaplane.Entities;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane.Drawnings;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningSeaplane : DrawningPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="floats">Признак наличия поплавков</param>
|
||||||
|
/// <param name="boat">Признак наличия лодки</param>
|
||||||
|
public DrawningSeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) : base(130, 50)
|
||||||
|
{
|
||||||
|
EntityPlane = new EntitySeaplane(speed, weight, bodyColor, additionalColor, floats, boat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityPlane == null || EntityPlane is not EntitySeaplane seaplane || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black, 2);
|
||||||
|
Brush additionalBrush = new SolidBrush(seaplane.AdditionalColor);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
//Надувнвя лодка
|
||||||
|
if (seaplane.Boat)
|
||||||
|
{
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Поплавки
|
||||||
|
if (seaplane.Floats)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs
Normal file
49
ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Самолёт"
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public class EntityPlane
|
||||||
|
{
|
||||||
|
/// <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 EntityPlane(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +1,9 @@
|
|||||||
namespace ProjectSeaplane;
|
namespace ProjectSeaplane.Entities;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Гидросамолёт"
|
/// Класс-сущность "Гидросамолёт"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntitySeaplane
|
public class EntitySeaplane : EntityPlane
|
||||||
{
|
{
|
||||||
/// <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>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -35,11 +20,6 @@ public class EntitySeaplane
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Boat { get; private set; }
|
public bool Boat { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения гидросамолёта
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса гидросамолёта
|
/// Инициализация полей объекта-класса гидросамолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -49,12 +29,8 @@ public class EntitySeaplane
|
|||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// <param name="floats">Признак наличия поплавков</param>
|
/// <param name="floats">Признак наличия поплавков</param>
|
||||||
/// <param name="boat">Признак наличия лодки</param>
|
/// <param name="boat">Признак наличия лодки</param>
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat)
|
||||||
additionalColor, bool floats, bool boat)
|
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Floats = floats;
|
Floats = floats;
|
||||||
Boat = boat;
|
Boat = boat;
|
@ -34,6 +34,7 @@
|
|||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
|
buttonCreatePlane = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -51,9 +52,9 @@
|
|||||||
buttonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateSeaplane.Location = new Point(12, 465);
|
buttonCreateSeaplane.Location = new Point(12, 465);
|
||||||
buttonCreateSeaplane.Name = "buttonCreateSeaplane";
|
buttonCreateSeaplane.Name = "buttonCreateSeaplane";
|
||||||
buttonCreateSeaplane.Size = new Size(75, 23);
|
buttonCreateSeaplane.Size = new Size(196, 23);
|
||||||
buttonCreateSeaplane.TabIndex = 1;
|
buttonCreateSeaplane.TabIndex = 1;
|
||||||
buttonCreateSeaplane.Text = "Создать";
|
buttonCreateSeaplane.Text = "Создать гидросамолёт";
|
||||||
buttonCreateSeaplane.UseVisualStyleBackColor = true;
|
buttonCreateSeaplane.UseVisualStyleBackColor = true;
|
||||||
buttonCreateSeaplane.Click += ButtonCreateSeaplane_Click;
|
buttonCreateSeaplane.Click += ButtonCreateSeaplane_Click;
|
||||||
//
|
//
|
||||||
@ -105,11 +106,23 @@
|
|||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreatePlane
|
||||||
|
//
|
||||||
|
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreatePlane.Location = new Point(214, 465);
|
||||||
|
buttonCreatePlane.Name = "buttonCreatePlane";
|
||||||
|
buttonCreatePlane.Size = new Size(196, 23);
|
||||||
|
buttonCreatePlane.TabIndex = 6;
|
||||||
|
buttonCreatePlane.Text = "Создать самолёт";
|
||||||
|
buttonCreatePlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreatePlane.Click += buttonCreatePlane_Click;
|
||||||
|
//
|
||||||
// FormSeaplane
|
// FormSeaplane
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(900, 500);
|
ClientSize = new Size(900, 500);
|
||||||
|
Controls.Add(buttonCreatePlane);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
@ -130,5 +143,6 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreatePlane;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
namespace ProjectSeaplane;
|
using ProjectSeaplane.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectSeaplane;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Форма работы с объектом "Спортивный автомобиль"
|
/// Форма работы с объектом "Спортивный автомобиль"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -7,7 +9,7 @@ public partial class FormSeaplane : Form
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningSeaplane? _drawningSeaplane;
|
private DrawningPlane? _drawningPlane;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -20,33 +22,58 @@ public partial class FormSeaplane : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningSeaplane == null)
|
if (_drawningPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningSeaplane.DrawTransport(gr);
|
_drawningPlane.DrawTransport(gr);
|
||||||
pictureBoxSeaplane.Image = bmp;
|
pictureBoxSeaplane.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningPlane):
|
||||||
|
_drawningPlane = new DrawningPlane(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(DrawningSeaplane):
|
||||||
|
_drawningPlane = new DrawningSeaplane(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;
|
||||||
|
}
|
||||||
|
_drawningPlane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||||
|
_drawningPlane.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 ButtonCreateSeaplane_Click(object sender, EventArgs e)
|
private void ButtonCreateSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSeaplane));
|
||||||
{
|
|
||||||
Random random = new();
|
/// <summary>
|
||||||
_drawningSeaplane = new DrawningSeaplane();
|
/// Обработка нажатия кнопки "Создать самолёт"
|
||||||
|
/// </summary>
|
||||||
_drawningSeaplane.Init(random.Next(100, 300), random.Next(1000, 3000),
|
/// <param name="sender"></param>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
/// <param name="e"></param>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
private void buttonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
_drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
|
||||||
_drawningSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -54,7 +81,7 @@ public partial class FormSeaplane : Form
|
|||||||
/// <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 (_drawningSeaplane == null)
|
if (_drawningPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -63,20 +90,16 @@ public partial class FormSeaplane : Form
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result =
|
result = _drawningPlane.MoveTransport(DirectionType.Up);
|
||||||
_drawningSeaplane.MoveTransport(DirectionType.Up);
|
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result =
|
result = _drawningPlane.MoveTransport(DirectionType.Down);
|
||||||
_drawningSeaplane.MoveTransport(DirectionType.Down);
|
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result =
|
result = _drawningPlane.MoveTransport(DirectionType.Left);
|
||||||
_drawningSeaplane.MoveTransport(DirectionType.Left);
|
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result =
|
result = _drawningPlane.MoveTransport(DirectionType.Right);
|
||||||
_drawningSeaplane.MoveTransport(DirectionType.Right);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
|
Loading…
Reference in New Issue
Block a user