diff --git a/Liner/Direction.cs b/Liner/Direction.cs new file mode 100644 index 0000000..fdfcd82 --- /dev/null +++ b/Liner/Direction.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liner +{ + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + } +} diff --git a/Liner/DrawingLiner.cs b/Liner/DrawingLiner.cs new file mode 100644 index 0000000..4579e25 --- /dev/null +++ b/Liner/DrawingLiner.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liner +{ + public class DrawingLiner + { + private Brush poolBrush = new SolidBrush(Color.Blue); + /// + /// Класс-сущность + /// + public EntityLiner? EntityLiner { get; private set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки лайнера + /// + private int _startPosX; + /// + /// Верхняя координата прорисовки лайнера + /// + private int _startPosY; + /// + /// Ширина прорисовки лайнера + /// + private readonly int _linerWidth = 100; + /// + /// Высота прорисовки лайнера + /// + private readonly int _linerHeight = 80; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес лайнера + /// Основной цвет + /// Признак наличия бассейна + /// Признак наличия доп палубы + /// Ширина картинки + /// Высота картинки + /// true - объект создан, false - проверка не пройдена, + /// нельзя создать объект в этих размерах + public bool Init(int speed, double weight, Color bodyColor,Color bottomColor, bool swimmingPool, bool deck, int width, int height) + { + if(width < _linerWidth || height < _linerHeight) + { + return false; + } + _pictureWidth = width; + _pictureHeight = height; + EntityLiner = new EntityLiner(); + EntityLiner.Init(speed, weight, bodyColor,bottomColor, swimmingPool,deck); + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if(x > _pictureWidth || y > _pictureHeight || x < 0 || y < 0) + { + _startPosX = 0; + _startPosY = 0; + } + _startPosX = x; + _startPosY = y; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (EntityLiner == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityLiner.Step > 0) + { + _startPosX -= (int)EntityLiner.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityLiner.Step > 0) + { + _startPosY -= (int)EntityLiner.Step; + } + break; + // вправо + case DirectionType.Right: + if (_startPosX + EntityLiner.Step < _pictureWidth - _linerWidth) + { + _startPosX += (int)EntityLiner.Step; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + EntityLiner.Step < _pictureHeight - _linerHeight) + { + _startPosY += (int)EntityLiner.Step; + } + break; + } + } + /// + /// Прорисовка объекта + /// + /// + // высота палубы - 20 пикселей + public void DrawTransport(Graphics g) + { + if (EntityLiner == null) + { + return; + } + Pen pen = new(Color.Black); + Brush bottomBrush = new SolidBrush(EntityLiner.BottomColor); + Brush deckBrush = new SolidBrush(EntityLiner.BodyColor); + // палуба + Point[] firstDeck = {new Point(_startPosX + 30, _startPosY), new Point(_startPosX + 30 + 60, _startPosY), + new Point(_startPosX + 30 + 60, _startPosY + 20), new Point(_startPosX + 30, _startPosY + 20)}; + int addY = 20; + // нижний корпус + Point[] bottom = {new Point(_startPosX, _startPosY), new Point(_startPosX + 100, _startPosY), + new Point(_startPosX+80, _startPosY + 40), new Point(_startPosX + 20, _startPosY + 40)}; + // бассейн + Point[] pool = {new Point(_startPosX + 10, _startPosY), new Point(_startPosX + 30, _startPosY), + new Point(_startPosX+30, _startPosY + 10), new Point(_startPosX + 10, _startPosY + 10)}; + g.FillPolygon(deckBrush, firstDeck); + g.DrawPolygon(pen, firstDeck);//рисуем палубу + Point[] currentDeck = new Point[4]; //буффер для прорисовки доп палуб + firstDeck.CopyTo(currentDeck, 0); + if(EntityLiner.Deck) //рисуем вторую палубу + { + for(int i = 0; i < 4; i++) + { + currentDeck[i].Y += addY; + } + g.FillPolygon(deckBrush, currentDeck); + g.DrawPolygon(pen, currentDeck); + addY += 20; + } + for(int i = 0; i < 4; i++) //сдвигаем элементы вниз на кол-во палуб + { + bottom[i].Y += addY; + pool[i].Y += addY; + } + g.FillPolygon(bottomBrush, bottom); + g.DrawPolygon(pen, bottom);//рисуем нижний корпус + if (EntityLiner.SwimmingPool) { g.FillPolygon(poolBrush, pool); }//рисуем бассейн + g.Dispose(); + } + } +} diff --git a/Liner/EntityLiner.cs b/Liner/EntityLiner.cs new file mode 100644 index 0000000..f2859df --- /dev/null +++ b/Liner/EntityLiner.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +namespace Liner +{ + public class EntityLiner + { + /// + /// Скорость + /// + public int Speed { get; private set; } + /// + /// Вес + /// + public double Weight { get; private set; } + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + /// + /// Доп цвет + /// + public Color BottomColor { get; private set; } + /// + /// Признак (опция) наличия бассейна + /// + public bool SwimmingPool { get; private set; } + /// + /// Признак (опция) наличия доп палубы + /// + public bool Deck { get; private set; } + /// + /// Шаг + /// + public double Step => (double)Speed * 100 / Weight; + /// + /// Инициализация полей объекта-класса лайнера + /// + /// Скорость + /// Вес лайнера + /// Основной цвет + /// Цвет палубы + /// Признак наличия бассейна + /// Признак наличия доп палубы + public void Init(int speed, double weight, Color bodyColor, Color bottomColor, bool swimmingPool, bool deck) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + BottomColor = bottomColor; + SwimmingPool = swimmingPool; + Deck = deck; + } + } +} diff --git a/Liner/Form1.Designer.cs b/Liner/Form1.Designer.cs deleted file mode 100644 index 731fe20..0000000 --- a/Liner/Form1.Designer.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace Liner -{ - partial class Form1 - { - /// - /// 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() - { - SuspendLayout(); - // - // Form1 - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Name = "Form1"; - Text = "Form1"; - Load += Form1_Load; - ResumeLayout(false); - } - - #endregion - } -} \ No newline at end of file diff --git a/Liner/Form1.cs b/Liner/Form1.cs deleted file mode 100644 index f94743a..0000000 --- a/Liner/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Liner -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Liner/Liner.csproj b/Liner/Liner.csproj index b57c89e..13ee123 100644 --- a/Liner/Liner.csproj +++ b/Liner/Liner.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/Liner/MainScreen.Designer.cs b/Liner/MainScreen.Designer.cs new file mode 100644 index 0000000..c909ae9 --- /dev/null +++ b/Liner/MainScreen.Designer.cs @@ -0,0 +1,136 @@ +namespace Liner +{ + partial class MainScreen : Form + { + /// + /// 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() + { + pictureBoxLiner = new PictureBox(); + buttonCreate = new Button(); + buttonUp = new Button(); + buttonDown = new Button(); + buttonLeft = new Button(); + buttonRight = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit(); + SuspendLayout(); + // + // pictureBoxLiner + // + pictureBoxLiner.Dock = DockStyle.Fill; + pictureBoxLiner.Location = new Point(0, 0); + pictureBoxLiner.Name = "pictureBoxLiner"; + pictureBoxLiner.Size = new Size(984, 661); + pictureBoxLiner.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxLiner.TabIndex = 0; + pictureBoxLiner.TabStop = false; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(34, 584); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(87, 43); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Create Liner"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(865, 561); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 2; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += buttonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(865, 597); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 3; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += buttonMove_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(829, 597); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 4; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += buttonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(901, 597); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 5; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += buttonMove_Click; + // + // MainScreen + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(984, 661); + Controls.Add(buttonRight); + Controls.Add(buttonLeft); + Controls.Add(buttonDown); + Controls.Add(buttonUp); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxLiner); + Name = "MainScreen"; + Text = "Liner"; + ((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxLiner; + private Button buttonCreate; + private Button buttonUp; + private Button buttonDown; + private Button buttonLeft; + private Button buttonRight; + } +} \ No newline at end of file diff --git a/Liner/MainScreen.cs b/Liner/MainScreen.cs new file mode 100644 index 0000000..5aca5b3 --- /dev/null +++ b/Liner/MainScreen.cs @@ -0,0 +1,74 @@ +namespace Liner +{ + public partial class MainScreen : Form + { + /// + /// - + /// + private DrawingLiner? _drawingLiner; + private Bitmap bmp; + /// + /// + /// + public MainScreen() + { + InitializeComponent(); + bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height); + } + /// + /// + /// + private void Draw() + { + if (_drawingLiner == null) + { + return; + } + Graphics gr = Graphics.FromImage(bmp); + gr.Clear(Color.White); + _drawingLiner.DrawTransport(gr); + pictureBoxLiner.Image = bmp; + gr.Dispose(); + } + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingLiner = new DrawingLiner(); + _drawingLiner.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)), + pictureBoxLiner.Width, pictureBoxLiner.Height); + _drawingLiner.SetPosition(random.Next(10, 100), + random.Next(10, 100)); + Draw(); + } + + private void buttonMove_Click(object sender, EventArgs e) + { + if (_drawingLiner == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawingLiner.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawingLiner.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawingLiner.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawingLiner.MoveTransport(DirectionType.Right); + break; + } + Draw(); + + } + } +} \ No newline at end of file diff --git a/Liner/Form1.resx b/Liner/MainScreen.resx similarity index 100% rename from Liner/Form1.resx rename to Liner/MainScreen.resx diff --git a/Liner/Program.cs b/Liner/Program.cs index 770750a..8976e9d 100644 --- a/Liner/Program.cs +++ b/Liner/Program.cs @@ -11,7 +11,7 @@ namespace Liner // 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 MainScreen()); } } } \ No newline at end of file diff --git a/Liner/Properties/Resources.Designer.cs b/Liner/Properties/Resources.Designer.cs new file mode 100644 index 0000000..393b3c2 --- /dev/null +++ b/Liner/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Liner.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Liner.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowDown { + get { + object obj = ResourceManager.GetObject("arrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowLeft { + get { + object obj = ResourceManager.GetObject("arrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowRight { + get { + object obj = ResourceManager.GetObject("arrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowUp { + get { + object obj = ResourceManager.GetObject("arrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Liner/Properties/Resources.resx b/Liner/Properties/Resources.resx new file mode 100644 index 0000000..cccc534 --- /dev/null +++ b/Liner/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Liner/resources/arrowDown.png b/Liner/resources/arrowDown.png new file mode 100644 index 0000000..e3242b0 Binary files /dev/null and b/Liner/resources/arrowDown.png differ diff --git a/Liner/resources/arrowLeft.png b/Liner/resources/arrowLeft.png new file mode 100644 index 0000000..a33506b Binary files /dev/null and b/Liner/resources/arrowLeft.png differ diff --git a/Liner/resources/arrowRight.png b/Liner/resources/arrowRight.png new file mode 100644 index 0000000..cf9ead0 Binary files /dev/null and b/Liner/resources/arrowRight.png differ diff --git a/Liner/resources/arrowUp.png b/Liner/resources/arrowUp.png new file mode 100644 index 0000000..1cad6dd Binary files /dev/null and b/Liner/resources/arrowUp.png differ