Lab02.1
This commit is contained in:
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
@@ -1,11 +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
|
||||
{
|
||||
internal class DrawningMotorBoat
|
||||
public class DrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityMotorBoat? EntityMotorBoat { get; private set; }
|
||||
public EntityBoat? EntityBoat { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@@ -20,12 +27,12 @@
|
||||
/// <summary>
|
||||
/// Координата прорисовки x
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата прорисовки y
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки
|
||||
@@ -38,25 +45,38 @@
|
||||
private readonly int _drawningMotorBoatHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="addTwoMotors">Два дополнительных мотора</param>
|
||||
/// <param name="sofa">Наличие дивана</param>
|
||||
/// <param name="sportLines">Наличие двух полос</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines)
|
||||
public DrawningBoat()
|
||||
{
|
||||
EntityMotorBoat = new EntityMotorBoat();
|
||||
EntityMotorBoat.Init(speed, weight, bodyColor, additionalColor, addTwoMotors, sofa, sportLines);
|
||||
_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="drawningMotorBoatWidth">Ширина прорисовки лодки</param>
|
||||
/// <param name="drawningMotorBoatHeight">Высота прорисовки лодки</param>
|
||||
protected DrawningBoat(int drawningMotorBoatWidth, int drawningMotorBoatHeight) : this()
|
||||
{
|
||||
_drawningMotorBoatWidth = drawningMotorBoatWidth;
|
||||
_drawningMotorBoatHeight = drawningMotorBoatHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@@ -65,8 +85,6 @@
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
@@ -124,7 +142,7 @@
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -133,30 +151,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 + 140 + EntityMotorBoat.Step < _pictureWidth)
|
||||
if (_startPosX.Value + 140 + EntityBoat.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityMotorBoat.Step;
|
||||
_startPosX += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + 60 + EntityMotorBoat.Step < _pictureHeight)
|
||||
if (_startPosY.Value + 60 + EntityBoat.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityMotorBoat.Step;
|
||||
_startPosY += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@@ -168,88 +186,51 @@
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityMotorBoat.AdditionalColor);
|
||||
|
||||
// добавляем два мотора
|
||||
if (EntityMotorBoat.AddTwoMotors)
|
||||
{
|
||||
Brush br1 = new SolidBrush(EntityMotorBoat.AdditionalColor);
|
||||
g.FillEllipse(br1, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.FillRectangle(br1, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.FillEllipse(br1, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.FillRectangle(br1, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
}
|
||||
|
||||
// нос лодки
|
||||
Brush br2 = new SolidBrush(EntityMotorBoat.BodyColor);
|
||||
Brush br2 = new SolidBrush(EntityBoat.BodyColor);
|
||||
g.FillEllipse(br2, _startPosX.Value + 40, _startPosY.Value + 5, 100, 50);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 100, 50);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 100, 50);
|
||||
|
||||
// лобовое стекло
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 87, _startPosY.Value + 10, 10, 40);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 87, _startPosY.Value + 10, 10, 40);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 87, _startPosY.Value + 10, 10, 40);
|
||||
|
||||
// тело лодки
|
||||
Brush br3 = new SolidBrush(EntityMotorBoat.BodyColor);
|
||||
Brush br3 = new SolidBrush(EntityBoat.BodyColor);
|
||||
g.FillRectangle(br3, _startPosX.Value + 22, _startPosY.Value + 5, 70, 50);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 5, 70, 50);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 5, 70, 50);
|
||||
|
||||
// пространство для пассажиров
|
||||
Brush brLightGray = new SolidBrush(Color.LightGray);
|
||||
g.FillRectangle(brLightGray, _startPosX.Value + 30, _startPosY.Value + 10, 62, 40);
|
||||
g.FillRectangle(brLightGray, _startPosX.Value + 30, _startPosY.Value + 10, 62, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 62, 40);
|
||||
|
||||
// прожектор лампа
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX.Value + 130, _startPosY.Value + 27, 6, 6);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 130, _startPosY.Value + 27, 6, 6);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 130, _startPosY.Value + 27, 6, 6);
|
||||
|
||||
// прожектор корпус
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBlack, _startPosX.Value + 129, _startPosY.Value + 26, 3, 8);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 129, _startPosY.Value + 26, 3, 8);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 129, _startPosY.Value + 26, 3, 8);
|
||||
|
||||
// мотор центральный
|
||||
Brush brDarkBlue = new SolidBrush(Color.DarkBlue);
|
||||
g.FillEllipse(brDarkBlue, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.FillRectangle(brDarkBlue, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
|
||||
// добавляем две полоски
|
||||
if (EntityMotorBoat.SportLines)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
}
|
||||
|
||||
// добавляем диван
|
||||
if (EntityMotorBoat.Sofa)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
}
|
||||
g.FillEllipse(brDarkBlue, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.FillRectangle(brDarkBlue, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 25, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 25, 5, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
72
MotorBoat/MotorBoat/Drawnings/DrawningMotorBoat.cs
Normal file
72
MotorBoat/MotorBoat/Drawnings/DrawningMotorBoat.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using MotorBoat.Entities;
|
||||
|
||||
namespace MotorBoat.Drawnings
|
||||
{
|
||||
public class DrawningMotorBoat : DrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="addTwoMotors">Два дополнительных мотора</param>
|
||||
/// <param name="sofa">Наличие дивана</param>
|
||||
/// <param name="sportLines">Наличие двух полос</param>
|
||||
public DrawningMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines) : base (140, 60)
|
||||
{
|
||||
EntityBoat = new EntityMotorBoat(speed, weight, bodyColor, additionalColor, addTwoMotors, sofa, sportLines);
|
||||
}
|
||||
|
||||
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 additionalBrush = new SolidBrush(motorBoat.AdditionalColor);
|
||||
base.DrawTransport(g);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
// добавляем два мотора
|
||||
if (motorBoat.AddTwoMotors)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 10, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 10, 5, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 40, 10, 10);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 5, 10);
|
||||
|
||||
}
|
||||
|
||||
// добавляем две полоски
|
||||
if (motorBoat.SportLines)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 22, 25, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 36, 25, 2);
|
||||
}
|
||||
|
||||
// добавляем диван
|
||||
if (motorBoat.Sofa)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 15, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 10, 3, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 10, 10, 2);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 33, _startPosY.Value + 48, 10, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
MotorBoat/MotorBoat/Entities/EntityBoat.cs
Normal file
42
MotorBoat/MotorBoat/Entities/EntityBoat.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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,25 +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>
|
||||
@@ -46,7 +31,7 @@
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
@@ -55,11 +40,8 @@
|
||||
/// <param name="addTwoMotors">Два дополнительных мотора</param>
|
||||
/// <param name="sofa">Наличие дивана</param>
|
||||
/// <param name="sportLines">Наличие полос</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines)
|
||||
public EntityMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor, bool addTwoMotors, bool sofa, bool sportLines) : base (speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
AddTwoMotors = addTwoMotors;
|
||||
Sofa = sofa;
|
||||
18
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
18
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
@@ -34,6 +34,7 @@
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateBoat = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -51,9 +52,9 @@
|
||||
buttonCreateMotorBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateMotorBoat.Location = new Point(12, 345);
|
||||
buttonCreateMotorBoat.Name = "buttonCreateMotorBoat";
|
||||
buttonCreateMotorBoat.Size = new Size(75, 23);
|
||||
buttonCreateMotorBoat.Size = new Size(169, 23);
|
||||
buttonCreateMotorBoat.TabIndex = 1;
|
||||
buttonCreateMotorBoat.Text = "Создать";
|
||||
buttonCreateMotorBoat.Text = "Создать спортивную лодку";
|
||||
buttonCreateMotorBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateMotorBoat.Click += ButtonCreateMotorBoat_Click;
|
||||
//
|
||||
@@ -105,11 +106,23 @@
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBoat
|
||||
//
|
||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBoat.Location = new Point(187, 345);
|
||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
||||
buttonCreateBoat.Size = new Size(169, 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(841, 380);
|
||||
Controls.Add(buttonCreateBoat);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
@@ -130,5 +143,6 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateBoat;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace MotorBoat
|
||||
using MotorBoat.Drawnings;
|
||||
|
||||
namespace MotorBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма работы с объектом
|
||||
@@ -8,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningMotorBoat? _drawningMotorBoat;
|
||||
private DrawningBoat? _drawningBoat;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@@ -23,34 +25,58 @@
|
||||
/// </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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
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(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)), 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)), 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>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@@ -59,7 +85,7 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningMotorBoat == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -69,16 +95,16 @@
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Up);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Down);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Left);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningMotorBoat.MoveTransport(DirectionType.Right);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -87,5 +113,7 @@
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user