Karamushko M.K lab2_base #4
@ -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)
|
||||
{
|
||||
|
79
AirFighter/AirFighter/DrawingModernAirFighter.cs
Normal file
79
AirFighter/AirFighter/DrawingModernAirFighter.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
AirFighter/AirFighter/DrawingObjectAirFighter.cs
Normal file
35
AirFighter/AirFighter/DrawingObjectAirFighter.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
49
AirFighter/AirFighter/EntityModernAirFighter.cs
Normal file
49
AirFighter/AirFighter/EntityModernAirFighter.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
14
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
14
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
18
AirFighter/AirFighter/IDrawingObject.cs
Normal file
18
AirFighter/AirFighter/IDrawingObject.cs
Normal 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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user