diff --git a/Traktor/Traktor/Direction.cs b/Traktor/Traktor/Direction.cs new file mode 100644 index 0000000..a764490 --- /dev/null +++ b/Traktor/Traktor/Direction.cs @@ -0,0 +1,11 @@ +namespace Traktor +{ + //Направление перемещения + internal enum Direction + { + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} diff --git a/Traktor/Traktor/EntityTraktor.cs b/Traktor/Traktor/EntityTraktor.cs new file mode 100644 index 0000000..28a65b6 --- /dev/null +++ b/Traktor/Traktor/EntityTraktor.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Traktor +{ + + //Класс-сущности "Трактор" + + internal class EntityTraktor + { + //Скорость + public int Speed { get; private set; } + //Вес + public float Weight { get; private set; } + //Цвет кузова + public Color BodyColor { get; private set; } + //Шаг перемещения трактора + public float Step => Speed * 100 / Weight; + + public void Init(int speed, float weight, Color bodycolor) + { + Random rnd = new Random(); + Speed = speed <= 0 ? rnd.Next(50, 150) : speed; + Weight = weight <= 0 ? rnd.Next(40, 70) : weight; + BodyColor = bodycolor; + } + } +} diff --git a/Traktor/Traktor/TraktorDraw.cs b/Traktor/Traktor/TraktorDraw.cs new file mode 100644 index 0000000..bd68486 --- /dev/null +++ b/Traktor/Traktor/TraktorDraw.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Traktor +{ + // Класс, отвечающий за прорисовку и перемещение объекта-сущности + internal class TraktorDraw + { + //Сущность + public EntityTraktor Traktor { get; private set; } + /// Левая координата отрисовки сущности + private float startPosX; + /// Верхняя кооридната отрисовки сущности + private float startPosY; + /// Ширина окна отрисовки + private int? pictureWidth = null; + /// Высота окна отрисовки + private int? pictureHeight = null; + /// Ширина отрисовки сущности + private readonly int entWidth = 0; + /// Высота отрисовки сущности + private readonly int entHeight = 0; + + public void Init(int speed, float weight, Color bodycolor) + { + Traktor = new EntityTraktor(); + Traktor.Init(speed, weight, bodycolor); + } + + //Установка позиции сущности + public void SetPosition(int x, int y, int widgh, int height) + { + startPosX = x; + startPosY = y; + pictureHeight = height; + pictureWidth = widgh; + } + + //Изменение направления перемещения + public void MoveTransport(Direction direction) + { + if (!pictureWidth.HasValue || !pictureHeight.HasValue) + { + return; + } + switch (direction) + { + case Direction.Right: + if (startPosX + entWidth + Traktor.Step < pictureWidth) + { + startPosX += Traktor.Step; + } + break; + case Direction.Left: + if (startPosX - Traktor.Step > 0) + { + startPosX -= Traktor.Step; + } + break; + case Direction.Down: + if (startPosY + entHeight + Traktor.Step < pictureHeight) + { + startPosY += Traktor.Step; + } + break; + case Direction.Up: + if (startPosY - Traktor.Step > 0) + { + startPosY -= Traktor.Step; + } + break; + } + } + + //Отрисовка сущности + public void DrawEntity(Graphics g) + { + + } + + //Смена границ формы + public void ChangeBorders(int width, int height) + { + pictureWidth = width; + pictureHeight = height; + if (pictureWidth <= entWidth || pictureHeight <= entHeight) + { + pictureWidth = null; + pictureHeight = null; + return; + } + if (startPosX + entWidth > pictureWidth) + { + startPosX = pictureWidth.Value - entWidth; + } + if (startPosY + entHeight > pictureHeight) + { + startPosY = pictureHeight.Value - entHeight; + } + } + } +}