diff --git a/AircraftCarrier/AircraftCarrier/AbstractMap.cs b/AircraftCarrier/AircraftCarrier/AbstractMap.cs index c42d91e..b500cc8 100644 --- a/AircraftCarrier/AircraftCarrier/AbstractMap.cs +++ b/AircraftCarrier/AircraftCarrier/AbstractMap.cs @@ -66,7 +66,6 @@ namespace AircraftCarrier } } break; - case Direction.Down: xNumOfCells = (int)Math.Ceiling((Right - Left) / _size_x); yNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_y); @@ -93,7 +92,6 @@ namespace AircraftCarrier } } break; - case Direction.Left: xNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_x); yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y); @@ -120,13 +118,11 @@ namespace AircraftCarrier } } break; - case Direction.Right: xNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_x); yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y); xObjOffset = (int)(Right / _size_x); yObjOffset = (int)Math.Ceiling(Top / _size_y); - for (int i = 0; i < yNumOfCells; i++) { if (!roadIsClear) @@ -148,7 +144,6 @@ namespace AircraftCarrier } break; } - if (roadIsClear) { _drawningObject.MoveObject(direction); @@ -186,6 +181,7 @@ namespace AircraftCarrier y += (int)_size_y; yObjOffset = (int)(y / _size_y); } + return false; } private bool AreaIsFree(int xNumOfCells, int yNumOfCells, int xObjOffset, int yObjOffset) @@ -206,7 +202,6 @@ namespace AircraftCarrier } return true; } - private Bitmap DrawMapWithObject() { Bitmap bmp = new(_width, _height); diff --git a/AircraftCarrier/AircraftCarrier/DrawningModernAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawningModernAircraftCarrier.cs index b820f0f..1df90f4 100644 --- a/AircraftCarrier/AircraftCarrier/DrawningModernAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/DrawningModernAircraftCarrier.cs @@ -14,6 +14,14 @@ dopColor, bool flightDeck, bool hangarDeck, bool route) : { AircraftCarrier = new EntityModernAircraftCarrier(speed, weight, bodyColor, dopColor, flightDeck, hangarDeck, route); } + public void ReturnColor(Color returnColor) + { + if (AircraftCarrier is not EntityModernAircraftCarrier modernAircraftCarrier) + { + return; + } + modernAircraftCarrier.DopColor = returnColor; + } public override void DrawTransport(Graphics g) { if (AircraftCarrier is not EntityModernAircraftCarrier modernAircraftCarrier) @@ -22,7 +30,6 @@ dopColor, bool flightDeck, bool hangarDeck, bool route) : } Pen pen = new(Color.Black); Brush dopBrush = new SolidBrush(modernAircraftCarrier.DopColor); - if (modernAircraftCarrier.FlightDeck) { g.DrawRectangle(pen, _startPosX + 10, _startPosY, 160, 10); diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs index 286fd02..b6dbf8c 100644 --- a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -10,7 +10,7 @@ namespace AircraftCarrier { public int Speed { get; private set; } public float Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public float Step => Speed * 100 / Weight; public EntityAircraftCarrier(int speed, float weight, Color bodyColor) { diff --git a/AircraftCarrier/AircraftCarrier/EntityModernAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityModernAircraftCarrier.cs index 9e152ec..a998c0c 100644 --- a/AircraftCarrier/AircraftCarrier/EntityModernAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/EntityModernAircraftCarrier.cs @@ -9,7 +9,7 @@ namespace AircraftCarrier { internal class EntityModernAircraftCarrier : EntityAircraftCarrier { - public Color DopColor { get; private set; } + public Color DopColor { get; set; } public bool FlightDeck { get; private set; } public bool HangarDeck { get; private set; } public bool Route { get; private set; } diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.Designer.cs new file mode 100644 index 0000000..6826ac5 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.Designer.cs @@ -0,0 +1,386 @@ +namespace AircraftCarrier +{ + partial class FormAircraftCarrierConfig + { + /// + /// 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.groupBoxConfig = new System.Windows.Forms.GroupBox(); + this.labelModifiedObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); + this.groupBoxColors = new System.Windows.Forms.GroupBox(); + this.panelPurple = new System.Windows.Forms.Panel(); + this.panelYellow = new System.Windows.Forms.Panel(); + this.panelBlack = new System.Windows.Forms.Panel(); + this.panelBlue = new System.Windows.Forms.Panel(); + this.panelGrey = new System.Windows.Forms.Panel(); + this.panelGreen = new System.Windows.Forms.Panel(); + this.panelWhite = new System.Windows.Forms.Panel(); + this.panelRed = new System.Windows.Forms.Panel(); + this.checkBoxRoute = new System.Windows.Forms.CheckBox(); + this.checkBoxHangarDeck = new System.Windows.Forms.CheckBox(); + this.checkBoxFlightDeck = new System.Windows.Forms.CheckBox(); + this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); + this.labelWeight = new System.Windows.Forms.Label(); + this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); + this.labelSpeed = new System.Windows.Forms.Label(); + this.pictureBoxObject = new System.Windows.Forms.PictureBox(); + this.panelObject = new System.Windows.Forms.Panel(); + this.labelDopColor = new System.Windows.Forms.Label(); + this.labelBaseColor = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxConfig.SuspendLayout(); + this.groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); + this.panelObject.SuspendLayout(); + this.SuspendLayout(); + // + // groupBoxConfig + // + this.groupBoxConfig.Controls.Add(this.labelModifiedObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); + this.groupBoxConfig.Controls.Add(this.groupBoxColors); + this.groupBoxConfig.Controls.Add(this.checkBoxRoute); + this.groupBoxConfig.Controls.Add(this.checkBoxHangarDeck); + this.groupBoxConfig.Controls.Add(this.checkBoxFlightDeck); + this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); + this.groupBoxConfig.Controls.Add(this.labelWeight); + this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); + this.groupBoxConfig.Controls.Add(this.labelSpeed); + this.groupBoxConfig.Location = new System.Drawing.Point(12, 12); + this.groupBoxConfig.Name = "groupBoxConfig"; + this.groupBoxConfig.Size = new System.Drawing.Size(852, 329); + this.groupBoxConfig.TabIndex = 0; + this.groupBoxConfig.TabStop = false; + this.groupBoxConfig.Text = "Параметры"; + //this.groupBoxConfig.Enter += new System.EventHandler(this.groupBox1_Enter); + // + // labelModifiedObject + // + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(690, 234); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(154, 65); + this.labelModifiedObject.TabIndex = 9; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + //this.labelModifiedObject.Click += new System.EventHandler(this.labelModifiedObject_Click); + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // labelSimpleObject + // + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(385, 234); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(143, 65); + this.labelSimpleObject.TabIndex = 8; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + // + // groupBoxColors + // + this.groupBoxColors.Controls.Add(this.panelPurple); + this.groupBoxColors.Controls.Add(this.panelYellow); + this.groupBoxColors.Controls.Add(this.panelBlack); + this.groupBoxColors.Controls.Add(this.panelBlue); + this.groupBoxColors.Controls.Add(this.panelGrey); + this.groupBoxColors.Controls.Add(this.panelGreen); + this.groupBoxColors.Controls.Add(this.panelWhite); + this.groupBoxColors.Controls.Add(this.panelRed); + this.groupBoxColors.Location = new System.Drawing.Point(385, 26); + this.groupBoxColors.Name = "groupBoxColors"; + this.groupBoxColors.Size = new System.Drawing.Size(459, 180); + this.groupBoxColors.TabIndex = 7; + this.groupBoxColors.TabStop = false; + this.groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.Location = new System.Drawing.Point(345, 112); + this.panelPurple.Name = "panelPurple"; + this.panelPurple.Size = new System.Drawing.Size(68, 62); + this.panelPurple.TabIndex = 7; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelYellow + // + this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.Location = new System.Drawing.Point(345, 26); + this.panelYellow.Name = "panelYellow"; + this.panelYellow.Size = new System.Drawing.Size(68, 59); + this.panelYellow.TabIndex = 6; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlack + // + this.panelBlack.BackColor = System.Drawing.Color.Black; + this.panelBlack.Location = new System.Drawing.Point(250, 112); + this.panelBlack.Name = "panelBlack"; + this.panelBlack.Size = new System.Drawing.Size(64, 62); + this.panelBlack.TabIndex = 5; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelBlue + // + this.panelBlue.BackColor = System.Drawing.Color.Blue; + this.panelBlue.Location = new System.Drawing.Point(250, 26); + this.panelBlue.Name = "panelBlue"; + this.panelBlue.Size = new System.Drawing.Size(64, 59); + this.panelBlue.TabIndex = 4; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGrey + // + this.panelGrey.BackColor = System.Drawing.Color.Gray; + this.panelGrey.Location = new System.Drawing.Point(138, 112); + this.panelGrey.Name = "panelGrey"; + this.panelGrey.Size = new System.Drawing.Size(67, 62); + this.panelGrey.TabIndex = 3; + this.panelGrey.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelGreen + // + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(138, 26); + this.panelGreen.Name = "panelGreen"; + this.panelGreen.Size = new System.Drawing.Size(67, 59); + this.panelGreen.TabIndex = 2; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelWhite + // + this.panelWhite.BackColor = System.Drawing.Color.White; + this.panelWhite.Location = new System.Drawing.Point(33, 112); + this.panelWhite.Name = "panelWhite"; + this.panelWhite.Size = new System.Drawing.Size(61, 62); + this.panelWhite.TabIndex = 1; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // panelRed + // + this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.Location = new System.Drawing.Point(33, 26); + this.panelRed.Name = "panelRed"; + this.panelRed.Size = new System.Drawing.Size(61, 59); + this.panelRed.TabIndex = 0; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // checkBoxRoute + // + this.checkBoxRoute.AutoSize = true; + this.checkBoxRoute.Location = new System.Drawing.Point(16, 245); + this.checkBoxRoute.Name = "checkBoxRoute"; + this.checkBoxRoute.Size = new System.Drawing.Size(228, 24); + this.checkBoxRoute.TabIndex = 6; + this.checkBoxRoute.Text = "Признак наличия маршрута"; + this.checkBoxRoute.UseVisualStyleBackColor = true; + // + // checkBoxHangarDeck + // + this.checkBoxHangarDeck.AutoSize = true; + this.checkBoxHangarDeck.Location = new System.Drawing.Point(16, 196); + this.checkBoxHangarDeck.Name = "checkBoxHangarDeck"; + this.checkBoxHangarDeck.Size = new System.Drawing.Size(281, 24); + this.checkBoxHangarDeck.TabIndex = 5; + this.checkBoxHangarDeck.Text = "Признак наличия аграрной палубы"; + this.checkBoxHangarDeck.UseVisualStyleBackColor = true; + // + // checkBoxFlightDeck + // + this.checkBoxFlightDeck.AutoSize = true; + this.checkBoxFlightDeck.Location = new System.Drawing.Point(16, 145); + this.checkBoxFlightDeck.Name = "checkBoxFlightDeck"; + this.checkBoxFlightDeck.Size = new System.Drawing.Size(281, 24); + this.checkBoxFlightDeck.TabIndex = 4; + this.checkBoxFlightDeck.Text = "Признак наличия полетной палубы"; + this.checkBoxFlightDeck.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + this.numericUpDownWeight.Location = new System.Drawing.Point(133, 81); + this.numericUpDownWeight.Name = "numericUpDownWeight"; + this.numericUpDownWeight.Size = new System.Drawing.Size(101, 27); + this.numericUpDownWeight.TabIndex = 3; + this.numericUpDownWeight.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelWeight + // + this.labelWeight.AutoSize = true; + this.labelWeight.Location = new System.Drawing.Point(16, 83); + this.labelWeight.Name = "labelWeight"; + this.labelWeight.Size = new System.Drawing.Size(36, 20); + this.labelWeight.TabIndex = 2; + this.labelWeight.Text = "Вес:"; + // + // numericUpDownSpeed + // + this.numericUpDownSpeed.Location = new System.Drawing.Point(133, 30); + this.numericUpDownSpeed.Name = "numericUpDownSpeed"; + this.numericUpDownSpeed.Size = new System.Drawing.Size(101, 27); + this.numericUpDownSpeed.TabIndex = 1; + this.numericUpDownSpeed.Value = new decimal(new int[] { + 100, + 0, + 0, + 0}); + // + // labelSpeed + // + this.labelSpeed.AutoSize = true; + this.labelSpeed.Location = new System.Drawing.Point(16, 32); + this.labelSpeed.Name = "labelSpeed"; + this.labelSpeed.Size = new System.Drawing.Size(76, 20); + this.labelSpeed.TabIndex = 0; + this.labelSpeed.Text = "Скорость:"; + // + // pictureBoxObject + // + this.pictureBoxObject.Location = new System.Drawing.Point(13, 89); + this.pictureBoxObject.Name = "pictureBoxObject"; + this.pictureBoxObject.Size = new System.Drawing.Size(262, 140); + this.pictureBoxObject.TabIndex = 1; + this.pictureBoxObject.TabStop = false; + // + // panelObject + // + this.panelObject.AllowDrop = true; + this.panelObject.Controls.Add(this.labelDopColor); + this.panelObject.Controls.Add(this.labelBaseColor); + this.panelObject.Controls.Add(this.pictureBoxObject); + this.panelObject.Location = new System.Drawing.Point(870, 25); + this.panelObject.Name = "panelObject"; + this.panelObject.Size = new System.Drawing.Size(300, 242); + this.panelObject.TabIndex = 2; + this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); + this.panelObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); + // + // labelDopColor + // + this.labelDopColor.AllowDrop = true; + this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelDopColor.Location = new System.Drawing.Point(164, 17); + this.labelDopColor.Name = "labelDopColor"; + this.labelDopColor.Size = new System.Drawing.Size(102, 45); + this.labelDopColor.TabIndex = 3; + this.labelDopColor.Text = "Дополнительный цвет"; + this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); + this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter); + // + // labelBaseColor + // + this.labelBaseColor.AllowDrop = true; + this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelBaseColor.Location = new System.Drawing.Point(13, 17); + this.labelBaseColor.Name = "labelBaseColor"; + this.labelBaseColor.Size = new System.Drawing.Size(99, 46); + this.labelBaseColor.TabIndex = 2; + this.labelBaseColor.Text = "Цвет"; + this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop); + this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter); + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(870, 283); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(112, 49); + this.buttonOk.TabIndex = 3; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(1048, 283); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(121, 49); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + //this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormAircraftCarrierConfig + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1186, 353); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.panelObject); + this.Controls.Add(this.groupBoxConfig); + this.Name = "FormAircraftCarrierConfig"; + this.Text = "Создание объекта"; + this.groupBoxConfig.ResumeLayout(false); + this.groupBoxConfig.PerformLayout(); + this.groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); + this.panelObject.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxConfig; + private CheckBox checkBoxRoute; + private CheckBox checkBoxHangarDeck; + private CheckBox checkBoxFlightDeck; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private Label labelModifiedObject; + private Label labelSimpleObject; + private GroupBox groupBoxColors; + private Panel panelPurple; + private Panel panelYellow; + private Panel panelBlack; + private Panel panelBlue; + private Panel panelGrey; + private Panel panelGreen; + private Panel panelWhite; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Panel panelObject; + private Label labelDopColor; + private Label labelBaseColor; + private Button buttonOk; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.cs new file mode 100644 index 0000000..021e413 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.cs @@ -0,0 +1,131 @@ +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 AircraftCarrier +{ + public partial class FormAircraftCarrierConfig : Form + { + DrawningAircraftCarrier _aircraftcarrier = null; + private event Action EventAddAircraftCarrier; + public FormAircraftCarrierConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGrey.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + // TODO buttonCancel.Click with lambda + buttonCancel.Click += (sender, e) => Close(); + } + private void DrawAircraftCarrier() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _aircraftcarrier?.SetPosition(5, 5, pictureBoxObject.Width, + pictureBoxObject.Height); + _aircraftcarrier?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + public void AddEvent(Action ev) + { + if (EventAddAircraftCarrier == null) + { + EventAddAircraftCarrier = new Action(ev); + } + else + { + EventAddAircraftCarrier += ev; + } + } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); + } + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.Text)) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _aircraftcarrier = new DrawningAircraftCarrier((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _aircraftcarrier = new DrawningModernAircraftCarrier((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, + checkBoxFlightDeck.Checked, checkBoxHangarDeck.Checked, checkBoxRoute.Checked); + break; + } + DrawAircraftCarrier(); + } + private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) + { + Color BaseColor = (Color)e.Data.GetData(typeof(Color)); + _aircraftcarrier.AircraftCarrier.BodyColor = BaseColor; + DrawAircraftCarrier(); + } + private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelDopColor_DragDrop(object sender, DragEventArgs e) + { + Color DopColor = (Color)e.Data.GetData(typeof(Color)); + if (_aircraftcarrier is DrawningModernAircraftCarrier _modernaircraftcarrier) + { + _modernaircraftcarrier.ReturnColor(DopColor); + DrawAircraftCarrier(); + } + } + private void LabelDopColor_DragEnter(object sender, DragEventArgs e) + { + if (_aircraftcarrier is DrawningModernAircraftCarrier) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy); + + } + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddAircraftCarrier?.Invoke(_aircraftcarrier); + Close(); + } + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.resx b/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrierConfig.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs index f0c5486..2ef0bc5 100644 --- a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs +++ b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs @@ -116,26 +116,27 @@ pictureBox.Height); } } private void ButtonAddAircraftCarrier_Click(object sender, EventArgs e) + { + var formAircraftCarrierConfig = new FormAircraftCarrierConfig(); + // TODO Call method AddEvent from formCarConfig + formAircraftCarrierConfig.AddEvent(AddAircraftCarrier); + formAircraftCarrierConfig.Show(); + } + private void AddAircraftCarrier(DrawningAircraftCarrier drawningAircraftCarrier) { if (listBoxMaps.SelectedIndex == -1) { return; } - FormAircraftCarrier form = new(); - if (form.ShowDialog() == DialogResult.OK) + DrawningObjectAircraftCarrier aircraftcarrier = new(drawningAircraftCarrier); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + aircraftcarrier != -1) { - DrawningObjectAircraftCarrier aircraftcarrier = new(form.SelectedAircraftCarrier); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? -string.Empty] + aircraftcarrier != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = - _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } private void buttonRemoveAircraftCarrier_Click(object sender, EventArgs e) @@ -164,6 +165,7 @@ string.Empty] - pos != null) { MessageBox.Show("Не удалось удалить объект"); } + } private void buttonShowStorage_Click(object sender, EventArgs e) { @@ -179,6 +181,7 @@ string.Empty] - pos != null) { return; } + pictureBox.Image = _mapAircraftCarriersCollectionGeneric.ShowOnMap(); } private void ButtonMove_Click(object sender, EventArgs e) diff --git a/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs b/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs index b2e97c1..3798b59 100644 --- a/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs +++ b/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs @@ -148,7 +148,7 @@ namespace AircraftCarrier 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); } @@ -164,8 +164,10 @@ namespace AircraftCarrier { int yNumOfPlaces = _pictureHeight / _placeSizeHeight; int xNumOfPlaces = _pictureWidth / _placeSizeWidth; + int rowNum = yNumOfPlaces - 1; int columnNum = 0; + for (int i = 0; i < _setAircraftCarriers.Count; i++) { if (_setAircraftCarriers[i] != null) diff --git a/AircraftCarrier/AircraftCarrier/MapsCollection.cs b/AircraftCarrier/AircraftCarrier/MapsCollection.cs index 3050853..c400950 100644 --- a/AircraftCarrier/AircraftCarrier/MapsCollection.cs +++ b/AircraftCarrier/AircraftCarrier/MapsCollection.cs @@ -72,5 +72,21 @@ namespace AircraftCarrier return mapWithSetAircraftCarriersGeneric; } } + public MapWithSetAircraftCarriersGeneric this[int index] + { + get + { + if ((index < 0) || (index >= Keys.Count)) + { + return null; + } + + else + { + string StringKey = Keys[index]; + return _mapStorages[StringKey]; + } + } + } } } \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs b/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs index 6521afa..b0e5bb6 100644 --- a/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs +++ b/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs @@ -75,6 +75,7 @@ namespace AircraftCarrier /// /// /// + public T this[int position] { get @@ -85,15 +86,14 @@ namespace AircraftCarrier { Insert(value, position); } - } - public IEnumerable GetAircraftCarriers() + public IEnumerable GetCars() { - foreach (var aircraftcarrier in _places) + foreach (var car in _places) { - if (aircraftcarrier != null) + if (car != null) { - yield return aircraftcarrier; + yield return car; } else { @@ -101,5 +101,6 @@ namespace AircraftCarrier } } } + } } \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/SimpleMap.cs b/AircraftCarrier/AircraftCarrier/SimpleMap.cs index fdd003f..b29a56c 100644 --- a/AircraftCarrier/AircraftCarrier/SimpleMap.cs +++ b/AircraftCarrier/AircraftCarrier/SimpleMap.cs @@ -47,6 +47,5 @@ namespace AircraftCarrier } } } - } } \ No newline at end of file