Добавление родителей и ввод конструкторов
This commit is contained in:
parent
b1154674c2
commit
bee6b03df2
@ -1,242 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection.Metadata.Ecma335;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLinkor
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
|
||||||
public class DrawingLinkor
|
|
||||||
{
|
|
||||||
/// <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 = 110;
|
|
||||||
/// <summary>
|
|
||||||
/// Высота прорисовки аэробуса
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _drawningLinkorHeight = 70;
|
|
||||||
/// <summary>
|
|
||||||
/// Инициализация свойств
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="rocket">Признак наличия обвеса</param>
|
|
||||||
/// <param name="gun">Признак наличия антикрыла</param>
|
|
||||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool gun)
|
|
||||||
{
|
|
||||||
EntityLinkor = new EntityLinkor();
|
|
||||||
EntityLinkor.Init(speed, weight, bodyColor, additionalColor, rocket, gun);
|
|
||||||
_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 > 110 && height > 70)
|
|
||||||
{
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
|
|
||||||
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 если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
|
||||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
|
|
||||||
if (_startPosX.Value + 110 > _pictureWidth)
|
|
||||||
{
|
|
||||||
_startPosX = _pictureWidth - 110;
|
|
||||||
}
|
|
||||||
if (_startPosY.Value + 70 > _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY = _pictureHeight - 70;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
public void CheckPosition()
|
|
||||||
{
|
|
||||||
if (_startPosX ==null || _startPosY==null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_startPosX.Value + _drawningLinkorWidth > _pictureWidth)
|
|
||||||
{
|
|
||||||
_startPosX = _pictureWidth - _drawningLinkorWidth;
|
|
||||||
}
|
|
||||||
if (_startPosY.Value + _drawningLinkorHeight > _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY = _pictureHeight - _drawningLinkorHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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);
|
|
||||||
|
|
||||||
Point[] body = { new Point(_startPosX.Value + 70, _startPosY.Value + 20),
|
|
||||||
new Point(_startPosX.Value + 100, _startPosY.Value + 40), new Point(_startPosX.Value +70, _startPosY.Value + 60) };
|
|
||||||
Point[] body2 = { new Point(_startPosX.Value + 50, _startPosY.Value + 10),
|
|
||||||
new Point(_startPosX.Value + 60, _startPosY.Value + 15), new Point(_startPosX.Value +50, _startPosY.Value + 20) };
|
|
||||||
Point[] body3 = { new Point(_startPosX.Value + 50, _startPosY.Value + 60),
|
|
||||||
new Point(_startPosX.Value + 60, _startPosY.Value + 65), new Point(_startPosX.Value + 50, _startPosY.Value + 70) };
|
|
||||||
|
|
||||||
|
|
||||||
//границы Линкора
|
|
||||||
g.DrawPolygon(pen, body);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 20, 60, 40);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 25, 5, 10);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 5, 10);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//корпус
|
|
||||||
Brush br = new SolidBrush(EntityLinkor.BodyColor);
|
|
||||||
g.FillPolygon(br, body);
|
|
||||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 20, 60, 40);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 65, _startPosY.Value + 35, 10, 10);
|
|
||||||
|
|
||||||
//Мачта
|
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
|
||||||
g.FillRectangle(brBlack, _startPosX.Value + 50, _startPosY.Value + 30, 10, 20);
|
|
||||||
g.FillRectangle(brBlack, _startPosX.Value + 30, _startPosY.Value + 35, 20, 10);
|
|
||||||
|
|
||||||
//задние трубы
|
|
||||||
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 25, 5, 10);
|
|
||||||
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 45, 5, 10);
|
|
||||||
|
|
||||||
// доп
|
|
||||||
if (EntityLinkor.Rocket)
|
|
||||||
{
|
|
||||||
//ракеты
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 20, 10);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 60, 20, 10);
|
|
||||||
g.FillPolygon(additionalBrush, body2);
|
|
||||||
g.FillPolygon(additionalBrush, body3);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (EntityLinkor.Gun)
|
|
||||||
{
|
|
||||||
//пушка
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 35, 10, 10);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 55, _startPosY.Value + 35, 30, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ProjectLinkor
|
namespace ProjectLinkor.Drawnings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
70
ProjectAirbus/ProjectAirbus/Drawnings/DrawingLinkor.cs
Normal file
70
ProjectAirbus/ProjectAirbus/Drawnings/DrawingLinkor.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata.Ecma335;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectLinkor.Entities;
|
||||||
|
|
||||||
|
namespace ProjectLinkor.Drawnings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawingLinkor : DrawingShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="rocket">Признак наличия обвеса</param>
|
||||||
|
/// <param name="gun">Признак наличия антикрыла</param>
|
||||||
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
|
|
||||||
|
public DrawingLinkor(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool gun) : base(110, 70)
|
||||||
|
{
|
||||||
|
EntityShip = new EntityLinkor(speed, weight, bodyColor, additionalColor, rocket, gun);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityShip == null || EntityShip is not EntityLinkor linkor || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(linkor.AdditionalColor);
|
||||||
|
|
||||||
|
Point[] body2 = { new Point(_startPosX.Value + 50, _startPosY.Value + 10),
|
||||||
|
new Point(_startPosX.Value + 60, _startPosY.Value + 15), new Point(_startPosX.Value +50, _startPosY.Value + 20) };
|
||||||
|
Point[] body3 = { new Point(_startPosX.Value + 50, _startPosY.Value + 60),
|
||||||
|
new Point(_startPosX.Value + 60, _startPosY.Value + 65), new Point(_startPosX.Value + 50, _startPosY.Value + 70) };
|
||||||
|
if (linkor.Rocket)
|
||||||
|
{
|
||||||
|
//ракеты
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 20, 10);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 60, 20, 10);
|
||||||
|
g.FillPolygon(additionalBrush, body2);
|
||||||
|
g.FillPolygon(additionalBrush, body3);
|
||||||
|
|
||||||
|
}
|
||||||
|
_startPosX += 5;
|
||||||
|
_startPosY += 20;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosX -= 5;
|
||||||
|
_startPosY -= 20;
|
||||||
|
|
||||||
|
if (linkor.Gun)
|
||||||
|
{
|
||||||
|
//пушка
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 35, 10, 10);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 55, _startPosY.Value + 35, 30, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
227
ProjectAirbus/ProjectAirbus/Drawnings/DrawingShip.cs
Normal file
227
ProjectAirbus/ProjectAirbus/Drawnings/DrawingShip.cs
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
using ProjectLinkor.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLinkor.Drawnings;
|
||||||
|
|
||||||
|
public class DrawingShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityShip? EntityShip { 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 _drawningLinkorWidth = 95;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота прорисовки корабля
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _drawningLinkorHeight = 40;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой конструктор
|
||||||
|
/// </summary>
|
||||||
|
private DrawingShip()
|
||||||
|
{
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
_startPosX = null;
|
||||||
|
_startPosY = null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
|
||||||
|
public DrawingShip(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityShip = new EntityShip(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследоваников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningLinkorWidth">Ширина прорисовки корабля</param>
|
||||||
|
/// <param name="drawningLinkorHeight">Высота прорисовки корабля</param>
|
||||||
|
protected DrawingShip(int drawningLinkorWidth, int drawningLinkorHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningLinkorWidth = drawningLinkorWidth;
|
||||||
|
_drawningLinkorHeight = drawningLinkorHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка границ поля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||||
|
public bool SetPictureSize(int width, int height)
|
||||||
|
{
|
||||||
|
// TODO проверка, что объект "влезает" в размеры поля
|
||||||
|
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||||
|
|
||||||
|
if (width > _drawningLinkorWidth && height > _drawningLinkorHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
|
||||||
|
if (_startPosX != null && _startPosY != null)
|
||||||
|
{
|
||||||
|
if (_startPosX.Value < 0) _startPosX = 0;
|
||||||
|
if (_startPosY.Value < 0) _startPosY = 0;
|
||||||
|
if (_startPosX.Value + _drawningLinkorWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth - _drawningLinkorWidth;
|
||||||
|
}
|
||||||
|
if (_startPosY.Value + _drawningLinkorHeight > _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 если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||||
|
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
|
||||||
|
if (_startPosX.Value < 0) _startPosX = 0;
|
||||||
|
if (_startPosY.Value < 0) _startPosY = 0;
|
||||||
|
if (_startPosX.Value + _drawningLinkorWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth - _drawningLinkorWidth;
|
||||||
|
}
|
||||||
|
if (_startPosY.Value + _drawningLinkorHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight - _drawningLinkorHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
|
public bool MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX.Value - EntityShip.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityShip.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
//вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY.Value - EntityShip.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityShip.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPosX.Value + _drawningLinkorWidth + EntityShip.Step < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityShip.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
//вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY.Value + _drawningLinkorHeight + EntityShip.Step < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityShip.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
|
||||||
|
Point[] body = { new Point(_startPosX.Value + 65, _startPosY.Value),
|
||||||
|
new Point(_startPosX.Value + 95, _startPosY.Value + 20), new Point(_startPosX.Value +65, _startPosY.Value + 40) };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//границы Линкора
|
||||||
|
g.DrawPolygon(pen, body);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value+ 5, _startPosY.Value, 60, 40);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 5, 10);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 5, 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//корпус
|
||||||
|
Brush br = new SolidBrush(EntityShip.BodyColor);
|
||||||
|
g.FillPolygon(br, body);
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value, 60, 40);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 60, _startPosY.Value + 15, 10, 10);
|
||||||
|
|
||||||
|
//Мачта
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
g.FillRectangle(brBlack, _startPosX.Value + 45, _startPosY.Value + 10, 10, 20);
|
||||||
|
g.FillRectangle(brBlack, _startPosX.Value + 25, _startPosY.Value + 15, 20, 10);
|
||||||
|
|
||||||
|
//задние трубы
|
||||||
|
g.FillRectangle(brBlack, _startPosX.Value, _startPosY.Value + 5, 5, 10);
|
||||||
|
g.FillRectangle(brBlack, _startPosX.Value, _startPosY.Value + 25, 5, 10);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,28 +4,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ProjectLinkor
|
namespace ProjectLinkor.Entities
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Линкор"
|
/// Класс-сущность "Линкор"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityLinkor
|
public class EntityLinkor : EntityShip
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Скорость
|
|
||||||
/// </summary>
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Вес
|
|
||||||
/// </summary>
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Основной цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
|
||||||
/// </summary>
|
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Признак (опция) наличия ракеты
|
/// Признак (опция) наличия ракеты
|
||||||
@ -50,16 +35,12 @@ namespace ProjectLinkor
|
|||||||
/// <param name="rocket">Признак наличия обвеса</param>
|
/// <param name="rocket">Признак наличия обвеса</param>
|
||||||
/// <param name="gun">Признак наличия антикрыла</param>
|
/// <param name="gun">Признак наличия антикрыла</param>
|
||||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
public EntityLinkor(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool rocket, bool gun)
|
additionalColor, bool rocket, bool gun) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Rocket = rocket;
|
Rocket = rocket;
|
||||||
Gun = gun;
|
Gun = gun;
|
||||||
//SportLine = sportLine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
45
ProjectAirbus/ProjectAirbus/Entities/EntityShip.cs
Normal file
45
ProjectAirbus/ProjectAirbus/Entities/EntityShip.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLinkor.Entities;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Корабль"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения корабля
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор сущности
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
|
||||||
|
public EntityShip(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
22
ProjectAirbus/ProjectAirbus/FormLinkor.Designer.cs
generated
22
ProjectAirbus/ProjectAirbus/FormLinkor.Designer.cs
generated
@ -34,14 +34,15 @@
|
|||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
|
buttonCreateShip = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxLinkor).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxLinkor).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxAirBus
|
// pictureBoxLinkor
|
||||||
//
|
//
|
||||||
pictureBoxLinkor.Dock = DockStyle.Fill;
|
pictureBoxLinkor.Dock = DockStyle.Fill;
|
||||||
pictureBoxLinkor.Location = new Point(0, 0);
|
pictureBoxLinkor.Location = new Point(0, 0);
|
||||||
pictureBoxLinkor.Name = "pictureBoxAirBus";
|
pictureBoxLinkor.Name = "pictureBoxLinkor";
|
||||||
pictureBoxLinkor.Size = new Size(800, 414);
|
pictureBoxLinkor.Size = new Size(800, 414);
|
||||||
pictureBoxLinkor.TabIndex = 0;
|
pictureBoxLinkor.TabIndex = 0;
|
||||||
pictureBoxLinkor.TabStop = false;
|
pictureBoxLinkor.TabStop = false;
|
||||||
@ -51,9 +52,9 @@
|
|||||||
buttonCreateAirBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateAirBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateAirBus.Location = new Point(12, 368);
|
buttonCreateAirBus.Location = new Point(12, 368);
|
||||||
buttonCreateAirBus.Name = "buttonCreateAirBus";
|
buttonCreateAirBus.Name = "buttonCreateAirBus";
|
||||||
buttonCreateAirBus.Size = new Size(112, 34);
|
buttonCreateAirBus.Size = new Size(170, 34);
|
||||||
buttonCreateAirBus.TabIndex = 1;
|
buttonCreateAirBus.TabIndex = 1;
|
||||||
buttonCreateAirBus.Text = "Создать";
|
buttonCreateAirBus.Text = "Создать линкор";
|
||||||
buttonCreateAirBus.UseVisualStyleBackColor = true;
|
buttonCreateAirBus.UseVisualStyleBackColor = true;
|
||||||
buttonCreateAirBus.Click += ButtonCreateLinkor_Click;
|
buttonCreateAirBus.Click += ButtonCreateLinkor_Click;
|
||||||
//
|
//
|
||||||
@ -105,11 +106,23 @@
|
|||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateShip
|
||||||
|
//
|
||||||
|
buttonCreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateShip.Location = new Point(188, 368);
|
||||||
|
buttonCreateShip.Name = "buttonCreateShip";
|
||||||
|
buttonCreateShip.Size = new Size(170, 34);
|
||||||
|
buttonCreateShip.TabIndex = 6;
|
||||||
|
buttonCreateShip.Text = "Создать корабль";
|
||||||
|
buttonCreateShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateShip.Click += ButtonCreateShip_Click;
|
||||||
|
//
|
||||||
// FormLinkor
|
// FormLinkor
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 414);
|
ClientSize = new Size(800, 414);
|
||||||
|
Controls.Add(buttonCreateShip);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
@ -132,5 +145,6 @@
|
|||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private Button buttonCreateShip;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,12 +7,14 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using ProjectLinkor.Drawnings;
|
||||||
|
|
||||||
namespace ProjectLinkor
|
namespace ProjectLinkor
|
||||||
{
|
{
|
||||||
public partial class FormLinkor : Form
|
public partial class FormLinkor : Form
|
||||||
{
|
{
|
||||||
private DrawingLinkor? _drawingLinkor;
|
private DrawingShip? _drawingShip;
|
||||||
|
|
||||||
public FormLinkor()
|
public FormLinkor()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -21,35 +23,62 @@ namespace ProjectLinkor
|
|||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawingLinkor == null)
|
if (_drawingShip == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
Bitmap bmp = new(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawingLinkor.DrawTransport(gr);
|
_drawingShip.DrawTransport(gr);
|
||||||
pictureBoxLinkor.Image = bmp;
|
pictureBoxLinkor.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawingShip):
|
||||||
|
_drawingShip = new DrawingShip(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(DrawingLinkor):
|
||||||
|
_drawingShip = new DrawingLinkor(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;
|
||||||
|
}
|
||||||
|
_drawingShip.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
||||||
|
_drawingShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать линкор"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void ButtonCreateLinkor_Click(object sender, EventArgs e)
|
private void ButtonCreateLinkor_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
CreateObject(nameof(DrawingLinkor));
|
||||||
_drawingLinkor = new DrawingLinkor();
|
|
||||||
_drawingLinkor.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)));
|
|
||||||
_drawingLinkor.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
|
||||||
_drawingLinkor.SetPosition(random.Next(40, 100), random.Next(40, 100));
|
|
||||||
Draw();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать корабль"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawingShip));
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawingLinkor == null)
|
if (_drawingShip == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -58,16 +87,16 @@ namespace ProjectLinkor
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawingLinkor.MoveTransport(DirectionType.Up);
|
result = _drawingShip.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawingLinkor.MoveTransport(DirectionType.Down);
|
result = _drawingShip.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawingLinkor.MoveTransport(DirectionType.Left);
|
result = _drawingShip.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawingLinkor.MoveTransport(DirectionType.Right);
|
result = _drawingShip.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
@ -80,15 +109,16 @@ namespace ProjectLinkor
|
|||||||
|
|
||||||
private void FormLinkor_SizeChanged(object sender, EventArgs e)
|
private void FormLinkor_SizeChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawingLinkor == null)
|
if (_drawingShip == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_drawingLinkor.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height))
|
if (_drawingShip.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height))
|
||||||
{
|
{
|
||||||
_drawingLinkor.CheckPosition();
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user