Compare commits

...

3 Commits

Author SHA1 Message Date
2b478161f0 л2 2023-11-13 14:05:09 +04:00
ce9b9e2d60 лабораторная работа 2 2023-11-13 14:04:53 +04:00
5eb0454b66 зафиксировать всё 2023-10-30 12:05:50 +04:00
63 changed files with 1086 additions and 56 deletions

Binary file not shown.

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using ProjectMotorShip.DrawingObjects;
namespace ProjectMotorShip.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMoveableObject? _movebleObject;
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;
_movebleObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestination())
{
_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 ObjectParametrs? GetObjectParametrs => _movebleObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _movebleObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestination();
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_movebleObject?.CheckCanMove(directionType) ?? false)
{
_movebleObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

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

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectMotorShip.Entities;
namespace ProjectMotorShip.DrawingObjects
{
public class DrawningMotorShip : DrawningShip
{
public DrawningMotorShip(int speed, double weight,
Color mainColor, Color optionalColor, bool pipes,
bool fuelCompartment, int width, int height) :
base(speed, weight, mainColor, width, height, 100, 60)
{
if (EntityShip != null)
{
EntityShip = new EntityMotorShip(speed, weight, mainColor,
optionalColor, pipes, fuelCompartment);
}
}
public override void DrawTrasport(Graphics g)
{
if (EntityShip is not EntityMotorShip motorShip)
{
return;
}
Pen pen = new(Color.Black);
Brush optionalBrush = new SolidBrush(motorShip.OptionalColor);
if (motorShip.Pipes)
{
g.FillRectangle(optionalBrush, _startPosX + 70, _startPosY, 10, 30);
g.FillRectangle(optionalBrush, _startPosX + 50, _startPosY + 10, 10, 20);
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 10, 10, 20);
g.DrawRectangle(pen, _startPosX + 70, _startPosY, 10, 30);
}
if (motorShip.FuelCompartment)
{
g.FillRectangle(optionalBrush, _startPosX + 10, _startPosY + 30, 10, 10);
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 30, 10, 10);
}
_startPosY += 30;
base.DrawTrasport(g);
_startPosY -= 30;
}
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectMotorShip.DrawingObjects;
namespace ProjectMotorShip.MovementStrategy
{
public class DrawningObjectShip : IMoveableObject
{
private readonly DrawningShip? _drawningShip = null;
public DrawningObjectShip(DrawningShip drawningShip)
{
_drawningShip = drawningShip;
}
public ObjectParametrs? GetObjectPosition
{
get
{
if (_drawningShip == null || _drawningShip.EntityShip == null)
{
return null;
}
return new ObjectParametrs(_drawningShip.GetPosX,
_drawningShip.GetPosY, _drawningShip.GetWidth,
_drawningShip.GetHeight);
}
}
public int GetStep => (int)(_drawningShip?.EntityShip?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningShip?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningShip?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectMotorShip.Entities;
namespace ProjectMotorShip.DrawingObjects
{
public class DrawningShip
{
public EntityShip? EntityShip { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _shipWidth = 100;
protected readonly int _shipHeight = 30;
public DrawningShip(int speed, double weight, Color mainColor, int width, int heigth)
{
if (width <= _shipWidth || heigth <= _shipHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = heigth;
EntityShip = new EntityShip(speed, weight, mainColor);
}
protected DrawningShip(int speed, double weight,
Color mainColor, int width, int heigth,
int shipWidth, int shipHeight)
{
if (width <= shipWidth || heigth <= shipHeight)
{
return;
}
_pictureHeight = heigth;
_pictureWidth = width;
_shipHeight = shipHeight;
_shipWidth = shipWidth;
EntityShip = new EntityShip(speed, weight, mainColor);
}
public void SetPosition(int x, int y)
{
if (x < 0 || y < 0 || x + _shipWidth > _pictureWidth || y + _shipHeight > _pictureHeight)
{
x = 10;
y = 10;
}
_startPosX = x;
_startPosY = y;
}
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _shipWidth;
public int GetHeight => _shipHeight;
public bool CanMove(DirectionType direction)
{
if (EntityShip == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityShip.Step > 0,
DirectionType.Up => _startPosY - EntityShip.Step > 0,
DirectionType.Right => _startPosX + EntityShip.Step + _shipWidth <= _pictureWidth,
DirectionType.Down => _startPosY + EntityShip.Step + _shipHeight <= _pictureHeight,
_ => false,
};
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityShip == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
_startPosX -= (int)EntityShip.Step;
break;
case DirectionType.Up:
_startPosY -= (int)EntityShip.Step;
break;
case DirectionType.Right:
_startPosX += (int)EntityShip.Step;
break;
case DirectionType.Down:
_startPosY += (int)EntityShip.Step;
break;
}
}
public virtual void DrawTrasport(Graphics g)
{
if (EntityShip == null)
{
return;
}
Pen pen = new(Color.Black);
Brush mainBrush = new SolidBrush(EntityShip.MainColor);
//палуба
g.FillRectangle(mainBrush, _startPosX + 30, _startPosY, 60, 10);
g.DrawRectangle(pen, _startPosX + 30, _startPosY, 60, 10);
//корпус
g.FillPolygon(mainBrush, new Point[]
{
new Point(_startPosX, _startPosY + 10),
new Point(_startPosX + 100, _startPosY + 10),
new Point(_startPosX + 90, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 30),
new Point(_startPosX, _startPosY + 10),
}
);
g.DrawPolygon(pen, new Point[]
{
new Point(_startPosX, _startPosY + 10),
new Point(_startPosX + 100, _startPosY + 10),
new Point(_startPosX + 90, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 30),
new Point(_startPosX, _startPosY + 10),
}
);
//якорь
g.DrawLine(pen, _startPosX + 25, _startPosY + 15, _startPosX + 25, _startPosY + 25);
g.DrawLine(pen, _startPosX + 20, _startPosY + 20, _startPosX + 30, _startPosY + 20);
g.DrawLine(pen, _startPosX + 23, _startPosY + 25, _startPosX + 27, _startPosY + 25);
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Collections.Specialized.BitVector32;
namespace ProjectMotorShip.Entities
{
public class EntityMotorShip : EntityShip
{
public Color OptionalColor { get; private set; }
public bool Pipes { get; private set; }
public bool FuelCompartment { get; private set; }
public EntityMotorShip(int speed, double weight,
Color mainColor, Color optionalColor,
bool pipes, bool fuelCompartment) : base(speed, weight, mainColor)
{
OptionalColor = optionalColor;
Pipes = pipes;
FuelCompartment = fuelCompartment;
}
}
}

View File

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

View File

@ -1,39 +0,0 @@
namespace ProjectMotorShip
{
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

@ -1,10 +0,0 @@
namespace ProjectMotorShip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

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

View File

@ -0,0 +1,174 @@
namespace ProjectMotorShip
{
partial class MotorShip
{
/// <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.pictureBox1 = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonStep = new System.Windows.Forms.Button();
this.buttonCreateShip = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(882, 453);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(39, 402);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(144, 29);
this.buttonCreate.TabIndex = 1;
this.buttonCreate.Text = "Создать теплоход";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click_1);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectMotorShip.Properties.Resources.стрелка2;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(746, 402);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonRight
//
this.buttonRight.BackgroundImage = global::ProjectMotorShip.Properties.Resources.стрелка;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(818, 402);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectMotorShip.Properties.Resources.стрелка3;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(782, 366);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonDown
//
this.buttonDown.BackgroundImage = global::ProjectMotorShip.Properties.Resources.стрелка1;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(782, 402);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// comboBoxStrategy
//
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"1",
"2"});
this.comboBoxStrategy.Location = new System.Drawing.Point(719, 23);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
this.comboBoxStrategy.TabIndex = 6;
//
// buttonStep
//
this.buttonStep.Location = new System.Drawing.Point(782, 57);
this.buttonStep.Name = "buttonStep";
this.buttonStep.Size = new System.Drawing.Size(88, 29);
this.buttonStep.TabIndex = 7;
this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true;
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
//
// buttonCreateShip
//
this.buttonCreateShip.Location = new System.Drawing.Point(201, 402);
this.buttonCreateShip.Name = "buttonCreateShip";
this.buttonCreateShip.Size = new System.Drawing.Size(153, 29);
this.buttonCreateShip.TabIndex = 8;
this.buttonCreateShip.Text = "Создать корабль";
this.buttonCreateShip.UseVisualStyleBackColor = true;
this.buttonCreateShip.Click += new System.EventHandler(this.buttonCreateShip_Click);
//
// MotorShip
//
this.ClientSize = new System.Drawing.Size(882, 453);
this.Controls.Add(this.buttonCreateShip);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBox1);
this.Name = "MotorShip";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBox1;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private Button buttonDown;
private ComboBox comboBoxStrategy;
private Button buttonStep;
private Button buttonCreateShip;
}
}

View File

@ -0,0 +1,127 @@
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using ProjectMotorShip.DrawingObjects;
using ProjectMotorShip.MovementStrategy;
using Status = ProjectMotorShip.MovementStrategy.Status;
using Button = System.Windows.Forms.Button;
namespace ProjectMotorShip
{
public partial class MotorShip : Form
{
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawningShip? _drawningShip;
private AbstractStrategy? _abstractStrategy;
private object _drawingShip;
public MotorShip()
{
InitializeComponent();
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû
/// </summary>
private void Draw()
{
if (_drawningShip == null)
{
return;
}
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningShip.DrawTrasport(gr); pictureBox1.Image = bmp;
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningShip == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningShip.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningShip.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningShip.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningShip.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonCreate_Click_1(object sender, EventArgs e)
{
Random random = new();
_drawningShip = new DrawningMotorShip(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), /*Convert.ToBoolean(random.Next(0, 2))*/
pictureBox1.Width, pictureBox1.Height);
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawningShip == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(
new DrawningObjectShip(_drawningShip),
pictureBox1.Width,
pictureBox1.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
private void buttonCreateShip_Click(object sender, EventArgs e)
{
Random random = new Random();
_drawningShip = new DrawningShip(
random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
pictureBox1.Width,
pictureBox1.Height);
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
}
}

View File

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

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorShip.MovementStrategy
{
internal class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestination()
{
var objParams = GetObjectParametrs;
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 = GetObjectParametrs;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorShip.MovementStrategy
{
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestination()
{
var objParams = GetObjectParametrs;
if (objParams == null)
{
return false;
}
return
Math.Abs(objParams.ObjectMiddleHorizontal - FieldWidth / 2) <= GetStep()
&&
Math.Abs(objParams.ObjectMiddleVertical - FieldHeight / 2) <= GetStep();
}
protected override void MoveToTarget()
{
var objParams = GetObjectParametrs;
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 ProjectMotorShip.MovementStrategy
{
public class ObjectParametrs
{
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 ObjectParametrs(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -11,7 +11,7 @@ namespace ProjectMotorShip
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new MotorShip());
} }
} }
} }

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </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> </Project>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Compile Update="Form1.cs"> <Compile Update="MotorShip.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectMotorShip.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("ProjectMotorShip.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 стрелка {
get {
object obj = ResourceManager.GetObject("стрелка", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap стрелка1 {
get {
object obj = ResourceManager.GetObject("стрелка1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap стрелка2 {
get {
object obj = ResourceManager.GetObject("стрелка2", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap стрелка3 {
get {
object obj = ResourceManager.GetObject("стрелка3", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -117,4 +117,17 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="стрелка" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\стрелка.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="стрелка2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\стрелка2.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="стрелка1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\стрелка1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="стрелка3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\стрелка3.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

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

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"ProjectMotorShip/1.0.0": {
"runtime": {
"ProjectMotorShip.dll": {}
}
}
}
},
"libraries": {
"ProjectMotorShip/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

View File

@ -0,0 +1,15 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "6.0.0"
}
]
}
}

View File

@ -0,0 +1 @@
556daec231b7e3b877f10be99e1b34a9bd49f3d7

View File

@ -0,0 +1,18 @@
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.csproj.AssemblyReference.cache
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.MotorShip.resources
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.Properties.Resources.resources
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.csproj.GenerateResource.cache
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.GeneratedMSBuildEditorConfig.editorconfig
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.AssemblyInfoInputs.cache
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.AssemblyInfo.cs
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.csproj.CoreCompileInputs.cache
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\bin\Debug\net6.0-windows\ProjectMotorShip.exe
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\bin\Debug\net6.0-windows\ProjectMotorShip.deps.json
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\bin\Debug\net6.0-windows\ProjectMotorShip.runtimeconfig.json
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\bin\Debug\net6.0-windows\ProjectMotorShip.dll
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\bin\Debug\net6.0-windows\ProjectMotorShip.pdb
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.dll
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\refint\ProjectMotorShip.dll
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.pdb
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ProjectMotorShip.genruntimeconfig.cache
C:\Users\Екатерина\OneDrive\Desktop\РПП\ProjectMotorShip\ProjectMotorShip\obj\Debug\net6.0-windows\ref\ProjectMotorShip.dll

View File

@ -0,0 +1 @@
05daa9d4e5f382269d4be57a313a0536afa893c4

View File

@ -0,0 +1 @@
obj\Debug\net6.0-windows\\_IsIncrementalBuild