diff --git a/Sailboat/Boat.cs b/Sailboat/Boat.cs
index 55a7c3f..e701e25 100644
--- a/Sailboat/Boat.cs
+++ b/Sailboat/Boat.cs
@@ -29,7 +29,7 @@ namespace Sailboat
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public Boat(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
diff --git a/Sailboat/BoatForm.Designer.cs b/Sailboat/BoatForm.Designer.cs
index 861bbfe..c3c8ccd 100644
--- a/Sailboat/BoatForm.Designer.cs
+++ b/Sailboat/BoatForm.Designer.cs
@@ -39,6 +39,7 @@ namespace Sailboat
this.btn_down = new System.Windows.Forms.Button();
this.btn_up = new System.Windows.Forms.Button();
this.btn_left = new System.Windows.Forms.Button();
+ this.btn_create_sailboat = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
this.SuspendLayout();
@@ -144,11 +145,22 @@ namespace Sailboat
this.btn_left.UseVisualStyleBackColor = true;
this.btn_left.Click += new System.EventHandler(this.btn_move_Click);
//
+ // btn_create_sailboat
+ //
+ this.btn_create_sailboat.Location = new System.Drawing.Point(113, 13);
+ this.btn_create_sailboat.Name = "btn_create_sailboat";
+ this.btn_create_sailboat.Size = new System.Drawing.Size(150, 29);
+ this.btn_create_sailboat.TabIndex = 8;
+ this.btn_create_sailboat.Text = "Создать парусник";
+ this.btn_create_sailboat.UseVisualStyleBackColor = true;
+ this.btn_create_sailboat.Click += new System.EventHandler(this.btn_create_sailboat_Click);
+ //
// BoatForm
//
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.btn_create_sailboat);
this.Controls.Add(this.btn_left);
this.Controls.Add(this.btn_up);
this.Controls.Add(this.btn_down);
@@ -180,6 +192,7 @@ namespace Sailboat
private System.Windows.Forms.Button btn_down;
private System.Windows.Forms.Button btn_up;
private System.Windows.Forms.Button btn_left;
+ private System.Windows.Forms.Button btn_create_sailboat;
}
}
diff --git a/Sailboat/BoatForm.cs b/Sailboat/BoatForm.cs
index 2c1f6e1..3b6d46b 100644
--- a/Sailboat/BoatForm.cs
+++ b/Sailboat/BoatForm.cs
@@ -12,7 +12,7 @@ namespace Sailboat
{
public partial class BoatForm : Form
{
- private DrawningBoat _boat;
+ private DrawingBoat _boat;
public BoatForm()
{
InitializeComponent();
@@ -25,18 +25,31 @@ namespace Sailboat
private void btn_create_Click(object sender, EventArgs e)
{
Random rnd = new();
- _boat = new DrawningBoat();
- _boat.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ _boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
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);
- toolStripLabel_color.Text = $"Скорость: {_boat.Boat.Speed}";
- toolStripLabel_weight.Text = $"Вес: {_boat.Boat.Weight}";
- toolStripLabel_color.Text = $"Цвет: { _boat.Boat.BodyColor.Name}";
+ SetData();
Draw();
}
///
- /// Изменение размеров формы
+ /// Обработка нажатия кнопки "Создать парусник"
+ ///
+ ///
+ ///
+ private void btn_create_sailboat_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ 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)));
+ _boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
+ pictureBoxBoat.Width, pictureBoxBoat.Height);
+ SetData();
+ Draw();
+ }
+ ///
+ /// Обработка нажатия стрелок
///
///
///
@@ -83,5 +96,16 @@ namespace Sailboat
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height);
Draw();
}
+ ///
+ /// Метод прорисовки машины
+ ///
+ private void SetData()
+ {
+ Random rnd = new();
+ toolStripLabel_color.Text = $"Скорость: {_boat.Boat.Speed}";
+ toolStripLabel_weight.Text = $"Вес: {_boat.Boat.Weight}";
+ toolStripLabel_color.Text = $"Цвет: { _boat.Boat.BodyColor.Name}";
+
+ }
}
}
diff --git a/Sailboat/DrawingBoat.cs b/Sailboat/DrawingBoat.cs
index adc3de7..369b836 100644
--- a/Sailboat/DrawingBoat.cs
+++ b/Sailboat/DrawingBoat.cs
@@ -10,20 +10,20 @@ namespace Sailboat
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
- internal class DrawningBoat
+ internal class DrawingBoat
{
///
/// Класс-сущность
///
- public Boat Boat{ private set; get; }
+ public Boat Boat{ protected set; get; }
/// `
/// Левая координата отрисовки автомобиля
///
- private float _startPosX;
+ protected float _startPosX;
///
/// Верхняя кооридната отрисовки автомобиля
///
- private float _startPosY;
+ protected float _startPosY;
///
/// Ширина окна отрисовки
///
@@ -46,10 +46,16 @@ namespace Sailboat
/// Скорость
/// Вес автомобиля
/// Цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawingBoat(int speed, float weight, Color bodyColor)
{
- Boat = new Boat();
- Boat.Init(speed, weight, bodyColor);
+ Boat = new Boat(speed, weight, bodyColor);
+ }
+
+ public DrawingBoat(int speed, float weight, Color bodyColor, int boatHeight, int boatWith):
+ this(speed, weight, bodyColor)
+ {
+ _boatHeight = boatHeight;
+ _boatWidth = boatWith;
}
///
/// Установка позиции автомобиля
@@ -115,7 +121,7 @@ namespace Sailboat
/// Отрисовка автомобиля
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
diff --git a/Sailboat/DrawingSailboat.cs b/Sailboat/DrawingSailboat.cs
new file mode 100644
index 0000000..a0c5a81
--- /dev/null
+++ b/Sailboat/DrawingSailboat.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Sailboat
+{
+ ///
+ /// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+ ///
+ class DrawingSailboat : DrawingBoat
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Признак наличия паруса
+ /// Признак наличия усиленного корпуса
+ public DrawingSailboat(int speed, float weight, Color bodyColor, bool sail, bool extendedBody) :
+ base(speed, weight, bodyColor, 50, 120)
+ {
+ Boat = new Sailboat(speed, weight, bodyColor, sail, extendedBody);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (Boat is not Sailboat sailboat)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush brush = new SolidBrush(Color.Black);
+
+ _startPosY += 40;
+ _startPosX += 20;
+ base.DrawTransport(g);
+ _startPosY -= 40;
+ _startPosX -= 20;
+
+ if (sailboat.Sail)
+ {
+ g.DrawLine(pen, _startPosX + 40, _startPosY, _startPosX + 60, _startPosY + 60);
+ g.DrawLine(pen, _startPosX + 40, _startPosY, _startPosX + 70, _startPosY + 30);
+ g.DrawLine(pen, _startPosX + 70, _startPosY + 30, _startPosX + 60, _startPosY + 55);
+ }
+
+ if (sailboat.ExtendedBody)
+ {
+ //корма
+ g.FillRectangle(brush, _startPosX + 15, _startPosY + 38, 70, 5);
+ g.FillRectangle(brush, _startPosX + 15, _startPosY + 78, 70, 5);
+ g.FillRectangle(brush, _startPosX + 15, _startPosY + 38, 5, 40);
+ //усиленный нос
+ g.FillRectangle(brush, _startPosX + 133, _startPosY + 55, 10, 10);
+ }
+
+
+ /*
+ Brush dopBrush = new SolidBrush(sportCar.DopColor);
+
+ if (sportCar.BodyKit)
+ {
+ 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 + 76, _startPosY + 23, 24, 15);
+ g.FillRectangle(dopBrush, _startPosX + 36, _startPosY + 23, 34, 15);
+ g.FillRectangle(dopBrush, _startPosX + 11, _startPosY + 23, 14, 15);
+ }
+
+ if (sportCar.Wing)
+ {
+ g.FillRectangle(dopBrush, _startPosX, _startPosY + 5, 10, 50);
+ g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, 50);
+ }
+ */
+ }
+
+ }
+}
diff --git a/Sailboat/Sailboat.cs b/Sailboat/Sailboat.cs
new file mode 100644
index 0000000..ce2f996
--- /dev/null
+++ b/Sailboat/Sailboat.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Sailboat
+{
+ internal class Sailboat : Boat
+ {
+ ///
+ /// Признак наличия усиленного корпуса
+ ///
+ public bool ExtendedBody { get; private set; }
+ ///
+ /// Признак наличия паруса
+ ///
+ public bool Sail { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Признак наличия паруса
+ /// Признак наличия усиленного корпуса
+ public Sailboat(int speed, float weight, Color bodyColor, bool sail, bool extendedBody) :
+ base(speed, weight, bodyColor)
+ {
+ Sail = sail;
+ ExtendedBody = extendedBody;
+ }
+ }
+}