From 1310766ce87a8226040f9579dcfb189f99a1ab99 Mon Sep 17 00:00:00 2001
From: AlyonaFr <149268946+AlyonaFr@users.noreply.github.com>
Date: Tue, 19 Mar 2024 21:06:59 +0400
Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?=
=?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?=
=?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?=
=?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?=
=?UTF-8?q?=D0=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../{ => Drawnings}/DirectionType.cs | 8 +-
.../DrawningBoat.cs} | 137 +++++++++---------
.../Drawnings/DrawningCatamaran.cs | 95 ++++++++++++
.../{ => Entities}/EntityCatamaran.cs | 30 +---
.../Entities/EntityCatamaran_1.cs | 47 ++++++
.../FormCatamaran.Designer.cs | 19 ++-
.../ProjectCatamaran/FormCatamaran.cs | 67 ++++++---
.../{ => Resources}/Program.cs | 2 +-
8 files changed, 277 insertions(+), 128 deletions(-)
rename ProjectCatamaran/ProjectCatamaran/{ => Drawnings}/DirectionType.cs (67%)
rename ProjectCatamaran/ProjectCatamaran/{DrawningCatamaran.cs => Drawnings/DrawningBoat.cs} (51%)
create mode 100644 ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningCatamaran.cs
rename ProjectCatamaran/ProjectCatamaran/{ => Entities}/EntityCatamaran.cs (67%)
create mode 100644 ProjectCatamaran/ProjectCatamaran/Entities/EntityCatamaran_1.cs
rename ProjectCatamaran/ProjectCatamaran/{ => Resources}/Program.cs (92%)
diff --git a/ProjectCatamaran/ProjectCatamaran/DirectionType.cs b/ProjectCatamaran/ProjectCatamaran/Drawnings/DirectionType.cs
similarity index 67%
rename from ProjectCatamaran/ProjectCatamaran/DirectionType.cs
rename to ProjectCatamaran/ProjectCatamaran/Drawnings/DirectionType.cs
index f76939e..d6c8da6 100644
--- a/ProjectCatamaran/ProjectCatamaran/DirectionType.cs
+++ b/ProjectCatamaran/ProjectCatamaran/Drawnings/DirectionType.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectCatamaran;
+namespace ProjectCatamaran.Drawnings;
public enum DirectionType
{
diff --git a/ProjectCatamaran/ProjectCatamaran/DrawningCatamaran.cs b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs
similarity index 51%
rename from ProjectCatamaran/ProjectCatamaran/DrawningCatamaran.cs
rename to ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs
index 5a01c1b..9ecd91a 100644
--- a/ProjectCatamaran/ProjectCatamaran/DrawningCatamaran.cs
+++ b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs
@@ -1,14 +1,18 @@
-namespace ProjectCatamaran;
+using ProjectCatamaran.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
-///
-/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
-///
-public class DrawningCatamaran
+namespace ProjectCatamaran.Drawnings;
+
+public class DrawningBoat
{
///
/// Класс-сущность
///
- public EntityCatamaran? EntityCatamaran { get; private set; }
+ public EntityBoat? EntityBoat { get; protected set; }
///
/// Ширина окна
@@ -23,43 +27,56 @@ public class DrawningCatamaran
///
/// Левая координата прорисовки катамарана
///
- private int? _startPosX;
+ protected int? _startPosX;
///
/// Верхняя координата прорисовки катамарана
///
- private int? _startPosY;
+ protected int? _startPosY;
///
/// Ширина прорисовки катамарана
///
- private readonly int _drawningCatamaranWidth = 87;
+ private readonly int _drawningCatamaranWidth = 80;
///
/// Высота прорисовки катамарана
///
- private readonly int _drawningCatamaranHeight = 81;
+ private readonly int _drawningCatamaranHeight = 62;
///
- /// Инициализация свойств
+ /// Пустой конструктор
///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool sail,
- bool leftfloater, bool rightfloater)
+ private DrawningBoat()
{
- EntityCatamaran = new EntityCatamaran();
- EntityCatamaran.Init(speed, weight, bodyColor, additionalColor, sail, leftfloater, rightfloater);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ /// Конструктор для наследников
+ ///
+ /// Ширина прорисовки катамарана
+ /// Высота прорисовки катамарана
+ protected DrawningBoat(int drawningCatamaranWidth, int drawningCatamaranHeight) : this()
+ {
+ _drawningCatamaranWidth = drawningCatamaranWidth;
+ _drawningCatamaranHeight = drawningCatamaranHeight;
+ }
+
///
/// Установка границ поля
@@ -98,14 +115,21 @@ public class DrawningCatamaran
return;
}
- if (x < 0 || x + _drawningCatamaranWidth > _pictureWidth || y < 0 || y + _drawningCatamaranHeight > _pictureHeight)
+ if (x < 0 || x + _drawningCatamaranWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningCatamaranWidth;
- _startPosY = _pictureHeight - _drawningCatamaranHeight;
}
else
{
_startPosX = x;
+ }
+
+ if (y < 0 || y + _drawningCatamaranHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawningCatamaranHeight;
+ }
+ else
+ {
_startPosY = y;
}
}
@@ -117,7 +141,7 @@ public class DrawningCatamaran
/// - перемещение выполнено, false - перемещение невозможно
public bool MoveTransport(DirectionType direction)
{
- if (EntityCatamaran == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@@ -125,31 +149,31 @@ public class DrawningCatamaran
{
//влево
case DirectionType.Left:
- if (_startPosX.Value - EntityCatamaran.Step > 0)
+ if (_startPosX.Value - EntityBoat.Step > 0)
{
- _startPosX -= (int)EntityCatamaran.Step;
+ _startPosX -= (int)EntityBoat.Step;
}
return true;
//вверх
case DirectionType.Up:
- if (_startPosY.Value - EntityCatamaran.Step > 0)
+ if (_startPosY.Value - EntityBoat.Step > 0)
{
- _startPosY -= (int)EntityCatamaran.Step;
+ _startPosY -= (int)EntityBoat.Step;
}
return true;
// вправо
case DirectionType.Right:
- if (_startPosX.Value + EntityCatamaran.Step + _drawningCatamaranWidth < _pictureWidth)
+ if (_startPosX.Value + EntityBoat.Step + _drawningCatamaranWidth < _pictureWidth)
{
- _startPosX += (int)EntityCatamaran.Step;
+ _startPosX += (int)EntityBoat.Step;
return true;
}
return true;
//вниз
case DirectionType.Down:
- if (_startPosY.Value + EntityCatamaran.Step + _drawningCatamaranHeight < _pictureHeight)
+ if (_startPosY.Value + EntityBoat.Step + _drawningCatamaranHeight < _pictureHeight)
{
- _startPosY += (int)EntityCatamaran.Step;
+ _startPosY += (int)EntityBoat.Step;
}
return true;
default:
@@ -161,57 +185,30 @@ public class DrawningCatamaran
/// Прорисовка объекта
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
- if (EntityCatamaran == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
- Brush bodyColorBrush = new SolidBrush(EntityCatamaran.BodyColor);
- Brush additionalBrush = new SolidBrush(EntityCatamaran.AdditionalColor);
+ Brush bodyColorBrush = new SolidBrush(EntityBoat.BodyColor);
//тело катамарана
- g.FillRectangle(bodyColorBrush, _startPosX.Value + 10, _startPosY.Value + 40, 57, 30);
- g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 57, 30);
+ g.FillRectangle(bodyColorBrush, _startPosX.Value, _startPosY.Value + 32, 57, 30);
+ g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 32, 57, 30);
- g.FillEllipse(bodyColorBrush, _startPosX.Value + 20, _startPosY.Value + 48, 40, 13);
- g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 48, 40, 13);
+ g.FillEllipse(bodyColorBrush, _startPosX.Value + 9, _startPosY.Value + 40, 40, 13);
+ g.DrawEllipse(pen, _startPosX.Value + 9, _startPosY.Value + 40, 40, 13);
//нос катамарана
Point[] Nose = new Point[3];
- Nose[0].X = _startPosX.Value + 67; Nose[0].Y = _startPosY.Value + 40;
- Nose[1].X = _startPosX.Value + 88; Nose[1].Y = _startPosY.Value + 55;
- Nose[2].X = _startPosX.Value + 67; Nose[2].Y = _startPosY.Value + 70;
+ Nose[0].X = _startPosX.Value + 57; Nose[0].Y = _startPosY.Value + 32;
+ Nose[1].X = _startPosX.Value + 80; Nose[1].Y = _startPosY.Value + 47;
+ Nose[2].X = _startPosX.Value + 57; Nose[2].Y = _startPosY.Value + 62;
g.FillPolygon(bodyColorBrush, Nose);
g.DrawPolygon(pen, Nose);
- //поплавки
- if (EntityCatamaran.Leftfloater)
- {
- g.FillEllipse(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 27, 57, 13);
- g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 27, 57, 13);
- }
-
- if (EntityCatamaran.Rightfloater)
- {
- g.FillEllipse(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 70, 57, 13);
- g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 70, 57, 13);
- }
-
- //флаг
- if (EntityCatamaran.Sail)
- {
- g.DrawLine(pen, _startPosX.Value + 38, _startPosY.Value + 55, _startPosX.Value + 38, _startPosY.Value + 10);
- Point[] Flag = new Point[3];
- Flag[0].X = _startPosX.Value + 38; Flag[0].Y = _startPosY.Value + 10;
- Flag[1].X = _startPosX.Value + 55; Flag[1].Y = _startPosY.Value + 45;
- Flag[2].X = _startPosX.Value + 38; Flag[2].Y = _startPosY.Value + 45;
- g.FillPolygon(additionalBrush, Flag);
- g.DrawPolygon(pen, Flag);
- }
}
-
-
}
diff --git a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningCatamaran.cs b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningCatamaran.cs
new file mode 100644
index 0000000..55c2890
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningCatamaran.cs
@@ -0,0 +1,95 @@
+using ProjectCatamaran.Entities;
+
+namespace ProjectCatamaran.Drawnings;
+
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+public class DrawningCatamaran : DrawningBoat
+{
+
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Левая координата прорисовки катамарана
+ ///
+ private int? GetPosX => _startPosX;
+
+ ///
+ /// Верхняя координата прорисовки катамарана
+ ///
+ private int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина прорисовки катамарана
+ ///
+ private readonly int _drawningCatamaranWidth = 79;
+
+ ///
+ /// Высота прорисовки катамарана
+ ///
+ private readonly int _drawningCatamaranHeight = 75;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public DrawningCatamaran(int speed, double weight, Color bodyColor, Color additionalColor, bool sail, bool leftfloater, bool rightfloater) : base(79, 75)
+ {
+ EntityBoat = new EntityCatamaran(speed, weight, bodyColor, additionalColor, sail, leftfloater, rightfloater);
+
+ }
+
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityBoat == null || EntityBoat is not EntityCatamaran catamaran || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new SolidBrush(catamaran.AdditionalColor);
+ base.DrawTransport(g);
+ //поплавки
+ if (catamaran.Leftfloater)
+ {
+ g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 20, 57, 13);
+ g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 57, 13);
+ }
+
+ if (catamaran.Rightfloater)
+ {
+ g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 62, 57, 13);
+ g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 62, 57, 13);
+ }
+
+ //флаг
+ if (catamaran.Sail)
+ {
+ g.DrawLine(pen, _startPosX.Value + 29, _startPosY.Value + 48, _startPosX.Value + 29, _startPosY.Value);
+ Point[] Flag = new Point[3];
+ Flag[0].X = _startPosX.Value + 29; Flag[0].Y = _startPosY.Value + 38;
+ Flag[1].X = _startPosX.Value + 48; Flag[1].Y = _startPosY.Value + 38;
+ Flag[2].X = _startPosX.Value + 29; Flag[2].Y = _startPosY.Value;
+ g.FillPolygon(additionalBrush, Flag);
+ g.DrawPolygon(pen, Flag);
+ }
+ }
+
+
+}
diff --git a/ProjectCatamaran/ProjectCatamaran/EntityCatamaran.cs b/ProjectCatamaran/ProjectCatamaran/Entities/EntityCatamaran.cs
similarity index 67%
rename from ProjectCatamaran/ProjectCatamaran/EntityCatamaran.cs
rename to ProjectCatamaran/ProjectCatamaran/Entities/EntityCatamaran.cs
index 25affe6..57ebd06 100644
--- a/ProjectCatamaran/ProjectCatamaran/EntityCatamaran.cs
+++ b/ProjectCatamaran/ProjectCatamaran/Entities/EntityCatamaran.cs
@@ -1,24 +1,10 @@
-namespace ProjectCatamaran;
+namespace ProjectCatamaran.Entities;
///
/// Класс-сущность "Катамаран"
///
-public class EntityCatamaran
+public class EntityCatamaran : EntityBoat
{
- ///
- /// Скорость
- ///
- public int Speed { get; private set; }
-
- ///
- /// Вес
- ///
- public double Weight { get; private set; }
-
- ///
- /// Основной цвет
- ///
- public Color BodyColor { get; private set; }
///
/// Дополнительный цвет (для опциональных элементов)
@@ -40,14 +26,9 @@ public class EntityCatamaran
///
public bool Sail { get; private set; }
- ///
- ///
- ///
- public double Step => Speed * 100 / Weight;
-
///
- ///
+ /// Инициализация полей объекта-класса катамарана
///
/// Скорость
/// Вес
@@ -56,11 +37,8 @@ public class EntityCatamaran
/// Признак наличия левого поплавка
/// Признак наличия правого поплавка
/// Признак наличия паруса
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool leftfloater, bool rightfloater, bool sail)
+ public EntityCatamaran(int speed, double weight, Color bodyColor, Color additionalColor, bool leftfloater, bool rightfloater, bool sail) : base(speed, weight, bodyColor)
{
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
AdditionalColor = additionalColor;
Leftfloater = leftfloater;
Rightfloater = rightfloater;
diff --git a/ProjectCatamaran/ProjectCatamaran/Entities/EntityCatamaran_1.cs b/ProjectCatamaran/ProjectCatamaran/Entities/EntityCatamaran_1.cs
new file mode 100644
index 0000000..fc61713
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/Entities/EntityCatamaran_1.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectCatamaran.Entities;
+
+///
+/// Класс-сущности "Катамарана_1"
+///
+public class EntityBoat
+{
+ ///
+ /// Скорость
+ ///
+ public int Speed { get; private set; }
+
+ ///
+ /// Вес
+ ///
+ public double Weight { get; private set; }
+
+ ///
+ /// Основной цвет
+ ///
+ public Color BodyColor { get; private set; }
+
+ ///
+ ///
+ ///
+ public double Step => Speed * 100 / Weight;
+
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+
+ public EntityBoat(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+}
diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs
index e1650d2..ece7e00 100644
--- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs
+++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs
@@ -34,6 +34,7 @@
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
+ buttonCreatBoat = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCatamaran).BeginInit();
SuspendLayout();
//
@@ -45,16 +46,15 @@
pictureBoxCatamaran.Size = new Size(800, 450);
pictureBoxCatamaran.TabIndex = 0;
pictureBoxCatamaran.TabStop = false;
- pictureBoxCatamaran.Click += ButtonMove_Click;
//
// buttonCreateCatamaran
//
buttonCreateCatamaran.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateCatamaran.Location = new Point(12, 409);
buttonCreateCatamaran.Name = "buttonCreateCatamaran";
- buttonCreateCatamaran.Size = new Size(94, 29);
+ buttonCreateCatamaran.Size = new Size(203, 29);
buttonCreateCatamaran.TabIndex = 1;
- buttonCreateCatamaran.Text = "Создать";
+ buttonCreateCatamaran.Text = "Создать катамаран";
buttonCreateCatamaran.UseVisualStyleBackColor = true;
buttonCreateCatamaran.Click += ButtonCreateCatamaran_Click;
//
@@ -108,11 +108,23 @@
buttonRight.UseVisualStyleBackColor = false;
buttonRight.Click += ButtonMove_Click;
//
+ // buttonCreatBoat
+ //
+ buttonCreatBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreatBoat.Location = new Point(233, 409);
+ buttonCreatBoat.Name = "buttonCreatBoat";
+ buttonCreatBoat.Size = new Size(203, 29);
+ buttonCreatBoat.TabIndex = 6;
+ buttonCreatBoat.Text = "Создать лодку";
+ buttonCreatBoat.UseVisualStyleBackColor = true;
+ buttonCreatBoat.Click += ButtonCreatBoat_Click;
+ //
// FormCatamaran
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
+ Controls.Add(buttonCreatBoat);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
@@ -133,5 +145,6 @@
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
+ private Button buttonCreatBoat;
}
}
\ No newline at end of file
diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs
index 507fc01..a57d253 100644
--- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs
+++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using ProjectCatamaran.Drawnings;
namespace ProjectCatamaran
{
@@ -15,7 +16,7 @@ namespace ProjectCatamaran
///
/// Поле-объект для прорисовки объекта
///
- private DrawningCatamaran? _drawningCatamaran;
+ private DrawningBoat? _drawningBoat;
///
/// Конструктор формы
@@ -25,40 +26,63 @@ namespace ProjectCatamaran
InitializeComponent();
}
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ ///
+ private void CreateObject(string type)
+ {
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawningBoat):
+ _drawningBoat = new DrawningBoat(random.Next(100,
+ 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
+ break;
+ case nameof(DrawningCatamaran):
+ _drawningBoat = new DrawningCatamaran(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ _drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
+ _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
///
- /// Обработка нажатия кнопки "Создать"
+ /// Обработка нажатия кнопки "Создать катамаран"
///
///
///
- private void ButtonCreateCatamaran_Click(object sender, EventArgs e)
- {
- Random random = new();
- _drawningCatamaran = new DrawningCatamaran();
- _drawningCatamaran.Init(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- _drawningCatamaran.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
- _drawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
- Draw();
+ private void ButtonCreateCatamaran_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCatamaran));
- }
+
+ ///
+ /// Обработка нажатия кнопки "Создать лодку"
+ ///
+ ///
+ ///
+ private void ButtonCreatBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
///
/// Метод прорисовки катамарана
///
private void Draw()
{
- if (_drawningCatamaran == null)
+ if (_drawningBoat == null)
{
return;
}
Bitmap bmp = new(pictureBoxCatamaran.Width,
pictureBoxCatamaran.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningCatamaran.DrawTransport(gr);
+ _drawningBoat.DrawTransport(gr);
pictureBoxCatamaran.Image = bmp;
}
@@ -70,7 +94,7 @@ namespace ProjectCatamaran
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawningCatamaran == null)
+ if (_drawningBoat == null)
{
return;
}
@@ -79,16 +103,16 @@ namespace ProjectCatamaran
switch (name)
{
case "buttonUp":
- result = _drawningCatamaran.MoveTransport(DirectionType.Up);
+ result = _drawningBoat.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- result = _drawningCatamaran.MoveTransport(DirectionType.Down);
+ result = _drawningBoat.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- result = _drawningCatamaran.MoveTransport(DirectionType.Left);
+ result = _drawningBoat.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- result = _drawningCatamaran.MoveTransport(DirectionType.Right);
+ result = _drawningBoat.MoveTransport(DirectionType.Right);
break;
}
if (result)
@@ -97,5 +121,6 @@ namespace ProjectCatamaran
}
}
+
}
}
diff --git a/ProjectCatamaran/ProjectCatamaran/Program.cs b/ProjectCatamaran/ProjectCatamaran/Resources/Program.cs
similarity index 92%
rename from ProjectCatamaran/ProjectCatamaran/Program.cs
rename to ProjectCatamaran/ProjectCatamaran/Resources/Program.cs
index 4d620b5..89a0c0b 100644
--- a/ProjectCatamaran/ProjectCatamaran/Program.cs
+++ b/ProjectCatamaran/ProjectCatamaran/Resources/Program.cs
@@ -1,4 +1,4 @@
-namespace ProjectCatamaran
+namespace ProjectCatamaran.Resources
{
internal static class Program
{