Готовая Lab_5
This commit is contained in:
parent
bfb444524a
commit
688a6b5333
@ -138,7 +138,7 @@ namespace Sailboat.DrawingObjects
|
|||||||
g.DrawPolygon(pen, hull);
|
g.DrawPolygon(pen, hull);
|
||||||
|
|
||||||
Brush addBrush = new
|
Brush addBrush = new
|
||||||
SolidBrush(Color.Green);
|
SolidBrush(Color.Aqua);
|
||||||
|
|
||||||
g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40);
|
g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40);
|
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||||
|
@ -26,7 +26,7 @@ namespace Sailboat.DrawingObjects
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Aqua);
|
||||||
Brush additionalBrush = new
|
Brush additionalBrush = new
|
||||||
SolidBrush(sailboat.AdditionalColor);
|
SolidBrush(sailboat.AdditionalColor);
|
||||||
|
|
||||||
|
@ -13,6 +13,14 @@ namespace Sailboat.Entities
|
|||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
public void setBodyColor(Color color) { BodyColor = color; }
|
public void setBodyColor(Color color) { BodyColor = color; }
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
public void ChangeColor(Color color)
|
||||||
|
{
|
||||||
|
BodyColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор с параметрами
|
||||||
|
/// </summary>
|
||||||
public EntityBoat(int speed, double weight, Color bodyColor)
|
public EntityBoat(int speed, double weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
|
@ -12,6 +12,14 @@ namespace Sailboat.Entities
|
|||||||
public void setAdditionalColor(Color color) { AdditionalColor = color; }
|
public void setAdditionalColor(Color color) { AdditionalColor = color; }
|
||||||
public bool Hull { get; private set; }
|
public bool Hull { get; private set; }
|
||||||
public bool Sail { get; private set; }
|
public bool Sail { get; private set; }
|
||||||
|
public void ChangeAddColor(Color color)
|
||||||
|
{
|
||||||
|
AdditionalColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей объекта-класса парусной лодки
|
||||||
|
/// </summary>
|
||||||
public EntitySailboat(int speed, double weight, Color bodyColor, Color
|
public EntitySailboat(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool hull, bool sail) : base (speed, weight, bodyColor)
|
additionalColor, bool hull, bool sail) : base (speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
|
@ -59,10 +59,11 @@ namespace Sailboat
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FormSailboat form = new();
|
FormBoatConfig form = new FormBoatConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
form.Show();
|
||||||
|
Action<DrawingBoat>? boatDelegate = new((plane) =>
|
||||||
{
|
{
|
||||||
if (obj + form.SelectedBoat)
|
if (obj + plane)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = obj.ShowBoats();
|
pictureBoxCollection.Image = obj.ShowBoats();
|
||||||
@ -71,7 +72,8 @@ namespace Sailboat
|
|||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
form.AddEvent(boatDelegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonRemoveBoat_Click(object sender, EventArgs e)
|
private void buttonRemoveBoat_Click(object sender, EventArgs e)
|
||||||
|
6
Sailboat/Sailboat/FormBoatConfig.Designer.cs
generated
6
Sailboat/Sailboat/FormBoatConfig.Designer.cs
generated
@ -176,7 +176,7 @@
|
|||||||
this.labelModifiedObject.TabIndex = 8;
|
this.labelModifiedObject.TabIndex = 8;
|
||||||
this.labelModifiedObject.Text = "Продвинутый";
|
this.labelModifiedObject.Text = "Продвинутый";
|
||||||
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
|
||||||
//
|
//
|
||||||
// labelSimpleObject
|
// labelSimpleObject
|
||||||
//
|
//
|
||||||
@ -187,7 +187,7 @@
|
|||||||
this.labelSimpleObject.TabIndex = 7;
|
this.labelSimpleObject.TabIndex = 7;
|
||||||
this.labelSimpleObject.Text = "Простой";
|
this.labelSimpleObject.Text = "Простой";
|
||||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LableObject_MouseDown);
|
||||||
//
|
//
|
||||||
// checkBoxSail
|
// checkBoxSail
|
||||||
//
|
//
|
||||||
@ -326,7 +326,7 @@
|
|||||||
this.buttonOk.TabIndex = 3;
|
this.buttonOk.TabIndex = 3;
|
||||||
this.buttonOk.Text = "Добавить";
|
this.buttonOk.Text = "Добавить";
|
||||||
this.buttonOk.UseVisualStyleBackColor = true;
|
this.buttonOk.UseVisualStyleBackColor = true;
|
||||||
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using Sailboat.DrawingObjects;
|
||||||
|
using Sailboat.Entities;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -8,19 +10,18 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Sailboat.DrawingObjects;
|
|
||||||
using Sailboat.Generics;
|
|
||||||
using Sailboat.MovementStrategy;
|
|
||||||
using Sailboat.Entities;
|
|
||||||
|
|
||||||
namespace Sailboat
|
namespace Sailboat
|
||||||
{
|
{
|
||||||
public partial class FormBoatConfig : Form
|
public partial class FormBoatConfig : Form
|
||||||
{
|
{
|
||||||
DrawingBoat? _boat = null;
|
DrawingBoat? _boat = null;
|
||||||
private event Action <DrawingBoat>? EventAddBoat;
|
private event Action<DrawingBoat>? EventAddBoat;
|
||||||
public FormBoatConfig()
|
public int _pictureWidth { get; private set; }
|
||||||
|
public int _pictureHeight { get; private set; }
|
||||||
|
public FormBoatConfig(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||||
@ -53,18 +54,21 @@ namespace Sailboat
|
|||||||
EventAddBoat += ev;
|
EventAddBoat += ev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
private void LableObject_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||||
{
|
{
|
||||||
e.Effect = DragDropEffects.Copy;
|
e.Effect = DragDropEffects.Copy;
|
||||||
@ -81,34 +85,29 @@ namespace Sailboat
|
|||||||
{
|
{
|
||||||
case "labelSimpleObject":
|
case "labelSimpleObject":
|
||||||
_boat = new DrawingBoat((int)numericUpDownSpeed.Value,
|
_boat = new DrawingBoat((int)numericUpDownSpeed.Value,
|
||||||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
(int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
|
||||||
pictureBoxObject.Height);
|
|
||||||
break;
|
break;
|
||||||
case "labelModifiedObject":
|
case "labelModifiedObject":
|
||||||
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
|
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value,
|
||||||
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
|
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxHull.Checked,
|
||||||
checkBoxSail.Checked, pictureBoxObject.Width,
|
checkBoxSail.Checked, _pictureWidth, _pictureHeight);
|
||||||
pictureBoxObject.Height);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DrawBoat();
|
DrawBoat();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
if (_boat == null)
|
if (_boat?.EntityBoat == null)
|
||||||
return;
|
return;
|
||||||
switch (((Label)sender).Name)
|
Color bodyColor = (Color)e.Data.GetData(typeof(Color));
|
||||||
{
|
_boat.EntityBoat.ChangeColor(bodyColor);
|
||||||
case "labelColor":
|
DrawBoat();
|
||||||
_boat.EntityBoat.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
}
|
||||||
break;
|
private void addColorLabel_DragDrop(object sender, DragEventArgs e)
|
||||||
case "labelAddColor":
|
{
|
||||||
if (!(_boat is DrawingSailboat))
|
if ((_boat?.EntityBoat == null) || (_boat is DrawingSailboat == false))
|
||||||
return;
|
return;
|
||||||
(_boat.EntityBoat as EntitySailboat).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
((EntitySailboat)_boat.EntityBoat).ChangeAddColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
break;
|
|
||||||
}
|
|
||||||
DrawBoat();
|
DrawBoat();
|
||||||
}
|
}
|
||||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
@ -122,8 +121,7 @@ namespace Sailboat
|
|||||||
e.Effect = DragDropEffects.None;
|
e.Effect = DragDropEffects.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void buttonOk_Click(object sender, EventArgs e)
|
||||||
private void ButtonOk_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
EventAddBoat?.Invoke(_boat);
|
EventAddBoat?.Invoke(_boat);
|
||||||
Close();
|
Close();
|
||||||
|
Loading…
Reference in New Issue
Block a user