From 1c8fb269b14f6b016a1122b225f895779c444301 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: Thu, 29 Sep 2022 20:50:38 +0400 Subject: [PATCH 1/4] Lab 3 not TODO --- GasolineTanker/GasolineTanker/Direction.cs | 2 +- .../GasolineTanker/DrawingGasolineTanker.cs | 2 +- .../GasolineTanker/EnityGasolineTanker.cs | 2 +- .../FormGasolineTanker.Designer.cs | 16 +- .../GasolineTanker/FormGasolineTanker.cs | 9 +- .../GasolineTanker/FormMap.Designer.cs | 208 ----------------- GasolineTanker/GasolineTanker/FormMap.cs | 86 ------- .../FormMapWithSetGasolineTanker.Designer.cs | 210 ++++++++++++++++++ .../FormMapWithSetGasolineTanker.cs | 133 +++++++++++ ...resx => FormMapWithSetGasolineTanker.resx} | 3 - .../MapWithSetGasolienTankerGeneric.cs | 118 ++++++++++ GasolineTanker/GasolineTanker/Program.cs | 2 +- .../SetGasolineTankerGeneric.cs | 45 ++++ 13 files changed, 533 insertions(+), 303 deletions(-) delete mode 100644 GasolineTanker/GasolineTanker/FormMap.Designer.cs delete mode 100644 GasolineTanker/GasolineTanker/FormMap.cs create mode 100644 GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs create mode 100644 GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs rename GasolineTanker/GasolineTanker/{FormMap.resx => FormMapWithSetGasolineTanker.resx} (93%) create mode 100644 GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs create mode 100644 GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs diff --git a/GasolineTanker/GasolineTanker/Direction.cs b/GasolineTanker/GasolineTanker/Direction.cs index c76c46a..22fdfbf 100644 --- a/GasolineTanker/GasolineTanker/Direction.cs +++ b/GasolineTanker/GasolineTanker/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace GasolineTanker { - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs index 1922061..76f7b42 100644 --- a/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingGasolineTanker.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace GasolineTanker { - internal class DrawingGasolineTanker + public class DrawingGasolineTanker { public EnityGasolineTanker GasolineTanker { get; protected set; } protected float _startPosX; diff --git a/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs b/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs index dd369c1..7053da6 100644 --- a/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/EnityGasolineTanker.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace GasolineTanker { - internal class EnityGasolineTanker + public class EnityGasolineTanker { public int Speed { get; private set; } public float Weight { get; private set; } diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs index 5be7d04..6ccdb31 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.Designer.cs @@ -39,6 +39,7 @@ this.keyLeft = new System.Windows.Forms.Button(); this.keyRight = new System.Windows.Forms.Button(); this.ButtonCreateImproved = new System.Windows.Forms.Button(); + this.buttonChoose = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -92,7 +93,7 @@ this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Create"; this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click_1); + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click_1); // // keyDown // @@ -152,11 +153,23 @@ this.ButtonCreateImproved.UseVisualStyleBackColor = true; this.ButtonCreateImproved.Click += new System.EventHandler(this.ButtonCreateImproved_Click); // + // buttonChoose + // + this.buttonChoose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonChoose.Location = new System.Drawing.Point(598, 390); + this.buttonChoose.Name = "buttonChoose"; + this.buttonChoose.Size = new System.Drawing.Size(75, 23); + this.buttonChoose.TabIndex = 8; + this.buttonChoose.Text = "Choose"; + this.buttonChoose.UseVisualStyleBackColor = true; + this.buttonChoose.Click += new System.EventHandler(this.ButtonChoose_Click); + // // FormGasolineTanker // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(807, 450); + this.Controls.Add(this.buttonChoose); this.Controls.Add(this.ButtonCreateImproved); this.Controls.Add(this.keyRight); this.Controls.Add(this.keyLeft); @@ -188,5 +201,6 @@ private Button keyLeft; private Button keyRight; private Button ButtonCreateImproved; + private Button buttonChoose; } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs index c7d0f1e..b73fe24 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs @@ -3,6 +3,7 @@ namespace GasolineTanker public partial class FormGasolineTanker : Form { private DrawingGasolineTanker _gasolineTanker; + public DrawingGasolineTanker SelectedGasolineTanker { get; private set; } public FormGasolineTanker() { InitializeComponent(); @@ -28,7 +29,7 @@ namespace GasolineTanker Draw(); } - private void buttonCreate_Click_1(object sender, EventArgs e) + private void ButtonCreate_Click_1(object sender, EventArgs e) { Random rnd = new(); _gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); @@ -75,5 +76,11 @@ namespace GasolineTanker SetData(); Draw(); } + + private void ButtonChoose_Click(object sender, EventArgs e) + { + SelectedGasolineTanker = _gasolineTanker; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormMap.Designer.cs b/GasolineTanker/GasolineTanker/FormMap.Designer.cs deleted file mode 100644 index a10c10d..0000000 --- a/GasolineTanker/GasolineTanker/FormMap.Designer.cs +++ /dev/null @@ -1,208 +0,0 @@ -namespace GasolineTanker -{ - partial class FormMap - { - /// - /// 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(); - this.ButtonCreateImproved = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - ((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(807, 428); - 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.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(807, 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"; - // - // 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - 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; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click_1); - // - // keyDown - // - 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(724, 386); - this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(30, 30); - this.keyDown.TabIndex = 3; - this.keyDown.UseVisualStyleBackColor = true; - this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // keyUp - // - 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(724, 350); - this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(30, 30); - this.keyUp.TabIndex = 4; - this.keyUp.UseVisualStyleBackColor = true; - this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); - // - // keyLeft - // - 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(688, 386); - this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(30, 30); - this.keyLeft.TabIndex = 5; - this.keyLeft.UseVisualStyleBackColor = true; - this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); - // - // keyRight - // - 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(760, 386); - this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(30, 30); - this.keyRight.TabIndex = 6; - this.keyRight.UseVisualStyleBackColor = true; - this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // ButtonCreateImproved - // - this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393); - this.ButtonCreateImproved.Name = "ButtonCreateImproved"; - this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23); - this.ButtonCreateImproved.TabIndex = 7; - this.ButtonCreateImproved.Text = "Improved"; - this.ButtonCreateImproved.UseVisualStyleBackColor = true; - this.ButtonCreateImproved.Click += new System.EventHandler(this.ButtonCreateImproved_Click); - // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Simple map", - "Long map"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); - this.comboBoxSelectorMap.TabIndex = 8; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(807, 450); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.ButtonCreateImproved); - 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 = "FormMap"; - this.Text = "Map"; - ((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; - private Button ButtonCreateImproved; - private ComboBox comboBoxSelectorMap; - } -} \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormMap.cs b/GasolineTanker/GasolineTanker/FormMap.cs deleted file mode 100644 index 5a322c0..0000000 --- a/GasolineTanker/GasolineTanker/FormMap.cs +++ /dev/null @@ -1,86 +0,0 @@ -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 GasolineTanker -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - - private void SetData(DrawingGasolineTanker gasolineTanker) - { - toolStripStatusSpeed.Text = $"Speed {gasolineTanker.GasolineTanker.Speed}"; - toolStripStatusWeight.Text = $"Weight {gasolineTanker.GasolineTanker.Weight}"; - toolStripStatusBodyColor.Text = $"Color {gasolineTanker.GasolineTanker.BodyColor.Name}"; - pictureBoxGasolineTanker.Image = _abstractMap.CreateMap(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height, - new DrawingObjectGasolineTanker(gasolineTanker)); - } - - private void buttonCreate_Click_1(object sender, EventArgs e) - { - Random rnd = new(); - var gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(gasolineTanker); - } - - private void ButtonMove_Click(object sender, EventArgs e) - { - //получаем имя кнопки - string name = ((Button)sender)?.Name ?? string.Empty; - Direction dir = Direction.None; - switch (name) - { - case "keyUp": - dir = Direction.Up; - break; - case "keyDown": - dir = Direction.Down; - break; - case "keyLeft": - dir = Direction.Left; - break; - case "keyRight": - dir = Direction.Right; - break; - } - pictureBoxGasolineTanker.Image = _abstractMap?.MoveObject(dir); - } - - private void ButtonCreateImproved_Click(object sender, EventArgs e) - { - Random rnd = new(); - var gasolineTanker = new DrawingImprovedGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); - SetData(gasolineTanker); - } - - private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Simple map": - _abstractMap = new SimpleMap(); - break; - case "Long map": - _abstractMap = new LongMap(); - break; - } - } - - } -} - diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs new file mode 100644 index 0000000..8e862fd --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs @@ -0,0 +1,210 @@ +namespace GasolineTanker +{ + partial class FormMapWithSetGasolineTanker + { + /// + /// 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.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.keyRight = new System.Windows.Forms.Button(); + this.keyLeft = new System.Windows.Forms.Button(); + this.keyUp = new System.Windows.Forms.Button(); + this.keyDown = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveGasolineTanker = new System.Windows.Forms.Button(); + this.buttonAddGasolineTanker = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + this.groupBoxTools.Controls.Add(this.keyRight); + this.groupBoxTools.Controls.Add(this.keyLeft); + this.groupBoxTools.Controls.Add(this.keyUp); + this.groupBoxTools.Controls.Add(this.keyDown); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker); + this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker); + this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBoxTools.Location = new System.Drawing.Point(600, 0); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(200, 450); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Tools"; + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 113); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23); + this.maskedTextBoxPosition.TabIndex = 11; + // + // keyRight + // + 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(122, 408); + this.keyRight.Name = "keyRight"; + this.keyRight.Size = new System.Drawing.Size(30, 30); + this.keyRight.TabIndex = 10; + this.keyRight.UseVisualStyleBackColor = true; + // + // keyLeft + // + 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(50, 408); + this.keyLeft.Name = "keyLeft"; + this.keyLeft.Size = new System.Drawing.Size(30, 30); + this.keyLeft.TabIndex = 9; + this.keyLeft.UseVisualStyleBackColor = true; + // + // keyUp + // + 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(86, 372); + this.keyUp.Name = "keyUp"; + this.keyUp.Size = new System.Drawing.Size(30, 30); + this.keyUp.TabIndex = 8; + this.keyUp.UseVisualStyleBackColor = true; + // + // keyDown + // + 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(86, 408); + this.keyDown.Name = "keyDown"; + this.keyDown.Size = new System.Drawing.Size(30, 30); + this.keyDown.TabIndex = 7; + this.keyDown.UseVisualStyleBackColor = true; + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(8, 326); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34); + this.buttonShowOnMap.TabIndex = 4; + this.buttonShowOnMap.Text = "Show on map"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(8, 241); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(186, 34); + this.buttonShowStorage.TabIndex = 3; + this.buttonShowStorage.Text = "Show storage"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveGasolineTanker + // + this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(10, 142); + this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker"; + this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonRemoveGasolineTanker.TabIndex = 2; + this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker"; + this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true; + this.buttonRemoveGasolineTanker.Click += new System.EventHandler(this.ButtonRemoveGasolineTanker_Click); + // + // buttonAddGasolineTanker + // + this.buttonAddGasolineTanker.Location = new System.Drawing.Point(8, 73); + this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker"; + this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonAddGasolineTanker.TabIndex = 1; + this.buttonAddGasolineTanker.Text = "Add gasoline tanker"; + this.buttonAddGasolineTanker.UseVisualStyleBackColor = true; + this.buttonAddGasolineTanker.Click += new System.EventHandler(this.ButtonAddGasolineTanker_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Simple map", + "Long map"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); + this.comboBoxSelectorMap.TabIndex = 12; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(600, 450); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetGasolineTanker + // + 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.pictureBox); + this.Controls.Add(this.groupBoxTools); + this.Name = "FormMapWithSetGasolineTanker"; + this.Text = "FormMapWithSetGasolineTanker"; + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemoveGasolineTanker; + private Button buttonAddGasolineTanker; + private ComboBox comboBoxSelectorMap; + private PictureBox pictureBox; + private Button keyRight; + private Button keyLeft; + private Button keyUp; + private Button keyDown; + private MaskedTextBox maskedTextBoxPosition; + } +} \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs new file mode 100644 index 0000000..9039fb5 --- /dev/null +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs @@ -0,0 +1,133 @@ +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 GasolineTanker +{ + public partial class FormMapWithSetGasolineTanker : Form + { + private MapWithSetGasolienTankerGeneric _mapGasolineTankerCollectionGeneric; + public FormMapWithSetGasolineTanker() + { + InitializeComponent(); + } + + + private void ButtonAddGasolineTanker_Click(object sender, EventArgs e) + { + if (_mapGasolineTankerCollectionGeneric == null) + { + return; + } + FormGasolineTanker form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawingObjectGasolineTanker GasolineTanker = new(form.SelectedGasolineTanker); + if (_mapGasolineTankerCollectionGeneric + GasolineTanker) + { + MessageBox.Show("Object added"); + pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Failed to add object"); + } + } + } + + private void ButtonRemoveGasolineTanker_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Delete object?", "Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapGasolineTankerCollectionGeneric - pos) + { + MessageBox.Show("Object deleted"); + pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Failed to delete object"); + } + } + + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapGasolineTankerCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); + } + + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapGasolineTankerCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowOnMap(); + } + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapGasolineTankerCollectionGeneric == null) + { + return; + } + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBox.Image = _mapGasolineTankerCollectionGeneric.MoveObject(dir); + } + + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Simple map": + map = new SimpleMap(); + break; + case "Long map": + map = new LongMap(); + break; + } + if (map != null) + { + _mapGasolineTankerCollectionGeneric = new MapWithSetGasolienTankerGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapGasolineTankerCollectionGeneric = null; + } + } + } +} diff --git a/GasolineTanker/GasolineTanker/FormMap.resx b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.resx similarity index 93% rename from GasolineTanker/GasolineTanker/FormMap.resx rename to GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.resx index 5cb320f..f298a7b 100644 --- a/GasolineTanker/GasolineTanker/FormMap.resx +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.resx @@ -57,7 +57,4 @@ 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/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs new file mode 100644 index 0000000..d8fe38f --- /dev/null +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class MapWithSetGasolienTankerGeneric + where T : class, IDrawingObject + where U : AbstractMap + { + private readonly int _pictureWidth; + private readonly int _pictureHeight; + private readonly int _placeSizeWidth = 210; + private readonly int _placeSizeHeight = 90; + private readonly SetGasolineTankerGeneric _setGasolineTanker; + private readonly U _map; + public MapWithSetGasolienTankerGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setGasolineTanker = new SetGasolineTankerGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + + public static bool operator +(MapWithSetGasolienTankerGeneric map, T GasolineTanker) + { + return map._setGasolineTanker.Insert(GasolineTanker); + } + + public static bool operator -(MapWithSetGasolienTankerGeneric map, int position) + { + return map._setGasolineTanker.Remove(position); + } + + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawGasolineTanker(gr); + return bmp; + } + + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setGasolineTanker.Count; i++) + { + var GasolineTanker = _setGasolineTanker.Get(i); + if (GasolineTanker != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, GasolineTanker); + } + } + return new(_pictureWidth, _pictureHeight); + } + + public Bitmap MoveObject(Direction direction) + { + if (_map != null) + { + return _map.MoveObject(direction); + } + return new(_pictureWidth, _pictureHeight); + } + + private void Shaking() + { + int j = _setGasolineTanker.Count - 1; + for (int i = 0; i < _setGasolineTanker.Count; i++) + { + if (_setGasolineTanker.Get(i) == null) + { + for (; j > i; j--) + { + var GasolineTanker = _setGasolineTanker.Get(j); + if (GasolineTanker != null) + { + _setGasolineTanker.Insert(GasolineTanker, i); + _setGasolineTanker.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + } + + private void DrawGasolineTanker(Graphics g) + { + for (int i = 0; i < _setGasolineTanker.Count; i++) + { + // TODO установка позиции + _setGasolineTanker.Get(i)?.DrawningObject(g); + } + } + } +} diff --git a/GasolineTanker/GasolineTanker/Program.cs b/GasolineTanker/GasolineTanker/Program.cs index b920f1e..145b9e2 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 FormMap()); + Application.Run(new FormMapWithSetGasolineTanker()); } } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs new file mode 100644 index 0000000..5e68e46 --- /dev/null +++ b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class SetGasolineTankerGeneric + where T : class + { + private readonly T[] _places; + public int Count => _places.Length; + public SetGasolineTankerGeneric(int count) + { + _places = new T[count]; + } + public bool Insert(T GasolineTanker) + { + // TODO вставка в начало набора + return true; + } + public bool Insert(T GasolineTanker, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = GasolineTanker; + return true; + } + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присовив элементу массива значение null + return true; + } + public T Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } +} From 7dda1f708a1ae71e325166cfeecd15f90d2d91e4 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: Tue, 4 Oct 2022 15:55:12 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetGasolineTanker.Designer.cs | 4 ++ .../FormMapWithSetGasolineTanker.cs | 12 ++-- .../MapWithSetGasolienTankerGeneric.cs | 21 ++++-- .../SetGasolineTankerGeneric.cs | 67 ++++++++++++++----- 4 files changed, 75 insertions(+), 29 deletions(-) diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs index 8e862fd..311cc56 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs @@ -82,6 +82,7 @@ this.keyRight.Size = new System.Drawing.Size(30, 30); this.keyRight.TabIndex = 10; this.keyRight.UseVisualStyleBackColor = true; + this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); // // keyLeft // @@ -93,6 +94,7 @@ this.keyLeft.Size = new System.Drawing.Size(30, 30); this.keyLeft.TabIndex = 9; this.keyLeft.UseVisualStyleBackColor = true; + this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); // // keyUp // @@ -104,6 +106,7 @@ this.keyUp.Size = new System.Drawing.Size(30, 30); this.keyUp.TabIndex = 8; this.keyUp.UseVisualStyleBackColor = true; + this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); // // keyDown // @@ -115,6 +118,7 @@ this.keyDown.Size = new System.Drawing.Size(30, 30); this.keyDown.TabIndex = 7; this.keyDown.UseVisualStyleBackColor = true; + this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs index 9039fb5..66b1d1c 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs @@ -29,7 +29,7 @@ namespace GasolineTanker if (form.ShowDialog() == DialogResult.OK) { DrawingObjectGasolineTanker GasolineTanker = new(form.SelectedGasolineTanker); - if (_mapGasolineTankerCollectionGeneric + GasolineTanker) + if (_mapGasolineTankerCollectionGeneric + GasolineTanker >= 0) { MessageBox.Show("Object added"); pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); @@ -52,7 +52,7 @@ namespace GasolineTanker return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapGasolineTankerCollectionGeneric - pos) + if (_mapGasolineTankerCollectionGeneric - pos != null) { MessageBox.Show("Object deleted"); pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); @@ -91,16 +91,16 @@ namespace GasolineTanker Direction dir = Direction.None; switch (name) { - case "buttonUp": + case "keyUp": dir = Direction.Up; break; - case "buttonDown": + case "keyDown": dir = Direction.Down; break; - case "buttonLeft": + case "keyLeft": dir = Direction.Left; break; - case "buttonRight": + case "keyRight": dir = Direction.Right; break; } diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs index d8fe38f..272210a 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -26,12 +26,12 @@ namespace GasolineTanker _map = map; } - public static bool operator +(MapWithSetGasolienTankerGeneric map, T GasolineTanker) + public static int operator +(MapWithSetGasolienTankerGeneric map, T GasolineTanker) { return map._setGasolineTanker.Insert(GasolineTanker); } - public static bool operator -(MapWithSetGasolienTankerGeneric map, int position) + public static T operator -(MapWithSetGasolienTankerGeneric map, int position) { return map._setGasolineTanker.Remove(position); } @@ -95,23 +95,30 @@ namespace GasolineTanker private void DrawBackground(Graphics g) { - Pen pen = new(Color.Black, 3); + Pen pen = new(Color.Black, 5); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) { - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2); + g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20); + g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } } private void DrawGasolineTanker(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + for (int i = 0; i < _setGasolineTanker.Count; i++) { - // TODO установка позиции - _setGasolineTanker.Get(i)?.DrawningObject(g); + if (_setGasolineTanker.Get(i) != null) + { + _setGasolineTanker.Get(i).SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + _setGasolineTanker.Get(i)?.DrawningObject(g); + } } } } diff --git a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs index 5e68e46..69ae434 100644 --- a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs @@ -15,30 +15,65 @@ namespace GasolineTanker { _places = new T[count]; } - public bool Insert(T GasolineTanker) + public int Insert(T GasolineTanker) { - // TODO вставка в начало набора - return true; + if (_places[Count - 1] == null) + { + for (int i = Count - 1; i > 0; i--) + { + _places[i] = _places[i - 1]; + } + _places[0] = GasolineTanker; + return 0; + } + return -1; } - public bool Insert(T GasolineTanker, int position) + public int Insert(T GasolineTanker, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции - _places[position] = GasolineTanker; - return true; + if (position < 0 || position >= Count) return -1; + if (_places[position] == null) + { + _places[position] = GasolineTanker; + return position; + } + else + { + if (_places[Count - 1] == null) + { + for (int i = Count - 1; i > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = GasolineTanker; + return position; + } + return -1; + } } - public bool Remove(int position) + public T Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присовив элементу массива значение null - return true; + if (position < 0 || position >= Count) + return null; + if (_places[position] != null) + { + T removed = _places[position]; + _places[position] = null; + if (position < Count - 1) + { + for (int k = position; k < Count - 1; k++) + { + _places[k] = _places[k + 1]; + } + } + return removed; + } + return null; } public T Get(int position) { - // TODO проверка позиции + if (position >= Count || position < 0) + return null; + return _places[position]; } } From ec6e19c626b8a10ba2f686ed788e5f68be65cc10 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, 5 Oct 2022 10:28:26 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingImprovedGasolineTanker.cs | 7 ++--- .../GasolineTanker/FormGasolineTanker.cs | 27 ++++++++++++++----- .../MapWithSetGasolienTankerGeneric.cs | 21 ++++++++------- .../SetGasolineTankerGeneric.cs | 10 +++---- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs index 3bc9e09..e76d523 100644 --- a/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingImprovedGasolineTanker.cs @@ -20,13 +20,10 @@ namespace GasolineTanker return; } - Pen pen = new(Color.Black); - Brush dopBrush = new SolidBrush(improvedGasolineTanker.DopColor); - if (improvedGasolineTanker.BodyKit) { - Brush brOrange = new SolidBrush(Color.Orange); - g.FillRectangle(brOrange, _startPosX + 25, _startPosY + 5, 100, 35); + Brush dopBrush = new SolidBrush(improvedGasolineTanker.DopColor); + g.FillRectangle(dopBrush, _startPosX + 25, _startPosY + 5, 100, 35); Brush brRed = new SolidBrush(Color.Red); g.FillRectangle(brRed, _startPosX + 80, _startPosY, 10, 5); } diff --git a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs index b73fe24..1d14c06 100644 --- a/GasolineTanker/GasolineTanker/FormGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormGasolineTanker.cs @@ -32,10 +32,16 @@ namespace GasolineTanker private void ButtonCreate_Click_1(object sender, EventArgs e) { Random rnd = new(); - _gasolineTanker = new DrawingGasolineTanker(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); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000),color); SetData(); Draw(); + } private void ButtonMove_Click(object sender, EventArgs e) @@ -69,10 +75,19 @@ namespace GasolineTanker private void ButtonCreateImproved_Click(object sender, EventArgs e) { Random rnd = new(); - _gasolineTanker = new DrawingImprovedGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + Color colorDop = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + colorDop = dialogDop.Color; + } + _gasolineTanker = new DrawingImprovedGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), color, colorDop, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); } diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs index 272210a..f25a19d 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Metrics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -26,9 +27,9 @@ namespace GasolineTanker _map = map; } - public static int operator +(MapWithSetGasolienTankerGeneric map, T GasolineTanker) + public static int operator +(MapWithSetGasolienTankerGeneric map, T gasolineTanker) { - return map._setGasolineTanker.Insert(GasolineTanker); + return map._setGasolineTanker.Insert(gasolineTanker); } public static T operator -(MapWithSetGasolienTankerGeneric map, int position) @@ -50,10 +51,10 @@ namespace GasolineTanker Shaking(); for (int i = 0; i < _setGasolineTanker.Count; i++) { - var GasolineTanker = _setGasolineTanker.Get(i); - if (GasolineTanker != null) + var gasolineTanker = _setGasolineTanker.Get(i); + if (gasolineTanker != null) { - return _map.CreateMap(_pictureWidth, _pictureHeight, GasolineTanker); + return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker); } } return new(_pictureWidth, _pictureHeight); @@ -77,10 +78,10 @@ namespace GasolineTanker { for (; j > i; j--) { - var GasolineTanker = _setGasolineTanker.Get(j); - if (GasolineTanker != null) + var gasolineTanker = _setGasolineTanker.Get(j); + if (gasolineTanker != null) { - _setGasolineTanker.Insert(GasolineTanker, i); + _setGasolineTanker.Insert(gasolineTanker, i); _setGasolineTanker.Remove(j); break; } @@ -109,8 +110,8 @@ namespace GasolineTanker private void DrawGasolineTanker(Graphics g) { - int width = _pictureWidth / _placeSizeWidth; - int height = _pictureHeight / _placeSizeHeight; + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; for (int i = 0; i < _setGasolineTanker.Count; i++) { diff --git a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs index 69ae434..c546fa5 100644 --- a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs @@ -15,7 +15,7 @@ namespace GasolineTanker { _places = new T[count]; } - public int Insert(T GasolineTanker) + public int Insert(T gasolineTanker) { if (_places[Count - 1] == null) { @@ -23,17 +23,17 @@ namespace GasolineTanker { _places[i] = _places[i - 1]; } - _places[0] = GasolineTanker; + _places[0] = gasolineTanker; return 0; } return -1; } - public int Insert(T GasolineTanker, int position) + public int Insert(T gasolineTanker, int position) { if (position < 0 || position >= Count) return -1; if (_places[position] == null) { - _places[position] = GasolineTanker; + _places[position] = gasolineTanker; return position; } else @@ -44,7 +44,7 @@ namespace GasolineTanker { _places[i] = _places[i - 1]; } - _places[position] = GasolineTanker; + _places[position] = gasolineTanker; return position; } return -1; From f0138b67c1e46225f03857b1658e6fbff991b40c 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: Sat, 8 Oct 2022 19:58:40 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D1=85=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs index 66b1d1c..e7b9072 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs @@ -16,9 +16,7 @@ namespace GasolineTanker public FormMapWithSetGasolineTanker() { InitializeComponent(); - } - - + } private void ButtonAddGasolineTanker_Click(object sender, EventArgs e) { if (_mapGasolineTankerCollectionGeneric == null)