This commit is contained in:
Володя 2022-11-19 17:45:04 +03:00
parent ab9fdf006d
commit 2bdfda9ce9
5 changed files with 76 additions and 37 deletions

View File

@ -20,16 +20,20 @@ namespace AirPlaneWithRadar
{ {
Plain = new EntetyPlain(speed, weight, bodycolor); Plain = new EntetyPlain(speed, weight, bodycolor);
} }
protected DrawingPlain(int speed, float weight,Color bodyColor,int plainWidth,int plainHeight): protected DrawingPlain(int speed, float weight, Color bodyColor, int plainWidth, int plainHeight) :
this(speed,weight, bodyColor) this(speed, weight, bodyColor)
{ {
this.plainWidth = plainWidth; this.plainWidth = plainWidth;
this.plainHeight = plainHeight; this.plainHeight = plainHeight;
} }
public void ReColor(Color col)
public void setPosition(int x,int y,int width,int height)
{ {
if (x + plainWidth > width || y + plainHeight > height || plainHeight > height || plainWidth > width || x <0 || y<0) Plain.BodyColor = col;
}
public void setPosition(int x, int y, int width, int height)
{
if (x + plainWidth > width || y + plainHeight > height || plainHeight > height || plainWidth > width || x < 0 || y < 0)
return; return;
else else
{ {
@ -39,9 +43,9 @@ namespace AirPlaneWithRadar
pictureHeight = height; pictureHeight = height;
} }
} }
public void MoveTransport (Direction direction) public void MoveTransport(Direction direction)
{ {
if(!pictureWidth.HasValue || !pictureHeight.HasValue) if (!pictureWidth.HasValue || !pictureHeight.HasValue)
{ return; } { return; }
switch (direction) switch (direction)
{ {
@ -51,7 +55,7 @@ namespace AirPlaneWithRadar
break; break;
case Direction.Left: case Direction.Left:
if (startPosX -Plain.Step > 0) if (startPosX - Plain.Step > 0)
startPosX -= Plain.Step; startPosX -= Plain.Step;
break; break;
case Direction.Down: case Direction.Down:
@ -59,14 +63,14 @@ namespace AirPlaneWithRadar
startPosY += Plain.Step; startPosY += Plain.Step;
break; break;
case Direction.Up: case Direction.Up:
if (startPosY - Plain.Step >0) if (startPosY - Plain.Step > 0)
startPosY -= Plain.Step; startPosY -= Plain.Step;
break; break;
} }
} }
public virtual void DrawTransoprt (Graphics g) public virtual void DrawTransoprt(Graphics g)
{ {
if(startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue) if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
{ {
return; return;
} }
@ -76,10 +80,10 @@ namespace AirPlaneWithRadar
g.DrawRectangle(pen, startPosX, startPosY, 20, 30); g.DrawRectangle(pen, startPosX, startPosY, 20, 30);
g.DrawRectangle(pen, startPosX, startPosY + 30, 100, 30); g.DrawRectangle(pen, startPosX, startPosY + 30, 100, 30);
g.DrawRectangle(pen, startPosX+100, startPosY + 40, 20, 15); g.DrawRectangle(pen, startPosX + 100, startPosY + 40, 20, 15);
//koleso1 //koleso1
g.DrawRectangle(pen, startPosX + 30, startPosY + 60, 5, 10); g.DrawRectangle(pen, startPosX + 30, startPosY + 60, 5, 10);
g.DrawEllipse(pen, startPosX+28, startPosY+70, 9, 9); g.DrawEllipse(pen, startPosX + 28, startPosY + 70, 9, 9);
//koleso2 //koleso2
g.DrawRectangle(pen, startPosX + 80, startPosY + 60, 5, 10); g.DrawRectangle(pen, startPosX + 80, startPosY + 60, 5, 10);
g.DrawEllipse(pen, startPosX + 78, startPosY + 70, 9, 9); g.DrawEllipse(pen, startPosX + 78, startPosY + 70, 9, 9);
@ -87,8 +91,8 @@ namespace AirPlaneWithRadar
//Korpys //Korpys
Brush br = new SolidBrush(Plain?.BodyColor ?? Color.Black); Brush br = new SolidBrush(Plain?.BodyColor ?? Color.Black);
g.FillRectangle(br, startPosX+3, startPosY + 33, 94, 24); g.FillRectangle(br, startPosX + 3, startPosY + 33, 94, 24);
g.FillRectangle(br, startPosX+1, startPosY+1, 19, 29); g.FillRectangle(br, startPosX + 1, startPosY + 1, 19, 29);
//krilya //krilya
@ -109,7 +113,7 @@ namespace AirPlaneWithRadar
{ {
pictureWidth = width; pictureWidth = width;
pictureHeight = height; pictureHeight = height;
if(pictureWidth < plainWidth || pictureHeight < plainHeight) if (pictureWidth < plainWidth || pictureHeight < plainHeight)
{ {
pictureWidth = null; pictureWidth = null;
pictureHeight = null; pictureHeight = null;
@ -118,7 +122,7 @@ namespace AirPlaneWithRadar
if (startPosX + plainWidth > pictureWidth) if (startPosX + plainWidth > pictureWidth)
startPosX = pictureWidth.Value - plainWidth; startPosX = pictureWidth.Value - plainWidth;
if(startPosY + plainHeight > pictureHeight) if (startPosY + plainHeight > pictureHeight)
startPosY = pictureHeight.Value - plainHeight; startPosY = pictureHeight.Value - plainHeight;
} }
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()

View File

@ -9,13 +9,18 @@ namespace AirPlaneWithRadar
{ {
internal class DrawingRadarPlane : DrawingPlain internal class DrawingRadarPlane : DrawingPlain
{ {
public DrawingRadarPlane(int speed, float weight, Color bodyColor,Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 110, 60) public DrawingRadarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 110, 60)
{ {
Plain = new RadioPlane(speed, weight, bodyColor, dopColor, radar, oilBox); Plain = new RadioPlane(speed, weight, bodyColor, dopColor, radar, oilBox);
} }
public void ReColorDop(Color dopCol)
{
(Plain as RadioPlane).DopColor = dopCol;
}
public override void DrawTransoprt(Graphics g) public override void DrawTransoprt(Graphics g)
{ {
if(Plain is not RadioPlane radioPlane) if (Plain is not RadioPlane radioPlane)
{ {
return; return;
} }
@ -27,7 +32,7 @@ namespace AirPlaneWithRadar
g.DrawRectangle(pen, startPosX + 40, startPosY + 48, 20, 10); g.DrawRectangle(pen, startPosX + 40, startPosY + 48, 20, 10);
g.FillRectangle(doBrush, startPosX + 40, startPosY + 48, 20, 10); g.FillRectangle(doBrush, startPosX + 40, startPosY + 48, 20, 10);
g.DrawRectangle(pen, startPosX , startPosY+15, 30, 10); g.DrawRectangle(pen, startPosX, startPosY + 15, 30, 10);
g.FillRectangle(doBrush, startPosX, startPosY + 15, 30, 10); g.FillRectangle(doBrush, startPosX, startPosY + 15, 30, 10);
} }
if (radioPlane.Radar) if (radioPlane.Radar)

View File

@ -9,9 +9,9 @@ namespace AirPlaneWithRadar
public class EntetyPlain public class EntetyPlain
{ {
public int Speed { get;private set; } public int Speed { get; private set; }
public float Weight { get; private set; } public float Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
public float Step => Speed * 100 / Weight; public float Step => Speed * 100 / Weight;
public EntetyPlain(int speed, float weight, Color bodyColor) public EntetyPlain(int speed, float weight, Color bodyColor)
@ -22,6 +22,5 @@ namespace AirPlaneWithRadar
BodyColor = bodyColor; BodyColor = bodyColor;
} }
} }
} }

View File

@ -87,7 +87,26 @@ namespace AirPlaneWithRadar
{ {
var formPlainConfig = new FormPlaneConfig(); var formPlainConfig = new FormPlaneConfig();
formPlainConfig.AddEvent(ReactEv);
formPlainConfig.Show(); formPlainConfig.Show();
}
public void ReactEv(DrawingPlain dp)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectPlane(dp)) >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
} }
private void ButtonRemovePlain_Click(object sender, EventArgs e) private void ButtonRemovePlain_Click(object sender, EventArgs e)
{ {

View File

@ -14,7 +14,7 @@ namespace AirPlaneWithRadar
{ {
DrawingPlain _Plane = null; DrawingPlain _Plane = null;
private event PlainDelegate EventAddPlane; private event Action<DrawingPlain> EventAddPlane;
public FormPlaneConfig() public FormPlaneConfig()
{ {
@ -40,7 +40,7 @@ namespace AirPlaneWithRadar
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }
public void AddEvent(PlainDelegate ev) public void AddEvent(Action<DrawingPlain> ev)
{ {
if (EventAddPlane == null) if (EventAddPlane == null)
{ {
@ -120,12 +120,24 @@ namespace AirPlaneWithRadar
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{ {
if (_Plane is null) return;
var col = e.Data.GetData(typeof(Color));
Color newCol = (Color)col;
labelBaseColor.BackColor = newCol;
_Plane?.ReColor(newCol);
DrawPlane();
} }
private void LabelDopColor_DragDrop(object sender, DragEventArgs e) private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{ {
if (_Plane is DrawingRadarPlane)
{
var col = e.Data.GetData(typeof(Color));
Color newCol = (Color)col;
labelDopColor.BackColor = newCol;
(_Plane as DrawingRadarPlane).ReColorDop(newCol);
DrawPlane();
}
} }