diff --git a/WarmlyShip/WarmlyShip/Direction.cs b/WarmlyShip/WarmlyShip/Direction.cs new file mode 100644 index 0000000..3dc9572 --- /dev/null +++ b/WarmlyShip/WarmlyShip/Direction.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + /// + /// Направление перемещения + /// + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + + } +} diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs new file mode 100644 index 0000000..bb181e9 --- /dev/null +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -0,0 +1,240 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawingWarmlyShip + { + /// + /// Класс-сущность + /// + public EntityWarmlyShip? EntityWarmlyShip { get; private set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки автомобиля + /// + private int _startPosX; + /// + /// Верхняя кооридната прорисовки автомобиля + /// + private int _startPosY; + /// + /// Ширина прорисовки автомобиля + /// + private readonly int _carWidth = 110; + /// + /// Высота прорисовки автомобиля + /// + private readonly int _carHeight = 60; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + /// Ширина картинки + /// Высота картинки + /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах +public bool Init(int speed, double weight, Color bodyColor, Color +additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) + { + // TODO: Продумать проверки + _pictureWidth = width; + _pictureHeight = height; + EntityWarmlyShip = new EntityWarmlyShip(); + EntityWarmlyShip.Init(speed, weight, bodyColor, additionalColor, + bodyKit, wing, sportLine); + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + // TODO: Изменение x, y + _startPosX = x; + _startPosY = y; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (EntityWarmlyShip == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityWarmlyShip.Step > 0) + { + _startPosX -= (int)EntityWarmlyShip.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityWarmlyShip.Step > 0) + { + _startPosY -= (int)EntityWarmlyShip.Step; + } + break; + // вправо + case DirectionType.Right: + // TODO: Продумать логику + break; + //вниз + case DirectionType.Down: + // TODO: Продумать логику + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityWarmlyShip == null) + { + return; + } + Pen pen = new(Color.Black); + Brush additionalBrush = new + SolidBrush(EntityWarmlyShip.AdditionalColor); + // обвесы + if (EntityWarmlyShip.BodyKit) + { + g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, + 20); + g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, + 20, 40); + g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, + 15); + g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, + 15, 15); + g.FillEllipse(additionalBrush, _startPosX + 90, + _startPosY, 20, 20); + g.FillEllipse(additionalBrush, _startPosX + 90, + _startPosY + 40, 20, 20); + g.FillRectangle(additionalBrush, _startPosX + 90, + _startPosY + 10, 20, 40); + g.FillRectangle(additionalBrush, _startPosX + 90, +_startPosY + 1, 15, 15); + g.FillRectangle(additionalBrush, _startPosX + 90, + _startPosY + 45, 15, 15); + g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20); + g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20); + g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, + 40); + g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, + 15); + g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, + 14, 15); + g.FillEllipse(additionalBrush, _startPosX, _startPosY, + 20, 20); + g.FillEllipse(additionalBrush, _startPosX, _startPosY + + 40, 20, 20); + g.FillRectangle(additionalBrush, _startPosX + 1, + _startPosY + 10, 25, 40); + g.FillRectangle(additionalBrush, _startPosX + 5, + _startPosY + 1, 15, 15); + g.FillRectangle(additionalBrush, _startPosX + 5, + _startPosY + 45, 15, 15); + g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, + 15); + g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, + 39, 15); + g.FillRectangle(additionalBrush, _startPosX + 35, + _startPosY + 1, 40, 15); + g.FillRectangle(additionalBrush, _startPosX + 35, + _startPosY + 45, 40, 15); + } + //границы автомобиля + g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20); + g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20); + g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30); + g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10, + 30); + g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52); + //задние фары + Brush brRed = new SolidBrush(Color.Red); + g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20); + g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20, + 20); + //передние фары + Brush brYellow = new SolidBrush(Color.Yellow); + g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20, + 20); + g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20, + 20); + //кузов + Brush br = new SolidBrush(EntityWarmlyShip.BodyColor); + g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30); + g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30); + g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50); + //стекла + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5, + 40); + g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5, + 40); + g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35, + 2); + g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35, + 2); + //выделяем рамкой крышу + g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35, + 40); + g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25, + 30); + g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15, + 30); + // спортивная линия + if (EntityWarmlyShip.SportLine) + { + g.FillRectangle(additionalBrush, _startPosX + 75, + _startPosY + 23, 25, 15); + g.FillRectangle(additionalBrush, _startPosX + 35, + _startPosY + 23, 35, 15); + g.FillRectangle(additionalBrush, _startPosX + 10, + _startPosY + 23, 20, 15); + } + // крыло + if (EntityWarmlyShip.Wing) + { + g.FillRectangle(additionalBrush, _startPosX, _startPosY + + 5, 10, 50); + g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, + 50); + } + } + + + + } +} diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs new file mode 100644 index 0000000..94f5114 --- /dev/null +++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + public class EntityWarmlyShip + { + /// + /// Скорость + /// + 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 BodyKit { get; private set; } + /// + /// Признак (опция) наличия антикрыла + /// + public bool Wing { get; private set; } + /// + /// Признак (опция) наличия гоночной полосы + /// + public bool SportLine { get; private set; } + /// + /// Шаг перемещения автомобиля + /// + public double Step => (double)Speed * 100 / Weight; + /// + /// Инициализация полей объекта-класса спортивного автомобиля + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool bodyKit, bool wing, bool sportLine) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + BodyKit = bodyKit; + Wing = wing; + SportLine = sportLine; + } + } +} diff --git a/WarmlyShip/WarmlyShip/Form1.cs b/WarmlyShip/WarmlyShip/Form1.cs deleted file mode 100644 index bca3f86..0000000 --- a/WarmlyShip/WarmlyShip/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace WarmlyShip -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/Form1.Designer.cs b/WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs similarity index 58% rename from WarmlyShip/WarmlyShip/Form1.Designer.cs rename to WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs index 3873b6f..9c525c9 100644 --- a/WarmlyShip/WarmlyShip/Form1.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs @@ -1,6 +1,6 @@ namespace WarmlyShip { - partial class Form1 + partial class FormWarmlyShip { /// /// Required designer variable. @@ -28,12 +28,28 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.SuspendLayout(); + // + // FormWarmlyShip + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; + this.ClientSize = new System.Drawing.Size(882, 453); + this.Name = "FormWarmlyShip"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Теплоход"; + this.ResumeLayout(false); + } #endregion + + /*private PictureBox pictureBoxWarmlyShip; + private Button buttonRight; + private Button buttonLeft; + private Button buttonUp; + private Button buttonDown; + private Button buttonCreate;*/ + } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormWarmlyShip.cs b/WarmlyShip/WarmlyShip/FormWarmlyShip.cs new file mode 100644 index 0000000..82ddecc --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormWarmlyShip.cs @@ -0,0 +1,84 @@ +namespace WarmlyShip +{ + public partial class FormWarmlyShip : Form + { + /// + /// - + /// + private DrawingWarmlyShip? _drawingWarmlyShip; + /// + /// + /// + public FormWarmlyShip() + { + InitializeComponent(); + } + /// + /// + /// + private void Draw() + { + if (_drawingWarmlyShip == null) + { + return; + } + Bitmap bmp = new(pictureBoxWarmlyShip.Width, + pictureBoxWarmlyShip.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingWarmlyShip.DrawTransport(gr); + pictureBoxWarmlyShip.Image = bmp; + } + /// + /// "" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingWarmlyShip = new DrawingWarmlyShip(); + _drawingWarmlyShip.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)), + pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height); + _drawingWarmlyShip.SetPosition(random.Next(10, 100), + random.Next(10, 100)); + Draw(); + } + /// + /// + /// + /// + /// + private void buttonMove_Click(object sender, EventArgs e) + { + if (_drawingWarmlyShip == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawingWarmlyShip.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawingWarmlyShip.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawingWarmlyShip.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawingWarmlyShip.MoveTransport(DirectionType.Right); + break; + } + Draw(); + + } + } +} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormWarmlyShip.resx b/WarmlyShip/WarmlyShip/FormWarmlyShip.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormWarmlyShip.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index 341c406..71da933 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -11,7 +11,7 @@ namespace WarmlyShip // 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 FormWarmlyShip()); } } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/Properties/Resources.Designer.cs b/WarmlyShip/WarmlyShip/Properties/Resources.Designer.cs new file mode 100644 index 0000000..1ab343c --- /dev/null +++ b/WarmlyShip/WarmlyShip/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace WarmlyShip.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("WarmlyShip.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 down_arrow { + get { + object obj = ResourceManager.GetObject("down-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap left_arrow { + get { + object obj = ResourceManager.GetObject("left-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap right_arrow { + get { + object obj = ResourceManager.GetObject("right-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap upper_arrow { + get { + object obj = ResourceManager.GetObject("upper-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/WarmlyShip/WarmlyShip/Form1.resx b/WarmlyShip/WarmlyShip/Properties/Resources.resx similarity index 83% rename from WarmlyShip/WarmlyShip/Form1.resx rename to WarmlyShip/WarmlyShip/Properties/Resources.resx index 1af7de1..4e13804 100644 --- a/WarmlyShip/WarmlyShip/Form1.resx +++ b/WarmlyShip/WarmlyShip/Properties/Resources.resx @@ -117,4 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\down-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\upper-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\left-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\right-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/Resources/down-arrow.png b/WarmlyShip/WarmlyShip/Resources/down-arrow.png new file mode 100644 index 0000000..9d67143 Binary files /dev/null and b/WarmlyShip/WarmlyShip/Resources/down-arrow.png differ diff --git a/WarmlyShip/WarmlyShip/Resources/left-arrow.png b/WarmlyShip/WarmlyShip/Resources/left-arrow.png new file mode 100644 index 0000000..046470d Binary files /dev/null and b/WarmlyShip/WarmlyShip/Resources/left-arrow.png differ diff --git a/WarmlyShip/WarmlyShip/Resources/right-arrow.png b/WarmlyShip/WarmlyShip/Resources/right-arrow.png new file mode 100644 index 0000000..fac4c96 Binary files /dev/null and b/WarmlyShip/WarmlyShip/Resources/right-arrow.png differ diff --git a/WarmlyShip/WarmlyShip/Resources/upper-arrow.png b/WarmlyShip/WarmlyShip/Resources/upper-arrow.png new file mode 100644 index 0000000..0bc323d Binary files /dev/null and b/WarmlyShip/WarmlyShip/Resources/upper-arrow.png differ diff --git a/WarmlyShip/WarmlyShip/WarmlyShip.csproj b/WarmlyShip/WarmlyShip/WarmlyShip.csproj index b57c89e..13ee123 100644 --- a/WarmlyShip/WarmlyShip/WarmlyShip.csproj +++ b/WarmlyShip/WarmlyShip/WarmlyShip.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file