Добавление родителей и ввод конструкторов
This commit is contained in:
parent
d7e0cc9517
commit
e83b888c84
@ -1,271 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectLinkor;
|
||||
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningLinkor
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityLinkor? EntityLinkor { 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 _drawningLinkorWidth = 150;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки линкора
|
||||
/// </summary>
|
||||
private readonly int _drawningLinkorHeight = 80;
|
||||
|
||||
/// <summary>
|
||||
/// Иницилизация полей объекта-класса линкора
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weigth">Вес линкора</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="gunTurret">Признак наличия орудийной башни</param>
|
||||
/// <param name="compartment">Признак наличия отсека под ракеты</param>
|
||||
/// <param name="linkorMotor">Признак наличия</param>
|
||||
public void Init(int speed, double weigth, Color bodyColor, Color additionalColor, bool gunTurret, bool compartment, bool linkorMotor)
|
||||
{
|
||||
EntityLinkor = new EntityLinkor();
|
||||
EntityLinkor.Init(speed, weigth, bodyColor, additionalColor, gunTurret, compartment, linkorMotor);
|
||||
_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 (_drawningLinkorWidth <= width && _drawningLinkorHeight <= height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawningLinkorWidth > _pictureWidth )
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningLinkorWidth;
|
||||
}
|
||||
|
||||
if (_startPosY + _drawningLinkorWidth <= _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningLinkorHeight;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Кордината X</param>
|
||||
/// <param name="y">Кордината Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
|
||||
else if (x + _drawningLinkorWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth.Value - _drawningLinkorWidth;
|
||||
}
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
else if (y + _drawningLinkorHeight > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight.Value - _drawningLinkorHeight;
|
||||
}
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityLinkor == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityLinkor.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityLinkor.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityLinkor.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityLinkor.Step;
|
||||
}
|
||||
return true;
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value+_drawningLinkorWidth + EntityLinkor.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityLinkor.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value+_drawningLinkorHeight + EntityLinkor.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityLinkor.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityLinkor == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityLinkor.AdditionalColor);
|
||||
Brush bodybrush = new SolidBrush(EntityLinkor.BodyColor);
|
||||
|
||||
|
||||
//Заливка лодки
|
||||
Point point1 = new Point(_startPosX.Value + 5, _startPosY.Value + 5);
|
||||
Point point2 = new Point(_startPosX.Value + 110, _startPosY.Value + 5);
|
||||
Point point3 = new Point(_startPosX.Value + 150, _startPosY.Value + 42);
|
||||
Point point4 = new Point(_startPosX.Value + 110, _startPosY.Value + 80);
|
||||
Point point5 = new Point(_startPosX.Value + 5, _startPosY.Value + 80);
|
||||
Point point6 = new Point(_startPosX.Value + 5, _startPosY.Value + 5);
|
||||
|
||||
Point[] LinkorLine = { point1, point2, point3, point4, point5, point6 };
|
||||
g.FillPolygon(additionalBrush, LinkorLine);
|
||||
|
||||
//границы линкора
|
||||
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 5, _startPosX.Value + 110, _startPosY.Value + 5);
|
||||
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 80, _startPosX.Value + 110, _startPosY.Value + 80);
|
||||
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 5, _startPosX.Value + 5, _startPosY.Value + 80);
|
||||
g.DrawLine(pen, _startPosX.Value + 110, _startPosY.Value + 5, _startPosX.Value + 150, _startPosY.Value + 42);
|
||||
g.DrawLine(pen, _startPosX.Value + 110, _startPosY.Value + 80, _startPosX.Value + 150, _startPosY.Value + 42);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 59, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 64, 15, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 12, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 17, 15, 5);
|
||||
//Парус
|
||||
g.DrawArc(pen, _startPosX.Value + 45, _startPosY.Value + 15, 35, 60, 280, 160);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 17, _startPosX.Value + 67, _startPosY.Value + 72);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 72);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 17);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 45);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 35);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 55);
|
||||
|
||||
|
||||
//заливка ракет
|
||||
Brush br = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(bodybrush, _startPosX.Value + 25, _startPosY.Value + 59, 15, 15);
|
||||
g.FillRectangle(bodybrush, _startPosX.Value + 10, _startPosY.Value + 64, 15, 5);
|
||||
g.FillRectangle(bodybrush, _startPosX.Value + 25, _startPosY.Value + 12, 15, 15);
|
||||
g.FillRectangle(bodybrush, _startPosX.Value + 10, _startPosY.Value + 17, 15, 5);
|
||||
|
||||
//Орудийная башня
|
||||
if (EntityLinkor.GunTurret)
|
||||
{
|
||||
Brush bri = new SolidBrush(Color.Gray);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 27, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 95, _startPosY.Value + 32, 20, 20);
|
||||
g.FillEllipse(bri, _startPosX.Value + 90, _startPosY.Value + 27, 30, 30);
|
||||
g.FillEllipse(br, _startPosX.Value + 95, _startPosY.Value + 32, 20, 20);
|
||||
}
|
||||
|
||||
//Дополнительная ракета
|
||||
if (EntityLinkor.Сompartment)
|
||||
{
|
||||
Brush brfara = new SolidBrush(Color.Blue);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 35, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 15, 5);
|
||||
g.FillRectangle(brfara, _startPosX.Value + 25, _startPosY.Value + 35, 15, 15);
|
||||
g.FillRectangle(brfara, _startPosX.Value + 10, _startPosY.Value + 40, 15, 5);
|
||||
|
||||
}
|
||||
|
||||
//Мотор
|
||||
if (EntityLinkor.LinkorMotor)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 59, 5, 15);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 59, 5, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 5, 15);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 10, 5, 15);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace ProjectLinkor;
|
||||
namespace ProjectLinkor.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
273
ProjectSportCar/ProjectSportCar/Drawnings/DrawingWarship.cs
Normal file
273
ProjectSportCar/ProjectSportCar/Drawnings/DrawingWarship.cs
Normal file
@ -0,0 +1,273 @@
|
||||
using ProjectLinkor.Entities;
|
||||
using static System.Windows.Forms.LinkLabel;
|
||||
|
||||
namespace ProjectLinkor.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение базового объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingWarship
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityWarship? EntityWarship { 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 _drawingWarshipWidth = 148;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки военного корабля
|
||||
/// </summary>
|
||||
private readonly int _drawingWarshipHeight = 75;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Х объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawingWarshipWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawingWarshipHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawingWarship()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawingWarship(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityWarship = new EntityWarship(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawingWarshipWidth">Ширина прорисовки военного корабля</param>
|
||||
/// <param name="drawingWarshipHeight">Высота прорисовки военного корабля</param>
|
||||
protected DrawingWarship(int drawingWarshipWidth, int drawingWarshipHeight) : this()
|
||||
{
|
||||
_drawingWarshipWidth = drawingWarshipWidth;
|
||||
_drawingWarshipHeight = drawingWarshipHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
//TODO проверка, что объект "влезает" в размеры поля
|
||||
//если влезает, сохраняем границы и корректируем позицию объекта, если она уже была установлена
|
||||
|
||||
if (_drawingWarshipWidth > width || _drawingWarshipHeight > height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
if (_startPosX.HasValue || _startPosY.HasValue)
|
||||
{
|
||||
|
||||
if (_startPosX + _drawingWarshipWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawingWarshipWidth;
|
||||
}
|
||||
else if (_startPosX < 0) _startPosX = 0;
|
||||
if (_startPosY + _drawingWarshipHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawingWarshipHeight;
|
||||
}
|
||||
else if (_startPosY < 0) _startPosY = 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
|
||||
if (x + _drawingWarshipWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawingWarshipWidth;
|
||||
}
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
|
||||
if (y + _drawingWarshipHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawingWarshipHeight;
|
||||
}
|
||||
else if (y < 0) _startPosY = 0;
|
||||
else _startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityWarship == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityWarship.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityWarship.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityWarship.Step + _drawingWarshipWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityWarship.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityWarship.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityWarship.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityWarship.Step + _drawingWarshipHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityWarship.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityWarship == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
Brush main = new SolidBrush(EntityWarship.BodyColor);
|
||||
//Заливка линкора
|
||||
Point point1 = new Point(_startPosX.Value + 5, _startPosY.Value + 5);
|
||||
Point point2 = new Point(_startPosX.Value + 110, _startPosY.Value + 5);
|
||||
Point point3 = new Point(_startPosX.Value + 150, _startPosY.Value + 42);
|
||||
Point point4 = new Point(_startPosX.Value + 110, _startPosY.Value + 80);
|
||||
Point point5 = new Point(_startPosX.Value + 5, _startPosY.Value + 80);
|
||||
Point point6 = new Point(_startPosX.Value + 5, _startPosY.Value + 5);
|
||||
|
||||
Point[] LinkorLine = { point1, point2, point3, point4, point5, point6 };
|
||||
g.FillPolygon(main, LinkorLine);
|
||||
|
||||
//границы линкора
|
||||
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 5, _startPosX.Value + 110, _startPosY.Value + 5);
|
||||
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 80, _startPosX.Value + 110, _startPosY.Value + 80);
|
||||
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 5, _startPosX.Value + 5, _startPosY.Value + 80);
|
||||
g.DrawLine(pen, _startPosX.Value + 110, _startPosY.Value + 5, _startPosX.Value + 150, _startPosY.Value + 42);
|
||||
g.DrawLine(pen, _startPosX.Value + 110, _startPosY.Value + 80, _startPosX.Value + 150, _startPosY.Value + 42);
|
||||
|
||||
|
||||
//ракета
|
||||
Brush brfara = new SolidBrush(Color.Blue);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 35, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 15, 5);
|
||||
g.FillRectangle(brfara, _startPosX.Value + 25, _startPosY.Value + 35, 15, 15);
|
||||
g.FillRectangle(brfara, _startPosX.Value + 10, _startPosY.Value + 40, 15, 5);
|
||||
|
||||
//Парус
|
||||
g.DrawArc(pen, _startPosX.Value + 45, _startPosY.Value + 15, 35, 60, 280, 160);
|
||||
g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 17, _startPosX.Value + 67, _startPosY.Value + 72);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 72);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 17);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 45);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 35);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 55);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
75
ProjectSportCar/ProjectSportCar/Drawnings/DrawningLinkor.cs
Normal file
75
ProjectSportCar/ProjectSportCar/Drawnings/DrawningLinkor.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using ProjectLinkor.Entities;
|
||||
|
||||
namespace ProjectLinkor.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningLinkor : DrawingWarship
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weigth">Вес линкора</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="gunTurret">Признак наличия орудийной башни</param>
|
||||
/// <param name="compartment">Признак наличия отсека под ракеты</param>
|
||||
/// <param name="linkorMotor">Признак наличия</param>
|
||||
public DrawningLinkor(int speed, double weigth, Color bodyColor, Color additionalColor, bool gunTurret, bool compartment, bool linkorMotor) : base(148, 75)
|
||||
{
|
||||
EntityWarship = new EntityLinkor(speed, weigth, bodyColor, additionalColor, gunTurret, compartment, linkorMotor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityWarship == null || EntityWarship is not EntityLinkor linkor || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(linkor.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
//Орудийная башня
|
||||
if (linkor.GunTurret)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 27, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 95, _startPosY.Value + 32, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 27, 30, 30);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 32, 20, 20);
|
||||
}
|
||||
|
||||
//Дополнительнst ракетs
|
||||
if (linkor.Сompartment)
|
||||
{
|
||||
//границы ракет
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 59, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 64, 15, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 12, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 17, 15, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 59, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 64, 15, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 12, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 17, 15, 5);
|
||||
|
||||
}
|
||||
|
||||
//Мотор
|
||||
if (linkor.LinkorMotor)
|
||||
{
|
||||
Brush br = new SolidBrush(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 59, 5, 15);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 59, 5, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 5, 15);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 10, 5, 15);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,23 +1,20 @@
|
||||
namespace ProjectLinkor;
|
||||
namespace ProjectLinkor.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Линкор"
|
||||
/// </summary>
|
||||
public class EntityLinkor
|
||||
public class EntityLinkor : EntityWarship
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weigth { get; private set; }
|
||||
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
@ -42,12 +39,12 @@ public class EntityLinkor
|
||||
public bool LinkorMotor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения линкора
|
||||
/// Перемещение линкора
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weigth;
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Иницилизация полей объекта-класса линкора
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="speed">Скорость</param>
|
||||
@ -57,10 +54,10 @@ public class EntityLinkor
|
||||
/// <param name="gunTurret">Признак наличия орудийной башни</param>
|
||||
/// <param name="compartment">Признак наличия отсека под ракеты</param>
|
||||
/// <param name="linkorMotor">Признак наличия</param>
|
||||
public void Init(int speed, double weigth, Color bodyColor, Color additionalColor, bool gunTurret, bool compartment, bool linkorMotor)
|
||||
public EntityLinkor(int speed, double weigth, Color bodyColor, Color additionalColor, bool gunTurret, bool compartment, bool linkorMotor) : base(speed, weigth, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weigth = weigth;
|
||||
Weight = weigth;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
GunTurret = gunTurret;
|
37
ProjectSportCar/ProjectSportCar/Entities/EntityWarship.cs
Normal file
37
ProjectSportCar/ProjectSportCar/Entities/EntityWarship.cs
Normal file
@ -0,0 +1,37 @@
|
||||
namespace ProjectLinkor.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Военный корабль"
|
||||
/// </summary>
|
||||
public class EntityWarship
|
||||
{
|
||||
/// <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 EntityWarship(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonWarship = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxLinkor).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -51,9 +52,9 @@
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 433);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.Size = new Size(191, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.Text = "Создать Линкор";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
@ -105,11 +106,22 @@
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonWarship
|
||||
//
|
||||
buttonWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonWarship.Location = new Point(209, 433);
|
||||
buttonWarship.Name = "buttonWarship";
|
||||
buttonWarship.Size = new Size(216, 29);
|
||||
buttonWarship.TabIndex = 6;
|
||||
buttonWarship.Text = "Создать Военный корабль";
|
||||
buttonWarship.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormLinkor
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(857, 474);
|
||||
Controls.Add(buttonWarship);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
@ -130,5 +142,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonWarship;
|
||||
}
|
||||
}
|
@ -1,81 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectLinkor.Drawnings;
|
||||
|
||||
namespace ProjectLinkor
|
||||
namespace ProjectLinkor;
|
||||
|
||||
public partial class FormLinkor : Form
|
||||
{
|
||||
public partial class FormLinkor : Form
|
||||
private DrawingWarship? _drawningWarship;
|
||||
|
||||
public FormLinkor()
|
||||
{
|
||||
private DrawningLinkor? _drawningLinkor;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public FormLinkor()
|
||||
private void Draw()
|
||||
{
|
||||
|
||||
if (_drawningWarship == null)
|
||||
{
|
||||
InitializeComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
Bitmap bmp = new(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningWarship.DrawTransport(gr);
|
||||
pictureBoxLinkor.Image = bmp;
|
||||
}
|
||||
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
|
||||
if (_drawningLinkor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningLinkor.DrawTransport(gr);
|
||||
pictureBoxLinkor.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningLinkor = new DrawningLinkor();
|
||||
_drawningLinkor.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
case nameof(DrawingWarship):
|
||||
_drawningWarship = new DrawingWarship(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(DrawningLinkor):
|
||||
_drawningWarship = new DrawningLinkor(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)));
|
||||
_drawningLinkor.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
||||
_drawningLinkor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningWarship.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
||||
_drawningWarship.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
Draw();
|
||||
/// <summary>
|
||||
/// обработка нажатия кнопки "создать линкор"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLinkor));
|
||||
|
||||
/// <summary>
|
||||
/// обработка нажатия кнопки "создать военный корабль"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingWarship));
|
||||
|
||||
/// <summary>
|
||||
/// кнопки вверх/вниз/влево/вправо
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningWarship == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
if (_drawningLinkor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningLinkor.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningLinkor.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningLinkor.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningLinkor.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
case "buttonUp":
|
||||
result = _drawningWarship.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningWarship.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningWarship.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningWarship.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user