добавил баззовые и дочерние классы

This commit is contained in:
tyxz0 2024-03-03 10:29:46 +04:00
parent 7bab8142b6
commit d9f60fed99
5 changed files with 86 additions and 241 deletions

View File

@ -23,8 +23,4 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="MovementStrategy\" />
</ItemGroup>
</Project>

View File

@ -9,29 +9,38 @@ namespace DoubleDeckerBus.Drawnings;
public class DrawingBus
{
public EntityBus? EntityBus { get; private set; }
public EntityBus? EntityBus { get; protected set; }
private int? _pictureWidth;
private int? _pictureHeight;
private int? _startPosX;
protected int? _startPosX;
private int? _startPosY;
protected int? _startPosY;
private readonly int _DrawingBusWidth = 120;
private readonly int _drawingBusWidth = 105;
private readonly int _DrawingBusHight = 60;
private readonly int _drawingBusHeight = 50;
public void Init(int speed, double weight, Color bodyColor)
private DrawingBus()
{
EntityBus = new EntityBus(speed, weight, bodyColor);
EntityBus.Init(speed, weight, bodyColor);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
public DrawingBus(int speed, int weight, Color bodyColor) : this()
{
EntityBus = new EntityBus(speed, weight, bodyColor);
}
protected DrawingBus(int drawingBusWidth, int drawingBusHeight) : this()
{
_drawingBusWidth = drawingBusWidth;
_drawingBusHeight = drawingBusHeight;
}
/// <summary>
/// размер окна
/// </summary>
@ -40,7 +49,7 @@ public class DrawingBus
/// <returns></returns>
public bool SetPictureSize(int width, int hight)
{
if (_DrawingBusWidth > width || _DrawingBusHight > hight)
if (_drawingBusWidth > width || _drawingBusHeight > hight)
{
return false;
}
@ -49,14 +58,14 @@ public class DrawingBus
_pictureWidth = width;
_pictureHeight = hight;
if (_startPosX.HasValue && _startPosX.Value + _DrawingBusWidth > _pictureWidth)
if (_startPosX.HasValue && _startPosX.Value + _drawingBusWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _DrawingBusWidth;
_startPosX = _pictureWidth - _drawingBusWidth;
}
if (_startPosY.HasValue && _startPosY + _DrawingBusHight > _pictureHeight)
if (_startPosY.HasValue && _startPosY + _drawingBusHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _DrawingBusHight;
_startPosY = _pictureHeight - _drawingBusHeight;
}
return true;
@ -83,18 +92,18 @@ public class DrawingBus
y = -y;
}
if (x + _DrawingBusWidth > _pictureWidth)
if (x + _drawingBusWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _DrawingBusWidth;
_startPosX = _pictureWidth - _drawingBusWidth;
}
else
{
_startPosX = x;
}
if (y + _DrawingBusHight > _pictureHeight)
if (y + _drawingBusHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _DrawingBusHight;
_startPosY = _pictureHeight - _drawingBusHeight;
}
else
{
@ -125,13 +134,13 @@ public class DrawingBus
}
return true;
case DirectionType.Right:
if (_startPosX.Value + _DrawingBusWidth + EntityBus.Step < _pictureWidth)
if (_startPosX.Value + _drawingBusWidth + EntityBus.Step < _pictureWidth)
{
_startPosX += (int)EntityBus.Step;
}
return true;
case DirectionType.Down:
if (_startPosY.Value + _DrawingBusHight + EntityBus.Step < _pictureHeight)
if (_startPosY.Value + _drawingBusHeight + EntityBus.Step < _pictureHeight)
{
_startPosY += (int)EntityBus.Step;
}
@ -142,7 +151,7 @@ public class DrawingBus
}
}
public void DrawTrasnport(Graphics g)
public virtual void DrawTrasnport(Graphics g)
{
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
@ -155,49 +164,49 @@ public class DrawingBus
//кузов 1го этажа
PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY + 20),
new PointF((float)_startPosX, (float)_startPosY + 45),
new PointF((float)_startPosX + 100, (float)_startPosY + 45),
PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY),
new PointF((float)_startPosX, (float)_startPosY + 25),
new PointF((float)_startPosX + 100, (float)_startPosY + 25),
new PointF((float)_startPosX + 97, (float)_startPosY + 20) };
new PointF((float)_startPosX + 100, (float)_startPosY + 5),
new PointF((float)_startPosX + 97, (float)_startPosY) };
g.FillPolygon(mainBrush, bus);
g.DrawPolygon(pen, bus);
//окна 1ый этаж
g.FillRectangle(blueBr, _startPosX.Value + 2, _startPosY.Value + 25, 12, 10);
g.FillRectangle(blueBr, _startPosX.Value + 16, _startPosY.Value + 25, 12, 10);
g.FillRectangle(blueBr, _startPosX.Value + 42, _startPosY.Value + 25, 6, 10);
g.FillRectangle(blueBr, _startPosX.Value + 50, _startPosY.Value + 25, 13, 10);
g.FillRectangle(blueBr, _startPosX.Value + 66, _startPosY.Value + 25, 14, 10);
g.FillRectangle(blueBr, _startPosX.Value + 2, _startPosY.Value + 5, 12, 10);
g.FillRectangle(blueBr, _startPosX.Value + 16, _startPosY.Value + 5, 12, 10);
g.FillRectangle(blueBr, _startPosX.Value + 42, _startPosY.Value + 5, 6, 10);
g.FillRectangle(blueBr, _startPosX.Value + 50, _startPosY.Value + 5, 13, 10);
g.FillRectangle(blueBr, _startPosX.Value + 66, _startPosY.Value + 5, 14, 10);
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 25, 12, 10);
g.DrawRectangle(pen, _startPosX.Value + 16, _startPosY.Value + 25, 12, 10);
g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 25, 6, 10);
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 25, 13, 10);
g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 25, 14, 10);
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 5, 12, 10);
g.DrawRectangle(pen, _startPosX.Value + 16, _startPosY.Value + 5, 12, 10);
g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 5, 6, 10);
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 5, 13, 10);
g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 5, 14, 10);
//переднее окно первый этаж
PointF[] window2 = { new PointF((float)_startPosX + 85, (float)_startPosY + 25),
new PointF((float)_startPosX + 100, (float)_startPosY + 25),
new PointF((float)_startPosX + 100, (float)_startPosY + 40),
new PointF((float)_startPosX + 85, (float)_startPosY + 35) };
PointF[] window2 = { new PointF((float)_startPosX + 85, (float)_startPosY + 5),
new PointF((float)_startPosX + 100, (float)_startPosY + 5),
new PointF((float)_startPosX + 100, (float)_startPosY + 20),
new PointF((float)_startPosX + 85, (float)_startPosY + 15) };
g.FillPolygon(blueBr, window2);
g.DrawPolygon(pen, window2);
//дверь
Brush brownBr = new SolidBrush(Color.Brown);
g.FillRectangle(blueBr, _startPosX.Value + 30, _startPosY.Value + 25, 10, 15);
g.FillRectangle(brownBr, _startPosX.Value + 30, _startPosY.Value + 40, 10, 5);
g.FillRectangle(blueBr, _startPosX.Value + 30, _startPosY.Value + 5, 10, 15);
g.FillRectangle(brownBr, _startPosX.Value + 30, _startPosY.Value + 20, 10, 5);
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 25, 10, 15);
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 40, 10, 5);
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 5, 10, 15);
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 20, 10, 5);
//колёса
g.FillEllipse(brownBr, _startPosX.Value + 6, _startPosY.Value + 37, 16, 16);
g.FillEllipse(brownBr, _startPosX.Value + 78, _startPosY.Value + 37, 16, 16);
g.FillEllipse(brownBr, _startPosX.Value + 6, _startPosY.Value + 17, 16, 16);
g.FillEllipse(brownBr, _startPosX.Value + 78, _startPosY.Value + 17, 16, 16);
g.DrawEllipse(pen, _startPosX.Value + 6, _startPosY.Value + 37, 16, 16);
g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 37, 16, 16);
g.DrawEllipse(pen, _startPosX.Value + 6, _startPosY.Value + 17, 16, 16);
g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 17, 16, 16);
}
}

View File

@ -4,165 +4,33 @@ namespace DoubleDeckerBus.Drawnings;
/// <summary>
///
/// </summary>
public class DrawingDoubleDeckerBus
public class DrawingDoubleDeckerBus : DrawingBus
{
public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; }
private int? _pictureWidth;
private int? _pictureHeight;
private int? _startPosX;
private int? _startPosY;
private readonly int _DrawingBusWidth = 120;
private readonly int _DrawingBusHight = 60;
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes)
public DrawingDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) : base (105,50)
{
EntityDoubleDeckerBus = new EntityDoubleDeckerBus();
EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor, secondFloor, stripes);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// размер окна
/// </summary>
/// <param name="width"></param>
/// <param name="hight"></param>
/// <returns></returns>
public bool SetPictureSize(int width, int hight)
{
if (_DrawingBusWidth > width || _DrawingBusHight > hight)
{
return false;
}
_pictureWidth = width;
_pictureHeight = hight;
if (_startPosX.HasValue && _startPosX.Value + _DrawingBusWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _DrawingBusWidth;
}
if (_startPosY.HasValue && _startPosY + _DrawingBusHight > _pictureHeight)
{
_startPosY = _pictureHeight - _DrawingBusHight;
}
return true;
}
/// <summary>
/// установить начальную позицию
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x < 0)
{
x = -x;
}
if (y < 0)
{
y = -y;
}
if (x + _DrawingBusWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _DrawingBusWidth;
}
else
{
_startPosX = x;
}
if (y + _DrawingBusHight > _pictureHeight)
{
_startPosY = _pictureHeight - _DrawingBusHight;
}
else
{
_startPosY = y;
}
EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor, additionalColor, secondFloor, stripes);
}
public bool MoveTransport(DirectionType direction)
public override void DrawTrasnport(Graphics g)
{
if (EntityDoubleDeckerBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX.Value - EntityDoubleDeckerBus.Step > 0)
{
_startPosX -= (int)EntityDoubleDeckerBus.Step;
}
return true;
case DirectionType.Up:
if (_startPosY.Value - EntityDoubleDeckerBus.Step > 0)
{
_startPosY -= (int)EntityDoubleDeckerBus.Step;
}
return true;
case DirectionType.Right:
if (_startPosX.Value + _DrawingBusWidth + EntityDoubleDeckerBus.Step < _pictureWidth)
{
_startPosX += (int)EntityDoubleDeckerBus.Step;
}
return true;
case DirectionType.Down:
if (_startPosY.Value + _DrawingBusHight + EntityDoubleDeckerBus.Step < _pictureHeight)
{
_startPosY += (int)EntityDoubleDeckerBus.Step;
}
return true;
default:
return false;
}
}
public void DrawTrasnport(Graphics g)
{
if (EntityDoubleDeckerBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityBus == null || EntityBus is not EntityDoubleDeckerBus doubleDeckerBus || !_startPosX.HasValue || !_startPosY.HasValue )
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityDoubleDeckerBus.AdditionalColor);
Brush mainBrush = new SolidBrush(EntityDoubleDeckerBus.BodyColor);
Brush additionalBrush = new SolidBrush(doubleDeckerBus.AdditionalColor);
Brush mainBrush = new SolidBrush(doubleDeckerBus.BodyColor);
Brush blueBr = new SolidBrush(Color.LightBlue);
//кузов 1го этажа
PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY + 20),
new PointF((float)_startPosX + 5, (float)_startPosY + 45),
new PointF((float)_startPosX + 105, (float)_startPosY + 45),
new PointF((float)_startPosX + 105, (float)_startPosY + 25),
new PointF((float)_startPosX + 102, (float)_startPosY + 20) };
g.FillPolygon(mainBrush, bus);
g.DrawPolygon(pen, bus);
_startPosX += 5;
_startPosY += 20;
base.DrawTrasnport(g);
_startPosX -= 5;
_startPosY -= 20;
//полоски
if (EntityDoubleDeckerBus.Stripes)
if (doubleDeckerBus.Stripes)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 39, 100, 3);
PointF[] stripe = { new PointF((float)_startPosX + 5, (float)_startPosY + 22), new PointF((float)_startPosX + 5, (float)_startPosY + 25), new PointF((float)_startPosX + 104, (float)_startPosY + 25), new PointF((float)_startPosX + 103, (float)_startPosY + 22) };
@ -170,44 +38,8 @@ public class DrawingDoubleDeckerBus
}
//окна 1ый этаж
g.FillRectangle(blueBr, _startPosX.Value + 7, _startPosY.Value + 25, 12, 10);
g.FillRectangle(blueBr, _startPosX.Value + 21, _startPosY.Value + 25, 12, 10);
g.FillRectangle(blueBr, _startPosX.Value + 47, _startPosY.Value + 25, 6, 10);
g.FillRectangle(blueBr, _startPosX.Value + 55, _startPosY.Value + 25, 13, 10);
g.FillRectangle(blueBr, _startPosX.Value + 71, _startPosY.Value + 25, 14, 10);
g.DrawRectangle(pen, _startPosX.Value + 7, _startPosY.Value + 25, 12, 10);
g.DrawRectangle(pen, _startPosX.Value + 21, _startPosY.Value + 25, 12, 10);
g.DrawRectangle(pen, _startPosX.Value + 47, _startPosY.Value + 25, 6, 10);
g.DrawRectangle(pen, _startPosX.Value + 55, _startPosY.Value + 25, 13, 10);
g.DrawRectangle(pen, _startPosX.Value + 71, _startPosY.Value + 25, 14, 10);
//переднее окно первый этаж
PointF[] window2 = { new PointF((float)_startPosX + 90, (float)_startPosY + 25),
new PointF((float)_startPosX + 105, (float)_startPosY + 25),
new PointF((float)_startPosX + 105, (float)_startPosY + 40),
new PointF((float)_startPosX + 90, (float)_startPosY + 35) };
g.FillPolygon(blueBr, window2);
g.DrawPolygon(pen, window2);
//дверь
Brush brownBr = new SolidBrush(Color.Brown);
g.FillRectangle(blueBr, _startPosX.Value + 35, _startPosY.Value + 25, 10, 15);
g.FillRectangle(brownBr, _startPosX.Value + 35, _startPosY.Value + 40, 10, 5);
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 25, 10, 15);
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 40, 10, 5);
//колёса
g.FillEllipse(brownBr, _startPosX.Value + 11, _startPosY.Value + 37, 16, 16);
g.FillEllipse(brownBr, _startPosX.Value + 83, _startPosY.Value + 37, 16, 16);
g.DrawEllipse(pen, _startPosX.Value + 11, _startPosY.Value + 37, 16, 16);
g.DrawEllipse(pen, _startPosX.Value + 83, _startPosY.Value + 37, 16, 16);
//второй этаж с всякими зафуфрючками
if (EntityDoubleDeckerBus.SecondFloor)
if (doubleDeckerBus.SecondFloor)
{
//верх кузова
PointF[] bus_second_floor = { new PointF((float)_startPosX + 5, (float)_startPosY + 5),

View File

@ -1,6 +1,6 @@
namespace DoubleDeckerBus.Entities;
public class EntityDoubleDeckerBus
{
public class EntityDoubleDeckerBus : EntityBus
{
public Color AdditionalColor { get; private set; }
/// <summary>
@ -13,22 +13,18 @@ public class EntityDoubleDeckerBus
public bool Stripes { get; private set; }
/// <summary>
///
/// Конструктор наследуемого класса
/// </summary>
/// <param name="speed"></param>
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <param name="additionalColor"></param>
/// <param name="sideMirrors"></param>
/// <param name="topSection"></param>
/// <param name="stripes"></param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes)
public EntityDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) : base(speed, weight, bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
SecondFloor = secondFloor;
Stripes = stripes;
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus.MovementStrategy
{
internal interface Interface1
{
}
}