вроде готовая лаба 5
This commit is contained in:
parent
9e26269aa5
commit
03c0f7a6ff
@ -132,6 +132,8 @@ namespace Sailboat.Generics
|
||||
{
|
||||
if (boat != null)
|
||||
{
|
||||
boat._pictureWidth = _pictureWidth;
|
||||
boat._pictureHeight = _pictureHeight;
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
boat.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
|
||||
boat.DrawTransport(g);
|
||||
|
@ -12,8 +12,8 @@ namespace Sailboat.DrawingObjects
|
||||
public class DrawingBoat
|
||||
{
|
||||
public EntityBoat? EntityBoat { get; protected set; }
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
public int _pictureWidth;
|
||||
public int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
private readonly int _boatWidth = 160;
|
||||
@ -143,7 +143,21 @@ namespace Sailboat.DrawingObjects
|
||||
g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||
|
||||
}
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityBoat.BodyColor = color;
|
||||
}
|
||||
|
||||
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
|
||||
{
|
||||
_pictureWidth = pictureBoxWidth;
|
||||
_pictureHeight = pictureBoxHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,5 +64,10 @@ namespace Sailboat.DrawingObjects
|
||||
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 120), new Point(_startPosX + 65, _startPosY));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAddColor(Color color)
|
||||
{
|
||||
((EntitySailboat)EntityBoat).AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace Sailboat.Entities
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color BodyColor { get; set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public EntityBoat(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ namespace Sailboat.Entities
|
||||
{
|
||||
public class EntitySailboat : EntityBoat
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public Color AdditionalColor { get; set; }
|
||||
public bool Hull { get; private set; }
|
||||
public bool Sail { get; private set; }
|
||||
public EntitySailboat(int speed, double weight, Color bodyColor, Color
|
||||
|
4
Sailboat/Sailboat/FormBoatConfig.Designer.cs
generated
4
Sailboat/Sailboat/FormBoatConfig.Designer.cs
generated
@ -302,6 +302,8 @@
|
||||
this.labelAddColor.TabIndex = 10;
|
||||
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);
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
@ -313,6 +315,8 @@
|
||||
this.labelColor.TabIndex = 9;
|
||||
this.labelColor.Text = "Цвет";
|
||||
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
|
@ -92,6 +92,36 @@ namespace Sailboat
|
||||
}
|
||||
DrawBoat();
|
||||
}
|
||||
|
||||
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_boat == null)
|
||||
return;
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelColor":
|
||||
_boat.SetColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAddColor":
|
||||
if (!(_boat is DrawingSailboat))
|
||||
return;
|
||||
(_boat as DrawingSailboat).SetAddColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawBoat();
|
||||
}
|
||||
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 ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddBoat?.Invoke(_boat);
|
||||
|
Loading…
Reference in New Issue
Block a user