diff --git a/MotorBoat/MotorBoat/DrawningMotorBoat.cs b/MotorBoat/MotorBoat/DrawningMotorBoat.cs
index 0f85560..71dae55 100644
--- a/MotorBoat/MotorBoat/DrawningMotorBoat.cs
+++ b/MotorBoat/MotorBoat/DrawningMotorBoat.cs
@@ -37,12 +37,12 @@ namespace MotorBoat
private int _startPosY = 0;
///
- /// Ширина прорисовки автомобиля
+ /// Ширина прорисовки катера
///
- private readonly int _boatWight = 120;
+ private readonly int _boatWight = 165;
///
- /// Высота прорисовки автомобиля
+ /// Высота прорисовки катера
///
private readonly int _boatHeight = 80;
@@ -53,17 +53,19 @@ namespace MotorBoat
/// Вес
/// Цвет корпуса
/// Дополнительный цвет
- /// Ширина картинки
+ /// Признак наличия двигателя в корме
+ /// Признак наличия защитного стекла впереди
+ /// Ширина картинки
/// Выслота картинки
/// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах
- public bool Init(int speed, double weight, Color bodyColor, Color AdditionalColor, int width, int height)
+ public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool engine, bool glass, int width, int height)
{
if (width <= _boatWight || height <= _boatHeight)
return false;
_pictureWight = width;
_pictureHeight = height;
EntityMotorBoat = new EntityMotorBoat();
- EntityMotorBoat.Init(speed, weight, bodyColor, AdditionalColor);
+ EntityMotorBoat.Init(speed, weight, bodyColor, additionalColor, engine, glass);
return true;
}
@@ -132,7 +134,7 @@ namespace MotorBoat
//вниз
case DirectionType.Down:
- if (_startPosY + _pictureHeight + EntityMotorBoat.Step < _pictureHeight)
+ if (_startPosY + _boatHeight + EntityMotorBoat.Step < _pictureHeight)
{
_startPosY += (int)EntityMotorBoat.Step;
}
@@ -150,17 +152,38 @@ namespace MotorBoat
{
return;
}
- Pen pen = new(Color.Black);
+ Pen pen = new(Color.Black, 1);
+
+ Brush mainBrush = new SolidBrush(EntityMotorBoat.BodyColor);
Brush additionalBrush = new SolidBrush(EntityMotorBoat.AdditionalColor);
- Point[] points = { new Point(_startPosX + _boatWight - 40, _startPosY + 10), new Point(_startPosX + _boatWight, _startPosY + 40), new Point(_startPosX + _boatWight - 40, _startPosY + 70) };
+ // корпус
+ Point[] hull = new Point[]
+ {
+ new Point(_startPosX + 5, _startPosY + 0),
+ new Point(_startPosX + 120, _startPosY + 0),
+ new Point(_startPosX + 160, _startPosY + 35),
+ new Point(_startPosX + 120, _startPosY + 70),
+ new Point(_startPosX + 5, _startPosY + 70),
+ };
+ g.FillPolygon(mainBrush, hull);
+ g.DrawPolygon(pen, hull);
- g.DrawRectangle(pen, _startPosX, _startPosY, _boatWight - 20, 10);
- g.DrawRectangle(pen, _startPosX + 10, _startPosY + 10, _boatWight - 50, 60);
- g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30); // палуба
- g.DrawPolygon(pen, points);
-
+ // стекло впереди
+ Brush glassBrush = new SolidBrush(Color.LightBlue);
+ g.FillEllipse(glassBrush, _startPosX + 20, _startPosY + 15, 100, 40);
+ g.DrawEllipse(pen, _startPosX + 20, _startPosY + 15, 100, 40);
+ // осн часть
+ Brush blockBrush = new SolidBrush(Color.Olive);
+ g.FillRectangle(blockBrush, _startPosX + 20, _startPosY + 15, 80, 40);
+ g.DrawRectangle(pen, _startPosX + 20, _startPosY + 15, 80, 40);
+
+ // двигатель
+ Brush engineBrush = new
+ SolidBrush(Color.Olive);
+ g.FillRectangle(engineBrush, _startPosX + 0, _startPosY + 10, 5, 50);
+ g.DrawRectangle(pen, _startPosX + 0, _startPosY + 10, 5, 50);
}
}
}
diff --git a/MotorBoat/MotorBoat/EntityMotorBoat.cs b/MotorBoat/MotorBoat/EntityMotorBoat.cs
index 3687804..05ce1ab 100644
--- a/MotorBoat/MotorBoat/EntityMotorBoat.cs
+++ b/MotorBoat/MotorBoat/EntityMotorBoat.cs
@@ -6,27 +6,37 @@ using System.Threading.Tasks;
namespace MotorBoat
{
- internal class EntityMotorBoat
+ public class EntityMotorBoat
{
///
/// Скорость
///
- public int Speed { get; set; }
+ public int Speed { get; private set; }
///
/// Вес
///
- public double Weight { get; set; }
+ public double Weight { get; private set; }
///
/// Основной цвет
///
- public Color BodyColor { get; set; }
+ public Color BodyColor { get; private set; }
///
/// Дополнительный цвет
///
- public Color AdditionalColor { get; set; }
+ public Color AdditionalColor { get; private set; }
+
+ ///
+ /// Признак (опция) наличия двигателя в корме
+ ///
+ public bool Engine { get; private set; }
+
+ ///
+ /// Признак (опция) наличия защитного стекла спереди
+ ///
+ public bool Glass { get; private set; }
///
/// Шаг перемещения моторной лодки
@@ -40,13 +50,17 @@ namespace MotorBoat
/// Вес катера
/// Основной цвет
/// Дополнительный цвет
+ /// Признак наличия двигателя в корме
+ /// Признак наличия защитного стекла впереди
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor)
+ public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool engine, bool glass)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
+ Engine = engine;
+ Glass = glass;
}
}
}
diff --git a/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs b/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
index 7305c2b..4cccdbb 100644
--- a/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
+++ b/MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
@@ -28,24 +28,24 @@
///
private void InitializeComponent()
{
- pictureBox1 = new PictureBox();
+ pictureBoxMotorBoat = new PictureBox();
buttonCreate = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonDown = new Button();
- ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit();
SuspendLayout();
//
- // pictureBox1
+ // pictureBoxMotorBoat
//
- pictureBox1.Dock = DockStyle.Fill;
- pictureBox1.Location = new Point(0, 0);
- pictureBox1.Name = "pictureBox1";
- pictureBox1.Size = new Size(884, 461);
- pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
- pictureBox1.TabIndex = 0;
- pictureBox1.TabStop = false;
+ pictureBoxMotorBoat.Dock = DockStyle.Fill;
+ pictureBoxMotorBoat.Location = new Point(0, 0);
+ pictureBoxMotorBoat.Name = "pictureBoxMotorBoat";
+ pictureBoxMotorBoat.Size = new Size(884, 461);
+ pictureBoxMotorBoat.SizeMode = PictureBoxSizeMode.AutoSize;
+ pictureBoxMotorBoat.TabIndex = 0;
+ pictureBoxMotorBoat.TabStop = false;
//
// buttonCreate
//
@@ -56,6 +56,7 @@
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
+ buttonCreate.Click += ButtonCreate_Click;
//
// buttonLeft
//
@@ -67,6 +68,7 @@
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
+ buttonLeft.Click += ButtonMove_Click;
//
// buttonRight
//
@@ -78,6 +80,7 @@
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
+ buttonRight.Click += ButtonMove_Click;
//
// buttonUp
//
@@ -89,6 +92,7 @@
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
+ buttonUp.Click += ButtonMove_Click;
//
// buttonDown
//
@@ -100,6 +104,7 @@
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
+ buttonDown.Click += ButtonMove_Click;
//
// FormMotorBoat
//
@@ -111,18 +116,18 @@
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
- Controls.Add(pictureBox1);
+ Controls.Add(pictureBoxMotorBoat);
Name = "FormMotorBoat";
StartPosition = FormStartPosition.CenterScreen;
Text = "FormMotorBoat";
- ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
- private PictureBox pictureBox1;
+ private PictureBox pictureBoxMotorBoat;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonRight;
diff --git a/MotorBoat/MotorBoat/FormMotorBoat.cs b/MotorBoat/MotorBoat/FormMotorBoat.cs
index 1611cc7..ddd8d4d 100644
--- a/MotorBoat/MotorBoat/FormMotorBoat.cs
+++ b/MotorBoat/MotorBoat/FormMotorBoat.cs
@@ -2,9 +2,80 @@ namespace MotorBoat
{
public partial class FormMotorBoat : Form
{
+ ///
+ /// -
+ ///
+ private DrawningMotorboat? _drawningMotorboat;
+
+ ///
+ ///
+ ///
public FormMotorBoat()
{
InitializeComponent();
}
+
+ ///
+ ///
+ ///
+ private void Draw()
+ {
+ if (_drawningMotorboat == null)
+ {
+ return;
+ }
+ Bitmap bmp = new(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningMotorboat.DrawTransport(gr);
+ pictureBoxMotorBoat.Image = bmp;
+ }
+
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random random = new();
+ _drawningMotorboat = new DrawningMotorboat();
+ _drawningMotorboat.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)),
+ pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
+ _drawningMotorboat.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningMotorboat == null)
+ {
+ return;
+ }
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ switch (name)
+ {
+ case "buttonUp":
+ _drawningMotorboat.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonDown":
+ _drawningMotorboat.MoveTransport(DirectionType.Down);
+ break;
+ case "buttonLeft":
+ _drawningMotorboat.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ _drawningMotorboat.MoveTransport(DirectionType.Right);
+ break;
+ }
+ Draw();
+ }
}
}
\ No newline at end of file
diff --git a/MotorBoat/MotorBoat/down.png b/MotorBoat/MotorBoat/down.png
new file mode 100644
index 0000000..c49c770
Binary files /dev/null and b/MotorBoat/MotorBoat/down.png differ
diff --git a/MotorBoat/MotorBoat/left.png b/MotorBoat/MotorBoat/left.png
new file mode 100644
index 0000000..42e3bd8
Binary files /dev/null and b/MotorBoat/MotorBoat/left.png differ
diff --git a/MotorBoat/MotorBoat/right.png b/MotorBoat/MotorBoat/right.png
new file mode 100644
index 0000000..5da511f
Binary files /dev/null and b/MotorBoat/MotorBoat/right.png differ
diff --git a/MotorBoat/MotorBoat/up.png b/MotorBoat/MotorBoat/up.png
new file mode 100644
index 0000000..9b45905
Binary files /dev/null and b/MotorBoat/MotorBoat/up.png differ