diff --git a/ProjectCruiser/DirectionType.cs b/ProjectCruiser/DirectionType.cs
new file mode 100644
index 0000000..d8cd3ba
--- /dev/null
+++ b/ProjectCruiser/DirectionType.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectCruiser;
+
+public enum DirectionType
+{
+ Up = 1,
+ Down = 2,
+ Left = 3,
+ Right = 4
+}
diff --git a/ProjectCruiser/DrawningBase.cs b/ProjectCruiser/DrawningBase.cs
new file mode 100644
index 0000000..169cdc2
--- /dev/null
+++ b/ProjectCruiser/DrawningBase.cs
@@ -0,0 +1,189 @@
+using System.Drawing.Drawing2D;
+
+namespace ProjectCruiser;
+public class DrawningBase
+{
+ // Класс-сущность
+ public EntityBase? EntityB { get; private set; }
+ private int? _pictureWidth; // Ширина окна
+ private int? _pictureHeight; // Высота окна
+ private int? _startPosX; // Левая координата прорисовки автомобиля
+ private int? _startPosY; // Верхняя кооридната прорисовки автомобиля
+
+ private readonly int _drawningWidth = 300; // Ширина прорисовки автомобиля
+ private readonly int _drawningHeight = 42; // Высота прорисовки автомобиля
+
+ // Инициализация свойств
+ public void Init(int speed, double weight,
+ Color bodyColor, Color additionalColor, bool pad,
+ bool hangar, bool deckhouse)
+ {
+ EntityB = new EntityBase();
+ EntityB.Init(speed, weight, bodyColor,
+ additionalColor, pad, hangar, deckhouse);
+
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+ public int getHeight() // для создания объекта в нижнем левом углу (*)
+ {
+ return _drawningHeight;
+ }
+
+ // Установка границ поля
+ public bool SetPictureSize(int w, int h)
+ {
+ if (w > _pictureWidth || h > _pictureHeight)
+ {
+ return false;
+ }
+
+ _pictureWidth = w;
+ _pictureHeight = h;
+
+ if (_startPosX != null || _startPosY != null)
+ {
+ SetPosition(_startPosX.Value, _startPosY.Value);
+ }
+
+ return true;
+ }
+
+ public void SetPosition(int x, int y)
+ {
+ if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
+ {
+ return;
+ }
+
+ if (x > _pictureWidth - _drawningWidth) _startPosX =
+ _pictureWidth - _drawningWidth;
+ else if (x < 0) _startPosX = 0;
+ else _startPosX = x;
+
+ if (y > _pictureHeight - _drawningHeight) _startPosY =
+ _pictureHeight.Value - _drawningHeight;
+ else if (y < 0) _startPosY = 0;
+ else _startPosY = y;
+ }
+
+ public bool MoveTransport(DirectionType direction)
+ {
+ if (EntityB == null || !_startPosX.HasValue ||
+ !_startPosY.HasValue)
+ {
+ return false;
+ }
+
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityB.Step > 0)
+ {
+ _startPosX -= (int)EntityB.Step;
+ }
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityB.Step > 0)
+ {
+ _startPosY -= (int)EntityB.Step;
+ }
+ return true;
+ // вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + _drawningWidth + EntityB.Step
+ < _pictureWidth.Value)
+ {
+ _startPosX += (int)EntityB.Step;
+ }
+ return true;
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY.Value + _drawningHeight + EntityB.Step
+ < _pictureHeight.Value)
+ {
+ _startPosY += (int)EntityB.Step;
+ }
+ return true;
+
+ default:
+ return false;
+ // Перемещение объекта (удалось перемещение - true \ false)
+ }
+ }
+
+ public void DrawTransport(Graphics g)
+ {
+ if (EntityB == null || !_startPosX.HasValue ||
+ !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black, 2);
+ Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
+ Brush additionalBrush = new SolidBrush(EntityB.AdditionalColor);
+ Brush mainBrush = new SolidBrush(EntityB.MainColor);
+
+ //границы cruiser
+ Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 7);
+ Point point1 = new Point(_startPosX.Value + 2, _startPosY.Value + 30);
+ Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 42);
+ Point point3 = new Point(_startPosX.Value + 260, _startPosY.Value + 34);
+ Point point4 = new Point(_startPosX.Value + 300, _startPosY.Value + 22);
+ Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 10);
+ Point point6 = new Point(_startPosX.Value + 184, _startPosY.Value + 2);
+
+ Point[] boarders = {
+ point0,
+ point1,
+ point2,
+ point3,
+ point4,
+ point5,
+ point6
+ };
+
+ g.DrawPolygon(pen, boarders);
+ g.FillPolygon(mainBrush, boarders);
+
+ // вертолетная площадка
+ if (EntityB.HelicopterPads)
+ {
+ g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
+ g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
+ }
+
+ // салон на верхней палубе
+ if (EntityB.Deckhouse)
+ {
+ // random location
+ int y_h = EntityB.values[1];
+ g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + y_h, 38, 24); // 40, 26
+
+ g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
+ g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
+ }
+
+ // ангар
+ if (EntityB.Hangar)
+ {
+ int n = EntityB.values[2];
+ if (n == 1) g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
+
+ else
+ {
+ g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
+ }
+ }
+ }
+}
+
diff --git a/ProjectCruiser/EntityBase.cs b/ProjectCruiser/EntityBase.cs
new file mode 100644
index 0000000..8d454ef
--- /dev/null
+++ b/ProjectCruiser/EntityBase.cs
@@ -0,0 +1,36 @@
+namespace ProjectCruiser;
+
+public class EntityBase
+{
+ // свойства
+ public int Speed { get; private set; } // скорость
+ public double Weight { get; private set; } // вес
+ public Color MainColor { get; private set; } // основной цвет
+ public Color AdditionalColor { get; private set; } // доп. цвет
+
+ // признаки (наличия)
+ public bool HelicopterPads { get; private set; } // вертолетная площадка
+ public bool Hangar { get; private set; } // ангар
+ public bool Deckhouse { get; private set; } // салон на верхней палубе
+ public double Step => Speed * 100 / Weight;
+
+ public int[] values = { 0, 0, 0 };
+
+ public void Init(int speed, double weight,
+ Color mainc, Color addtc, bool pad,
+ bool hangar, bool deckhouse)
+ {
+ Random rn = new();
+
+ Speed = speed;
+ Weight = weight;
+ MainColor = mainc;
+ AdditionalColor = addtc;
+ HelicopterPads = pad;
+ Hangar = hangar;
+ Deckhouse = deckhouse;
+ values[0] = rn.Next(1, 4);
+ values[1] = rn.Next(5, 10);
+ values[2] = rn.Next(1, 3);
+ }
+}
diff --git a/ProjectCruiser/OceanForm1.Designer.cs b/ProjectCruiser/OceanForm1.Designer.cs
new file mode 100644
index 0000000..eeab7be
--- /dev/null
+++ b/ProjectCruiser/OceanForm1.Designer.cs
@@ -0,0 +1,114 @@
+namespace ProjectCruiser;
+partial class OceanForm1
+{
+ /// Required designer variable.
+ private System.ComponentModel.IContainer components = null;
+
+ /// Clean up any resources being used.
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ private void InitializeComponent()
+ {
+ btnLeftArrow = new Button();
+ btnDownArrow = new Button();
+ btnRightArrow = new Button();
+ btnUpArrow = new Button();
+ btnCreateBase = new Button();
+ pictureBoxCr = new PictureBox();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCr).BeginInit();
+ SuspendLayout();
+ //
+ // btnLeftArrow
+ //
+ btnLeftArrow.Location = new Point(926, 634);
+ btnLeftArrow.Name = "btnLeftArrow";
+ btnLeftArrow.Size = new Size(141, 132);
+ btnLeftArrow.TabIndex = 0;
+ btnLeftArrow.UseVisualStyleBackColor = true;
+ btnLeftArrow.Click += BtnMove_Click;
+ //
+ // btnDownArrow
+ //
+ btnDownArrow.Location = new Point(1073, 634);
+ btnDownArrow.Name = "btnDownArrow";
+ btnDownArrow.Size = new Size(141, 132);
+ btnDownArrow.TabIndex = 1;
+ btnDownArrow.UseVisualStyleBackColor = true;
+ btnDownArrow.Click += BtnMove_Click;
+ //
+ // btnRightArrow
+ //
+ btnRightArrow.Location = new Point(1220, 634);
+ btnRightArrow.Name = "btnRightArrow";
+ btnRightArrow.Size = new Size(141, 132);
+ btnRightArrow.TabIndex = 2;
+ btnRightArrow.UseVisualStyleBackColor = true;
+ btnRightArrow.Click += BtnMove_Click;
+ //
+ // btnUpArrow
+ //
+ btnUpArrow.Location = new Point(1073, 496);
+ btnUpArrow.Name = "btnUpArrow";
+ btnUpArrow.Size = new Size(141, 132);
+ btnUpArrow.TabIndex = 3;
+ btnUpArrow.UseVisualStyleBackColor = true;
+ btnUpArrow.Click += BtnMove_Click;
+ //
+ // btnCreateBase
+ //
+ btnCreateBase.Location = new Point(928, 12);
+ btnCreateBase.Name = "btnCreateBase";
+ btnCreateBase.Size = new Size(435, 46);
+ btnCreateBase.TabIndex = 4;
+ btnCreateBase.Text = "Create";
+ btnCreateBase.UseVisualStyleBackColor = true;
+ btnCreateBase.Click += ButtonCreateBase_Click;
+ //
+ // pictureBoxCr
+ //
+ pictureBoxCr.Dock = DockStyle.Fill;
+ pictureBoxCr.Location = new Point(0, 0);
+ pictureBoxCr.Name = "pictureBoxCr";
+ pictureBoxCr.Size = new Size(1375, 778);
+ pictureBoxCr.TabIndex = 5;
+ pictureBoxCr.TabStop = false;
+ //
+ // OceanForm1
+ //
+ AutoScaleDimensions = new SizeF(13F, 32F);
+ AutoScaleMode = AutoScaleMode.Font;
+ BackColor = Color.Turquoise;
+ ClientSize = new Size(1375, 778);
+ Controls.Add(btnCreateBase);
+ Controls.Add(btnUpArrow);
+ Controls.Add(btnRightArrow);
+ Controls.Add(btnDownArrow);
+ Controls.Add(btnLeftArrow);
+ Controls.Add(pictureBoxCr);
+ Name = "OceanForm1";
+ Text = "OceanForm1";
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCr).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button btnLeftArrow;
+ private Button btnDownArrow;
+ private Button btnRightArrow;
+ private Button btnUpArrow;
+ private Button btnCreateBase;
+ private PictureBox pictureBoxCr;
+}
\ No newline at end of file
diff --git a/ProjectCruiser/OceanForm1.cs b/ProjectCruiser/OceanForm1.cs
new file mode 100644
index 0000000..9c55215
--- /dev/null
+++ b/ProjectCruiser/OceanForm1.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ProjectCruiser
+{
+ public partial class OceanForm1 : Form
+ {
+ // Поле-объект для прорисовки объекта
+ private DrawningBase? _drawningCruiser;
+
+ public OceanForm1()
+ {
+ InitializeComponent();
+ }
+
+ // Метод прорисовки transport
+ private void Draw()
+ {
+ if (_drawningCruiser == null)
+ {
+ return;
+ }
+ Bitmap bmp = new(pictureBoxCr.Width,
+ pictureBoxCr.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningCruiser.DrawTransport(gr);
+ pictureBoxCr.Image = bmp;
+ }
+
+ // Обработка нажатия кнопки "Create"
+ private void ButtonCreateBase_Click(object sender, EventArgs e)
+ {
+ Random random = new();
+ _drawningCruiser = new DrawningBase();
+
+ _drawningCruiser.Init(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
+ Convert.ToBoolean(random.Next(0, 2)));
+
+ _drawningCruiser.SetPictureSize(pictureBoxCr.Width, pictureBoxCr.Height);
+ _drawningCruiser.SetPosition(random.Next(10, 100),
+ pictureBoxCr.Height - random.Next(10, 100) - _drawningCruiser.getHeight());
+ Draw();
+ }
+
+
+ private void BtnMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningCruiser == null)
+ {
+ return;
+ }
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ bool result = false;
+ switch (name)
+ {
+ case "btnUpArrow":
+ result =
+ _drawningCruiser.MoveTransport(DirectionType.Up);
+ break;
+ case "btnDownArrow":
+ result =
+ _drawningCruiser.MoveTransport(DirectionType.Down);
+ break;
+ case "btnLeftArrow":
+ result =
+ _drawningCruiser.MoveTransport(DirectionType.Left);
+ break;
+ case "btnRightArrow":
+ result =
+ _drawningCruiser.MoveTransport(DirectionType.Right);
+ break;
+ }
+ if (result)
+ {
+ Draw();
+ }
+ }
+ }
+}
diff --git a/ProjectCruiser/OceanForm1.resx b/ProjectCruiser/OceanForm1.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectCruiser/OceanForm1.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectCruiser/Program.cs b/ProjectCruiser/Program.cs
index 2ddf3fc..5669fde 100644
--- a/ProjectCruiser/Program.cs
+++ b/ProjectCruiser/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectCruiser
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Form1());
+ Application.Run(new OceanForm1());
}
}
}
\ No newline at end of file