Compare commits
No commits in common. "00d9cfc7d1d78357508ecebf72823e560a17bff8" and "dd3c7079533ba40db2e28da064a7a3ea36ca1719" have entirely different histories.
00d9cfc7d1
...
dd3c707953
@ -1,70 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,7 +15,8 @@ namespace AirBomber
|
|||||||
protected int _startPosY;
|
protected int _startPosY;
|
||||||
protected readonly int _airPlaneWidth = 150;
|
protected readonly int _airPlaneWidth = 150;
|
||||||
protected readonly int _airPlaneHeight = 118;
|
protected readonly int _airPlaneHeight = 118;
|
||||||
public DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height)
|
public DrawningAirPlane(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height)
|
||||||
{
|
{
|
||||||
if (width < _airPlaneWidth || height < _airPlaneHeight)
|
if (width < _airPlaneWidth || height < _airPlaneHeight)
|
||||||
{
|
{
|
||||||
@ -25,7 +26,8 @@ namespace AirBomber
|
|||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor);
|
EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
protected DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height, int airPlaneWidth, int airPlaneHeight)
|
protected DrawningAirPlane(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height, int airPlaneWidth, int airPlaneHeight)
|
||||||
{
|
{
|
||||||
if (width < _airPlaneWidth || height < _airPlaneHeight)
|
if (width < _airPlaneWidth || height < _airPlaneHeight)
|
||||||
{
|
{
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
public class DrawningObjectAirPlane : IMoveableObject
|
|
||||||
{
|
|
||||||
private readonly DrawningAirPlane? _drawningAirPlane = null;
|
|
||||||
public DrawningObjectAirPlane(DrawningAirPlane drawningAirPlane)
|
|
||||||
{
|
|
||||||
_drawningAirPlane = drawningAirPlane;
|
|
||||||
}
|
|
||||||
public ObjectParameters? GetObjectPosition
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_drawningAirPlane == null || _drawningAirPlane.EntityAirPlane == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new ObjectParameters(_drawningAirPlane.GetPosX, _drawningAirPlane.GetPosY, _drawningAirPlane.GetWidth, _drawningAirPlane.GetHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int GetStep => (int)(_drawningAirPlane?.EntityAirPlane?.Step ?? 0);
|
|
||||||
public bool CheckCanMove(DirectionType direction) => _drawningAirPlane?.CanMove(direction) ?? false;
|
|
||||||
public void MoveObject(DirectionType direction) => _drawningAirPlane?.MovePlane(direction);
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,17 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirBomber
|
namespace AirBomber
|
||||||
{
|
{
|
||||||
public class EntityAirPlane
|
internal class EntityAirPlane
|
||||||
{
|
{
|
||||||
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 EntityAirPlane(int speed, double weight, Color bodyColor)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
65
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
65
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
@ -28,28 +28,25 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
buttonCreateAirBomber = new Button();
|
buttonCreate = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
pictureBoxAirBomber = new PictureBox();
|
pictureBoxAirBomber = new PictureBox();
|
||||||
buttonCreateAirPlane = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
|
||||||
buttonStep = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonCreateAirBomber
|
// buttonCreate
|
||||||
//
|
//
|
||||||
buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateAirBomber.Location = new Point(40, 343);
|
buttonCreate.Location = new Point(47, 364);
|
||||||
buttonCreateAirBomber.Name = "buttonCreateAirBomber";
|
buttonCreate.Name = "buttonCreate";
|
||||||
buttonCreateAirBomber.Size = new Size(186, 66);
|
buttonCreate.Size = new Size(186, 45);
|
||||||
buttonCreateAirBomber.TabIndex = 0;
|
buttonCreate.TabIndex = 0;
|
||||||
buttonCreateAirBomber.Text = "Создать бомбардировщик";
|
buttonCreate.Text = "Создать";
|
||||||
buttonCreateAirBomber.UseVisualStyleBackColor = true;
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
buttonCreateAirBomber.Click += buttonCreateAirBomber_Click;
|
buttonCreate.Click += buttonCreate_Click;
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -108,51 +105,16 @@
|
|||||||
pictureBoxAirBomber.TabIndex = 5;
|
pictureBoxAirBomber.TabIndex = 5;
|
||||||
pictureBoxAirBomber.TabStop = false;
|
pictureBoxAirBomber.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreateAirPlane
|
|
||||||
//
|
|
||||||
buttonCreateAirPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreateAirPlane.Location = new Point(248, 343);
|
|
||||||
buttonCreateAirPlane.Name = "buttonCreateAirPlane";
|
|
||||||
buttonCreateAirPlane.Size = new Size(186, 66);
|
|
||||||
buttonCreateAirPlane.TabIndex = 6;
|
|
||||||
buttonCreateAirPlane.Text = "Создать самолёт";
|
|
||||||
buttonCreateAirPlane.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateAirPlane.Click += buttonCreateAirPlane_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
|
||||||
//
|
|
||||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
|
||||||
comboBoxStrategy.Location = new Point(590, 21);
|
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
|
||||||
comboBoxStrategy.Size = new Size(182, 33);
|
|
||||||
comboBoxStrategy.TabIndex = 7;
|
|
||||||
//
|
|
||||||
// buttonStep
|
|
||||||
//
|
|
||||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
||||||
buttonStep.Location = new Point(660, 70);
|
|
||||||
buttonStep.Name = "buttonStep";
|
|
||||||
buttonStep.Size = new Size(112, 34);
|
|
||||||
buttonStep.TabIndex = 8;
|
|
||||||
buttonStep.Text = "Шаг";
|
|
||||||
buttonStep.UseVisualStyleBackColor = true;
|
|
||||||
buttonStep.Click += buttonStep_Click;
|
|
||||||
//
|
|
||||||
// FormAirBomber
|
// FormAirBomber
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
Controls.Add(buttonStep);
|
|
||||||
Controls.Add(comboBoxStrategy);
|
|
||||||
Controls.Add(buttonCreateAirPlane);
|
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonCreateAirBomber);
|
Controls.Add(buttonCreate);
|
||||||
Controls.Add(pictureBoxAirBomber);
|
Controls.Add(pictureBoxAirBomber);
|
||||||
Name = "FormAirBomber";
|
Name = "FormAirBomber";
|
||||||
Text = "Бомбардировщик";
|
Text = "Бомбардировщик";
|
||||||
@ -162,14 +124,11 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Button buttonCreateAirBomber;
|
private Button buttonCreate;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private PictureBox pictureBoxAirBomber;
|
private PictureBox pictureBoxAirBomber;
|
||||||
private Button buttonCreateAirPlane;
|
|
||||||
private ComboBox comboBoxStrategy;
|
|
||||||
private Button buttonStep;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,48 +2,36 @@ namespace AirBomber
|
|||||||
{
|
{
|
||||||
public partial class FormAirBomber : Form
|
public partial class FormAirBomber : Form
|
||||||
{
|
{
|
||||||
private DrawningAirPlane? _drawningAirPlane;
|
private DrawningAirBomber? _drawningAirBomber;
|
||||||
private AbstractStrategy? _abstractStrategy;
|
|
||||||
public FormAirBomber()
|
public FormAirBomber()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningAirPlane == null)
|
if (_drawningAirBomber == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningAirPlane.DrawPlane(gr);
|
_drawningAirBomber.DrawBomber(gr);
|
||||||
pictureBoxAirBomber.Image = bmp;
|
pictureBoxAirBomber.Image = bmp;
|
||||||
}
|
}
|
||||||
private void buttonCreateAirPlane_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000),
|
_drawningAirBomber = new DrawningAirBomber();
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
_drawningAirBomber.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
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)),
|
||||||
|
random.Next(1, 4) * 2, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
|
||||||
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void buttonCreateAirBomber_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
_drawningAirPlane = new DrawningAirBomber(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)),
|
|
||||||
pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
|
||||||
|
|
||||||
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
Draw();
|
|
||||||
|
|
||||||
}
|
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningAirPlane == null)
|
if (_drawningAirBomber == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -51,56 +39,19 @@ namespace AirBomber
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_drawningAirPlane.MovePlane(DirectionType.Up);
|
_drawningAirBomber.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_drawningAirPlane.MovePlane(DirectionType.Down);
|
_drawningAirBomber.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_drawningAirPlane.MovePlane(DirectionType.Left);
|
_drawningAirBomber.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_drawningAirPlane.MovePlane(DirectionType.Right);
|
_drawningAirBomber.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonStep_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawningAirPlane == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (comboBoxStrategy.Enabled)
|
|
||||||
{
|
|
||||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
||||||
switch
|
|
||||||
{
|
|
||||||
0 => new MoveToCenter(),
|
|
||||||
1 => new MoveToBorder(),
|
|
||||||
_ => null,
|
|
||||||
};
|
|
||||||
if (_abstractStrategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_abstractStrategy.SetData(new
|
|
||||||
DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width,
|
|
||||||
pictureBoxAirBomber.Height);
|
|
||||||
comboBoxStrategy.Enabled = false;
|
|
||||||
}
|
|
||||||
if (_abstractStrategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_abstractStrategy.MakeStep();
|
|
||||||
Draw();
|
|
||||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
||||||
{
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
_abstractStrategy = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
public interface IMoveableObject
|
|
||||||
{
|
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
|
||||||
int GetStep { get; }
|
|
||||||
bool CheckCanMove(DirectionType direction);
|
|
||||||
void MoveObject(DirectionType direction);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
public class MoveToBorder : AbstractStrategy
|
|
||||||
{
|
|
||||||
protected override bool IsTargetDestinaion()
|
|
||||||
{
|
|
||||||
var objParams = GetObjectParameters;
|
|
||||||
if (objParams == null) return false;
|
|
||||||
|
|
||||||
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
|
|
||||||
}
|
|
||||||
protected override void MoveToTarget()
|
|
||||||
{
|
|
||||||
var objParams = GetObjectParameters;
|
|
||||||
if (objParams == null) return;
|
|
||||||
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
|
|
||||||
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
public enum Status
|
|
||||||
{
|
|
||||||
NotInit,
|
|
||||||
InProgress,
|
|
||||||
Finish
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user