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];
+ }
+ }
+}