начало лаб2
This commit is contained in:
parent
21a467a473
commit
7bab8142b6
@ -23,4 +23,8 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="MovementStrategy\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,5 +1,4 @@
|
|||||||
|
namespace DoubleDeckerBus.Drawnings;
|
||||||
namespace DoubleDeckerBus;
|
|
||||||
|
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{ /// <summary>
|
{ /// <summary>
|
203
DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingBus.cs
Normal file
203
DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingBus.cs
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
using DoubleDeckerBus.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus.Drawnings;
|
||||||
|
|
||||||
|
public class DrawingBus
|
||||||
|
{
|
||||||
|
public EntityBus? EntityBus { 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)
|
||||||
|
{
|
||||||
|
EntityBus = new EntityBus(speed, weight, bodyColor);
|
||||||
|
EntityBus.Init(speed, weight, bodyColor);
|
||||||
|
_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX.Value - EntityBus.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY.Value - EntityBus.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPosX.Value + _DrawingBusWidth + EntityBus.Step < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY.Value + _DrawingBusHight + EntityBus.Step < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTrasnport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush mainBrush = new SolidBrush(EntityBus.BodyColor);
|
||||||
|
Brush blueBr = new SolidBrush(Color.LightBlue);
|
||||||
|
|
||||||
|
|
||||||
|
//кузов 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),
|
||||||
|
new PointF((float)_startPosX + 100, (float)_startPosY + 25),
|
||||||
|
new PointF((float)_startPosX + 97, (float)_startPosY + 20) };
|
||||||
|
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.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);
|
||||||
|
|
||||||
|
//переднее окно первый этаж
|
||||||
|
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) };
|
||||||
|
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.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 25, 10, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 40, 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.DrawEllipse(pen, _startPosX.Value + 6, _startPosY.Value + 37, 16, 16);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 37, 16, 16);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
namespace DoubleDeckerBus;
|
using DoubleDeckerBus.Entities;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus.Drawnings;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -18,7 +20,7 @@ public class DrawingDoubleDeckerBus
|
|||||||
|
|
||||||
private readonly int _DrawingBusHight = 60;
|
private readonly int _DrawingBusHight = 60;
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,bool secondFloor, bool stripes)
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes)
|
||||||
{
|
{
|
||||||
EntityDoubleDeckerBus = new EntityDoubleDeckerBus();
|
EntityDoubleDeckerBus = new EntityDoubleDeckerBus();
|
||||||
EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor, secondFloor, stripes);
|
EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor, secondFloor, stripes);
|
||||||
@ -44,12 +46,12 @@ public class DrawingDoubleDeckerBus
|
|||||||
_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 + _DrawingBusHight > _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY = _pictureHeight - _DrawingBusHight;
|
_startPosY = _pictureHeight - _DrawingBusHight;
|
||||||
}
|
}
|
42
DoubleDeckerBus/DoubleDeckerBus/Entities/EntityBus.cs
Normal file
42
DoubleDeckerBus/DoubleDeckerBus/Entities/EntityBus.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus.Entities;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс сущность автобус
|
||||||
|
/// </summary>
|
||||||
|
public class EntityBus
|
||||||
|
{
|
||||||
|
/// <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 EntityBus(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,7 @@
|
|||||||
namespace DoubleDeckerBus;
|
namespace DoubleDeckerBus.Entities;
|
||||||
public class EntityDoubleDeckerBus
|
public class EntityDoubleDeckerBus
|
||||||
{
|
{
|
||||||
public int Speed { get; private set; }
|
|
||||||
|
|
||||||
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>
|
||||||
/// Признак (опция) наличия второго этажа
|
/// Признак (опция) наличия второго этажа
|
||||||
@ -20,10 +11,7 @@
|
|||||||
/// Признак (опция) наличия полосок на автобусе
|
/// Признак (опция) наличия полосок на автобусе
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Stripes { get; private set; }
|
public bool Stripes { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения автобуса
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
@ -7,6 +7,7 @@ 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 DoubleDeckerBus.Drawnings;
|
||||||
|
|
||||||
namespace DoubleDeckerBus
|
namespace DoubleDeckerBus
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user