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

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> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="MovementStrategy\" />
</ItemGroup>
</Project> </Project>

View File

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

View File

@ -4,165 +4,33 @@ namespace DoubleDeckerBus.Drawnings;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class DrawingDoubleDeckerBus public class DrawingDoubleDeckerBus : DrawingBus
{ {
public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; } public DrawingDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) : base (105,50)
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)
{ {
EntityDoubleDeckerBus = new EntityDoubleDeckerBus(); EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor, additionalColor, secondFloor, stripes);
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;
} }
public override void DrawTrasnport(Graphics g)
_pictureWidth = width;
_pictureHeight = hight;
if (_startPosX.HasValue && _startPosX.Value + _DrawingBusWidth > _pictureWidth)
{ {
_startPosX = _pictureWidth - _DrawingBusWidth; if (EntityBus == null || EntityBus is not EntityDoubleDeckerBus doubleDeckerBus || !_startPosX.HasValue || !_startPosY.HasValue )
}
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;
}
}
public bool MoveTransport(DirectionType direction)
{
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)
{ {
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityDoubleDeckerBus.AdditionalColor); Brush additionalBrush = new SolidBrush(doubleDeckerBus.AdditionalColor);
Brush mainBrush = new SolidBrush(EntityDoubleDeckerBus.BodyColor); Brush mainBrush = new SolidBrush(doubleDeckerBus.BodyColor);
Brush blueBr = new SolidBrush(Color.LightBlue); Brush blueBr = new SolidBrush(Color.LightBlue);
_startPosX += 5;
//кузов 1го этажа _startPosY += 20;
PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY + 20), base.DrawTrasnport(g);
new PointF((float)_startPosX + 5, (float)_startPosY + 45), _startPosX -= 5;
new PointF((float)_startPosX + 105, (float)_startPosY + 45), _startPosY -= 20;
new PointF((float)_startPosX + 105, (float)_startPosY + 25),
new PointF((float)_startPosX + 102, (float)_startPosY + 20) };
g.FillPolygon(mainBrush, bus);
g.DrawPolygon(pen, bus);
//полоски //полоски
if (EntityDoubleDeckerBus.Stripes) if (doubleDeckerBus.Stripes)
{ {
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 39, 100, 3); 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) }; 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), PointF[] bus_second_floor = { new PointF((float)_startPosX + 5, (float)_startPosY + 5),

View File

@ -1,5 +1,5 @@
namespace DoubleDeckerBus.Entities; namespace DoubleDeckerBus.Entities;
public class EntityDoubleDeckerBus public class EntityDoubleDeckerBus : EntityBus
{ {
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
@ -13,22 +13,18 @@ public class EntityDoubleDeckerBus
public bool Stripes { get; private set; } public bool Stripes { get; private set; }
/// <summary> /// <summary>
/// /// Конструктор наследуемого класса
/// </summary> /// </summary>
/// <param name="speed"></param> /// <param name="speed"></param>
/// <param name="weight"></param> /// <param name="weight"></param>
/// <param name="bodyColor"></param> /// <param name="bodyColor"></param>
/// <param name="additionalColor"></param> /// <param name="additionalColor"></param>
/// <param name="sideMirrors"></param>
/// <param name="topSection"></param>
/// <param name="stripes"></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; AdditionalColor = additionalColor;
SecondFloor = secondFloor; SecondFloor = secondFloor;
Stripes = stripes; 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
{
}
}