WIP: ПИбд-12, Гурьянов Никита Николаевич, 1 #2
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -37,12 +38,12 @@ public class DrawningElectricLocomotive
|
||||
private int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// Ширина прорисовки электровоза
|
||||
/// </summary>
|
||||
private readonly int _drawningEntityElectricLocomotiveWidth = 110;
|
||||
private readonly int _drawningEntityElectricLocomotiveWidth = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// Высота прорисовки электровоза
|
||||
/// </summary>
|
||||
private readonly int _drawningEntityElectricLocomotiveHeight = 60;
|
||||
|
||||
@ -53,13 +54,12 @@ public class DrawningElectricLocomotive
|
||||
/// <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 void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
/// <param name="horns">Признак наличия рогов</param>
|
||||
/// <param name="compartment">Признак наличия отсека</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns, bool compartment)
|
||||
{
|
||||
entityElectricLocomotive = new EntityElectricLocomotive();
|
||||
entityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
|
||||
entityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, horns, compartment);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
@ -74,7 +74,10 @@ public class DrawningElectricLocomotive
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// проверка, что объект "влезает" в размеры поля
|
||||
if (width <= 0 || height <= 0) return false;
|
||||
if (_drawningEntityElectricLocomotiveWidth > width || _drawningEntityElectricLocomotiveHeight > height) return false;
|
||||
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
@ -88,13 +91,11 @@ public class DrawningElectricLocomotive
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) return;
|
||||
if (x < 0 || y < 0 ||
|
||||
x + _drawningEntityElectricLocomotiveWidth > _pictureWidth ||
|
||||
y + _drawningEntityElectricLocomotiveHeight > _pictureHeight) return;
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
@ -160,90 +161,55 @@ public class DrawningElectricLocomotive
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(entityElectricLocomotive.AdditionalColor);
|
||||
|
||||
// обвесы
|
||||
if (entityElectricLocomotive.BodyKit)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value, 15, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 10, 20, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value, 14, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 14, 15);
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value, 20, 20);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 40, 20, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 1, _startPosY.Value + 10, 25, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 1, 15, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 45, 15, 15);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 39, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 45, 39, 15);
|
||||
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 1, 40, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 45, 40, 15);
|
||||
// рога для подключения к проводам
|
||||
if (entityElectricLocomotive.Horns)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 38, _startPosY.Value + 50, 20, 11);
|
||||
}
|
||||
|
||||
//границы автомобиля
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70, 52);
|
||||
// отсек под электрические батареи
|
||||
if (entityElectricLocomotive.Compartment)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 18, _startPosY.Value + 0, 32, 2);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 15, _startPosX.Value + 35, _startPosY.Value + 2);
|
||||
}
|
||||
|
||||
//задние фары
|
||||
Brush brRed = new SolidBrush(Color.Red);
|
||||
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20);
|
||||
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
|
||||
|
||||
//передние фары
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20);
|
||||
//границы Электровоза
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 15, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 67, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 28, 80, 23);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 22, 6, 29);
|
||||
|
||||
//переходный тамбур
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 22, 6, 29);
|
||||
|
||||
//лобовое стекло
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 70, _startPosY.Value + 15, 20, 20);
|
||||
|
||||
//кузов
|
||||
Brush br = new SolidBrush(entityElectricLocomotive.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30);
|
||||
g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70, 50);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 67, 20);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 28, 80, 23);
|
||||
|
||||
//стекла
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 70, _startPosY.Value + 10, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 30, _startPosY.Value + 10, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 8, 35, 2);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 51, 35, 2);
|
||||
//стёкла
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 14, _startPosY.Value + 15, 10, 20);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 45, _startPosY.Value + 15, 10, 20);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 55, _startPosY.Value + 15, 10, 20);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 77, _startPosY.Value + 25, 13, 10);
|
||||
|
||||
//выделяем рамкой крышу
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 10, 35, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 15, 25, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 15, 30);
|
||||
//дверь
|
||||
g.DrawRectangle(pen, _startPosX.Value + 26, _startPosY.Value + 16, 15, 33);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 35, 5, 2);
|
||||
|
||||
// спортивная линия
|
||||
if (entityElectricLocomotive.SportLine)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 23, 25, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 23, 35, 15);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 23, 20, 15);
|
||||
}
|
||||
|
||||
// крыло
|
||||
if (entityElectricLocomotive.Wing)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 5, 10, 50);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 10, 50);
|
||||
}
|
||||
//колеса
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 10, _startPosY.Value + 50, 12, 12);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 24, _startPosY.Value + 50, 12, 12);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 60, _startPosY.Value + 50, 12, 12);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 74, _startPosY.Value + 50, 12, 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 15, _startPosY.Value + 50, _startPosX.Value + 0, _startPosY.Value + 55);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 50, _startPosX.Value + 105, _startPosY.Value + 55);
|
||||
}
|
||||
}
|
@ -28,17 +28,13 @@ public class EntityElectricLocomotive
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак опция наличие обвеса
|
||||
/// Признак опция рога
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
public bool Horns { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак опция наличие антикрыла
|
||||
/// Признак опция отсек для батарей
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак опция наличие гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
public bool Compartment { get; private set; }
|
||||
/// <summary>
|
||||
/// шаг перемещение
|
||||
/// </summary>
|
||||
@ -50,19 +46,16 @@ public class EntityElectricLocomotive
|
||||
/// <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 void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
/// <param name="horns"></param>
|
||||
/// <param name="compartment"></param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns, bool compartment)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
|
||||
Horns = horns;
|
||||
Compartment = compartment;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public partial class FormElectricLocomotive : Form
|
||||
_drawningElectricLocomotive.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)));
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningElectricLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||
_drawningElectricLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user