Compare commits

...

9 Commits
main ... lab2

Author SHA1 Message Date
dfa3c7252c зафиксировать 2023-12-25 20:39:50 +04:00
7e8a612c8c зафиксировать 2023-12-25 19:54:22 +04:00
1dc31cff6b зафиксировать 2023-12-25 02:24:08 +04:00
8c0dce53ae p 2023-12-25 02:10:53 +04:00
05ec3b8972 pfabrcbhjdfnm 2023-12-25 02:09:56 +04:00
ec76794b98 зафиксировать 2023-12-25 01:16:25 +04:00
6295e00999 зафиксировать 2023-12-25 00:13:20 +04:00
126cd2332b зафиксировать 2023-12-10 22:19:19 +04:00
93c5ba6742 зафиксировать 2023-12-10 22:18:33 +04:00
25 changed files with 3299 additions and 0 deletions

25
Boat_Hard/Boat_Hard.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Boat_Hard", "Boat_Hard\Boat_Hard.csproj", "{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6F3D5F9-6B0F-40E6-B0A1-4F6D3783D0CC}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.OLE.Interop" Version="17.8.37221" />
</ItemGroup>
<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>

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,212 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boat_Hard.Entities;
using Boat_Hard.MovementStrategy;
namespace Boat_Hard.DrawningObjects
{
public class DrawningBoat
{
public EntityBoat? EntityBoat { get; protected set; }
public IMoveableObject GetMoveableObject => new DrawningObjectBoat(this);
private int _pictureWidth;
private int _pictureHeight;
public int _startPosX;
public int _startPosY;
private readonly int _boatWidth = 160;
private readonly int _boatHeight = 118;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _boatWidth;
public int GetHeight => _boatHeight;
private IDrawningOars drawningsOars;
//private DrawningOars drawningOars;
//public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool motor, int oars, int width, int height)
//{
// if (width < _boatWidth || height < _boatHeight)
// {
// return false;
// }
// _pictureWidth = width;
// _pictureHeight = height;
// EntityBoat = new EntityBoat();
// EntityBoat.Init(speed, weight, bodyColor, additionalColor, motor, oars);
// drawningOars = new DrawningOars();
// drawningOars.SetAmount(oars);
// return true;
//}
public DrawningBoat(int speed, float weight, Color bodyColor, int width, int height, int oarsNumbers, int oarsShape)
{
if (width < _boatWidth || height < _boatHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityBoat = new EntityBoat(speed, weight, bodyColor);
switch (oarsShape)
{
case 1:
drawningsOars = new DrawningOarsOval();
break;
case 2:
drawningsOars = new DrawningOarsTriangle();
break;
default:
drawningsOars = new DrawningOarsRectangle();
break;
}
drawningsOars.ChangeOarsNumber(oarsNumbers);
}
public void SetPosition(int x, int y)
{
if (x < 0 || x + _boatWidth > _pictureWidth)
{
x = _pictureWidth - _boatWidth;
}
if (y < 0 || y + _boatWidth > _pictureHeight)
{
y = _pictureHeight - _boatHeight;
}
_startPosX = x;
_startPosY = y;
}
public bool CanMove(DirectionType direction)
{
if (EntityBoat == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityBoat.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityBoat.Step > 0,
//вправо
DirectionType.Right => _startPosX + _boatWidth + EntityBoat.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + _boatHeight + EntityBoat.Step < _pictureHeight,
_ => false,
};
}
public void MoveTransport(DirectionType direction)
{
//if (EntityBoat == null)
//{
// return;
//}
//switch (direction)
//{
// case DirectionType.Left:
// if (_startPosX - EntityBoat.Step > 0)
// {
// _startPosX -= (int)EntityBoat.Step;
// }
// break;
// case DirectionType.Up:
// if (_startPosY - EntityBoat.Step > 0)
// {
// _startPosY -= (int)EntityBoat.Step;
// }
// break;
// case DirectionType.Right:
// if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
// {
// _startPosX += (int)EntityBoat.Step;
// }
// break;
// case DirectionType.Down:
// if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
// {
// _startPosY += (int)EntityBoat.Step;
// }
// break;
//}
if (!CanMove(direction) || EntityBoat == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
_startPosX -= (int)EntityBoat.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityBoat.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityBoat.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityBoat.Step;
break;
}
}
//public void DrawBoat(Graphics g)
//{
// if (EntityBoat == null)
// {
// return;
// }
// Pen pen = new(Color.Black);
// Brush additionalBrush = new SolidBrush(EntityBoat.BodyColor);
// Brush mainBrush = new SolidBrush(EntityBoat.AdditionalColor);
// drawningOars.DrawOars(g, _startPosX, _startPosY);
// g.FillRectangle(mainBrush, _startPosX + 20, _startPosY + 20, 150, 90);
// g.DrawEllipse(pen, _startPosX + 30, _startPosY + 30, 130, 70);
// g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY + 30, 130, 70);
// #region Координаты переда лодки
// Point b1 = new Point(_startPosX + 170, _startPosY + 20);
// Point b2 = new Point(_startPosX + 200, _startPosY + 70);
// Point b3 = new Point(_startPosX + 170, _startPosY + 110);
// Point[] pointsBoat = { b1, b2, b3 };
// #endregion
// g.DrawPolygon(pen, pointsBoat);
// g.FillPolygon(mainBrush, pointsBoat);
//}
public virtual void DrawTransport(Graphics g)
{
if (EntityBoat == null)
{
return;
}
Pen pen = new(Color.Black);
Brush mainBrush = new SolidBrush(EntityBoat.BodyColor);
drawningsOars.DrawOarsNumber(g, _startPosX, _startPosY);
g.FillRectangle(mainBrush, _startPosX + 20, _startPosY + 20, 150, 90);
#region Координаты переда лодки
Point b1 = new Point(_startPosX + 170, _startPosY + 20);
Point b2 = new Point(_startPosX + 200, _startPosY + 70);
Point b3 = new Point(_startPosX + 170, _startPosY + 110);
Point[] pointsBoat = { b1, b2, b3 };
#endregion
g.DrawPolygon(pen, pointsBoat);
g.FillPolygon(mainBrush, pointsBoat);
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boat_Hard.Entities;
using Boat_Hard.MovementStrategy;
namespace Boat_Hard.DrawningObjects
{
internal class DrawningMotorboat: DrawningBoat
{
public EntityMotorboat? EntityMotorboat { get; protected set; }
public DrawningMotorboat(int speed, float weight, Color bodyColor,
Color additionalColor, bool ismotor, int oarsNumbers, int oars, int width, int height, int oarsShape) :
base(speed, weight, bodyColor, width, height, oarsNumbers, oarsShape)
{
if (EntityBoat != null)
{
EntityBoat = new EntityMotorboat(speed, weight, bodyColor,
additionalColor, ismotor, oars, oarsNumbers);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityBoat is not EntityMotorboat motorboat)
{
return;
}
Pen pen = new(Color.Black);
Brush brAdditionalColor = new SolidBrush(motorboat.AdditionalColor);
Brush oarsColor = new SolidBrush(Color.Black);
//g.FillPolygon(oarsColor, new Point[] // up
// {
// new Point(_startPosX + 31, _startPosY - 10),
// new Point(_startPosX + 41, _startPosY - 10),
// new Point(_startPosX + 41, _startPosY + 90),
// new Point(_startPosX + 31, _startPosY + 90),
// }
//);
//g.FillPolygon(oarsColor, new Point[] // down
// {
// new Point(_startPosX + 31, _startPosY + 30),
// new Point(_startPosX + 41, _startPosY + 30),
// new Point(_startPosX + 41, _startPosY + 140),
// new Point(_startPosX + 31, _startPosY + 140),
// }
//);
base.DrawTransport(g);
g.DrawEllipse(pen, _startPosX + 30, _startPosY + 30, 130, 70);
g.FillEllipse(brAdditionalColor, _startPosX + 30, _startPosY + 30, 130, 70);
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.DrawningObjects
{
internal class DrawningOarsOval: IDrawningOars
{
public OarsNumbers _oarsNumbers;
public void ChangeOarsNumber(int x)
{
if (x <= 1)
{
_oarsNumbers = OarsNumbers.One;
}
if (x == 2)
{
_oarsNumbers = OarsNumbers.Two;
}
if (x >= 3)
{
_oarsNumbers = OarsNumbers.Three;
}
}
public void DrawOarsNumber(Graphics g, int _startPosX, int _startPosY)
{
Pen pen = new(Color.White);
Brush brBlue = new SolidBrush(Color.Black);
g.FillEllipse(brBlue, _startPosX + 50, _startPosY-11, 12, 100);// up
g.FillEllipse(brBlue, _startPosX + 50, _startPosY +30, 12, 100);// down
if (_oarsNumbers == OarsNumbers.Two || _oarsNumbers == OarsNumbers.Three)
{
g.FillEllipse(brBlue, _startPosX + 80, _startPosY - 11, 12, 100);// up
g.FillEllipse(brBlue, _startPosX + 80, _startPosY + 30, 12, 100);// down
}
if (_oarsNumbers == OarsNumbers.Three)
{
g.FillEllipse(brBlue, _startPosX + 110, _startPosY - 11, 12, 100);// up
g.FillEllipse(brBlue, _startPosX + 110, _startPosY + 30, 12, 100);// down
}
}
}
}

View File

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.DrawningObjects
{
internal class DrawningOarsRectangle: IDrawningOars
{
public OarsNumbers _oarsNumbers;
public void ChangeOarsNumber(int x)
{
if (x <= 1)
{
_oarsNumbers = OarsNumbers.One;
}
if (x == 2)
{
_oarsNumbers = OarsNumbers.Two;
}
if (x >= 3)
{
_oarsNumbers = OarsNumbers.Three;
}
}
public void DrawOarsNumber(Graphics g, int _startPosX, int _startPosY)
{
Pen pen = new(Color.White);
Brush brBlue = new SolidBrush(Color.Black);
g.FillPolygon(brBlue, new Point[] // up
{
new Point(_startPosX + 31, _startPosY - 10),
new Point(_startPosX + 41, _startPosY - 10),
new Point(_startPosX + 41, _startPosY + 90),
new Point(_startPosX + 31, _startPosY + 90),
}
);
g.FillPolygon(brBlue, new Point[] // down
{
new Point(_startPosX + 31, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 140),
new Point(_startPosX + 31, _startPosY + 140),
}
);
if (_oarsNumbers == OarsNumbers.Two || _oarsNumbers == OarsNumbers.Three)
{
g.FillPolygon(brBlue, new Point[] // up
{
new Point(_startPosX + 61, _startPosY - 10),
new Point(_startPosX + 71, _startPosY - 10),
new Point(_startPosX + 71, _startPosY + 90),
new Point(_startPosX + 61, _startPosY + 90),
}
);
g.FillPolygon(brBlue, new Point[] // down
{
new Point(_startPosX + 61, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 140),
new Point(_startPosX + 61, _startPosY + 140),
}
);
}
if (_oarsNumbers == OarsNumbers.Three)
{
g.FillPolygon(brBlue, new Point[] // up
{
new Point(_startPosX + 61, _startPosY - 10),
new Point(_startPosX + 71, _startPosY - 10),
new Point(_startPosX + 71, _startPosY + 90),
new Point(_startPosX + 61, _startPosY + 90),
}
);
g.FillPolygon(brBlue, new Point[] // down
{
new Point(_startPosX + 61, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 140),
new Point(_startPosX + 61, _startPosY + 140),
}
);
}
}
}
}

View File

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.DrawningObjects
{
internal class DrawningOarsTriangle: IDrawningOars
{
public OarsNumbers _oarsNumbers;
public void ChangeOarsNumber(int x)
{
if (x <= 1)
{
_oarsNumbers = OarsNumbers.One;
}
if (x == 2)
{
_oarsNumbers = OarsNumbers.Two;
}
if (x >= 3)
{
_oarsNumbers = OarsNumbers.Three;
}
}
public void DrawOarsNumber(Graphics g, int _startPosX, int _startPosY)
{
Pen pen = new(Color.White);
Brush brBlue = new SolidBrush(Color.Black);
g.FillPolygon(brBlue, new Point[] // up
{
new Point(_startPosX + 31, _startPosY - 10),
new Point(_startPosX + 41, _startPosY - 10),
new Point(_startPosX + 21, _startPosY + 90),
new Point(_startPosX + 31, _startPosY + 90),
}
);
g.FillPolygon(brBlue, new Point[] // down
{
new Point(_startPosX + 31, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 30),
new Point(_startPosX + 21, _startPosY + 140),
new Point(_startPosX + 31, _startPosY + 140),
}
);
if (_oarsNumbers == OarsNumbers.Two || _oarsNumbers == OarsNumbers.Three)
{
g.FillPolygon(brBlue, new Point[] // up
{
new Point(_startPosX + 61, _startPosY - 10),
new Point(_startPosX + 71, _startPosY - 10),
new Point(_startPosX + 51, _startPosY + 90),
new Point(_startPosX + 61, _startPosY + 90),
}
);
g.FillPolygon(brBlue, new Point[] // down
{
new Point(_startPosX + 61, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 30),
new Point(_startPosX + 51, _startPosY + 140),
new Point(_startPosX + 61, _startPosY + 140),
}
);
}
if (_oarsNumbers == OarsNumbers.Three)
{
g.FillPolygon(brBlue, new Point[] // up
{
new Point(_startPosX + 91, _startPosY - 10),
new Point(_startPosX + 101, _startPosY - 10),
new Point(_startPosX + 81, _startPosY + 90),
new Point(_startPosX + 91, _startPosY + 90),
}
);
g.FillPolygon(brBlue, new Point[] // down
{
new Point(_startPosX + 91, _startPosY + 30),
new Point(_startPosX + 101, _startPosY + 30),
new Point(_startPosX + 81, _startPosY + 140),
new Point(_startPosX + 91, _startPosY + 140),
}
);
}
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.Entities
{
public class EntityBoat
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public EntityBoat(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.Entities
{
public class EntityMotorboat: EntityBoat
{
public Color AdditionalColor { get; private set; }
public bool isMotor { get; private set; }
public int Oars { get; private set; }
public int OarsNumbers { get; private set; }
public EntityMotorboat(int speed, double weight, Color bodyColor, Color
additionalColor, bool ismotor, int oars, int oarsNumbers) : base (speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
isMotor = ismotor;
Oars = oars;
OarsNumbers = oarsNumbers;
}
}
}

171
Boat_Hard/Boat_Hard/FormBoat.Designer.cs generated Normal file
View File

@ -0,0 +1,171 @@
namespace Boat_Hard
{
partial class FormBoat
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBoat));
buttonCreate = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonLeft = new Button();
pictureBoxBoat = new PictureBox();
buttonMotorboatCreate = new Button();
comboBoxStrategy = new ComboBox();
button1 = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit();
SuspendLayout();
//
// buttonCreate
//
buttonCreate.Location = new Point(23, 573);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(112, 34);
buttonCreate.TabIndex = 0;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// buttonUp
//
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(936, 525);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 1;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
//
// buttonDown
//
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(936, 577);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 2;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
// buttonRight
//
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(972, 550);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// buttonLeft
//
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(900, 550);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 4;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
//
// pictureBoxBoat
//
pictureBoxBoat.Dock = DockStyle.Fill;
pictureBoxBoat.Location = new Point(0, 0);
pictureBoxBoat.Name = "pictureBoxBoat";
pictureBoxBoat.Size = new Size(1035, 619);
pictureBoxBoat.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxBoat.TabIndex = 5;
pictureBoxBoat.TabStop = false;
//
// buttonMotorboatCreate
//
buttonMotorboatCreate.Location = new Point(141, 573);
buttonMotorboatCreate.Name = "buttonMotorboatCreate";
buttonMotorboatCreate.Size = new Size(196, 34);
buttonMotorboatCreate.TabIndex = 6;
buttonMotorboatCreate.Text = "Создать моторную";
buttonMotorboatCreate.UseVisualStyleBackColor = true;
buttonMotorboatCreate.Click += buttonMotorboatCreate_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
comboBoxStrategy.Location = new Point(853, 0);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(182, 33);
comboBoxStrategy.TabIndex = 7;
comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
//
// button1
//
button1.Location = new Point(903, 39);
button1.Name = "button1";
button1.Size = new Size(99, 34);
button1.TabIndex = 8;
button1.Text = "шаг";
button1.UseVisualStyleBackColor = true;
button1.Click += buttonStep_Click;
//
// FormBoat
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1035, 619);
Controls.Add(button1);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonMotorboatCreate);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxBoat);
Name = "FormBoat";
Text = "FormBoat";
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCreate;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private PictureBox pictureBoxBoat;
private Button buttonMotorboatCreate;
private ComboBox comboBoxStrategy;
private Button button1;
}
}

View File

@ -0,0 +1,121 @@
using Boat_Hard.DrawningObjects;
using Boat_Hard.MovementStrategy;
namespace Boat_Hard
{
public partial class FormBoat : Form
{
private DrawningBoat? _drawningBoat;
private AbstractStrategy? _strategy;
public DrawningBoat? SelectedBoat { get; private set; }
public FormBoat()
{
InitializeComponent();
}
private void Draw()
{
if (_drawningBoat == null)
{
return;
}
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningBoat.DrawTransport(gr);
pictureBoxBoat.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_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)),
pictureBoxBoat.Width, pictureBoxBoat.Height, random.Next(2, 6), random.Next(0, 4));
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningBoat == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningBoat.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningBoat.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningBoat.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningBoat.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonMotorboatCreate_Click(object sender, EventArgs e)
{
Random random = new();
_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)), random.Next(0, 256),
//Convert.ToBoolean(random.Next(0, 2)),
random.Next(1, 4) * 2, pictureBoxBoat.Width, pictureBoxBoat.Height, random.Next(0, 4));
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawningBoat == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(_drawningBoat.GetMoveableObject,
pictureBoxBoat.Width, pictureBoxBoat.Height);
}
if (_strategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_strategy = null;
}
}
private void buttonStep_Click_Click(object sender, EventArgs e)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
internal interface IDrawningOars
{
public void ChangeOarsNumber(int x);
public void DrawOarsNumber(Graphics g, int _startPosX, int _startPosY);
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Boat_Hard.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int
height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boat_Hard.DrawningObjects;
namespace Boat_Hard.MovementStrategy
{
public class DrawningObjectBoat: IMoveableObject
{
private readonly DrawningBoat? _drawningBoat = null;
public DrawningObjectBoat(DrawningBoat drawningBus)
{
_drawningBoat = drawningBus;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningBoat == null || _drawningBoat.EntityBoat == null)
{
return null;
}
return new ObjectParameters(_drawningBoat.GetPosX,
_drawningBoat.GetPosY, _drawningBoat.GetWidth, _drawningBoat.GetHeight);
}
}
public int GetStep => (int)(_drawningBoat?.EntityBoat?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningBoat?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningBoat?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.MovementStrategy
{
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
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 = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.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

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.MovementStrategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
public enum OarsNumbers
{
One,
Two,
Three
}
}

View File

@ -0,0 +1,17 @@
namespace Boat_Hard
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormBoat());
}
}
}

View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Boat_Hard.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.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("Boat_Hard.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;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>