Продвинутый объект
This commit is contained in:
parent
7e26948aff
commit
7196d002ec
@ -8,9 +8,9 @@ namespace AirplaneWithRadar
|
|||||||
{
|
{
|
||||||
internal class DrawingAirplane
|
internal class DrawingAirplane
|
||||||
{
|
{
|
||||||
public EntityAirplane Airplane { get; private set; }
|
public EntityAirplane Airplane { get; protected set; }
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
private int? _pictureHeight = null;
|
private int? _pictureHeight = null;
|
||||||
private readonly int _airplaneWidth = 50;
|
private readonly int _airplaneWidth = 50;
|
||||||
@ -19,6 +19,12 @@ namespace AirplaneWithRadar
|
|||||||
{
|
{
|
||||||
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_airplaneWidth = airplaneWidth;
|
||||||
|
_airplaneHeight = airplaneHeight;
|
||||||
|
}
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
if (x + _airplaneWidth <= width && y + _airplaneHeight <= height && x >= 0 && y >= 0)
|
if (x + _airplaneWidth <= width && y + _airplaneHeight <= height && x >= 0 && y >= 0)
|
||||||
@ -67,7 +73,7 @@ namespace AirplaneWithRadar
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
internal class DrawningAirplaneWithRadar : DrawingAirplane
|
||||||
|
{
|
||||||
|
public DrawningAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool ladder, bool window) :
|
||||||
|
base(speed, weight, bodyColor, 135, 60)
|
||||||
|
{
|
||||||
|
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, ladder, window);
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black, 2);
|
||||||
|
Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
if (airplaneWithRadar.Radar)
|
||||||
|
{
|
||||||
|
g.DrawEllipse(new Pen(Color.Black), _startPosX + 18, _startPosY + 3, 9, 4);
|
||||||
|
g.DrawRectangle(new Pen(Color.Black), _startPosX + 20, _startPosY + 6, 5, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (airplaneWithRadar.Window)
|
||||||
|
{
|
||||||
|
g.DrawEllipse(new Pen(Color.Black), _startPosX + 40, _startPosY + 13, 5, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (airplaneWithRadar.Ladder)
|
||||||
|
{
|
||||||
|
g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 18, _startPosX + 3, _startPosY + 12);
|
||||||
|
g.DrawLine(new Pen(Color.Black), _startPosX + 7, _startPosY + 18, _startPosX + 7, _startPosY + 12);
|
||||||
|
g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 16, _startPosX + 7, _startPosY + 16);
|
||||||
|
g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 13, _startPosX + 7, _startPosY + 13);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
internal class EntityAirplaneWithRadar : EntityAirplane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия радара
|
||||||
|
/// </summary>
|
||||||
|
public bool Radar { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия лестницы
|
||||||
|
/// </summary>
|
||||||
|
public bool Ladder { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия окон
|
||||||
|
/// </summary>
|
||||||
|
public bool Window { get; private set; }
|
||||||
|
public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool ladder, bool window) :
|
||||||
|
base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
Radar = radar;
|
||||||
|
Ladder = ladder;
|
||||||
|
Window = window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -38,6 +38,7 @@
|
|||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateModify = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -143,11 +144,22 @@
|
|||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModify
|
||||||
|
//
|
||||||
|
this.buttonCreateModify.Location = new System.Drawing.Point(111, 391);
|
||||||
|
this.buttonCreateModify.Name = "buttonCreateModify";
|
||||||
|
this.buttonCreateModify.Size = new System.Drawing.Size(133, 29);
|
||||||
|
this.buttonCreateModify.TabIndex = 7;
|
||||||
|
this.buttonCreateModify.Text = "Модификация";
|
||||||
|
this.buttonCreateModify.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_Click);
|
||||||
|
//
|
||||||
// FormAirplane
|
// FormAirplane
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 451);
|
this.ClientSize = new System.Drawing.Size(800, 451);
|
||||||
|
this.Controls.Add(this.buttonCreateModify);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
@ -177,5 +189,6 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private Button buttonCreateModify;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,14 +14,22 @@ namespace AirplaneWithRadar
|
|||||||
_airplane?.DrawTransport(gr);
|
_airplane?.DrawTransport(gr);
|
||||||
pictureBoxAirplane.Image = bmp;
|
pictureBoxAirplane.Image = bmp;
|
||||||
}
|
}
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
/// <summary>
|
||||||
|
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||||
|
/// </summary>
|
||||||
|
private void SetData()
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
@ -50,5 +58,20 @@ namespace AirplaneWithRadar
|
|||||||
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateModify_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_airplane = new DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user