Compare commits

..

No commits in common. "lab_02" and "main" have entirely different histories.
lab_02 ... main

27 changed files with 79 additions and 1327 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "speed_Boat", "speed_Boat\speed_Boat.csproj", "{69814DF7-C284-4ACE-A27E-C43EAA333896}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpeedBoat", "SpeedBoat\SpeedBoat.csproj", "{CA504B35-DFE8-449C-97F5-02C7D392541A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,15 +11,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{69814DF7-C284-4ACE-A27E-C43EAA333896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69814DF7-C284-4ACE-A27E-C43EAA333896}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69814DF7-C284-4ACE-A27E-C43EAA333896}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69814DF7-C284-4ACE-A27E-C43EAA333896}.Release|Any CPU.Build.0 = Release|Any CPU
{CA504B35-DFE8-449C-97F5-02C7D392541A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA504B35-DFE8-449C-97F5-02C7D392541A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA504B35-DFE8-449C-97F5-02C7D392541A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA504B35-DFE8-449C-97F5-02C7D392541A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BAB091BF-94E7-44DA-94F6-70065AB46382}
SolutionGuid = {74698B56-6881-4BCE-9439-4D163E6F4EC5}
EndGlobalSection
EndGlobal

41
SpeedBoat/SpeedBoat/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,41 @@

namespace SpeedBoat
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpeedBoat
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -117,17 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="DOWN" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\DOWN.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="LEFT" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\LEFT.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="RIGHT" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\RIGHT.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="UP" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\UP.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpeedBoatLab
namespace SpeedBoat
{
static class Program
{
@ -17,7 +17,7 @@ namespace SpeedBoatLab
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormSpeedBoat());
Application.Run(new Form1());
}
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>

View File

@ -1,132 +0,0 @@
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;
}
}
}

View File

@ -1,32 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpeedBoatLab.Drawings
{
/// <summary>
/// Направление перемещения
/// </summary>
public enum DirectionType
{
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}
}

View File

@ -1,38 +0,0 @@
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);
}
}

View File

@ -1,57 +0,0 @@
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);
}
}
}

View File

@ -1,43 +0,0 @@
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 EntityBoat
{
/// <summary>
/// Скорость катера
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес самого катера
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color MainColor { get; private set; }
/// <summary>
/// Шаг перемещения катера
/// </summary>
public double Step => (double)Speed * 100 / (Weight);
public EntityBoat(int speed, double weight, Color mainColor)
{
Speed = speed;
Weight = weight;
MainColor = mainColor;
}
}
}

View File

@ -1,41 +0,0 @@
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;
}
}
}

View File

@ -1,190 +0,0 @@

namespace SpeedBoatLab
{
partial class FormSpeedBoat
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxSpeedBoat = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = 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();
this.SuspendLayout();
//
// pictureBoxSpeedBoat
//
this.pictureBoxSpeedBoat.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxSpeedBoat.Location = new System.Drawing.Point(0, 0);
this.pictureBoxSpeedBoat.Name = "pictureBoxSpeedBoat";
this.pictureBoxSpeedBoat.Size = new System.Drawing.Size(800, 450);
this.pictureBoxSpeedBoat.TabIndex = 0;
this.pictureBoxSpeedBoat.TabStop = false;
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.BackColor = System.Drawing.Color.White;
this.buttonCreate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonCreate.Location = new System.Drawing.Point(12, 387);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(103, 51);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать катер";
this.buttonCreate.UseVisualStyleBackColor = false;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::speed_Boat.Properties.Resources.UP;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonUp.Location = new System.Drawing.Point(716, 372);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 10;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::speed_Boat.Properties.Resources.LEFT;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonLeft.Location = new System.Drawing.Point(680, 408);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 9;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::speed_Boat.Properties.Resources.DOWN;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonDown.Location = new System.Drawing.Point(716, 408);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 8;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::speed_Boat.Properties.Resources.RIGHT;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonRight.Location = new System.Drawing.Point(752, 408);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 7;
this.buttonRight.UseVisualStyleBackColor = true;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
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.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxSpeedBoat);
this.Name = "FormSpeedBoat";
this.Text = "Движение катера";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSpeedBoat)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBoxSpeedBoat;
private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.Button buttonUp;
private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonDown;
private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button StepButton;
private System.Windows.Forms.Button buttonCreateSpeedBoat;
}
}

View File

@ -1,150 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SpeedBoatLab.Drawings;
using SpeedBoatLab.Entity;
using speed_Boat.MovementStrategy;
namespace SpeedBoatLab
{
public partial class FormSpeedBoat : Form
{
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawingBoat? _boatMovement;
/// <summary>
/// Стратегия перемещения
/// </summary>
private AbstractStrategy? _abstractStrategy;
public FormSpeedBoat()
{
InitializeComponent();
}
/// <summary>
/// Метод прорисовки лодки
/// </summary>
private void Draw()
{
if (_boatMovement == null)
{
return;
}
Bitmap bmp = new(pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_boatMovement.DrawTransport(gr);
pictureBoxSpeedBoat.Image = bmp;
}
/// <summary>
/// Обработка создания обьекта
/// </summary>
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_boatMovement = new DrawingBoat(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
//startXCoord and startYCoord
_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();
}
/// <summary>
/// Обработка движения обьекта
/// </summary>
private void buttonMove_Click(object sender, EventArgs e)
{
if (_boatMovement == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_boatMovement.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_boatMovement.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_boatMovement.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_boatMovement.MoveTransport(DirectionType.Right);
break;
}
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;
}
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,26 +0,0 @@
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);
}
}

View File

@ -1,44 +0,0 @@
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();
}
}
}
}

View File

@ -1,59 +0,0 @@
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();
}
}
}
}
}

View File

@ -1,53 +0,0 @@
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;
}
}
}

View File

@ -1,103 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace speed_Boat.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("speed_Boat.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap DOWN {
get {
object obj = ResourceManager.GetObject("DOWN", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap LEFT {
get {
object obj = ResourceManager.GetObject("LEFT", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap RIGHT {
get {
object obj = ResourceManager.GetObject("RIGHT", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap UP {
get {
object obj = ResourceManager.GetObject("UP", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -1,239 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SpeedBoatLab;
using System.Drawing;
using SpeedBoatLab.Entity;
namespace SpeedBoatLab.Drawings
{
public class DrawingBoat
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityBoat? _entityBoat { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
private int screenWidth;
/// <summary>
/// Высота окна
/// </summary>
private int screenHeight;
/// <summary>
/// Х-координата обьекта
/// </summary>
protected int startXCoord;
/// <summary>
/// Y-координата обьекта
/// </summary>
protected int startYCoord;
/// <summary>
/// Ширина обьекта
/// </summary>
protected readonly int widthBoat = 100;
/// <summary>
/// Высота обьекта
/// </summary>
protected readonly int heightBoat = 80;
/// <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;
screenHeight = height;
_entityBoat = new EntityBoat(speed, weight, mainColor);
/// <summary>
/// Проверка на вместимость обьекта в рамки сцены
/// </summary>
if ((widthBoat >= screenWidth) || (heightBoat >= screenHeight))
{
Console.WriteLine("проверка не пройдена, нельзя создать объект в этих размерах");
if(widthBoat >= screenWidth)
{
widthBoat = screenWidth - widthBoat;
}
if (heightBoat >= screenWidth)
{
heightBoat = screenWidth - heightBoat;
}
}
else
Console.WriteLine("объект создан");
}
/// <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>
public void SetPosition(int x, int y)
{
if ((x + widthBoat > screenWidth) || (y + heightBoat > screenHeight))
{
startXCoord = screenWidth - widthBoat;
startYCoord = screenHeight - heightBoat;
}
else
{
startXCoord = x;
startYCoord = y;
}
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
public void MoveBoat(DirectionType direction)
{
if (_entityBoat == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (startXCoord - _entityBoat.Step > 0)
{
startXCoord -= (int)_entityBoat.Step;
}
break;
//вверх
case DirectionType.Up:
if (startYCoord - _entityBoat.Step > 0)
{
startYCoord -= (int)_entityBoat.Step;
}
break;
// вправо
case DirectionType.Right:
if (startXCoord + _entityBoat.Step + widthBoat < screenWidth)
{
startXCoord += (int)_entityBoat.Step;
}
break;
//вниз
case DirectionType.Down:
if (startYCoord + _entityBoat.Step + heightBoat < screenHeight)
{
startYCoord += (int)_entityBoat.Step;
}
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
public virtual void DrawTransport(Graphics g)
{
if (_entityBoat == null)
{
return;
}
Pen pen = new(Color.Black);
Brush mainBrush = new SolidBrush(_entityBoat.MainColor);
#region Координаты переда лодки
Point b1 = new Point(startXCoord + 80, startYCoord + 20);
Point b2 = new Point(startXCoord + 100, startYCoord + 40);
Point b3 = new Point(startXCoord + 80, startYCoord + 60);
Point[] pointsBoat = { b1, b2, b3 };
#endregion
//основа катера
g.DrawRectangle(pen, startXCoord + 20, startYCoord + 20, widthBoat - 40, heightBoat - 40);
g.DrawEllipse(pen, startXCoord + 25, startYCoord + 25, widthBoat - 50, heightBoat - 50);
g.DrawPolygon(pen, pointsBoat);
g.FillRectangle(mainBrush, startXCoord + 20, startYCoord + 20, widthBoat - 40, heightBoat - 40);
g.FillEllipse(mainBrush, startXCoord + 25, startYCoord + 25, widthBoat - 50, heightBoat - 50);
g.FillPolygon(mainBrush, pointsBoat);
}
}
}

View File

@ -1,15 +0,0 @@
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
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>