diff --git a/.gitignore b/.gitignore
index 8e7a151..f8819ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -398,3 +398,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
+/WarmlyShip/WarmlyShip/Properties
diff --git a/WarmlyShip/WarmlyShip.sln b/WarmlyShip/WarmlyShip.sln
index 9a23b39..fdeb5b4 100644
--- a/WarmlyShip/WarmlyShip.sln
+++ b/WarmlyShip/WarmlyShip.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarmlyShip", "WarmlyShip\WarmlyShip.csproj", "{007C3F82-87B9-4701-BE6F-6598A4B1AE7E}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WarmlyShip", "WarmlyShip\WarmlyShip.csproj", "{007C3F82-87B9-4701-BE6F-6598A4B1AE7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/WarmlyShip/WarmlyShip/DrawningShip.cs b/WarmlyShip/WarmlyShip/DrawningShip.cs
new file mode 100644
index 0000000..6fb6d1b
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/DrawningShip.cs
@@ -0,0 +1,188 @@
+namespace WarmlyShip
+{
+ internal class DrawningShip
+ {
+ ///
+ /// Класс-сущность
+ ///
+ public EntityShip Ship { get; protected set; }
+ ///
+ /// Левая координата отрисовки коробля
+ ///
+ protected float _startPosX;
+ ///
+ /// Верхняя кооридната отрисовки коробля
+ ///
+ protected float _startPosY;
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private int? _pictureWidth = null;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private int? _pictureHeight = null;
+ ///
+ /// Ширина отрисовки коробля
+ ///
+ private readonly int _shipWidth = 170;
+ ///
+ /// Высота отрисовки коробля
+ ///
+ private readonly int _shipHeight = 65;
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес корабля
+ /// Цвет корабля
+ public DrawningShip(int speed, float weight, Color bodyColor)
+ {
+ Ship = new EntityShip(speed, weight, bodyColor);
+ }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес коробля
+ /// Цвет основной части
+ /// Ширина отрисовки корабля
+ /// Высота отрисовки корабля
+
+ protected DrawningShip(int speed, float weight, Color bodyColor, int shipWidth, int shipHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _shipWidth = shipWidth;
+ _shipHeight = shipHeight;
+ }
+ ///
+ /// Установка позиции коробля
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина картинки
+ /// Высота картинки
+ ///
+
+ public void SetPosition(int x, int y, int width, int height)
+ {
+ if (x < 0 || y < 0 || width < x + _shipWidth || height < y + _shipHeight)
+ {
+ _pictureHeight = null;
+ _pictureWidth = null;
+ return;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ _pictureWidth = width;
+ _pictureHeight = height;
+ }
+ ///
+ /// Изменение направления пермещения
+ ///
+ /// Направление
+ public void MoveTransport(Direction direction)
+ {
+ if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
+ {
+ return;
+ }
+ switch (direction)
+ {
+ // вправо
+ case Direction.Right:
+ if (_startPosX + _shipWidth + Ship.Step < _pictureWidth)
+ {
+ _startPosX += Ship.Step;
+ }
+ break;
+ //влево
+ case Direction.Left:
+
+ if (_startPosX - Ship.Step > 0)
+ {
+ _startPosX -= Ship.Step;
+ }
+ break;
+ //вверх
+ case Direction.Up:
+
+ if (_startPosY - Ship.Step > 0)
+ {
+ _startPosY -= Ship.Step;
+ }
+ break;
+ //вниз
+ case Direction.Down:
+ if (_startPosY + _shipHeight + Ship.Step < _pictureHeight)
+ {
+ _startPosY += Ship.Step;
+ }
+ break;
+ }
+ }
+ ///
+ /// Отрисовка корабля
+ ///
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ if (_startPosX < 0 || _startPosY < 0
+ || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
+ {
+ return;
+ }
+
+
+ //заполнение коробля
+
+ PointF[] P =
+ {
+ new Point((int)(_startPosX),(int) _startPosY + 35),
+ new Point((int)_startPosX + 170, (int)_startPosY + 35),
+ new Point( (int) _startPosX + 150,(int) _startPosY + 65),
+ new Point((int) _startPosX + 50, (int) _startPosY + 65),
+ new Point((int) _startPosX, (int) _startPosY + 35),
+
+ };
+ Brush br = new SolidBrush(Ship?.BodyColor ?? Color.Black);
+ g.FillPolygon(br, P);
+
+ Brush brBlue = new SolidBrush(Color.LightBlue);
+ g.FillRectangle(brBlue, _startPosX + 50, _startPosY + 1, 100, 34);
+
+ Pen pen = new(Color.Black);
+ //границы коробля
+ g.DrawRectangle(pen, _startPosX + 50, _startPosY + 1, 100, 34);
+ g.DrawLine(pen, _startPosX, _startPosY + 35, _startPosX + 170, _startPosY + 35);
+ g.DrawLine(pen, _startPosX, _startPosY + 35, _startPosX + 50, _startPosY + 65);
+ g.DrawLine(pen, _startPosX + 50, _startPosY + 65, _startPosX + 150, _startPosY + 65);
+ g.DrawLine(pen, _startPosX + 150, _startPosY + 65, _startPosX + 170, _startPosY + 35);
+ }
+
+ ///
+ /// Смена границ формы отрисовки
+ ///
+ /// Ширина картинки
+ /// Высота картинки
+ public void ChangeBorders(int width, int height)
+ {
+ _pictureWidth = width;
+ _pictureHeight = height;
+ if (_pictureWidth <= _shipWidth || _pictureHeight <= _shipHeight)
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ return;
+ }
+ if (_startPosX + _shipWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth.Value - _shipWidth;
+ }
+ if (_startPosY + _shipHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight.Value - _shipHeight;
+ }
+ }
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
index b467f6d..3a10285 100644
--- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
@@ -1,170 +1,58 @@
-namespace WarmlyShip
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
{
- internal class DrawningWarmlyShip
+ internal class DrawningWarmlyShip : DrawningShip
{
- ///
- /// Класс-сущность
- ///
- public EntityWarmlyShip Ship { get; private set; }
- ///
- /// Левая координата отрисовки коробля
- ///
- private float _startPosX;
- ///
- /// Верхняя кооридната отрисовки коробля
- ///
- private float _startPosY;
- ///
- /// Ширина окна отрисовки
- ///
- private int? _pictureWidth = null;
- ///
- /// Высота окна отрисовки
- ///
- private int? _pictureHeight = null;
- ///
- /// Ширина отрисовки коробля
- ///
- private readonly int _shipWidth = 170;
- ///
- /// Высота отрисовки коробля
- ///
- private readonly int _shipHeight = 65;
///
/// Инициализация свойств
///
/// Скорость
- /// Вес коробля
- /// Цвет основной части
- public DrawningWarmlyShip(int speed, float weight, Color bodyColor)
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия труб
+ /// Признак наличия топливного отсека
+ public DrawningWarmlyShip(int speed, float weight, Color bodyColor, Color dopColor, bool pipes, bool fuelCompartment) :
+ base(speed, weight, bodyColor, 175, 65)
{
- Ship = new EntityWarmlyShip(speed, weight, bodyColor);
- }
- ///
- /// Установка позиции коробля
- ///
- /// Координата X
- /// Координата Y
- /// Ширина картинки
- /// Высота картинки
- public void SetPosition(int x, int y, int width, int height)
- {
- if (x < 0 || y < 0 || width < x + _shipWidth || height < y + _shipHeight)
- {
- _pictureHeight = null;
- _pictureWidth = null;
- return;
- }
- _startPosX = x;
- _startPosY = y;
- _pictureWidth = width;
- _pictureHeight = height;
+ Ship = new EntityWarmlyShip(speed, weight, bodyColor, dopColor, pipes, fuelCompartment);
}
- ///
- /// Изменение направления пермещения
- ///
- /// Направление
- public void MoveTransport(Direction direction)
+ public override void DrawTransport(Graphics g)
{
- if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
+ if (Ship is not EntityWarmlyShip warmlyShip)
{
return;
}
- switch (direction)
- {
- // вправо
- case Direction.Right:
- if (_startPosX + _shipWidth + Ship.Step < _pictureWidth)
- {
- _startPosX += Ship.Step;
- }
- break;
- //влево
- case Direction.Left:
-
- if (_startPosX - Ship.Step > 0)
- {
- _startPosX -= Ship.Step;
- }
- break;
- //вверх
- case Direction.Up:
-
- if (_startPosY - Ship.Step > 0)
- {
- _startPosY -= Ship.Step;
- }
- break;
- //вниз
- case Direction.Down:
- if (_startPosY + _shipHeight + Ship.Step < _pictureHeight)
- {
- _startPosY += Ship.Step;
- }
- break;
- }
- }
- ///
- /// Отрисовка корабля
- ///
- ///
- public void DrawTransport(Graphics g)
- {
- if (_startPosX < 0 || _startPosY < 0
- || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
- {
- return;
- }
-
-
- //заполнение коробля
-
- PointF[] P =
- {
- new Point((int)(_startPosX),(int) _startPosY + 35),
- new Point((int)_startPosX + 170, (int)_startPosY + 35),
- new Point( (int) _startPosX + 150,(int) _startPosY + 65),
- new Point((int) _startPosX + 50, (int) _startPosY + 65),
- new Point((int) _startPosX, (int) _startPosY + 35),
-
- };
- Brush br = new SolidBrush(Ship?.BodyColor ?? Color.Black);
- g.FillPolygon(br, P);
-
- Brush brBlue = new SolidBrush(Color.LightBlue);
- g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 1, 70, 34);
Pen pen = new(Color.Black);
- //границы коробля
- g.DrawRectangle(pen, _startPosX + 70, _startPosY + 1 , 70, 34);
- g.DrawLine(pen, _startPosX, _startPosY + 35, _startPosX + 170, _startPosY + 35);
- g.DrawLine(pen, _startPosX, _startPosY + 35, _startPosX + 50, _startPosY + 65);
- g.DrawLine(pen, _startPosX + 50, _startPosY + 65, _startPosX + 150, _startPosY + 65);
- g.DrawLine(pen, _startPosX + 150, _startPosY + 65, _startPosX + 170, _startPosY + 35);
- }
+ Brush dopBrush = new SolidBrush(warmlyShip.DopColor);
- ///
- /// Смена границ формы отрисовки
- ///
- /// Ширина картинки
- /// Высота картинки
- public void ChangeBorders(int width, int height)
- {
- _pictureWidth = width;
- _pictureHeight = height;
- if (_pictureWidth <= _shipWidth || _pictureHeight <= _shipHeight)
+ if (warmlyShip.Pipes)
{
- _pictureWidth = null;
- _pictureHeight = null;
- return;
+ g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 10, 20, 26);
+ g.DrawRectangle(pen, _startPosX + 60, _startPosY + 10, 20, 26);
+ g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 5, 20, 31);
+ g.DrawRectangle(pen, _startPosX + 90, _startPosY + 5, 20, 31);
+ g.FillRectangle(dopBrush, _startPosX + 120, _startPosY + 1, 20, 35);
+ g.DrawRectangle(pen, _startPosX + 120, _startPosY + 1, 20, 35);
+
}
- if (_startPosX + _shipWidth > _pictureWidth)
+
+ //_startPosX += 10;
+ _startPosY += 30;
+ base.DrawTransport(g);
+ //_startPosX -= 10;
+ _startPosY -= 30;
+
+ if (warmlyShip.FuelCompartment)
{
- _startPosX = _pictureWidth.Value - _shipWidth;
- }
- if (_startPosY + _shipHeight > _pictureHeight)
- {
- _startPosY = _pictureHeight.Value - _shipHeight;
+ g.FillRectangle(dopBrush, _startPosX + 135, _startPosY + 70, 10, 5);
+ g.DrawRectangle(pen, _startPosX + 135, _startPosY + 70, 10, 5);
}
}
}
diff --git a/WarmlyShip/WarmlyShip/EntityShip.cs b/WarmlyShip/WarmlyShip/EntityShip.cs
new file mode 100644
index 0000000..dbf97ae
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/EntityShip.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ internal class EntityShip
+ {
+ ///
+ /// Скорость
+ ///
+ public int Speed { get; private set; }
+ ///
+ /// Вес
+ ///
+ public float Weight { get; private set; }
+ ///
+ /// Цвет кузова
+ ///
+ public Color BodyColor { get; private set; }
+ ///
+ /// Шаг перемещения автомобиля
+ ///
+ public float Step => Speed * 100 / Weight;
+ ///
+ /// Инициализация полей объекта-класса автомобиля
+ ///
+ ///
+ ///
+ ///
+ ///
+ public EntityShip(int speed, float weight, Color bodyColor)
+ {
+ Random rnd = new();
+ Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
+ Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
+ BodyColor = bodyColor;
+ }
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
index 1e364f4..70c42b4 100644
--- a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
@@ -6,37 +6,35 @@ using System.Threading.Tasks;
namespace WarmlyShip
{
- internal class EntityWarmlyShip
+ internal class EntityWarmlyShip : EntityShip
{
///
- /// Скорость
+ /// Дополнительный цвет
///
- public int Speed { get; private set; }
+ public Color DopColor { get; private set; }
///
- /// Вес
+ /// Признак наличия труб
///
- public float Weight { get; private set; }
+ public bool Pipes { get; private set; }
///
- /// Цвет кузова
+ /// Признак наличия топливного отсека
///
- public Color BodyColor { get; private set; }
+ public bool FuelCompartment { get; private set; }
///
- /// Шаг перемещения автомобиля
+ /// Инициализация свойств
///
- public float Step => Speed * 100 / Weight;
- ///
- /// Инициализация полей объекта-класса автомобиля
- ///
- ///
- ///
- ///
- ///
- public EntityWarmlyShip(int speed, float weight, Color bodyColor)
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия труб
+ /// Признак наличия топливного отсека
+ public EntityWarmlyShip(int speed, float weight, Color bodyColor, Color dopColor, bool pipes, bool fuelCompartment) :
+ base(speed, weight, bodyColor)
{
- Random rnd = new();
- Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
- Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
- BodyColor = bodyColor;
+ DopColor = dopColor;
+ Pipes = pipes;
+ FuelCompartment = fuelCompartment;
}
}
}
diff --git a/WarmlyShip/WarmlyShip/FormShip.Designer.cs b/WarmlyShip/WarmlyShip/FormShip.Designer.cs
index ec87a9a..ebe438e 100644
--- a/WarmlyShip/WarmlyShip/FormShip.Designer.cs
+++ b/WarmlyShip/WarmlyShip/FormShip.Designer.cs
@@ -38,6 +38,7 @@
this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
+ this.ButtonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -146,11 +147,23 @@
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
+ // ButtonCreateModif
+ //
+ this.ButtonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ButtonCreateModif.Location = new System.Drawing.Point(124, 369);
+ this.ButtonCreateModif.Name = "ButtonCreateModif";
+ this.ButtonCreateModif.Size = new System.Drawing.Size(120, 29);
+ this.ButtonCreateModif.TabIndex = 7;
+ this.ButtonCreateModif.Text = "Модификация";
+ this.ButtonCreateModif.UseVisualStyleBackColor = true;
+ this.ButtonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormShip
//
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.ButtonCreateModif);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
@@ -180,5 +193,6 @@
private Button buttonUp;
private Button buttonRight;
private Button buttonLeft;
+ private Button ButtonCreateModif;
}
}
\ No newline at end of file
diff --git a/WarmlyShip/WarmlyShip/FormShip.cs b/WarmlyShip/WarmlyShip/FormShip.cs
index d4eb684..b2f2c52 100644
--- a/WarmlyShip/WarmlyShip/FormShip.cs
+++ b/WarmlyShip/WarmlyShip/FormShip.cs
@@ -2,11 +2,22 @@ namespace WarmlyShip
{
public partial class FormShip : Form
{
- private DrawningWarmlyShip _ship;
+ private DrawningShip _ship;
public FormShip()
{
InitializeComponent();
}
+ ///
+ ///
+ ///
+ private void SetData()
+ {
+ Random rnd = new();
+ _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
+ toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_ship.Ship.BodyColor.Name}";
+ }
private void Draw()
{
Bitmap bmp = new(pictureBoxShip.Width, pictureBoxShip.Height);
@@ -22,11 +33,9 @@ namespace WarmlyShip
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _ship = new DrawningWarmlyShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ _ship = new DrawningShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
- toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}";
- toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}";
- toolStripStatusLabelBodyColor.Text = $": {_ship.Ship.BodyColor.Name}";
+ SetData();
Draw();
}
@@ -51,5 +60,21 @@ namespace WarmlyShip
}
Draw();
}
+
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _ship = new DrawningWarmlyShip(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();
+ }
}
}
\ No newline at end of file