Продвинутый объект.
This commit is contained in:
parent
ae14815155
commit
16ad990871
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32819.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AirplaneWithRadar", "AirplaneWithRadar\AirplaneWithRadar.csproj", "{5BE6CDF5-36FB-4F6F-83FE-AA87400376ED}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AirplaneWithRadar", "AirplaneWithRadar\AirplaneWithRadar.csproj", "{5BE6CDF5-36FB-4F6F-83FE-AA87400376ED}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{D63FD6F4-AAFA-44BE-8233-A8A2B38C4526}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -14,15 +14,15 @@ namespace AirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplane Airplane { private set; get; }
|
||||
public EntityAirplane Airplane { protected set; get; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -49,6 +49,20 @@ namespace AirplaneWithRadar
|
||||
{
|
||||
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="carWidth">Ширина отрисовки автомобиля</param>
|
||||
/// <param name="carHeight">Высота отрисовки автомобиля</param>
|
||||
protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : this(speed, weight, bodyColor)
|
||||
{
|
||||
_airplaneWidth = airplaneWidth;
|
||||
_airplaneHeight = airplaneHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
/// </summary>
|
||||
@ -124,7 +138,7 @@ namespace AirplaneWithRadar
|
||||
/// Отрисовка автомобиля
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
|
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawingAirplaneWithRadar : DrawingAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет самолета</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="extraFuelTank">Признак наличия дополнительных топливных баков</param>
|
||||
public DrawingAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, extraFuelTank);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 5);
|
||||
Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor);
|
||||
|
||||
if (airplaneWithRadar.Radar)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + 120, _startPosY + 30, _startPosX + 110, _startPosY + 60);
|
||||
g.DrawLine(pen, _startPosX + 150, _startPosY + 60, _startPosX + 140, _startPosY + 30);
|
||||
Point point1 = new Point((int)_startPosX + 120, (int)_startPosY + 30);
|
||||
Point point2 = new Point((int)_startPosX + 110, (int)_startPosY + 60);
|
||||
Point point3 = new Point((int)_startPosX + 150, (int)_startPosY + 60);
|
||||
Point point4 = new Point((int)_startPosX + 140, (int)_startPosY + 30);
|
||||
Point[] radarPoints = { point1, point2, point3, point4 };
|
||||
g.FillPolygon(dopBrush, radarPoints);
|
||||
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 15, 90, 20);
|
||||
g.FillEllipse(dopBrush, _startPosX + 85, _startPosY + 15, 90, 20);
|
||||
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
if (airplaneWithRadar.ExtraFuelTank)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + 145, _startPosY + 98, _startPosX + 145, _startPosY + 108);
|
||||
g.DrawLine(pen, _startPosX + 167, _startPosY + 98, _startPosX + 167, _startPosY + 108);
|
||||
g.FillRectangle(dopBrush, _startPosX + 145, _startPosY + 98, 22, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 130, _startPosY + 102, 30, 6);
|
||||
g.FillEllipse(dopBrush, _startPosX + 130, _startPosY + 102, 30, 6);
|
||||
g.DrawLine(pen, _startPosX + 140, _startPosY + 102, _startPosX + 170, _startPosY + 102);
|
||||
g.DrawLine(pen, _startPosX + 140, _startPosY + 108, _startPosX + 170, _startPosY + 108);
|
||||
g.FillRectangle(dopBrush, _startPosX + 140, _startPosY + 102, 30, 6);
|
||||
g.DrawLine(pen, _startPosX + 169, _startPosY + 102, _startPosX + 190, _startPosY + 105);
|
||||
g.DrawLine(pen, _startPosX + 169, _startPosY + 108, _startPosX + 190, _startPosY + 105);
|
||||
g.DrawLine(pen, _startPosX + 170, _startPosY + 105, _startPosX + 194, _startPosY + 105);
|
||||
Point point1 = new Point((int)_startPosX + 169, (int)_startPosY + 102);
|
||||
Point point2 = new Point((int)_startPosX + 190, (int)_startPosY + 105);
|
||||
Point point3 = new Point((int)_startPosX + 169, (int)_startPosY + 108);
|
||||
Point[] fuelTankPoints = { point1, point2, point3 };
|
||||
g.FillPolygon(dopBrush, fuelTankPoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
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 ExtraFuelTank { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="extraFuelTank">Признак наличия дополнительных топливных баков</param>
|
||||
public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Radar = radar;
|
||||
ExtraFuelTank = extraFuelTank;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.statusStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -142,11 +143,22 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(130, 372);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(140, 34);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// FormAirplaneWithRadar
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -176,5 +188,6 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -20,6 +20,17 @@ namespace AirplaneWithRadar
|
||||
pictureBoxAirplane.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -27,13 +38,8 @@ namespace AirplaneWithRadar
|
||||
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)));
|
||||
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
||||
pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
||||
_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();
|
||||
}
|
||||
|
||||
@ -70,7 +76,18 @@ namespace AirplaneWithRadar
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_airplane = new DrawingAirplaneWithRadar(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)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
8
AirplaneWithRadar/EntityAirplaneWithRadar.cs
Normal file
8
AirplaneWithRadar/EntityAirplaneWithRadar.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
public Class1()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user