lab_02
This commit is contained in:
parent
c6a5960e15
commit
72e2df80a7
132
speed_Boat/speed_Boat/AbstractStrategy.cs
Normal file
132
speed_Boat/speed_Boat/AbstractStrategy.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SpeedBoatLab.Drawings;
|
||||||
|
using SpeedBoatLab.Entity;
|
||||||
|
|
||||||
|
namespace speed_Boat.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещаемый объект
|
||||||
|
/// </summary>
|
||||||
|
private IMovementObject? _movementObject;
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Высота поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
public Status GetStatus()
|
||||||
|
{
|
||||||
|
return _state;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка данных
|
||||||
|
/// </summary>
|
||||||
|
public void SetData(IMovementObject moveableObject, int width, int height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_movementObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения
|
||||||
|
/// </summary>
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение влево
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вправо
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вверх
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вниз
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры объекта
|
||||||
|
/// </summary>
|
||||||
|
protected ObjectParameters? GetObjectParameters => _movementObject?.GetObjectPosition;
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _movementObject?.GetStep;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение к цели
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
/// <summary>
|
||||||
|
/// Достигнута ли цель
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка перемещения в требуемом направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directionType">Направление</param>
|
||||||
|
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(DirectionType directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_movementObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_movementObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SpeedBoatLab
|
namespace SpeedBoatLab.Drawings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
|
38
speed_Boat/speed_Boat/DrawingObjectBoat.cs
Normal file
38
speed_Boat/speed_Boat/DrawingObjectBoat.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SpeedBoatLab.Entity;
|
||||||
|
using SpeedBoatLab.Drawings;
|
||||||
|
|
||||||
|
namespace speed_Boat.MovementStrategy
|
||||||
|
{
|
||||||
|
class DrawingObjectBoat : IMovementObject
|
||||||
|
{
|
||||||
|
private readonly DrawingBoat? _drawingBoat = null;
|
||||||
|
|
||||||
|
public DrawingObjectBoat(DrawingBoat drawingBoat)
|
||||||
|
{
|
||||||
|
_drawingBoat = drawingBoat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(_drawingBoat == null || _drawingBoat._entityBoat == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawingBoat.GetPoseX, _drawingBoat.GetPoseY, _drawingBoat.GetWidth, _drawingBoat.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStep => (int)(_drawingBoat?._entityBoat?.Step ?? 0);
|
||||||
|
|
||||||
|
public bool CheckCanMove(DirectionType direction) => _drawingBoat?.CanMove(direction) ?? false;
|
||||||
|
|
||||||
|
public void MoveObject(DirectionType direction) => _drawingBoat?.MoveBoat(direction);
|
||||||
|
}
|
||||||
|
}
|
57
speed_Boat/speed_Boat/DrawingSpeedBoat.cs
Normal file
57
speed_Boat/speed_Boat/DrawingSpeedBoat.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SpeedBoatLab.Entity;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace SpeedBoatLab.Drawings
|
||||||
|
{
|
||||||
|
public class DrawingSpeedBoat : DrawingBoat
|
||||||
|
{
|
||||||
|
public DrawingSpeedBoat(int speed, double weight, Color mainColor, Color secondColor, bool _isMotor, bool _isProtectedGlass, int width, int height) :
|
||||||
|
base(speed, weight, mainColor, width, height, 100, 80)
|
||||||
|
{
|
||||||
|
if (_entityBoat != null)
|
||||||
|
{
|
||||||
|
_entityBoat = new EntitySpeedboat(speed, weight, mainColor, secondColor, _isMotor, _isProtectedGlass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (_entityBoat is not EntitySpeedboat speedBoat)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(speedBoat.SecondColor);
|
||||||
|
|
||||||
|
#region Координаты защитного стекла
|
||||||
|
Point g1 = new Point(startXCoord + 70, startYCoord + 25);
|
||||||
|
Point g2 = new Point(startXCoord + 80, startYCoord + 20);
|
||||||
|
Point g3 = new Point(startXCoord + 80, startYCoord + 60);
|
||||||
|
Point g4 = new Point(startXCoord + 70, startYCoord + 55);
|
||||||
|
Point[] pointsGlass = { g1, g2, g3, g4 };
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//мотор
|
||||||
|
if (speedBoat.isMotor)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, startXCoord + 10, startYCoord + 30, widthBoat - 90, heightBoat - 60);
|
||||||
|
|
||||||
|
g.FillRectangle(additionalBrush, startXCoord + 10, startYCoord + 30, widthBoat - 90, heightBoat - 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
//защитное стекло
|
||||||
|
if (speedBoat.isProtectedGlass)
|
||||||
|
{
|
||||||
|
g.DrawPolygon(pen, pointsGlass);
|
||||||
|
|
||||||
|
g.FillPolygon(new SolidBrush(Color.Aqua), pointsGlass);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,9 +5,12 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace SpeedBoatLab
|
namespace SpeedBoatLab.Entity
|
||||||
{
|
{
|
||||||
public class SpeedBoat
|
/// <summary>
|
||||||
|
/// Катер
|
||||||
|
/// </summary>
|
||||||
|
public class EntityBoat
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость катера
|
/// Скорость катера
|
||||||
@ -19,39 +22,21 @@ namespace SpeedBoatLab
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double Weight { get; private set; }
|
public double Weight { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Наличие мотора
|
|
||||||
/// </summary>
|
|
||||||
public bool isMotor { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Наличие защитного стекла
|
|
||||||
/// </summary>
|
|
||||||
public bool isProtectedGlass { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Основной цвет
|
/// Основной цвет
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color MainColor { get; private set; }
|
public Color MainColor { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Доп. цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color SecondColor { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения катера
|
/// Шаг перемещения катера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double Step => (double)Speed * 100 / (Weight);
|
public double Step => (double)Speed * 100 / (Weight);
|
||||||
|
|
||||||
public void Init(int speed, double weight, bool _isMotor, bool _isProtectedGlass, Color mainColor, Color secondColor)
|
public EntityBoat(int speed, double weight, Color mainColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
isMotor = _isMotor;
|
|
||||||
isProtectedGlass = _isProtectedGlass;
|
|
||||||
MainColor = mainColor;
|
MainColor = mainColor;
|
||||||
SecondColor = secondColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
41
speed_Boat/speed_Boat/EntitySpeedboat.cs
Normal file
41
speed_Boat/speed_Boat/EntitySpeedboat.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace SpeedBoatLab.Entity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность скоростного катера
|
||||||
|
/// </summary>
|
||||||
|
public class EntitySpeedboat : EntityBoat
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Наличие мотора
|
||||||
|
/// </summary>
|
||||||
|
public bool isMotor { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Наличие защитного стекла
|
||||||
|
/// </summary>
|
||||||
|
public bool isProtectedGlass { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доп. цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color SecondColor { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры катера
|
||||||
|
/// </summary>
|
||||||
|
public EntitySpeedboat(int speed, double weight, Color mainColor, Color secondColor, bool _isMotor, bool _isProtectedGlass) :
|
||||||
|
base(speed, weight, mainColor)
|
||||||
|
{
|
||||||
|
isMotor = _isMotor;
|
||||||
|
isProtectedGlass = _isProtectedGlass;
|
||||||
|
SecondColor = secondColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
speed_Boat/speed_Boat/FormSpeedBoat.Designer.cs
generated
49
speed_Boat/speed_Boat/FormSpeedBoat.Designer.cs
generated
@ -35,6 +35,9 @@ namespace SpeedBoatLab
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
||||||
|
this.StepButton = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateSpeedBoat = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSpeedBoat)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSpeedBoat)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -56,7 +59,7 @@ namespace SpeedBoatLab
|
|||||||
this.buttonCreate.Name = "buttonCreate";
|
this.buttonCreate.Name = "buttonCreate";
|
||||||
this.buttonCreate.Size = new System.Drawing.Size(103, 51);
|
this.buttonCreate.Size = new System.Drawing.Size(103, 51);
|
||||||
this.buttonCreate.TabIndex = 2;
|
this.buttonCreate.TabIndex = 2;
|
||||||
this.buttonCreate.Text = "Создать обьект";
|
this.buttonCreate.Text = "Создать катер";
|
||||||
this.buttonCreate.UseVisualStyleBackColor = false;
|
this.buttonCreate.UseVisualStyleBackColor = false;
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||||
//
|
//
|
||||||
@ -112,11 +115,52 @@ namespace SpeedBoatLab
|
|||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
//
|
||||||
|
// comboBox1
|
||||||
|
//
|
||||||
|
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBox1.FormattingEnabled = true;
|
||||||
|
this.comboBox1.Items.AddRange(new object[] {
|
||||||
|
"MoveToCenter",
|
||||||
|
"MoveToBorder"});
|
||||||
|
this.comboBox1.Location = new System.Drawing.Point(637, 12);
|
||||||
|
this.comboBox1.Name = "comboBox1";
|
||||||
|
this.comboBox1.Size = new System.Drawing.Size(151, 28);
|
||||||
|
this.comboBox1.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// StepButton
|
||||||
|
//
|
||||||
|
this.StepButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.StepButton.BackColor = System.Drawing.Color.White;
|
||||||
|
this.StepButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
this.StepButton.Location = new System.Drawing.Point(731, 46);
|
||||||
|
this.StepButton.Name = "StepButton";
|
||||||
|
this.StepButton.Size = new System.Drawing.Size(57, 33);
|
||||||
|
this.StepButton.TabIndex = 12;
|
||||||
|
this.StepButton.Text = "Шаг";
|
||||||
|
this.StepButton.UseVisualStyleBackColor = false;
|
||||||
|
this.StepButton.Click += new System.EventHandler(this.StepButton_Click);
|
||||||
|
//
|
||||||
|
// buttonCreateSpeedBoat
|
||||||
|
//
|
||||||
|
this.buttonCreateSpeedBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonCreateSpeedBoat.BackColor = System.Drawing.Color.White;
|
||||||
|
this.buttonCreateSpeedBoat.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
this.buttonCreateSpeedBoat.Location = new System.Drawing.Point(121, 387);
|
||||||
|
this.buttonCreateSpeedBoat.Name = "buttonCreateSpeedBoat";
|
||||||
|
this.buttonCreateSpeedBoat.Size = new System.Drawing.Size(143, 51);
|
||||||
|
this.buttonCreateSpeedBoat.TabIndex = 13;
|
||||||
|
this.buttonCreateSpeedBoat.Text = "Создать скоростной катер";
|
||||||
|
this.buttonCreateSpeedBoat.UseVisualStyleBackColor = false;
|
||||||
|
this.buttonCreateSpeedBoat.Click += new System.EventHandler(this.buttonCreateSpeedBoat_Click);
|
||||||
|
//
|
||||||
// FormSpeedBoat
|
// FormSpeedBoat
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonCreateSpeedBoat);
|
||||||
|
this.Controls.Add(this.StepButton);
|
||||||
|
this.Controls.Add(this.comboBox1);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
@ -138,6 +182,9 @@ namespace SpeedBoatLab
|
|||||||
private System.Windows.Forms.Button buttonLeft;
|
private System.Windows.Forms.Button buttonLeft;
|
||||||
private System.Windows.Forms.Button buttonDown;
|
private System.Windows.Forms.Button buttonDown;
|
||||||
private System.Windows.Forms.Button buttonRight;
|
private System.Windows.Forms.Button buttonRight;
|
||||||
|
private System.Windows.Forms.ComboBox comboBox1;
|
||||||
|
private System.Windows.Forms.Button StepButton;
|
||||||
|
private System.Windows.Forms.Button buttonCreateSpeedBoat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using SpeedBoatLab.Drawings;
|
||||||
|
using SpeedBoatLab.Entity;
|
||||||
|
using speed_Boat.MovementStrategy;
|
||||||
|
|
||||||
namespace SpeedBoatLab
|
namespace SpeedBoatLab
|
||||||
{
|
{
|
||||||
@ -15,25 +18,30 @@ namespace SpeedBoatLab
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private SpeedBoatMovement? _tankerMovement;
|
private DrawingBoat? _boatMovement;
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
|
||||||
public FormSpeedBoat()
|
public FormSpeedBoat()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод прорисовки машины
|
/// Метод прорисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_tankerMovement == null)
|
if (_boatMovement == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
Bitmap bmp = new(pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_tankerMovement.DrawTransport(gr);
|
_boatMovement.DrawTransport(gr);
|
||||||
pictureBoxSpeedBoat.Image = bmp;
|
pictureBoxSpeedBoat.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,18 +51,33 @@ namespace SpeedBoatLab
|
|||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_tankerMovement = new SpeedBoatMovement();
|
_boatMovement = new DrawingBoat(random.Next(100, 300),
|
||||||
|
|
||||||
_tankerMovement.Init(random.Next(100, 300),
|
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000),
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
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)),
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
||||||
|
|
||||||
//startXCoord and startYCoord
|
//startXCoord and startYCoord
|
||||||
_tankerMovement.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_boatMovement.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка создания скоростного обьекта
|
||||||
|
/// </summary>
|
||||||
|
private void buttonCreateSpeedBoat_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_boatMovement = new DrawingSpeedBoat(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)),
|
||||||
|
pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
||||||
|
|
||||||
|
//startXCoord and startYCoord
|
||||||
|
_boatMovement.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
@ -64,7 +87,7 @@ namespace SpeedBoatLab
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_tankerMovement == null)
|
if (_boatMovement == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,19 +95,56 @@ namespace SpeedBoatLab
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_tankerMovement.MoveTransport(DirectionType.Up);
|
_boatMovement.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_tankerMovement.MoveTransport(DirectionType.Down);
|
_boatMovement.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_tankerMovement.MoveTransport(DirectionType.Left);
|
_boatMovement.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_tankerMovement.MoveTransport(DirectionType.Right);
|
_boatMovement.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Шаг"
|
||||||
|
/// </summary>
|
||||||
|
private void StepButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if(_boatMovement == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(comboBox1.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBox1.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
if(_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new DrawingObjectBoat(_boatMovement), pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
||||||
|
comboBox1.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if(_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBox1.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
speed_Boat/speed_Boat/IMovementObject.cs
Normal file
26
speed_Boat/speed_Boat/IMovementObject.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SpeedBoatLab.Drawings;
|
||||||
|
|
||||||
|
namespace speed_Boat.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMovementObject
|
||||||
|
{
|
||||||
|
//Получение координаты Х обьекта
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
//шаг обьекта
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
//проверка на перемещение
|
||||||
|
bool CheckCanMove(DirectionType direction);
|
||||||
|
|
||||||
|
//изменение направления перемещения обьекта
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
44
speed_Boat/speed_Boat/MoveToBorder.cs
Normal file
44
speed_Boat/speed_Boat/MoveToBorder.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace speed_Boat.MovementStrategy
|
||||||
|
{
|
||||||
|
class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//return objParams.RightBorder == FieldWidth && objParams.DownBorder == FieldHeight;
|
||||||
|
return objParams.RightBorder <= FieldWidth &&
|
||||||
|
objParams.RightBorder + GetStep() >= FieldWidth&&
|
||||||
|
objParams.DownBorder <= FieldHeight &&
|
||||||
|
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = FieldWidth - objParams.RightBorder;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
var diffY = FieldHeight - objParams.DownBorder;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
59
speed_Boat/speed_Boat/MoveToCenter.cs
Normal file
59
speed_Boat/speed_Boat/MoveToCenter.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SpeedBoatLab.Drawings;
|
||||||
|
using SpeedBoatLab.Entity;
|
||||||
|
|
||||||
|
namespace speed_Boat.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if(objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
speed_Boat/speed_Boat/ObjectParameters.cs
Normal file
53
speed_Boat/speed_Boat/ObjectParameters.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace speed_Boat.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Левая граница
|
||||||
|
/// </summary>
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int TopBorder => _y;
|
||||||
|
/// <summary>
|
||||||
|
/// Правая граница
|
||||||
|
/// </summary>
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
/// <summary>
|
||||||
|
/// Нижняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -5,16 +5,17 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using SpeedBoatLab;
|
using SpeedBoatLab;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using SpeedBoatLab.Entity;
|
||||||
|
|
||||||
|
|
||||||
namespace SpeedBoatLab
|
namespace SpeedBoatLab.Drawings
|
||||||
{
|
{
|
||||||
class SpeedBoatMovement
|
public class DrawingBoat
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SpeedBoat? _speedBoat { get; private set; }
|
public EntityBoat? _entityBoat { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -28,27 +29,92 @@ namespace SpeedBoatLab
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Х-координата обьекта
|
/// Х-координата обьекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int startXCoord;
|
protected int startXCoord;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Y-координата обьекта
|
/// Y-координата обьекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int startYCoord;
|
protected int startYCoord;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина обьекта
|
/// Ширина обьекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int widthBoat = 100;
|
protected readonly int widthBoat = 100;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота обьекта
|
/// Высота обьекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int heightBoat = 80;
|
protected readonly int heightBoat = 80;
|
||||||
|
|
||||||
public bool Init(int speed, double weight, bool _isMotor, bool _isProtectedGlass, Color mainColor, Color secondColor, int width, int height)
|
/// <summary>
|
||||||
|
/// Х-координата обьекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPoseX => startXCoord;
|
||||||
|
/// <summary>
|
||||||
|
/// Y-координата обьекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPoseY => startYCoord;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина обьекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => widthBoat;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота обьекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => heightBoat;
|
||||||
|
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (_entityBoat == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//Left
|
||||||
|
DirectionType.Left => startXCoord - _entityBoat.Step > 0,
|
||||||
|
//Up
|
||||||
|
DirectionType.Up => startYCoord - _entityBoat.Step > 0,
|
||||||
|
//Down
|
||||||
|
DirectionType.Down => startYCoord + _entityBoat.Step < screenHeight,
|
||||||
|
//Right
|
||||||
|
DirectionType.Right => startXCoord + _entityBoat.Step < screenWidth
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//Изменение направления перемещения
|
||||||
|
public void MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if(!CanMove(direction) || _entityBoat == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch(direction)
|
||||||
|
{
|
||||||
|
case DirectionType.Left:
|
||||||
|
startXCoord -= (int)_entityBoat.Step;
|
||||||
|
break;
|
||||||
|
case DirectionType.Up:
|
||||||
|
startYCoord -= (int)_entityBoat.Step;
|
||||||
|
break;
|
||||||
|
case DirectionType.Right:
|
||||||
|
startXCoord += (int)_entityBoat.Step;
|
||||||
|
break;
|
||||||
|
case DirectionType.Down:
|
||||||
|
startYCoord += (int)_entityBoat.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// конструктор
|
||||||
|
/// </summary>
|
||||||
|
public DrawingBoat(int speed, double weight, Color mainColor, int width, int height)
|
||||||
{
|
{
|
||||||
screenWidth = width;
|
screenWidth = width;
|
||||||
screenHeight = height;
|
screenHeight = height;
|
||||||
_speedBoat = new SpeedBoat();
|
_entityBoat = new EntityBoat(speed, weight, mainColor);
|
||||||
_speedBoat.Init(speed, weight, _isMotor, _isProtectedGlass, mainColor, secondColor);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Проверка на вместимость обьекта в рамки сцены
|
/// Проверка на вместимость обьекта в рамки сцены
|
||||||
@ -56,13 +122,30 @@ namespace SpeedBoatLab
|
|||||||
if ((widthBoat >= screenWidth) || (heightBoat >= screenHeight))
|
if ((widthBoat >= screenWidth) || (heightBoat >= screenHeight))
|
||||||
{
|
{
|
||||||
Console.WriteLine("проверка не пройдена, нельзя создать объект в этих размерах");
|
Console.WriteLine("проверка не пройдена, нельзя создать объект в этих размерах");
|
||||||
return false;
|
if(widthBoat >= screenWidth)
|
||||||
|
{
|
||||||
|
widthBoat = screenWidth - widthBoat;
|
||||||
|
}
|
||||||
|
if (heightBoat >= screenWidth)
|
||||||
|
{
|
||||||
|
heightBoat = screenWidth - heightBoat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Console.WriteLine("объект создан");
|
Console.WriteLine("объект создан");
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// конструктор
|
||||||
|
/// </summary>
|
||||||
|
protected DrawingBoat(int speed, double weight, Color mainColor, int width, int height, int _widthBoat, int _heightBoat)
|
||||||
|
{
|
||||||
|
screenWidth = width;
|
||||||
|
screenHeight = height;
|
||||||
|
widthBoat = _widthBoat;
|
||||||
|
heightBoat = _heightBoat;
|
||||||
|
_entityBoat = new EntityBoat(speed, weight, mainColor);
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -83,9 +166,9 @@ namespace SpeedBoatLab
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Изменение направления перемещения
|
/// Изменение направления перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void MoveTransport(DirectionType direction)
|
public void MoveBoat(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (_speedBoat == null)
|
if (_entityBoat == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -94,30 +177,30 @@ namespace SpeedBoatLab
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (startXCoord - _speedBoat.Step > 0)
|
if (startXCoord - _entityBoat.Step > 0)
|
||||||
{
|
{
|
||||||
startXCoord -= (int)_speedBoat.Step;
|
startXCoord -= (int)_entityBoat.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (startYCoord - _speedBoat.Step > 0)
|
if (startYCoord - _entityBoat.Step > 0)
|
||||||
{
|
{
|
||||||
startYCoord -= (int)_speedBoat.Step;
|
startYCoord -= (int)_entityBoat.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (startXCoord + _speedBoat.Step + widthBoat < screenWidth)
|
if (startXCoord + _entityBoat.Step + widthBoat < screenWidth)
|
||||||
{
|
{
|
||||||
startXCoord += (int)_speedBoat.Step;
|
startXCoord += (int)_entityBoat.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (startYCoord + _speedBoat.Step + heightBoat < screenHeight)
|
if (startYCoord + _entityBoat.Step + heightBoat < screenHeight)
|
||||||
{
|
{
|
||||||
startYCoord += (int)_speedBoat.Step;
|
startYCoord += (int)_entityBoat.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -126,16 +209,15 @@ namespace SpeedBoatLab
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_speedBoat == null)
|
if (_entityBoat == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new SolidBrush(_speedBoat.SecondColor);
|
Brush mainBrush = new SolidBrush(_entityBoat.MainColor);
|
||||||
Brush mainBrush = new SolidBrush(_speedBoat.MainColor);
|
|
||||||
|
|
||||||
#region Координаты переда лодки
|
#region Координаты переда лодки
|
||||||
Point b1 = new Point(startXCoord + 80, startYCoord + 20);
|
Point b1 = new Point(startXCoord + 80, startYCoord + 20);
|
||||||
@ -144,39 +226,14 @@ namespace SpeedBoatLab
|
|||||||
Point[] pointsBoat = { b1, b2, b3 };
|
Point[] pointsBoat = { b1, b2, b3 };
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Координаты защитного стекла
|
|
||||||
Point g1 = new Point(startXCoord + 70, startYCoord + 25);
|
|
||||||
Point g2 = new Point(startXCoord + 80, startYCoord + 20);
|
|
||||||
Point g3 = new Point(startXCoord + 80, startYCoord + 60);
|
|
||||||
Point g4 = new Point(startXCoord + 70, startYCoord + 55);
|
|
||||||
Point[] pointsGlass = { g1, g2, g3, g4 };
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//основа катера
|
//основа катера
|
||||||
g.DrawRectangle(pen, startXCoord + 20, startYCoord + 20, widthBoat - 40, heightBoat - 40);
|
g.DrawRectangle(pen, startXCoord + 20, startYCoord + 20, widthBoat - 40, heightBoat - 40);
|
||||||
g.DrawEllipse(pen, startXCoord + 25, startYCoord + 25, widthBoat - 50, heightBoat - 50);
|
g.DrawEllipse(pen, startXCoord + 25, startYCoord + 25, widthBoat - 50, heightBoat - 50);
|
||||||
g.DrawPolygon(pen, pointsBoat);
|
g.DrawPolygon(pen, pointsBoat);
|
||||||
|
|
||||||
g.FillRectangle(mainBrush, startXCoord + 20, startYCoord + 20, widthBoat - 40, heightBoat - 40);
|
g.FillRectangle(mainBrush, startXCoord + 20, startYCoord + 20, widthBoat - 40, heightBoat - 40);
|
||||||
g.FillEllipse(additionalBrush, startXCoord + 25, startYCoord + 25, widthBoat - 50, heightBoat - 50);
|
g.FillEllipse(mainBrush, startXCoord + 25, startYCoord + 25, widthBoat - 50, heightBoat - 50);
|
||||||
g.FillPolygon(mainBrush, pointsBoat);
|
g.FillPolygon(mainBrush, pointsBoat);
|
||||||
|
|
||||||
|
|
||||||
//мотор
|
|
||||||
if (_speedBoat.isMotor)
|
|
||||||
{
|
|
||||||
g.DrawRectangle(pen, startXCoord + 10, startYCoord + 30, widthBoat - 90, heightBoat - 60);
|
|
||||||
|
|
||||||
g.FillRectangle(additionalBrush, startXCoord + 10, startYCoord + 30, widthBoat - 90, heightBoat - 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
//защитное стекло
|
|
||||||
if (_speedBoat.isProtectedGlass)
|
|
||||||
{
|
|
||||||
g.DrawPolygon(pen, pointsGlass);
|
|
||||||
|
|
||||||
g.FillPolygon(new SolidBrush(Color.Aqua), pointsGlass);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
speed_Boat/speed_Boat/Status.cs
Normal file
15
speed_Boat/speed_Boat/Status.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace speed_Boat.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit = 1,
|
||||||
|
InProgress = 2,
|
||||||
|
Finish = 3
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user