diff --git a/lainer/Lainer1/DrawingLainer.cs b/lainer/Lainer1/DrawingLainer.cs index c4cadf3..a2464f8 100644 --- a/lainer/Lainer1/DrawingLainer.cs +++ b/lainer/Lainer1/DrawingLainer.cs @@ -1,4 +1,5 @@ using ProjectLainer.Entities; +using ProjectLainer.MovementStrategy; using System.Drawing; namespace ProjectLainer.DrawningObjects @@ -10,6 +11,7 @@ namespace ProjectLainer.DrawningObjects private int _pictureHeight; protected int _startPosX; protected int _startPosY; + public IMoveableObject GetMoveableObject => new DrawningObjectLainer(this); public DrawingLainer(int speed, double weight, Color bodyColor, int width, int height) { @@ -19,7 +21,7 @@ namespace ProjectLainer.DrawningObjects _pictureHeight = height; EntityLainer = new EntityLainer(speed, weight, bodyColor); } - + protected DrawingLainer(int speed, double weight, Color bodyColor, int width, int height, int carWidth, int carHeight) { @@ -33,6 +35,7 @@ namespace ProjectLainer.DrawningObjects } public void SetPosition(int x, int y) { + if (x + _LainerWidth < _pictureWidth && x + _LainerWidth > 0) { _startPosX = x; @@ -156,4 +159,3 @@ namespace ProjectLainer.DrawningObjects } } } - diff --git a/lainer/Lainer1/FormLainerCollection.Designer.cs b/lainer/Lainer1/FormLainerCollection.Designer.cs new file mode 100644 index 0000000..7bc9105 --- /dev/null +++ b/lainer/Lainer1/FormLainerCollection.Designer.cs @@ -0,0 +1,109 @@ +namespace ProjectLainer +{ + partial class FormLainerCollection + { + /// + /// 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() + { + pictureBoxCollection = new PictureBox(); + ButtonAddLainer = new Button(); + ButtonRemove = new Button(); + ButtonRefresh = new Button(); + maskedTextBoxNumber = new MaskedTextBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + SuspendLayout(); + // + // pictureBoxCollection + // + pictureBoxCollection.Location = new Point(16, 14); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(781, 297); + pictureBoxCollection.TabIndex = 0; + pictureBoxCollection.TabStop = false; + // + // ButtonAddLainer + // + ButtonAddLainer.Location = new Point(813, 40); + ButtonAddLainer.Name = "ButtonAddLainer"; + ButtonAddLainer.Size = new Size(154, 52); + ButtonAddLainer.TabIndex = 1; + ButtonAddLainer.Text = "добавить лайнер"; + ButtonAddLainer.UseVisualStyleBackColor = true; + ButtonAddLainer.Click += ButtonAddLainer_Click; + // + // ButtonRemove + // + ButtonRemove.Location = new Point(812, 158); + ButtonRemove.Name = "ButtonRemove"; + ButtonRemove.Size = new Size(139, 65); + ButtonRemove.TabIndex = 2; + ButtonRemove.Text = "удалить лайнер"; + ButtonRemove.UseVisualStyleBackColor = true; + ButtonRemove.Click += ButtonRemove_Click; + // + // ButtonRefresh + // + ButtonRefresh.Location = new Point(803, 247); + ButtonRefresh.Name = "ButtonRefresh"; + ButtonRefresh.Size = new Size(164, 54); + ButtonRefresh.TabIndex = 3; + ButtonRefresh.Text = "обновить коллекцию"; + ButtonRefresh.UseVisualStyleBackColor = true; + ButtonRefresh.Click += ButtonRefresh_Click; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(826, 111); + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(125, 27); + maskedTextBoxNumber.TabIndex = 4; + // + // FormLainerCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1003, 450); + Controls.Add(maskedTextBoxNumber); + Controls.Add(ButtonRefresh); + Controls.Add(ButtonRemove); + Controls.Add(ButtonAddLainer); + Controls.Add(pictureBoxCollection); + Name = "FormLainerCollection"; + Text = "FormLainerCollection"; + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxCollection; + private Button ButtonAddLainer; + private Button ButtonRemove; + private Button ButtonRefresh; + private MaskedTextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/lainer/Lainer1/FormLainerCollection.cs b/lainer/Lainer1/FormLainerCollection.cs new file mode 100644 index 0000000..c153019 --- /dev/null +++ b/lainer/Lainer1/FormLainerCollection.cs @@ -0,0 +1,59 @@ +using ProjectLainer.DrawningObjects; +using ProjectLainer.Generics; +using ProjectLainer.MovementStrategy; + +namespace ProjectLainer +{ + public partial class FormLainerCollection : Form + { + private readonly LainersGenericCollection _lainers; + public FormLainerCollection() + { + InitializeComponent(); + _lainers = new LainersGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + private void ButtonAddLainer_Click(object sender, EventArgs e) + { + LainerForm form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_lainers + form.SelectedLainer) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _lainers.ShowLainers(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + private void ButtonRemove_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + try + { + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_lainers - pos == true) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _lainers.ShowLainers(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + catch { MessageBox.Show("Не удалось удалить объект"); } + + } + private void ButtonRefresh_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _lainers.ShowLainers(); + } + } +} diff --git a/lainer/Lainer1/FormLainerCollection.resx b/lainer/Lainer1/FormLainerCollection.resx new file mode 100644 index 0000000..0f362c9 --- /dev/null +++ b/lainer/Lainer1/FormLainerCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/lainer/Lainer1/Program.cs b/lainer/Lainer1/Program.cs index bd98bf8..0116f3f 100644 --- a/lainer/Lainer1/Program.cs +++ b/lainer/Lainer1/Program.cs @@ -3,7 +3,7 @@ namespace ProjectLainer internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -11,7 +11,7 @@ namespace ProjectLainer // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new LainerForm()); + Application.Run(new FormLainerCollection()); } } -} \ No newline at end of file +}