Добавление более высокоуровневых классов и конструкторов
This commit is contained in:
parent
3d9e5a8ad1
commit
7aa8954791
@ -1,250 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLabRad1
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningTankZU
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTankZU? EntityTankZU { get; private set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningTankWidth = 90;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningTankHeight = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bashnya">Признак наличия обвеса</param>
|
||||
/// <param name="zenorudie">Признак наличия антикрыла</param>
|
||||
/// <param name="radar">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, bool bashnya, bool zenorudie,
|
||||
bool radar)
|
||||
{
|
||||
EntityTankZU = new EntityTankZU();
|
||||
EntityTankZU.Init(speed, weight, bodyColor, additionalColor, bashnya, zenorudie, radar);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// Паша - написаЛ проверку:
|
||||
if (width <= _drawningTankWidth || height <= _drawningTankHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
int endx = x + _drawningTankWidth;
|
||||
|
||||
int endy = y + _drawningTankHeight;
|
||||
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// Паша - написаЛ проверку
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
if (endx > _pictureWidth || x < 0 || endy > _pictureHeight || y < 0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityTankZU == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityTankZU.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityTankZU.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
//Паша - НаписаЛ
|
||||
if (_startPosX.Value + _drawningTankWidth + EntityTankZU.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
//Паша - НаписаЛ
|
||||
if (_startPosY.Value + _drawningTankHeight + EntityTankZU.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityTankZU.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTankZU == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
Brush additionalBrush = new SolidBrush(EntityTankZU.AdditionalColor);
|
||||
|
||||
// Осн. корпус
|
||||
Brush br = new SolidBrush(EntityTankZU.BodyColor);
|
||||
|
||||
// Гусеницы, колёса
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 60, 70, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 50, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 50, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 22, _startPosY.Value + 50, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 50, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 50, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 70, _startPosY.Value + 50, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 22, _startPosY.Value + 50, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 45, _startPosY.Value + 50, 20, 20);
|
||||
|
||||
// ВЛД контур
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 70, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 50, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 40, 20, 20);
|
||||
|
||||
// ВЛД заливка
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 40, 70, 20);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 50, 10, 10);
|
||||
g.FillRectangle(br, _startPosX.Value + 80, _startPosY.Value + 50, 10, 10);
|
||||
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 70, _startPosY.Value + 40, 20, 20);
|
||||
|
||||
// Допы
|
||||
|
||||
//Зенорудие
|
||||
if (EntityTankZU.Zenorudie)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 20, 10, 10);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 30, _startPosX.Value + 80, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 40, _startPosY.Value + 30, _startPosX.Value + 70, _startPosY.Value);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 20, 10, 10);
|
||||
}
|
||||
|
||||
// Башня
|
||||
if (EntityTankZU.Bashnya)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 20, 30, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 20, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 20, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 20, 30, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 30, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 20, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 20, 20, 20);
|
||||
}
|
||||
|
||||
// Радар
|
||||
if (EntityTankZU.Radar)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 50, _startPosX.Value + 10, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 40, _startPosX.Value + 10, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 25, _startPosY.Value);
|
||||
|
||||
Point point1 = new Point(_startPosX.Value + 10, _startPosY.Value);
|
||||
Point point3 = new Point(_startPosX.Value + 10, _startPosY.Value + 20);
|
||||
Point point5 = new Point(_startPosX.Value + 30, _startPosY.Value + 10);
|
||||
Point[] curvePoints = { point1, point3, point5 };
|
||||
float tension = 0.8F;
|
||||
g.DrawCurve(pen, curvePoints, tension);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLabRad1
|
||||
namespace WinFormsLabRad1.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
207
WinFormsLabRad1/WinFormsLabRad1/Drawnings/DrawningPlatforma.cs
Normal file
207
WinFormsLabRad1/WinFormsLabRad1/Drawnings/DrawningPlatforma.cs
Normal file
@ -0,0 +1,207 @@
|
||||
using WinFormsLabRad1.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLabRad1.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта базовой сущности
|
||||
/// </summary>
|
||||
public class DrawningPlatforma
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityPlatforma? EntityPlatforma { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningPlatformaWidth = 90;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningPlatformaHeight = 30;
|
||||
|
||||
private DrawningPlatforma()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningPlatforma(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityPlatforma = new EntityPlatforma(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningMachineWidth">Ширина прорисовки машины</param>
|
||||
/// <param name="drawningMachineHeight">Высота прорисовки машины</param>
|
||||
protected DrawningPlatforma(int drawningMachineWidth, int drawningMachineHeight) : this()
|
||||
{
|
||||
_drawningPlatformaWidth = drawningMachineWidth;
|
||||
_pictureHeight = drawningMachineHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// Паша - написаЛ проверку:
|
||||
if (width <= _drawningPlatformaWidth || height <= _drawningPlatformaHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// int endx = x + _drawningTankWidth;
|
||||
|
||||
// int endy = y + _drawningTankHeight;
|
||||
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// Паша - написаЛ проверку
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
if (x > _pictureWidth || x < 0 || y > _pictureHeight || y < 0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityPlatforma == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityPlatforma.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityPlatforma.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityPlatforma.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityPlatforma.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
//Паша - НаписаЛ
|
||||
if (_startPosX.Value + _drawningPlatformaWidth + EntityPlatforma.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityPlatforma.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
//Паша - НаписаЛ
|
||||
if (_startPosY.Value + _drawningPlatformaHeight + EntityPlatforma.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityPlatforma.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlatforma == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
// Осн. корпус
|
||||
Brush br = new SolidBrush(EntityPlatforma.BodyColor);
|
||||
|
||||
// Гусеницы, колёса
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 20, 70, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 10, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 10, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 22, _startPosY.Value + 10, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 10, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 10, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 70, _startPosY.Value + 10, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 22, _startPosY.Value + 10, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 45, _startPosY.Value + 10, 20, 20);
|
||||
|
||||
// ВЛД контур
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value, 70, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value, 20, 20);
|
||||
|
||||
// ВЛД заливка
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value, 70, 20);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 10, 10, 10);
|
||||
g.FillRectangle(br, _startPosX.Value + 80, _startPosY.Value + 10, 10, 10);
|
||||
g.FillEllipse(br, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(br, _startPosX.Value + 70, _startPosY.Value, 20, 20);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
98
WinFormsLabRad1/WinFormsLabRad1/Drawnings/DrawningTankZU.cs
Normal file
98
WinFormsLabRad1/WinFormsLabRad1/Drawnings/DrawningTankZU.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WinFormsLabRad1.Entities;
|
||||
|
||||
namespace WinFormsLabRad1.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningTankZU : DrawningPlatforma
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawningTankZU(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine) : base(90, 70)
|
||||
{
|
||||
EntityPlatforma = new EntityTankZU(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlatforma == null || EntityPlatforma is not EntityTankZU TankZU || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
Brush additionalBrush = new SolidBrush(TankZU.AdditionalColor);
|
||||
|
||||
// Допы
|
||||
|
||||
//Зенорудие
|
||||
if (TankZU.Zenorudie)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 20, 10, 10);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 30, _startPosX.Value + 80, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 40, _startPosY.Value + 30, _startPosX.Value + 70, _startPosY.Value);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 20, 10, 10);
|
||||
}
|
||||
|
||||
// Башня
|
||||
if (TankZU.Bashnya)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 20, 30, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 20, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 20, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 20, 30, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 30, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 30, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 20, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 20, 20, 20);
|
||||
}
|
||||
|
||||
// Радар
|
||||
if (TankZU.Radar)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 50, _startPosX.Value + 10, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 40, _startPosX.Value + 10, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 25, _startPosY.Value);
|
||||
|
||||
Point point1 = new Point(_startPosX.Value + 10, _startPosY.Value);
|
||||
Point point3 = new Point(_startPosX.Value + 10, _startPosY.Value + 20);
|
||||
Point point5 = new Point(_startPosX.Value + 30, _startPosY.Value + 10);
|
||||
Point[] curvePoints = { point1, point3, point5 };
|
||||
float tension = 0.8F;
|
||||
g.DrawCurve(pen, curvePoints, tension);
|
||||
}
|
||||
|
||||
_startPosY += 40;
|
||||
base.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
43
WinFormsLabRad1/WinFormsLabRad1/Entities/EntityPlatforma.cs
Normal file
43
WinFormsLabRad1/WinFormsLabRad1/Entities/EntityPlatforma.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLabRad1.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Платформа(ходовая)"
|
||||
/// </summary>
|
||||
public class EntityPlatforma
|
||||
{
|
||||
/// <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 EntityPlatforma(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
45
WinFormsLabRad1/WinFormsLabRad1/Entities/EntityTankZU.cs
Normal file
45
WinFormsLabRad1/WinFormsLabRad1/Entities/EntityTankZU.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLabRad1.Entities
|
||||
/// <summary>
|
||||
/// Класс-сущность "ЗУ с башней, с З.О. и Радаром"
|
||||
/// </summary>
|
||||
{
|
||||
public class EntityTankZU : EntityPlatforma
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия башни
|
||||
/// </summary>
|
||||
public bool Bashnya { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия З.О.
|
||||
/// </summary>
|
||||
public bool Zenorudie { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Должен быть конструктор наследника
|
||||
/// </summary>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bashnya">Признак наличия обвеса</param>
|
||||
/// <param name="zenorudie">Признак наличия антикрыла</param>
|
||||
/// <param name="radar">Признак наличия гоночной полосы</param>
|
||||
public EntityTankZU(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, bool bashnya, bool zenorudie,
|
||||
bool radar) : base (speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Bashnya = bashnya;
|
||||
Zenorudie = zenorudie;
|
||||
Radar = radar;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLabRad1
|
||||
/// <summary>
|
||||
/// Класс-сущность "ЗУ с башней, с З.О. и Радаром"
|
||||
/// </summary>
|
||||
{
|
||||
public class EntityTankZU
|
||||
{
|
||||
/// <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 Bashnya { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия З.О.
|
||||
/// </summary>
|
||||
public bool Zenorudie { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { 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="bashnya">Признак наличия обвеса</param>
|
||||
/// <param name="zenorudie">Признак наличия антикрыла</param>
|
||||
/// <param name="radar">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed,double weight, Color bodyColor,
|
||||
Color additionalColor, bool bashnya, bool zenorudie,
|
||||
bool radar)
|
||||
{ Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Bashnya = bashnya;
|
||||
Zenorudie = zenorudie;
|
||||
Radar = radar;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,11 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBox1 = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonCreateZU = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreatePlatforma = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -47,16 +48,16 @@
|
||||
pictureBox1.TabIndex = 0;
|
||||
pictureBox1.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateZU
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 289);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(102, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Новая машина";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click_1;
|
||||
buttonCreateZU.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateZU.Location = new Point(12, 289);
|
||||
buttonCreateZU.Name = "buttonCreateZU";
|
||||
buttonCreateZU.Size = new Size(69, 23);
|
||||
buttonCreateZU.TabIndex = 1;
|
||||
buttonCreateZU.Text = "Новая ЗУ";
|
||||
buttonCreateZU.UseVisualStyleBackColor = true;
|
||||
buttonCreateZU.Click += buttonCreate_Click_1;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
@ -106,16 +107,28 @@
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreatePlatforma
|
||||
//
|
||||
buttonCreatePlatforma.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreatePlatforma.Location = new Point(87, 289);
|
||||
buttonCreatePlatforma.Name = "buttonCreatePlatforma";
|
||||
buttonCreatePlatforma.Size = new Size(115, 23);
|
||||
buttonCreatePlatforma.TabIndex = 6;
|
||||
buttonCreatePlatforma.Text = "Новая платформа";
|
||||
buttonCreatePlatforma.UseVisualStyleBackColor = true;
|
||||
buttonCreatePlatforma.Click += buttonCreatePlatforma_Click;
|
||||
//
|
||||
// FormTankZU
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(874, 324);
|
||||
Controls.Add(buttonCreatePlatforma);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonCreateZU);
|
||||
Controls.Add(pictureBox1);
|
||||
Name = "FormTankZU";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
@ -128,10 +141,11 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBox1;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateZU;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreatePlatforma;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using WinFormsLabRad1.Drawnings;
|
||||
|
||||
namespace WinFormsLabRad1
|
||||
{
|
||||
@ -18,7 +19,7 @@ namespace WinFormsLabRad1
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningTankZU? _drawningTankZU;
|
||||
private DrawningPlatforma? _drawningPlatforma;
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
@ -32,34 +33,62 @@ namespace WinFormsLabRad1
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningTankZU == null)
|
||||
if (_drawningPlatforma == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningTankZU.DrawTransport(gr);
|
||||
_drawningPlatforma.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningPlatforma):
|
||||
_drawningPlatforma = new DrawningPlatforma(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(DrawningTankZU):
|
||||
_drawningPlatforma = new DrawningTankZU(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;
|
||||
}
|
||||
_drawningPlatforma.SetPictureSize(pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningPlatforma.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
// _strategy = null;
|
||||
// comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать Платформу"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void buttonCreate_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningTankZU = new DrawningTankZU();
|
||||
_drawningTankZU.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)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningTankZU.SetPictureSize(pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningTankZU.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreatePlatforma_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlatforma));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать ЗУ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void buttonCreate_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawningTankZU));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@ -68,7 +97,7 @@ namespace WinFormsLabRad1
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTankZU == null)
|
||||
if (_drawningPlatforma == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -76,23 +105,24 @@ namespace WinFormsLabRad1
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningTankZU.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningTankZU.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningTankZU.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningTankZU.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonUp":
|
||||
result = _drawningPlatforma.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningPlatforma.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningPlatforma.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningPlatforma.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user