From bdcc4d3512727d2e9c10ffe9c0d0d5043c306335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Wed, 7 Sep 2022 00:01:51 +0400 Subject: [PATCH 1/2] 50% work --- GasolineTanker/GasolineTanker/Direction.cs | 16 ++ .../GasolineTanker/DrawingGasolineTanker.cs | 90 ++++++++++ .../GasolineTanker/EnityGasolineTanker.cs | 23 +++ .../GasolineTanker/Form1.Designer.cs | 39 ---- GasolineTanker/GasolineTanker/Form1.cs | 10 -- .../FormGasolineTanker.Designer.cs | 169 ++++++++++++++++++ .../GasolineTanker/FormGasolineTanker.cs | 20 +++ .../GasolineTanker/FormGasolineTanker.resx | 63 +++++++ .../GasolineTanker/GasolineTanker.csproj | 15 ++ GasolineTanker/GasolineTanker/Program.cs | 2 +- .../Properties/Resources.Designer.cs | 103 +++++++++++ .../{Form1.resx => Properties/Resources.resx} | 13 ++ .../GasolineTanker/Resources/KeyDown.png | Bin 0 -> 1433 bytes .../GasolineTanker/Resources/KeyLeft.png | Bin 0 -> 1265 bytes .../GasolineTanker/Resources/KeyRight.png | Bin 0 -> 1310 bytes .../GasolineTanker/Resources/KeyUp.png | Bin 0 -> 1278 bytes 16 files changed, 513 insertions(+), 50 deletions(-) create mode 100644 GasolineTanker/GasolineTanker/Direction.cs create mode 100644 GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs create mode 100644 GasolineTanker/GasolineTanker/EnityGasolineTanker.cs delete mode 100644 GasolineTanker/GasolineTanker/Form1.Designer.cs delete mode 100644 GasolineTanker/GasolineTanker/Form1.cs create mode 100644 GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs create mode 100644 GasolineTanker/GasolineTanker/FormGasolineTanker.cs create mode 100644 GasolineTanker/GasolineTanker/FormGasolineTanker.resx create mode 100644 GasolineTanker/GasolineTanker/Properties/Resources.Designer.cs rename GasolineTanker/GasolineTanker/{Form1.resx => Properties/Resources.resx} (83%) create mode 100644 GasolineTanker/GasolineTanker/Resources/KeyDown.png create mode 100644 GasolineTanker/GasolineTanker/Resources/KeyLeft.png create mode 100644 GasolineTanker/GasolineTanker/Resources/KeyRight.png create mode 100644 GasolineTanker/GasolineTanker/Resources/KeyUp.png diff --git a/GasolineTanker/GasolineTanker/Direction.cs b/GasolineTanker/GasolineTanker/Direction.cs new file mode 100644 index 0000000..8fd3c1c --- /dev/null +++ b/GasolineTanker/GasolineTanker/Direction.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal enum Direction + { + Up = 1, + Down = 2, + Left = 3, + Right = 4, + } +} diff --git a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs new file mode 100644 index 0000000..ae56d2a --- /dev/null +++ b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class DrawingGasolineTanker + { + public EnityGasolineTanker GasolineTanker { get; private set; } + private float _startPosX; + private float _startPosY; + private int? _pictureWidth = null; + private int? _pictureHeight = null; + private readonly int _gasolineTankerWidth = 80; + private readonly int _gasolineTankerHeight = 50; + + public void Init(int speed, float weight, Color bodyColor) + { + GasolineTanker = new EnityGasolineTanker(); + GasolineTanker.Init(speed, weight, bodyColor); + } + + public void SetPosition(int x, int y, int width, int height) + { + // Check + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; + } + + public void MoveTransport(Direction direction) + { + if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) + { + return; + } + switch (direction) + { + // вправо + case Direction.Right: + if (_startPosX + _gasolineTankerWidth + GasolineTanker.Step < _pictureWidth) + { + _startPosX += GasolineTanker.Step; + } + break; + //влево + case Direction.Left: + // TODO: Продумать логику + break; + //вверх + case Direction.Up: + // TODO: Продумать логику + break; + //вниз + case Direction.Down: + if (_startPosY + _gasolineTankerHeight + GasolineTanker.Step < _pictureHeight) + { + _startPosY += GasolineTanker.Step; + } + break; + } + } + public void DrawTransport(Graphics g) + { + + } + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _gasolineTankerWidth || _pictureHeight <= _gasolineTankerHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _gasolineTankerWidth > _pictureWidth) + { + _startPosX = _pictureWidth.Value - _gasolineTankerWidth; + } + if (_startPosY + _gasolineTankerHeight > _pictureHeight) + { + _startPosY = _pictureHeight.Value - _gasolineTankerHeight; + } + } + } +} diff --git a/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs b/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs new file mode 100644 index 0000000..e3f5b3b --- /dev/null +++ b/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class EnityGasolineTanker + { + 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, 100) : speed; + Weight = weight <= 0 ? rnd.Next(30, 60) : weight; + BodyColor = bodyColor; + } + } +} diff --git a/GasolineTanker/GasolineTanker/Form1.Designer.cs b/GasolineTanker/GasolineTanker/Form1.Designer.cs deleted file mode 100644 index 521f5d0..0000000 --- a/GasolineTanker/GasolineTanker/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace GasolineTanker -{ - 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() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/Form1.cs b/GasolineTanker/GasolineTanker/Form1.cs deleted file mode 100644 index da846e9..0000000 --- a/GasolineTanker/GasolineTanker/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace GasolineTanker -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs new file mode 100644 index 0000000..667c238 --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs @@ -0,0 +1,169 @@ +namespace GasolineTanker +{ + partial class FormGasolineTanker + { + /// + /// 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() + { + this.pictureBoxGasolineTanker = new System.Windows.Forms.PictureBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.KeyDown = new System.Windows.Forms.Button(); + this.KeyUp = new System.Windows.Forms.Button(); + this.KeyLeft = new System.Windows.Forms.Button(); + this.KeyRight = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxGasolineTanker + // + this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); + this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; + this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(800, 428); + this.pictureBoxGasolineTanker.TabIndex = 0; + this.pictureBoxGasolineTanker.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusSpeed, + this.toolStripStatusWeight, + this.toolStripStatusBodyColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(800, 22); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusSpeed + // + this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; + this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusSpeed.Text = "Speed"; + this.toolStripStatusSpeed.Click += new System.EventHandler(this.toolStripStatusLabel1_Click); + // + // toolStripStatusWeight + // + this.toolStripStatusWeight.Name = "toolStripStatusWeight"; + this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17); + this.toolStripStatusWeight.Text = "Weight"; + // + // toolStripStatusBodyColor + // + this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor"; + this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusBodyColor.Text = "Color"; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(12, 393); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Create"; + this.buttonCreate.UseVisualStyleBackColor = true; + // + // KeyDown + // + this.KeyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; + this.KeyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.KeyDown.Location = new System.Drawing.Point(624, 386); + this.KeyDown.Name = "KeyDown"; + this.KeyDown.Size = new System.Drawing.Size(30, 30); + this.KeyDown.TabIndex = 3; + this.KeyDown.UseVisualStyleBackColor = true; + // + // KeyUp + // + this.KeyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; + this.KeyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.KeyUp.Location = new System.Drawing.Point(624, 350); + this.KeyUp.Name = "KeyUp"; + this.KeyUp.Size = new System.Drawing.Size(30, 30); + this.KeyUp.TabIndex = 4; + this.KeyUp.UseVisualStyleBackColor = true; + // + // KeyLeft + // + this.KeyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; + this.KeyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.KeyLeft.Location = new System.Drawing.Point(588, 386); + this.KeyLeft.Name = "KeyLeft"; + this.KeyLeft.Size = new System.Drawing.Size(30, 30); + this.KeyLeft.TabIndex = 5; + this.KeyLeft.UseVisualStyleBackColor = true; + // + // KeyRight + // + this.KeyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; + this.KeyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.KeyRight.Location = new System.Drawing.Point(660, 386); + this.KeyRight.Name = "KeyRight"; + this.KeyRight.Size = new System.Drawing.Size(30, 30); + this.KeyRight.TabIndex = 6; + this.KeyRight.UseVisualStyleBackColor = true; + // + // FormGasolineTanker + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.KeyRight); + this.Controls.Add(this.KeyLeft); + this.Controls.Add(this.KeyUp); + this.Controls.Add(this.KeyDown); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxGasolineTanker); + this.Controls.Add(this.statusStrip1); + this.Name = "FormGasolineTanker"; + this.Text = "Gasoline tanker"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxGasolineTanker; + private StatusStrip statusStrip1; + private ToolStripStatusLabel toolStripStatusSpeed; + private ToolStripStatusLabel toolStripStatusWeight; + private ToolStripStatusLabel toolStripStatusBodyColor; + private Button buttonCreate; + private Button KeyDown; + private Button KeyUp; + private Button KeyLeft; + private Button KeyRight; + } +} \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs new file mode 100644 index 0000000..eafa89b --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs @@ -0,0 +1,20 @@ +namespace GasolineTanker +{ + public partial class FormGasolineTanker : Form + { + public FormGasolineTanker() + { + InitializeComponent(); + } + + private void toolStripStatusLabel1_Click(object sender, EventArgs e) + { + + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.resx b/GasolineTanker/GasolineTanker/FormGasolineTanker.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/GasolineTanker.csproj b/GasolineTanker/GasolineTanker/GasolineTanker.csproj index b57c89e..13ee123 100644 --- a/GasolineTanker/GasolineTanker/GasolineTanker.csproj +++ b/GasolineTanker/GasolineTanker/GasolineTanker.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/Program.cs b/GasolineTanker/GasolineTanker/Program.cs index feb86c7..1b6a3e0 100644 --- a/GasolineTanker/GasolineTanker/Program.cs +++ b/GasolineTanker/GasolineTanker/Program.cs @@ -11,7 +11,7 @@ namespace GasolineTanker // 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 FormGasolineTanker()); } } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/Properties/Resources.Designer.cs b/GasolineTanker/GasolineTanker/Properties/Resources.Designer.cs new file mode 100644 index 0000000..af947f3 --- /dev/null +++ b/GasolineTanker/GasolineTanker/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace GasolineTanker.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("GasolineTanker.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 KeyDown { + get { + object obj = ResourceManager.GetObject("KeyDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KeyLeft { + get { + object obj = ResourceManager.GetObject("KeyLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KeyRight { + get { + object obj = ResourceManager.GetObject("KeyRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KeyUp { + get { + object obj = ResourceManager.GetObject("KeyUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/GasolineTanker/GasolineTanker/Form1.resx b/GasolineTanker/GasolineTanker/Properties/Resources.resx similarity index 83% rename from GasolineTanker/GasolineTanker/Form1.resx rename to GasolineTanker/GasolineTanker/Properties/Resources.resx index 1af7de1..3cca124 100644 --- a/GasolineTanker/GasolineTanker/Form1.resx +++ b/GasolineTanker/GasolineTanker/Properties/Resources.resx @@ -117,4 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\KeyDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KeyLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KeyRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KeyUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/Resources/KeyDown.png b/GasolineTanker/GasolineTanker/Resources/KeyDown.png new file mode 100644 index 0000000000000000000000000000000000000000..ff09b70c28c9988dac153284fd98a56020d7069e GIT binary patch literal 1433 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 UC`*H+82|tP07*qoM6N<$g5dIoJpcdz literal 0 HcmV?d00001 diff --git a/GasolineTanker/GasolineTanker/Resources/KeyUp.png b/GasolineTanker/GasolineTanker/Resources/KeyUp.png new file mode 100644 index 0000000000000000000000000000000000000000..0e4bf6ffa0263f78b54fa34ba68c98c19ef64090 GIT binary patch literal 1278 zcmVu0sj2jo~ zRd69$DB?mv1Ys_yAR;J1xPw^=BIrVV#=N^8vk2))+H~x`={O|#K`km>b*fH%b?VeP z74q`(qB-ZN1xjgEoe)y9o!9SSeg6#Z{+Ub$)T3?7<6E&-180mm6~8v+7w-Oz$_s+_ zW$Y_gvDu)c#1kQ;jTv*>70`UY6BJ(Kl^JqFYu(0-5kjD~{=erD3JCp=+4f}&2yRnB zZ7l5eZriG4%4rj5#1_K0Vy%Xnfmj$e#VCVR(y3=M8JMPtj*bo#i^V|lz5G?(K7o7q zfKm#KGe{|+ltM0-!`$2)E-o&hwf+(ZUpsVe5R5U{whhiX48y?w{yuhgb`Xt5F+M(y zuC6ZFw%v@O9W;$Gr4$%rxVgE(^71lfXJ>JIe2kxe|AY{t>8w$pw8!feH$H368Hd&y zT50U=?&9I$0a8l*^~az1vGN1Ax3@411B|i{vVoFKRhAFqQ&Lqt6$=}-uwhviu98<+ zTU*2E=qQ8`0Dx>Zi@m))NFgDWY#MV-QOq<=q|<3^ZEc~iug^IJZ7DD`G=!Cv75w_= z7b1}eq?DnJTe-uU=Eu&@&#|$wf&Tt}Xsw}?axU8g0|VIH+(a&yLuG0rOw_copioMc zY>RVn&hh;GjMdduOiWBTTd*v93#!Sg~EsSwrwMu&0=I^1dEG{xVyUx zowb^Z1@&uMYgm?rL?VHBJdWPpUI-z;7=vk=wFjmYQc5t!u)VzvLWom$`zbHKrM0fw z5#@SlSt=S;o(mgrficDZeVb55DN`Kg6^r#Q)Gv%1mLcA-$f%*+g~ zuCCDC-TmRa`v4(?fKuw%Wlv8J5{U#(PEIgAJq@LluW`NRnM$R?QA`Md`}=#OQYl0t zkq_U!CQ2y_Kox~$Sq@8-Qr|XK55Dq>ZUk-b zj=S73ROL4GlREG-e%ofLz7=aV_&Piq&HH)fCH&%dV#Ky(>|3!`gRk6u(A@cFHuV)L z?zUy@Td`IHH%${#%DQ$G)DO9BsL_8V`01~;b}r*mO7QphcXUQOOB3=?pwUb6R~#0V zv0SlO1kdO5uq>NBO~#ODRKNK{wpSANF6I%1Twr o<>gd#GZFSF=_S7`R|tWB0pFkf#1au;M1& literal 0 HcmV?d00001 From f1c9bfed5f5e0ef385eb9e78808aa4a694aa23d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Wed, 7 Sep 2022 11:11:00 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GasolineTanker/DrawingGasolineTanker.cs | 53 ++++++-- .../FormGasolineTanker.Designer.cs | 128 ++++++++++-------- .../GasolineTanker/FormGasolineTanker.cs | 51 ++++++- 3 files changed, 164 insertions(+), 68 deletions(-) diff --git a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs index ae56d2a..20b1dea 100644 --- a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs @@ -13,8 +13,8 @@ namespace GasolineTanker private float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; - private readonly int _gasolineTankerWidth = 80; - private readonly int _gasolineTankerHeight = 50; + private readonly int _gasolineTankerWidth = 160; + private readonly int _gasolineTankerHeight = 55; public void Init(int speed, float weight, Color bodyColor) { @@ -24,11 +24,13 @@ namespace GasolineTanker public void SetPosition(int x, int y, int width, int height) { - // Check - _startPosX = x; - _startPosY = y; - _pictureWidth = width; - _pictureHeight = height; + if (x >= 0 && x + _gasolineTankerWidth <= width && y >= 0 && y + _gasolineTankerHeight <= height) + { + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; + } } public void MoveTransport(Direction direction) @@ -48,11 +50,17 @@ namespace GasolineTanker break; //влево case Direction.Left: - // TODO: Продумать логику + if (_startPosX - GasolineTanker.Step > 0) + { + _startPosX -= GasolineTanker.Step; + } break; //вверх case Direction.Up: - // TODO: Продумать логику + if (_startPosY - GasolineTanker.Step > 0) + { + _startPosY -= GasolineTanker.Step; + } break; //вниз case Direction.Down: @@ -65,7 +73,34 @@ namespace GasolineTanker } public void DrawTransport(Graphics g) { + if (_startPosX < 0 || _startPosY < 0 + || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + Pen pen = new(Color.Black); + Brush brBlack = new SolidBrush(Color.Black); + g.FillEllipse(brBlack, _startPosX + 130, _startPosY + 35, 20, 20); + g.FillEllipse(brBlack, _startPosX + 10, _startPosY + 35, 20, 20); + g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 35, 20, 20); + + Brush brRed = new SolidBrush(Color.Red); + g.FillEllipse(brRed, _startPosX+5, _startPosY + 35, 10, 10); + + Brush brYellow = new SolidBrush(Color.Yellow); + g.FillEllipse(brYellow, _startPosX + 140, _startPosY + 30, 10, 10); + + Brush br = new SolidBrush(GasolineTanker?.BodyColor ?? Color.Black); + g.FillRectangle(br, _startPosX + 115, _startPosY+5, 40, 40); + g.FillRectangle(br, _startPosX + 10, _startPosY + 35, 140, 10); + + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX + 120, _startPosY + 10, 25, 25); + + g.DrawRectangle(pen, _startPosX + 120, _startPosY + 10, 25, 25); + g.DrawRectangle(pen, _startPosX + 115, _startPosY + 5, 40, 40); + g.DrawRectangle(pen, _startPosX + 10, _startPosY + 35, 105, 10); } public void ChangeBorders(int width, int height) { diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs index 667c238..462148b 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs @@ -34,10 +34,10 @@ this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonCreate = new System.Windows.Forms.Button(); - this.KeyDown = new System.Windows.Forms.Button(); - this.KeyUp = new System.Windows.Forms.Button(); - this.KeyLeft = new System.Windows.Forms.Button(); - this.KeyRight = new System.Windows.Forms.Button(); + this.keyDown = new System.Windows.Forms.Button(); + this.keyUp = new System.Windows.Forms.Button(); + this.keyLeft = new System.Windows.Forms.Button(); + this.keyRight = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -46,103 +46,121 @@ // this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); + this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; - this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(800, 428); + this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(922, 574); this.pictureBoxGasolineTanker.TabIndex = 0; this.pictureBoxGasolineTanker.TabStop = false; // // statusStrip1 // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusSpeed, this.toolStripStatusWeight, this.toolStripStatusBodyColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Location = new System.Drawing.Point(0, 574); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(800, 22); + this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); + this.statusStrip1.Size = new System.Drawing.Size(922, 26); this.statusStrip1.TabIndex = 1; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusSpeed // this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; - this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusSpeed.Size = new System.Drawing.Size(51, 20); this.toolStripStatusSpeed.Text = "Speed"; - this.toolStripStatusSpeed.Click += new System.EventHandler(this.toolStripStatusLabel1_Click); // // toolStripStatusWeight // this.toolStripStatusWeight.Name = "toolStripStatusWeight"; - this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17); + this.toolStripStatusWeight.Size = new System.Drawing.Size(56, 20); this.toolStripStatusWeight.Text = "Weight"; // // toolStripStatusBodyColor // this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor"; - this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusBodyColor.Size = new System.Drawing.Size(45, 20); this.toolStripStatusBodyColor.Text = "Color"; // // buttonCreate // - this.buttonCreate.Location = new System.Drawing.Point(12, 393); + this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreate.Location = new System.Drawing.Point(14, 524); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.Size = new System.Drawing.Size(86, 31); this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Create"; this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click_1); // - // KeyDown + // keyDown // - this.KeyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; - this.KeyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.KeyDown.Location = new System.Drawing.Point(624, 386); - this.KeyDown.Name = "KeyDown"; - this.KeyDown.Size = new System.Drawing.Size(30, 30); - this.KeyDown.TabIndex = 3; - this.KeyDown.UseVisualStyleBackColor = true; + this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; + this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyDown.Location = new System.Drawing.Point(827, 515); + this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyDown.Name = "keyDown"; + this.keyDown.Size = new System.Drawing.Size(34, 40); + this.keyDown.TabIndex = 3; + this.keyDown.UseVisualStyleBackColor = true; + this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); // - // KeyUp + // keyUp // - this.KeyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; - this.KeyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.KeyUp.Location = new System.Drawing.Point(624, 350); - this.KeyUp.Name = "KeyUp"; - this.KeyUp.Size = new System.Drawing.Size(30, 30); - this.KeyUp.TabIndex = 4; - this.KeyUp.UseVisualStyleBackColor = true; + this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; + this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyUp.Location = new System.Drawing.Point(827, 467); + this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyUp.Name = "keyUp"; + this.keyUp.Size = new System.Drawing.Size(34, 40); + this.keyUp.TabIndex = 4; + this.keyUp.UseVisualStyleBackColor = true; + this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); // - // KeyLeft + // keyLeft // - this.KeyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; - this.KeyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.KeyLeft.Location = new System.Drawing.Point(588, 386); - this.KeyLeft.Name = "KeyLeft"; - this.KeyLeft.Size = new System.Drawing.Size(30, 30); - this.KeyLeft.TabIndex = 5; - this.KeyLeft.UseVisualStyleBackColor = true; + this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; + this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyLeft.Location = new System.Drawing.Point(786, 515); + this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyLeft.Name = "keyLeft"; + this.keyLeft.Size = new System.Drawing.Size(34, 40); + this.keyLeft.TabIndex = 5; + this.keyLeft.UseVisualStyleBackColor = true; + this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); // - // KeyRight + // keyRight // - this.KeyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; - this.KeyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.KeyRight.Location = new System.Drawing.Point(660, 386); - this.KeyRight.Name = "KeyRight"; - this.KeyRight.Size = new System.Drawing.Size(30, 30); - this.KeyRight.TabIndex = 6; - this.KeyRight.UseVisualStyleBackColor = true; + this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; + this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.keyRight.Location = new System.Drawing.Point(868, 515); + this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyRight.Name = "keyRight"; + this.keyRight.Size = new System.Drawing.Size(34, 40); + this.keyRight.TabIndex = 6; + this.keyRight.UseVisualStyleBackColor = true; + this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); // // FormGasolineTanker // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.KeyRight); - this.Controls.Add(this.KeyLeft); - this.Controls.Add(this.KeyUp); - this.Controls.Add(this.KeyDown); + this.ClientSize = new System.Drawing.Size(922, 600); + this.Controls.Add(this.keyRight); + this.Controls.Add(this.keyLeft); + this.Controls.Add(this.keyUp); + this.Controls.Add(this.keyDown); this.Controls.Add(this.buttonCreate); this.Controls.Add(this.pictureBoxGasolineTanker); this.Controls.Add(this.statusStrip1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormGasolineTanker"; this.Text = "Gasoline tanker"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); @@ -161,9 +179,9 @@ private ToolStripStatusLabel toolStripStatusWeight; private ToolStripStatusLabel toolStripStatusBodyColor; private Button buttonCreate; - private Button KeyDown; - private Button KeyUp; - private Button KeyLeft; - private Button KeyRight; + private Button keyDown; + private Button keyUp; + private Button keyLeft; + private Button keyRight; } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs index eafa89b..46d150d 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs @@ -2,19 +2,62 @@ namespace GasolineTanker { public partial class FormGasolineTanker : Form { + private DrawingGasolineTanker _gasolineTanker; public FormGasolineTanker() { InitializeComponent(); } - - private void toolStripStatusLabel1_Click(object sender, EventArgs e) + private void Draw() { - + Bitmap bmp = new(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + Graphics gr = Graphics.FromImage(bmp); + _gasolineTanker?.DrawTransport(gr); + pictureBoxGasolineTanker.Image = bmp; + } + private void PictureBoxCar_Resize(object sender, EventArgs e) + { + _gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + Draw(); } - private void ButtonCreate_Click(object sender, EventArgs e) + private void buttonCreate_Click_1(object sender, EventArgs e) { + Random rnd = new(); + _gasolineTanker = new DrawingGasolineTanker(); + _gasolineTanker.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _gasolineTanker.SetPosition(rnd.Next(10, 100),rnd.Next(50, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}"; + toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}"; + toolStripStatusBodyColor.Text = $"Color {_gasolineTanker.GasolineTanker.BodyColor.Name}"; + Draw(); + } + private void ButtonMove_Click(object sender, EventArgs e) + { + // + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "keyUp": + _gasolineTanker?.MoveTransport(Direction.Up); + break; + case "keyDown": + _gasolineTanker?.MoveTransport(Direction.Down); + break; + case "keyLeft": + _gasolineTanker?.MoveTransport(Direction.Left); + break; + case "keyRight": + _gasolineTanker?.MoveTransport(Direction.Right); + break; + } + Draw(); + } + + private void PictureBoxGasolineTanker_Resize(object sender, EventArgs e) + { + _gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + Draw(); } } } \ No newline at end of file