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