Продвинутый объект
This commit is contained in:
parent
6b21c79439
commit
b3426afea9
@ -14,15 +14,15 @@ namespace Boats
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBoat Boat { private set; get; }
|
||||
public EntityBoat Boat { protected set; get; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки лодки
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки лодки
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -34,11 +34,11 @@ namespace Boats
|
||||
/// <summary>
|
||||
/// Ширина отрисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _boatWidth = 100;
|
||||
protected readonly int _boatWidth = 100;
|
||||
/// <summary>
|
||||
/// Высота отрисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _boatHeight = 40;
|
||||
protected readonly int _boatHeight = 40;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
@ -50,6 +50,20 @@ namespace Boats
|
||||
Boat = new EntityBoat(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес лодки</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="boatWidth">Ширина отрисовки лодки</param>
|
||||
/// <param name="boatHeight">Высота отрисовки лодки</param>
|
||||
protected DrawingBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_boatWidth = boatWidth;
|
||||
_boatHeight = boatHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции лодки
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
@ -113,7 +127,7 @@ namespace Boats
|
||||
/// Отрисовка лодки
|
||||
/// </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)
|
||||
|
82
Boats/Boats/DrawingCatamaran.cs
Normal file
82
Boats/Boats/DrawingCatamaran.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boats
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для отрисовки катамарана
|
||||
/// </summary>
|
||||
internal class DrawingCatamaran : DrawingBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес катамарана</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bobbers">Признак наличия поплавков</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
public DrawingCatamaran(int speed, float weight, Color bodyColor,
|
||||
Color dopColor, bool bobbers, bool sail) :
|
||||
base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
Boat = new EntityCatamaran(speed, weight, bodyColor, dopColor, bobbers, sail);
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод для отрисовки катамарана
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Boat is not EntityCatamaran catamaran)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Brush dopBrush = new SolidBrush(catamaran.DopColor);
|
||||
|
||||
int bobbersWidth = _boatWidth / 4;
|
||||
int bobbersHeight = _boatHeight / 5;
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (catamaran.Bobbers)
|
||||
{
|
||||
// Отрисовка верхних поплавков
|
||||
g.FillRectangle(dopBrush, _startPosX, _startPosY, bobbersWidth, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX, _startPosY, bobbersWidth, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight);
|
||||
|
||||
g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight);
|
||||
|
||||
// Отрисовка нижних поплавков
|
||||
g.FillRectangle(dopBrush, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight);
|
||||
|
||||
g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight);
|
||||
}
|
||||
|
||||
if (catamaran.Sail)
|
||||
{
|
||||
float downPointSailX = _startPosX + _boatWidth / 2 - _boatWidth / 8;
|
||||
float downPointSailY = _startPosY + _boatHeight / 2 + _boatWidth / 8;
|
||||
|
||||
PointF[] sailPoints = new PointF[3];
|
||||
sailPoints[0] = new PointF(downPointSailX, downPointSailY);
|
||||
sailPoints[1] = new PointF(downPointSailX, _startPosY);
|
||||
sailPoints[2] = new PointF(downPointSailX - _boatWidth / 4, downPointSailY - _boatHeight / 4);
|
||||
// Отрисовка паруса
|
||||
g.FillPolygon(dopBrush, sailPoints);
|
||||
g.DrawPolygon(Pens.Black, sailPoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
Boats/Boats/EntityCatamaran.cs
Normal file
41
Boats/Boats/EntityCatamaran.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boats
|
||||
{
|
||||
internal class EntityCatamaran : EntityBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия поплавков
|
||||
/// </summary>
|
||||
public bool Bobbers { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия паруса
|
||||
/// </summary>
|
||||
public bool Sail { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес катамарана</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bobbers">Признак наличия поплавков</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
public EntityCatamaran(int speed, float weight, Color bodyColor,
|
||||
Color dopColor, bool bobbers, bool sail) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Bobbers = bobbers;
|
||||
Sail = sail;
|
||||
}
|
||||
}
|
||||
}
|
14
Boats/Boats/FormBoat.Designer.cs
generated
14
Boats/Boats/FormBoat.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.ButtonLeft = new System.Windows.Forms.Button();
|
||||
this.ButtonRight = new System.Windows.Forms.Button();
|
||||
this.ButtonDown = new System.Windows.Forms.Button();
|
||||
this.ButtonCreateModificate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -143,11 +144,23 @@
|
||||
this.ButtonDown.UseVisualStyleBackColor = true;
|
||||
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ButtonCreateModificate
|
||||
//
|
||||
this.ButtonCreateModificate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreateModificate.Location = new System.Drawing.Point(138, 381);
|
||||
this.ButtonCreateModificate.Name = "ButtonCreateModificate";
|
||||
this.ButtonCreateModificate.Size = new System.Drawing.Size(117, 29);
|
||||
this.ButtonCreateModificate.TabIndex = 7;
|
||||
this.ButtonCreateModificate.Text = "Модификация";
|
||||
this.ButtonCreateModificate.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreateModificate.Click += new System.EventHandler(this.ButtonCreateModificate_Click);
|
||||
//
|
||||
// FormBoat
|
||||
//
|
||||
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.ButtonCreateModificate);
|
||||
this.Controls.Add(this.ButtonDown);
|
||||
this.Controls.Add(this.ButtonRight);
|
||||
this.Controls.Add(this.ButtonLeft);
|
||||
@ -177,5 +190,6 @@
|
||||
private Button ButtonLeft;
|
||||
private Button ButtonRight;
|
||||
private Button ButtonDown;
|
||||
private Button ButtonCreateModificate;
|
||||
}
|
||||
}
|
@ -18,6 +18,22 @@ namespace Boats
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод установки данных
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_boat.SetPosition(
|
||||
rnd.Next(10, 100),
|
||||
rnd.Next(10, 100),
|
||||
pictureBoxBoat.Width,
|
||||
pictureBoxBoat.Height
|
||||
);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки лодки
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
@ -41,15 +57,7 @@ namespace Boats
|
||||
Color.FromArgb(rnd.Next(0, 256),
|
||||
rnd.Next(0, 256), rnd.Next(0, 256))
|
||||
);
|
||||
_boat.SetPosition(
|
||||
rnd.Next(10, 100),
|
||||
rnd.Next(10, 100),
|
||||
pictureBoxBoat.Width,
|
||||
pictureBoxBoat.Height
|
||||
);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -88,5 +96,24 @@ namespace Boats
|
||||
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Модификация"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateModificate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_boat = new DrawingCatamaran(
|
||||
rnd.Next(100, 300),
|
||||
rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)),
|
||||
Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2))
|
||||
);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user