сделала что то

This commit is contained in:
Казначеева Елизавета 2023-11-08 11:12:20 +04:00
parent 1516f11c25
commit 27b4633cdc
5 changed files with 83 additions and 19 deletions

View File

@ -39,5 +39,10 @@ namespace Battleship.Entities
Tower = tower; Tower = tower;
Section = section; Section = section;
} }
internal void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
} }
} }

View File

@ -37,5 +37,10 @@ namespace Battleship.Entities
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
internal void setBodyColor(Color color)
{
BodyColor = color;
}
} }
} }

View File

@ -106,6 +106,24 @@ namespace Battleship
{ {
return; return;
} }
var FormShipConfig = new FormShipConfig();
FormShipConfig.AddEvent(AddShip);
FormShipConfig.Show();
}
private void AddShip(DrawningShip drawningShip)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormBattleship form = new(); FormBattleship form = new();
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -136,7 +154,18 @@ namespace Battleship
{ {
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
int pos;
try
{
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
}
catch
{
MessageBox.Show("Не удалось удалить объект");
return;
}
if (obj - pos != null) if (obj - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
@ -162,18 +191,6 @@ namespace Battleship
} }
pictureBoxCollection.Image = obj.ShowShips(); pictureBoxCollection.Image = obj.ShowShips();
} }
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddCar_Click(object sender, EventArgs e)
{
var formCarConfig = new FormShipConfig();
// TODO Call method AddEvent from formCarConfig
formCarConfig.Show();
}
} }
} }

View File

@ -281,9 +281,12 @@
this.panelPicture.Name = "panelPicture"; this.panelPicture.Name = "panelPicture";
this.panelPicture.Size = new System.Drawing.Size(256, 216); this.panelPicture.Size = new System.Drawing.Size(256, 216);
this.panelPicture.TabIndex = 9; this.panelPicture.TabIndex = 9;
this.panelPicture.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelPicture.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
// //
// labelAddColor // labelAddColor
// //
this.labelAddColor.AllowDrop = true;
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAddColor.Location = new System.Drawing.Point(145, 17); this.labelAddColor.Location = new System.Drawing.Point(145, 17);
this.labelAddColor.Name = "labelAddColor"; this.labelAddColor.Name = "labelAddColor";
@ -291,9 +294,12 @@
this.labelAddColor.TabIndex = 12; this.labelAddColor.TabIndex = 12;
this.labelAddColor.Text = "Доп. цвет"; this.labelAddColor.Text = "Доп. цвет";
this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_dragDrop);
this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter);
// //
// labelBodyColor // labelBodyColor
// //
this.labelBodyColor.AllowDrop = true;
this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBodyColor.Location = new System.Drawing.Point(15, 17); this.labelBodyColor.Location = new System.Drawing.Point(15, 17);
this.labelBodyColor.Name = "labelBodyColor"; this.labelBodyColor.Name = "labelBodyColor";
@ -301,6 +307,8 @@
this.labelBodyColor.TabIndex = 11; this.labelBodyColor.TabIndex = 11;
this.labelBodyColor.Text = "Цвет"; this.labelBodyColor.Text = "Цвет";
this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelBodyColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBodyColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_dragDrop);
this.labelBodyColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter);
// //
// pictureBoxObject // pictureBoxObject
// //

View File

@ -38,11 +38,13 @@ namespace Battleship
panelBlue.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown;
// TODO buttonCancel.Click with lambda // TODO buttonCancel.Click with lambda
buttonCancel.Click += (s, e) => Close();
} }
/// <summary> /// <summary>
/// Отрисовать машину /// Отрисовать машину
/// </summary> /// </summary>
private void DrawCar() private void DrawShip()
{ {
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
@ -72,8 +74,7 @@ namespace Battleship
/// <param name="e"></param> /// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e) private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{ {
(sender as Label)?.DoDragDrop((sender as Label)?.Name, (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
DragDropEffects.Move | DragDropEffects.Copy);
} }
/// <summary> /// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому) /// Проверка получаемой информации (ее типа на соответствие требуемому)
@ -110,7 +111,7 @@ namespace Battleship
checkBoxRocket.Checked, pictureBoxObject.Width, pictureBoxObject.Height); checkBoxRocket.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
break; break;
} }
DrawCar(); DrawShip();
} }
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
/// <summary> /// <summary>
@ -118,7 +119,7 @@ namespace Battleship
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
EventAddShip?.Invoke(_ship); EventAddShip?.Invoke(_ship);
Close(); Close();
@ -126,7 +127,35 @@ namespace Battleship
private void PanelColor_MouseDown(object sender, MouseEventArgs e) private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{ {
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void labelColor_dragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelColor_dragDrop(object sender, DragEventArgs e)
{
if (_ship == null)
return;
switch (((Label)sender).Name)
{
case "labelBodyColor":
_ship?.EntityShip?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAddColor":
if (!(_ship is DrawningBattleship))
return;
(_ship.EntityShip as EntityBattleship)?.setAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
break;
}
DrawShip();
} }
} }
} }