PIBD-13 Ishtuganov A.M. LabWork02 Base #2
@ -1,4 +1,4 @@
|
||||
namespace MotorBoat
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
|
||||
/// <summary>
|
@ -1,14 +1,18 @@
|
||||
namespace MotorBoat
|
||||
using MotorBoat.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningMotorBoat
|
||||
public class DrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityMotorBoat? EntityMotorBoat { get; private set; }
|
||||
public EntityBoat? EntityBoat { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -20,39 +24,51 @@
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки лодки
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки лодки
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _drawningBoatWidth = 153;
|
||||
private readonly int _drawningBoatWidth = 143;
|
||||
/// <summary>
|
||||
/// Высота прорисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _drawningBoatHeight = 75;
|
||||
private readonly int _drawningBoatHeight = 38;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="protectiveGlass">Признак наличия защитного стекла</param>
|
||||
/// <param name="engine">Признак наличия мотора</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
bool protectiveGlass, bool engine)
|
||||
private DrawningBoat()
|
||||
{
|
||||
EntityMotorBoat = new EntityMotorBoat();
|
||||
EntityMotorBoat.Init(speed, weight, bodyColor, additionalColor, protectiveGlass, engine);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBoat(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningBoatWidth">Ширина прорисовки лодки</param>
|
||||
/// <param name="drawningBoatHeight">Высота прорисовки лодки</param>
|
||||
protected DrawningBoat(int drawningBoatWidth, int drawningBoatHeight) : this()
|
||||
{
|
||||
_drawningBoatWidth = drawningBoatWidth;
|
||||
_drawningBoatHeight = drawningBoatHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
@ -68,10 +84,10 @@
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if (_startPosX.Value < 0)
|
||||
{
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY.Value < 0)
|
||||
if (_startPosY.Value < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
@ -126,7 +142,7 @@
|
||||
/// невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -134,30 +150,30 @@
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityMotorBoat.Step > 0)
|
||||
if (_startPosX.Value - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityMotorBoat.Step;
|
||||
_startPosX -= (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityMotorBoat.Step > 0)
|
||||
if (_startPosY.Value - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityMotorBoat.Step;
|
||||
_startPosY -= (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningBoatWidth + EntityMotorBoat.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningBoatWidth + EntityBoat.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityMotorBoat.Step;
|
||||
_startPosX += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningBoatHeight + EntityMotorBoat.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawningBoatHeight + EntityBoat.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityMotorBoat.Step;
|
||||
_startPosY += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -169,26 +185,25 @@
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityMotorBoat == null || !_startPosX.HasValue ||
|
||||
if (EntityBoat == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brushBodyColor = new SolidBrush(EntityMotorBoat.BodyColor);
|
||||
Brush brushAdditionalColor = new SolidBrush(EntityMotorBoat.AdditionalColor);
|
||||
Brush brushBodyColor = new SolidBrush(EntityBoat.BodyColor);
|
||||
|
||||
Point[] body =
|
||||
Point[] body =
|
||||
{
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 25),
|
||||
new Point(_startPosX.Value + 110, _startPosY.Value + 25),
|
||||
new Point(_startPosX.Value + 155, _startPosY.Value + 45),
|
||||
new Point(_startPosX.Value + 110, _startPosY.Value + 65),
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 65),
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 25)
|
||||
new Point(_startPosX.Value, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 145, _startPosY.Value + 20),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value + 40),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 40),
|
||||
new Point(_startPosX.Value, _startPosY.Value)
|
||||
};
|
||||
|
||||
// корпус
|
||||
@ -196,34 +211,11 @@
|
||||
g.DrawPolygon(pen, body);
|
||||
|
||||
//боковина лодки
|
||||
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 30, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 30, 30, 30);
|
||||
g.DrawLine(pen, _startPosX.Value + 37, _startPosY.Value + 30, _startPosX.Value + 83, _startPosY.Value + 30);
|
||||
g.DrawLine(pen, _startPosX.Value + 37, _startPosY.Value + 60, _startPosX.Value + 83, _startPosY.Value + 60);
|
||||
g.FillRectangle(brushBodyColor, _startPosX.Value + 37, _startPosY.Value + 31, 50, 29);
|
||||
|
||||
|
||||
//защитное стекло спереди
|
||||
if (EntityMotorBoat.ProtectiveGlass)
|
||||
{
|
||||
Point[] glass =
|
||||
{
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 25),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value + 25),
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 25)
|
||||
};
|
||||
g.FillPolygon(brushAdditionalColor, glass);
|
||||
g.DrawPolygon(pen, glass);
|
||||
}
|
||||
|
||||
//мотор
|
||||
if (EntityMotorBoat.Engine)
|
||||
{
|
||||
g.FillRectangle(brushAdditionalColor, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
||||
}
|
||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 5, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 5, 30, 30);
|
||||
g.DrawLine(pen, _startPosX.Value + 27, _startPosY.Value + 5, _startPosX.Value + 73, _startPosY.Value + 5);
|
||||
g.DrawLine(pen, _startPosX.Value + 27, _startPosY.Value + 35, _startPosX.Value + 73, _startPosY.Value + 35);
|
||||
g.FillRectangle(brushBodyColor, _startPosX.Value + 27, _startPosY.Value + 6, 50, 29);
|
||||
|
||||
}
|
||||
|
65
MotorBoat/MotorBoat/Drawnings/DrawningMotorBoat.cs
Normal file
65
MotorBoat/MotorBoat/Drawnings/DrawningMotorBoat.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using MotorBoat.Entities;
|
||||
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningMotorBoat : DrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="protectiveGlass">Признак наличия защитного стекла</param>
|
||||
/// <param name="engine">Признак наличия мотора</param>
|
||||
public DrawningMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
bool protectiveGlass, bool engine) : base(153, 75)
|
||||
{
|
||||
EntityBoat = new EntityMotorBoat(speed, weight, bodyColor, additionalColor, protectiveGlass, engine);
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBoat == null || EntityBoat is not EntityMotorBoat motorBoat
|
||||
|| !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brushAdditionalColor = new SolidBrush(motorBoat.AdditionalColor);
|
||||
|
||||
//защитное стекло спереди
|
||||
if (motorBoat.ProtectiveGlass)
|
||||
{
|
||||
Point[] glass =
|
||||
{
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 25),
|
||||
new Point(_startPosX.Value + 100, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 90, _startPosY.Value + 25),
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 25)
|
||||
};
|
||||
g.FillPolygon(brushAdditionalColor, glass);
|
||||
g.DrawPolygon(pen, glass);
|
||||
}
|
||||
_startPosX += 10;
|
||||
_startPosY += 25;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 25;
|
||||
//мотор
|
||||
if (motorBoat.Engine)
|
||||
{
|
||||
g.FillRectangle(brushAdditionalColor, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
MotorBoat/MotorBoat/Entities/EntityBoat.cs
Normal file
43
MotorBoat/MotorBoat/Entities/EntityBoat.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Лодка"
|
||||
/// </summary>
|
||||
public class EntityBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения лодки
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес лодки</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityBoat(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +1,10 @@
|
||||
namespace MotorBoat
|
||||
namespace MotorBoat.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Моторная лодка"
|
||||
/// </summary>
|
||||
public class EntityMotorBoat
|
||||
public class EntityMotorBoat : EntityBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
@ -42,12 +30,9 @@
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="protectiveGlass">Признак наличия защитного стекла</param>
|
||||
/// <param name="engine">Признак наличия мотора</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
bool protectiveGlass, bool engine)
|
||||
public EntityMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
bool protectiveGlass, bool engine) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
ProtectiveGlass = protectiveGlass;
|
||||
Engine = engine;
|
38
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
38
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
@ -29,11 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxMotorBoat = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonCreateMotorBoat = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateBoat = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -46,16 +47,16 @@
|
||||
pictureBoxMotorBoat.TabIndex = 0;
|
||||
pictureBoxMotorBoat.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateMotorBoat
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 412);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreateMotorBoat_Click;
|
||||
buttonCreateMotorBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateMotorBoat.Location = new Point(12, 412);
|
||||
buttonCreateMotorBoat.Name = "buttonCreateMotorBoat";
|
||||
buttonCreateMotorBoat.Size = new Size(174, 23);
|
||||
buttonCreateMotorBoat.TabIndex = 1;
|
||||
buttonCreateMotorBoat.Text = "Создать моторную лодку";
|
||||
buttonCreateMotorBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateMotorBoat.Click += ButtonCreateMotorBoat_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
@ -105,16 +106,28 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBoat
|
||||
//
|
||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBoat.Location = new Point(203, 412);
|
||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
||||
buttonCreateBoat.Size = new Size(174, 23);
|
||||
buttonCreateBoat.TabIndex = 6;
|
||||
buttonCreateBoat.Text = "Создать лодку";
|
||||
buttonCreateBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateBoat.Click += ButtonCreateBoat_Click;
|
||||
//
|
||||
// FormMotorBoat
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(861, 447);
|
||||
Controls.Add(buttonCreateBoat);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonCreateMotorBoat);
|
||||
Controls.Add(pictureBoxMotorBoat);
|
||||
Name = "FormMotorBoat";
|
||||
Text = "Моторная лодка";
|
||||
@ -125,10 +138,11 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxMotorBoat;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateMotorBoat;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateBoat;
|
||||
}
|
||||
}
|
@ -7,12 +7,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using MotorBoat.Drawnings;
|
||||
|
||||
namespace MotorBoat
|
||||
{
|
||||
public partial class FormMotorBoat : Form
|
||||
{
|
||||
private DrawningMotorBoat? _drawningMotorBoat;
|
||||
private DrawningBoat? _drawningBoat;
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
@ -25,36 +26,50 @@ namespace MotorBoat
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningMotorBoat == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxMotorBoat.Width,
|
||||
pictureBoxMotorBoat.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningMotorBoat.DrawTransport(gr);
|
||||
_drawningBoat.DrawTransport(gr);
|
||||
pictureBoxMotorBoat.Image = bmp;
|
||||
}
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new Random();
|
||||
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(DrawningMotorBoat):
|
||||
_drawningBoat = new DrawningMotorBoat(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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningBoat.SetPictureSize(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Обработка нажатия кнопки "Создать моторную лодку"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateMotorBoat_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)));
|
||||
_drawningMotorBoat.SetPictureSize(pictureBoxMotorBoat.Width,
|
||||
pictureBoxMotorBoat.Height);
|
||||
_drawningMotorBoat.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateMotorBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMotorBoat));
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать лодку"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
@ -62,7 +77,7 @@ namespace MotorBoat
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningMotorBoat == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -72,19 +87,19 @@ namespace MotorBoat
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawningMotorBoat.MoveTransport(DirectionType.Up);
|
||||
_drawningBoat.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawningMotorBoat.MoveTransport(DirectionType.Down);
|
||||
_drawningBoat.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawningMotorBoat.MoveTransport(DirectionType.Left);
|
||||
_drawningBoat.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningMotorBoat.MoveTransport(DirectionType.Right);
|
||||
_drawningBoat.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user