From d229bc8f731cf52f3604d2897c1a58e951acbfe0 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Wed, 21 Sep 2022 08:04:55 +0300 Subject: [PATCH] main commit --- AirFighter/AirFighter/DrawingAirFighter.cs | 19 ++++- .../AirFighter/DrawingModernAirFighter.cs | 79 +++++++++++++++++++ .../AirFighter/DrawingObjectAirFighter.cs | 35 ++++++++ .../AirFighter/EntityModernAirFighter.cs | 49 ++++++++++++ .../AirFighter/FormAirFighter.Designer.cs | 14 ++++ AirFighter/AirFighter/FormAirFighter.cs | 27 ++++++- AirFighter/AirFighter/IDrawingObject.cs | 18 +++++ 7 files changed, 234 insertions(+), 7 deletions(-) create mode 100644 AirFighter/AirFighter/DrawingModernAirFighter.cs create mode 100644 AirFighter/AirFighter/DrawingObjectAirFighter.cs create mode 100644 AirFighter/AirFighter/EntityModernAirFighter.cs create mode 100644 AirFighter/AirFighter/IDrawingObject.cs diff --git a/AirFighter/AirFighter/DrawingAirFighter.cs b/AirFighter/AirFighter/DrawingAirFighter.cs index 5d85573..00bdbf6 100644 --- a/AirFighter/AirFighter/DrawingAirFighter.cs +++ b/AirFighter/AirFighter/DrawingAirFighter.cs @@ -8,10 +8,10 @@ namespace AirFighter { internal class DrawingAirFighter { - public EntityAirFighter AirFighter { get; private set; } + public EntityAirFighter AirFighter { get; protected set; } - private float _startPosX; - private float _startPosY; + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; @@ -23,6 +23,12 @@ namespace AirFighter { AirFighter = new EntityAirFighter(speed, weight, bodyColor); } + public DrawingAirFighter(int speed, float weight, Color bodyColor, int airFighterWidth, int airFighterHeight) : + this(speed, weight, bodyColor) + { + _airFighterWidth = airFighterWidth; + _airFighterHeight = airFighterHeight; + } public void SetPosition(int x, int y, int width, int height) { @@ -78,7 +84,12 @@ namespace AirFighter } - public void DrawTransport(Graphics g) + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return ( _startPosX, _startPosX + _airFighterWidth, _startPosY, _startPosY + _airFighterHeight ); + } + public virtual void DrawTransport(Graphics g) { if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) { diff --git a/AirFighter/AirFighter/DrawingModernAirFighter.cs b/AirFighter/AirFighter/DrawingModernAirFighter.cs new file mode 100644 index 0000000..81ad6e7 --- /dev/null +++ b/AirFighter/AirFighter/DrawingModernAirFighter.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirFighter +{ + internal class DrawingModernAirFighter : DrawingAirFighter + { + public DrawingModernAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWings, bool rockets, bool sportLine) : + base(speed, weight, bodyColor, 110, 60) + { + AirFighter = new EntityModernAirFighter(speed, weight, bodyColor, dopColor, dopWings, + rockets, sportLine); + } + public override void DrawTransport(Graphics g) + { + if (AirFighter is not EntityModernAirFighter sportCar) + { + return; + } + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(sportCar.DopColor); + if (sportCar.DopWings) + { + g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, 20); + g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, 20, 40); + g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 15); + g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, 15, 15); + g.FillEllipse(dopBrush, _startPosX + 90, _startPosY, 20, 20); + g.FillEllipse(dopBrush, _startPosX + 90, _startPosY + 40, 20, 20); + g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 10, 20, + 40); + g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 1, 15, + 15); + g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 45, 15, + 15); + g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20); + g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20); + g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, 40); + g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, 15); + g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, 14, 15); + g.FillEllipse(dopBrush, _startPosX, _startPosY, 20, 20); + g.FillEllipse(dopBrush, _startPosX, _startPosY + 40, 20, 20); + g.FillRectangle(dopBrush, _startPosX + 1, _startPosY + 10, 25, + 40); + g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 1, 15, 15); + g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 45, 15, + 15); + g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, 15); + g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, 39, 15); + g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 1, 40, + 15); + g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 45, 40, + 15); + } + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + if (sportCar.SportLine) + { + g.FillRectangle(dopBrush, _startPosX + 75, _startPosY + 23, 25, + 15); + g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 23, 35, + 15); + g.FillRectangle(dopBrush, _startPosX, _startPosY + 23, 20, 15); + } + if (sportCar.Rockets) + { + g.FillRectangle(dopBrush, _startPosX, _startPosY + 5, 10, 50); + g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, 50); + } + } + } +} diff --git a/AirFighter/AirFighter/DrawingObjectAirFighter.cs b/AirFighter/AirFighter/DrawingObjectAirFighter.cs new file mode 100644 index 0000000..fefe8a2 --- /dev/null +++ b/AirFighter/AirFighter/DrawingObjectAirFighter.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirFighter +{ + internal class DrawingObjectAirFighter + { + private DrawingAirFighter _airFighter = null; + public DrawingObjectAirFighter(DrawingAirFighter car) + { + _airFighter = car; + } + public float Step => _airFighter?.AirFighter?.Step ?? 0; + public (float Left, float Right, float Top, float Bottom) + GetCurrentPosition() + { + return _airFighter?.GetCurrentPosition() ?? default; + } + public void MoveObject(Direction direction) + { + _airFighter?.MoveTransport(direction); + } + public void SetObject(int x, int y, int width, int height) + { + _airFighter.SetPosition(x, y, width, height); + } + public void DrawningObject(Graphics g) + { + // TODO + } + } +} diff --git a/AirFighter/AirFighter/EntityModernAirFighter.cs b/AirFighter/AirFighter/EntityModernAirFighter.cs new file mode 100644 index 0000000..4845793 --- /dev/null +++ b/AirFighter/AirFighter/EntityModernAirFighter.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +// EntityModernAirFighter + +namespace AirFighter +{ + internal class EntityModernAirFighter : EntityAirFighter + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия обвеса + /// + public bool DopWings { get; private set; } + /// + /// Признак наличия антикрыла + /// + public bool Rockets { get; private set; } + /// + /// Признак наличия гоночной полосы + /// + public bool SportLine { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public EntityModernAirFighter(int speed, float weight, Color bodyColor, Color + dopColor, bool dopWings, bool rockets, bool sportLine) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + DopWings = dopWings; + Rockets = rockets; + SportLine = sportLine; + } + } +} diff --git a/AirFighter/AirFighter/FormAirFighter.Designer.cs b/AirFighter/AirFighter/FormAirFighter.Designer.cs index ff1bd69..d76f966 100644 --- a/AirFighter/AirFighter/FormAirFighter.Designer.cs +++ b/AirFighter/AirFighter/FormAirFighter.Designer.cs @@ -38,6 +38,7 @@ this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.button1 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -147,11 +148,23 @@ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20); this.toolStripStatusLabelBodyColor.Text = "цвет:"; // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.button1.Location = new System.Drawing.Point(121, 389); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(148, 29); + this.button1.TabIndex = 7; + this.button1.Text = "create modern"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.CreateModernButton_Click); + // // FormAirFighter // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button1); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.RightButton); this.Controls.Add(this.LeftButton); @@ -181,5 +194,6 @@ private ToolStripStatusLabel toolStripStatusLabelSpeed; private ToolStripStatusLabel toolStripStatusLabelWeight; private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button button1; } } \ No newline at end of file diff --git a/AirFighter/AirFighter/FormAirFighter.cs b/AirFighter/AirFighter/FormAirFighter.cs index 4c3639b..84b87f5 100644 --- a/AirFighter/AirFighter/FormAirFighter.cs +++ b/AirFighter/AirFighter/FormAirFighter.cs @@ -9,6 +9,13 @@ namespace AirFighter InitializeComponent(); } + private void SetData(DrawingAirFighter airFighter) + { + toolStripStatusLabelSpeed.Text = $": {_airFighter.AirFighter.Speed}"; + toolStripStatusLabelWeight.Text = $": {_airFighter.AirFighter.Weight}"; + toolStripStatusLabelBodyColor.Text = $": { _airFighter.AirFighter.BodyColor.Name}"; + } + private void CreateButton_Click(object sender, EventArgs e) { Random rnd = new(); @@ -18,10 +25,24 @@ namespace AirFighter _airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height); - toolStripStatusLabelSpeed.Text = $": {_airFighter.AirFighter.Speed}"; - toolStripStatusLabelWeight.Text = $": {_airFighter.AirFighter.Weight}"; - toolStripStatusLabelBodyColor.Text = $": { _airFighter.AirFighter.BodyColor.Name}"; + SetData(_airFighter); + Draw(); + } + private void CreateModernButton_Click(object sender, EventArgs e) + { + Random rnd = new(); + + _airFighter = new DrawingModernAirFighter(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))); + + + _airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height); + + SetData(_airFighter); Draw(); } diff --git a/AirFighter/AirFighter/IDrawingObject.cs b/AirFighter/AirFighter/IDrawingObject.cs new file mode 100644 index 0000000..cdc5255 --- /dev/null +++ b/AirFighter/AirFighter/IDrawingObject.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirFighter +{ + internal interface IDrawningObject + { + public float Step { get; } + void SetObject(int x, int y, int width, int height); + void MoveObject(Direction direction); + void DrawningObject(Graphics g); + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } + +}