diff --git a/lainer/Lainer1/DirectionTypeEnum.cs b/lainer/Lainer1/DirectionTypeEnum.cs new file mode 100644 index 0000000..82cd54b --- /dev/null +++ b/lainer/Lainer1/DirectionTypeEnum.cs @@ -0,0 +1,10 @@ +namespace ProjectLainer +{ + public enum DirectionType + { + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} \ No newline at end of file diff --git a/lainer/Lainer1/DrawningLainer.cs b/lainer/Lainer1/DrawningLainer.cs new file mode 100644 index 0000000..3f8174e --- /dev/null +++ b/lainer/Lainer1/DrawningLainer.cs @@ -0,0 +1,144 @@ +namespace ProjectLainer +{ + public class DrawningLainer + { + public EntityLainer? EntityLainer { get; private set; } + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX; + private int _startPosY; + private readonly int _LainerWidth = 150; + private readonly int _LainerHeight = 80; + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool ispool, bool addDecks, int width, int height) + { + if(width <= _LainerWidth || height <= _LainerHeight) + { + return false; + } + _pictureWidth = width; + _pictureHeight = height; + EntityLainer = new EntityLainer(); + EntityLainer.Init(speed, weight, bodyColor, additionalColor, ispool, addDecks); + return true; + } + public void SetPosition(int x, int y) + { + if(x + _LainerWidth < _pictureWidth && x + _LainerWidth > 0) + { + _startPosX = x; + } + if (y + _LainerHeight < _pictureHeight && y + _LainerHeight > 0) + { + _startPosY = y; + } + } + public void MoveTransport(DirectionType direction) + { + if (EntityLainer == null) + + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityLainer.Step > 0) + { + _startPosX -= (int)EntityLainer.Step; + } + else + { + _startPosX = 1; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityLainer.Step > 0) + { + _startPosY -= (int)EntityLainer.Step; + } + else + { + _startPosY = 1; + } + break; + // вправо + case DirectionType.Right: + if (_startPosX + EntityLainer.Step <= _pictureWidth - _LainerWidth) + { + _startPosX += (int)EntityLainer.Step; + } + else + { + _startPosX = _pictureWidth - _LainerWidth; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + EntityLainer.Step <= _pictureHeight - _LainerHeight) + { + _startPosY += (int)EntityLainer.Step; + } + else + { + _startPosY = _pictureHeight - _LainerHeight; + } + break; + } + } + public void DrawTransport(Graphics g) + { + if (EntityLainer == null) + { + return; + } + Brush brBlue = new SolidBrush(Color.LightBlue); + Pen pen = new(Color.Black); + Brush additionalBrush = new + SolidBrush(EntityLainer.AdditionalColor); + var brush = new SolidBrush(Color.Black); + // доп палубы и отрисовка труб + Rectangle smokestack1 = new Rectangle(_startPosX + 20, _startPosY, 20, 50); + Rectangle smokestack2 = new Rectangle(_startPosX + 60, _startPosY, 20, 50); + g.FillRectangle(brush, smokestack1); + g.FillRectangle(brush, smokestack2); + if (EntityLainer.Decks) + { + Rectangle deck2 = new Rectangle(_startPosX + 10, _startPosY + 10, _LainerWidth - 18, 20); + g.FillRectangle(additionalBrush, deck2); + for (int i = 2; i < 6; i++) + { + g.FillEllipse(brBlue, _startPosX + i * 16, _startPosY + 15, 12, 12); + } + } + //границы лайнера + pen = new(Color.Red); + brush = new SolidBrush(Color.Red); + Point point1 = new Point(_startPosX, _startPosY + 50); + Point point2 = new Point(_startPosX + _LainerWidth, _startPosY+50); + Point point3 = new Point(_startPosX + 20, _startPosY+80); + Point point4 = new Point(_startPosX + 80, _startPosY + 80); + Point[] points = { point1, point2, point4, point3}; + g.DrawPolygon(pen, points); + g.FillPolygon(brush, points); + //1 палуба + brush = new SolidBrush(Color.Green); + Rectangle deck = new Rectangle(_startPosX + 5, _startPosY + 30, _LainerWidth - 10, 20); + g.FillRectangle(brush,deck); + //стекла + for (int i = 1; i < 7; i++) + { + g.FillEllipse(brBlue, _startPosX + i*16, _startPosY + 33, 14, 14); + } + // бассейн + if (EntityLainer.Pool) + { + g.FillEllipse(brBlue, _startPosX + _LainerWidth - 35, _startPosY + _LainerHeight - 55, 35, 12); + brush = new SolidBrush(Color.DarkGray); + Rectangle rect2 = new Rectangle(_startPosX + _LainerWidth - 35, _startPosY + _LainerHeight - 50, 35, 20); + g.FillRectangle(brush, rect2); + } + } + } +} \ No newline at end of file diff --git a/lainer/Lainer1/EntityLainer.cs b/lainer/Lainer1/EntityLainer.cs new file mode 100644 index 0000000..78941b9 --- /dev/null +++ b/lainer/Lainer1/EntityLainer.cs @@ -0,0 +1,23 @@ +namespace ProjectLainer +{ + public class EntityLainer + { + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color BodyColor { get; private set; } + public Color AdditionalColor { get; private set; } + public bool Pool { get; private set; } + public bool Decks { get; private set; } + public double Step => (double)Speed * 100 / Weight; + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool ispool, bool addDecks) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Pool = ispool; + Decks = addDecks; + } + } +} diff --git a/lainer/Lainer1/Lainer1.csproj b/lainer/Lainer1/Lainer1.csproj new file mode 100644 index 0000000..714c472 --- /dev/null +++ b/lainer/Lainer1/Lainer1.csproj @@ -0,0 +1,26 @@ +п»ї + + + WinExe + net6.0-windows + enable + true + enable + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file