main commit

This commit is contained in:
MaxKarme 2022-09-21 08:04:55 +03:00
parent 496f946e45
commit d229bc8f73
7 changed files with 234 additions and 7 deletions

View File

@ -8,10 +8,10 @@ namespace AirFighter
{ {
internal class DrawingAirFighter internal class DrawingAirFighter
{ {
public EntityAirFighter AirFighter { get; private set; } public EntityAirFighter AirFighter { 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;
@ -23,6 +23,12 @@ namespace AirFighter
{ {
AirFighter = new EntityAirFighter(speed, weight, bodyColor); 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) 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) if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{ {

View File

@ -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);
}
}
}
}

View File

@ -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
}
}
}

View File

@ -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
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия обвеса
/// </summary>
public bool DopWings { get; private set; }
/// <summary>
/// Признак наличия антикрыла
/// </summary>
public bool Rockets { get; private set; }
/// <summary>
/// Признак наличия гоночной полосы
/// </summary>
public bool SportLine { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
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;
}
}
}

View File

@ -38,6 +38,7 @@
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = 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(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -147,11 +148,23 @@
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20); this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20);
this.toolStripStatusLabelBodyColor.Text = "цвет:"; 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 // FormAirFighter
// //
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, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button1);
this.Controls.Add(this.statusStrip1); this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.RightButton); this.Controls.Add(this.RightButton);
this.Controls.Add(this.LeftButton); this.Controls.Add(this.LeftButton);
@ -181,5 +194,6 @@
private ToolStripStatusLabel toolStripStatusLabelSpeed; private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight; private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor; private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button button1;
} }
} }

View File

@ -9,6 +9,13 @@ namespace AirFighter
InitializeComponent(); 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) private void CreateButton_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
@ -18,10 +25,24 @@ namespace AirFighter
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height); _airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter.Speed}"; SetData(_airFighter);
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter.Weight}"; Draw();
toolStripStatusLabelBodyColor.Text = $"Öâåò: { _airFighter.AirFighter.BodyColor.Name}"; }
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(); Draw();
} }

View File

@ -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();
}
}