сделала что то
This commit is contained in:
parent
1516f11c25
commit
27b4633cdc
@ -39,5 +39,10 @@ namespace Battleship.Entities
|
||||
Tower = tower;
|
||||
Section = section;
|
||||
}
|
||||
|
||||
internal void setAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,5 +37,10 @@ namespace Battleship.Entities
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
internal void setBodyColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,24 @@ namespace Battleship
|
||||
{
|
||||
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();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
@ -136,7 +154,18 @@ namespace Battleship
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
|
||||
int pos;
|
||||
try
|
||||
{
|
||||
|
||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
return;
|
||||
}
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
@ -162,18 +191,6 @@ namespace Battleship
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
8
Battleship/Battleship/FormShipConfig.Designer.cs
generated
8
Battleship/Battleship/FormShipConfig.Designer.cs
generated
@ -281,9 +281,12 @@
|
||||
this.panelPicture.Name = "panelPicture";
|
||||
this.panelPicture.Size = new System.Drawing.Size(256, 216);
|
||||
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
|
||||
//
|
||||
this.labelAddColor.AllowDrop = true;
|
||||
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelAddColor.Location = new System.Drawing.Point(145, 17);
|
||||
this.labelAddColor.Name = "labelAddColor";
|
||||
@ -291,9 +294,12 @@
|
||||
this.labelAddColor.TabIndex = 12;
|
||||
this.labelAddColor.Text = "Доп. цвет";
|
||||
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
|
||||
//
|
||||
this.labelBodyColor.AllowDrop = true;
|
||||
this.labelBodyColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelBodyColor.Location = new System.Drawing.Point(15, 17);
|
||||
this.labelBodyColor.Name = "labelBodyColor";
|
||||
@ -301,6 +307,8 @@
|
||||
this.labelBodyColor.TabIndex = 11;
|
||||
this.labelBodyColor.Text = "Цвет";
|
||||
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
|
||||
//
|
||||
|
@ -38,11 +38,13 @@ namespace Battleship
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
|
||||
// TODO buttonCancel.Click with lambda
|
||||
buttonCancel.Click += (s, e) => Close();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать машину
|
||||
/// </summary>
|
||||
private void DrawCar()
|
||||
private void DrawShip()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
@ -72,8 +74,7 @@ namespace Battleship
|
||||
/// <param name="e"></param>
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||
DragDropEffects.Move | DragDropEffects.Copy);
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
@ -110,7 +111,7 @@ namespace Battleship
|
||||
checkBoxRocket.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawCar();
|
||||
DrawShip();
|
||||
}
|
||||
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
|
||||
/// <summary>
|
||||
@ -118,7 +119,7 @@ namespace Battleship
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddShip?.Invoke(_ship);
|
||||
Close();
|
||||
@ -126,7 +127,35 @@ namespace Battleship
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user