This commit is contained in:
Ivan Rotov 2025-02-20 11:35:46 +04:00
parent 449a5c1655
commit 6e2d342101
16 changed files with 583 additions and 187 deletions

View File

@ -1,49 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormTrooper;
public class EntityStormTrooper
{
//speed
public int Speed { get; private set; }
//weight
public double Weight { get; private set; }
//maincolor
public Color BodyColor { get; private set; }
//additionalcolor
public Color AdditionalColor { get; private set; }
public bool BodyRockets { get; private set; }
public bool Bombs { get; private set; }
//movement
public double Step => Speed * 500 / Weight;
public bool Wing { get; private set; }
public void Init(bool wing, int speed, double weight, Color bodyColor, Color additionalColor, bool bodyRockets, bool bombs)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Wing = wing;
BodyRockets = bodyRockets;
Bombs = bombs;
}
}

View File

@ -4,9 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormTrooper;
namespace ProjectStormTrooper.Drawings;
public enum DirectionType
{
Unknown = -1,
Up = 1,
Down = 2,
Left = 3,

View File

@ -0,0 +1,88 @@
using ProjectStormTrooper.Entities;
namespace ProjectStormTrooper.Drawings;
public class DrawingStormTrooper : DrawingStormTrooperSimple
{
private new EntityStormTrooper? EntityStormTrooper { get; set; }
public DrawingStormTrooper(int speed, double weight, Color bodyColor, bool wing, Color additionalColor, bool bodyRockets, bool bombs) : base(speed, weight, bodyColor, wing)
{
EntityStormTrooper = new EntityStormTrooper(speed, weight, bodyColor, wing, additionalColor, bodyRockets, bombs);
}
public override void DrawTransport(Graphics g)
{
if (EntityStormTrooper == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(EntityStormTrooper.BodyColor);
Brush brushBlack = new SolidBrush(EntityStormTrooper.BodyColor);
Brush additionalBrush = new SolidBrush(EntityStormTrooper.AdditionalColor);
if (EntityStormTrooper.BodyRockets)
{
// Толщина толстой палочки ракеты
int rocketWidth = 6;
// Длина толстой палочки ракеты
int rocketLength = 15;
PointF[] rocketsTop =
{
new(_startPosX.Value + 90, _startPosY.Value + 13),
new(_startPosX.Value + 90, _startPosY.Value + 33)
};
PointF[] rocketsBottom =
{
new(_startPosX.Value + 90, _startPosY.Value + 103),
new(_startPosX.Value + 90, _startPosY.Value + 123)
};
// Прорисовка ракет на верхнем крыле
foreach (PointF rocketPos in rocketsTop)
{
// Толстая палочка для ракеты
g.FillRectangle(additionalBrush, rocketPos.X, rocketPos.Y - rocketWidth / 2, rocketLength, rocketWidth);
}
// Прорисовка ракет на нижнем крыле
foreach (PointF rocketPos in rocketsBottom)
{
// Толстая палочка для ракеты
g.FillRectangle(additionalBrush, rocketPos.X, rocketPos.Y - rocketWidth / 2, rocketLength, rocketWidth);
}
}
// Прорисовка бомб под крыльями
if (EntityStormTrooper.Bombs)
{
int bombWidth = 10;
int bombHeight = 10;
// Позиции бомб под верхним и нижним крылом
PointF[] bombs =
{
new(_startPosX.Value + 75, _startPosY.Value + 15), // Под верхним крылом
new(_startPosX.Value + 75, _startPosY.Value + 105) // Под нижним крылом
};
// Рисуем бомбы
foreach (PointF bombPos in bombs)
{
g.FillEllipse(additionalBrush, bombPos.X, bombPos.Y, bombWidth, bombHeight);
g.DrawEllipse(pen, bombPos.X, bombPos.Y, bombWidth, bombHeight);
}
}
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
}
}

View File

@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectStormTrooper.Entities;
namespace ProjectStormTrooper;
namespace ProjectStormTrooper.Drawings;
public class DrawingStormTrooper
public class DrawingStormTrooperSimple
{
public EntityStormTrooper? EntityStormTrooper { get; private set; }
public EntityStormTrooperSimple? EntityStormTrooper { get; protected set; }
//windowswidth
@ -16,29 +12,43 @@ public class DrawingStormTrooper
private int? _pictureHeight;
private int? _startPosX;
protected int? _startPosX;
private int? _startPosY;
protected int? _startPosY;
private readonly int _drawingTrooperWidth = 140;
private readonly int _drawingTrooperHeight = 120;
public void Init(bool wing, int speed, double weight, Color bodyColor, Color additionalColor, bool bodyRockets, bool bombs)
public int? GetPosX => _startPosX;
public int? GetPosY => _startPosY;
public int GetWidth => _drawingTrooperWidth;
public int GetHeight => _drawingTrooperHeight;
private DrawingStormTrooperSimple()
{
EntityStormTrooper = new EntityStormTrooper();
EntityStormTrooper.Init(wing, speed, weight, bodyColor, additionalColor, bodyRockets, bombs);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
public DrawingStormTrooperSimple(int speed, double weight, Color bodyColor, bool wing) : this()
{
EntityStormTrooper = new EntityStormTrooperSimple(speed, weight, bodyColor, wing);
}
protected DrawingStormTrooperSimple(int drawingTrooperWidth, int drawingTrooperHeight) : this()
{
_drawingTrooperWidth = drawingTrooperWidth;
_drawingTrooperHeight = drawingTrooperHeight;
}
public bool SetPictureSize(int width, int height)
{
if (_drawingTrooperHeight > height || _drawingTrooperWidth > width) { return false; }
_pictureWidth = width;
_pictureHeight = height;
@ -88,7 +98,7 @@ public class DrawingStormTrooper
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityStormTrooper.Step + _drawingTrooperHeight< _pictureHeight)
if (_startPosY.Value + EntityStormTrooper.Step + _drawingTrooperHeight < _pictureHeight)
{
_startPosY += (int)EntityStormTrooper.Step;
}
@ -98,7 +108,7 @@ public class DrawingStormTrooper
}
}
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (EntityStormTrooper == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
@ -109,68 +119,11 @@ public class DrawingStormTrooper
{
Width = 2
};
Pen additionalPen = new(EntityStormTrooper.AdditionalColor)
{
Width = 2
};
Brush brushBlack = new SolidBrush(EntityStormTrooper.BodyColor);
Brush additionalBrush = new SolidBrush(EntityStormTrooper.AdditionalColor);
if (EntityStormTrooper.BodyRockets)
{
// Толщина толстой палочки ракеты
int rocketWidth = 6;
// Длина толстой палочки ракеты
int rocketLength = 15;
PointF[] rocketsTop =
{
new(_startPosX.Value + 90, _startPosY.Value + 13),
new(_startPosX.Value + 90, _startPosY.Value + 33)
};
PointF[] rocketsBottom =
{
new(_startPosX.Value + 90, _startPosY.Value + 103),
new(_startPosX.Value + 90, _startPosY.Value + 123)
};
// Прорисовка ракет на верхнем крыле
foreach (PointF rocketPos in rocketsTop)
{
// Толстая палочка для ракеты
g.FillRectangle(additionalBrush, rocketPos.X, rocketPos.Y - (rocketWidth / 2), rocketLength, rocketWidth);
}
// Прорисовка ракет на нижнем крыле
foreach (PointF rocketPos in rocketsBottom)
{
// Толстая палочка для ракеты
g.FillRectangle(additionalBrush, rocketPos.X, rocketPos.Y - (rocketWidth / 2), rocketLength, rocketWidth);
}
}
// Прорисовка бомб под крыльями
if (EntityStormTrooper.Bombs)
{
int bombWidth = 10;
int bombHeight = 15;
// Позиции бомб под верхним и нижним крылом
PointF[] bombs =
{
new(_startPosX.Value + 75, _startPosY.Value + 15), // Под верхним крылом
new(_startPosX.Value + 75, _startPosY.Value + 105) // Под нижним крылом
};
// Рисуем бомбы
foreach (PointF bombPos in bombs)
{
g.FillEllipse(additionalBrush, bombPos.X, bombPos.Y, bombWidth, bombHeight);
g.DrawEllipse(pen, bombPos.X, bombPos.Y, bombWidth, bombHeight);
}
}
// Определение точек основных элементов объекта
PointF[] front =
{

View File

@ -0,0 +1,17 @@
namespace ProjectStormTrooper.Entities;
public class EntityStormTrooper : EntityStormTrooperSimple
{
public Color AdditionalColor { get; private set; }
public bool BodyRockets { get; private set; }
public bool Bombs { get; private set; }
public EntityStormTrooper(int speed, double weight, Color bodyColor, bool wing, Color additionalColor, bool bodyRockets, bool bombs)
: base(speed, weight, bodyColor, wing)
{
AdditionalColor = additionalColor;
BodyRockets = bodyRockets;
Bombs = bombs;
}
}

View File

@ -0,0 +1,19 @@
namespace ProjectStormTrooper.Entities;
public class EntityStormTrooperSimple
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public bool Wing { get; private set; }
public double Step => Speed * 500 / Weight;
public EntityStormTrooperSimple(int speed, double weight, Color bodyColor, bool wing)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
Wing = wing;
}
}

View File

@ -0,0 +1,68 @@
namespace ProjectStormTrooper.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMoveableObject _moveableObject;
private StrategyStatus _state = StrategyStatus.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public StrategyStatus GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
_state = StrategyStatus.NotInit;
return;
}
_state = StrategyStatus.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)
{
return;
}
if (IsTargetDestination())
{
_state = StrategyStatus.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
protected bool MoveRight() => MoveTo(MovementDirection.Right);
protected bool MoveUp() => MoveTo(MovementDirection.Up);
protected bool MoveDown() => MoveTo(MovementDirection.Down);
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != StrategyStatus.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestination();
private bool MoveTo(MovementDirection movementDirection)
{
if (_state != StrategyStatus.InProgress)
{
return false;
}
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
}
}
}

View File

@ -0,0 +1,12 @@

namespace ProjectStormTrooper.MovementStrategy;
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool TryMoveObject(MovementDirection direction);
}

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormTrooper.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestination()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder + GetStep() >= FieldWidth
&& objParams.DownBorder + GetStep() >= FieldWidth;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
}
int diffY = objParams.ObjectMiddleVertical - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
}
}
}

View File

@ -0,0 +1,53 @@
namespace ProjectStormTrooper.MovementStrategy;
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestination()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,49 @@
using ProjectStormTrooper.Drawings;
namespace ProjectStormTrooper.MovementStrategy;
public class MoveableStormTrooper : IMoveableObject
{
private readonly DrawingStormTrooper? _stormTrooper = null;
public MoveableStormTrooper(DrawingStormTrooper stormTrooper)
{
_stormTrooper = stormTrooper;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_stormTrooper == null || _stormTrooper.EntityStormTrooper == null ||
!_stormTrooper.GetPosX.HasValue || !_stormTrooper.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_stormTrooper.GetPosX.Value,
_stormTrooper.GetPosY.Value, _stormTrooper.GetWidth, _stormTrooper.GetHeight);
}
}
public int GetStep => (int)(_stormTrooper?.EntityStormTrooper?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_stormTrooper == null || _stormTrooper.EntityStormTrooper == null)
{
return false;
}
return _stormTrooper.MoveStormTrooper(GetDirectionType(direction));
}
private static DirectionType GetDirectionType(MovementDirection direction)
{
return direction switch
{
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
MovementDirection.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
_ => DirectionType.Unknown,
};
}
}

View File

@ -0,0 +1,11 @@

namespace ProjectStormTrooper.MovementStrategy
{
public enum MovementDirection
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,29 @@
namespace ProjectStormTrooper.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,9 @@
namespace ProjectStormTrooper.MovementStrategy
{
public enum StrategyStatus
{
NotInit,
InProgress,
Finish
}
}

View File

@ -34,6 +34,9 @@
buttonUp = new Button();
buttonDown = new Button();
pictureBox2 = new PictureBox();
comboBox1 = new ComboBox();
buttonCreate2 = new Button();
button1 = new Button();
((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit();
SuspendLayout();
//
@ -42,11 +45,11 @@
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 409);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(94, 29);
buttonCreate.Size = new Size(139, 29);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Create";
buttonCreate.Text = "Базовая версия";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
buttonCreate.Click += ButtonCreateSimple_Click;
//
// buttonLeft
//
@ -107,11 +110,45 @@
pictureBox2.TabStop = false;
pictureBox2.Click += ButtonMove_Click;
//
// comboBox1
//
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "К центру", "К краю" });
comboBox1.Location = new Point(710, 21);
comboBox1.Name = "comboBox1";
comboBox1.Size = new Size(151, 28);
comboBox1.TabIndex = 7;
//
// buttonCreate2
//
buttonCreate2.Location = new Point(157, 409);
buttonCreate2.Name = "buttonCreate2";
buttonCreate2.Size = new Size(194, 29);
buttonCreate2.TabIndex = 8;
buttonCreate2.Text = "С ракетами и бомбами";
buttonCreate2.UseVisualStyleBackColor = true;
buttonCreate2.Click += ButtonCreate_Click;
//
// button1
//
button1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
button1.Location = new Point(710, 55);
button1.Name = "button1";
button1.Size = new Size(151, 29);
button1.TabIndex = 9;
button1.Text = "Шаг";
button1.UseVisualStyleBackColor = true;
button1.Click += ButtonStrategy_Click;
//
// StormTrooperForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 453);
Controls.Add(button1);
Controls.Add(buttonCreate2);
Controls.Add(comboBox1);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
@ -121,7 +158,6 @@
Name = "StormTrooperForm";
StartPosition = FormStartPosition.CenterScreen;
Text = "StormTrooperForm";
Load += StormTrooperForm_Load;
Click += ButtonMove_Click;
((System.ComponentModel.ISupportInitialize)pictureBox2).EndInit();
ResumeLayout(false);
@ -135,5 +171,8 @@
private Button buttonUp;
private Button buttonDown;
private PictureBox pictureBox2;
private ComboBox comboBox1;
private Button buttonCreate2;
private Button button1;
}
}

View File

@ -7,91 +7,145 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectStormTrooper.Drawings;
using ProjectStormTrooper.MovementStrategy;
namespace ProjectStormTrooper
namespace ProjectStormTrooper;
public partial class StormTrooperForm : Form
{
public partial class StormTrooperForm : Form
private DrawingStormTrooperSimple? _drawingStormTrooper;
private AbstractStrategy? _strategy;
public StormTrooperForm()
{
private DrawingStormTrooper? _drawingStormTrooper;
InitializeComponent();
_strategy = null;
}
public StormTrooperForm()
public void Draw()
{
if (_drawingStormTrooper == null)
{
InitializeComponent();
return;
}
Bitmap bmp = new(pictureBox2.Width, pictureBox2.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingStormTrooper.DrawTransport(gr);
pictureBox2.Image = bmp;
}
public void Draw()
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
if (_drawingStormTrooper == null)
{
case nameof(DrawingStormTrooperSimple):
_drawingStormTrooper = new DrawingStormTrooperSimple(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)));
break;
case nameof(DrawingStormTrooper):
_drawingStormTrooper = new DrawingStormTrooper(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)),
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)));
break;
default:
return;
}
Bitmap bmp = new(pictureBox2.Width, pictureBox2.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingStormTrooper.DrawTransport(gr);
pictureBox2.Image = bmp;
}
_drawingStormTrooper.SetPictureSize(pictureBox2.Width,
pictureBox2.Height);
_drawingStormTrooper.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBox1.Enabled = true;
Draw();
}
private void PictureBox2_Click(object sender, EventArgs e)
private void ButtonCreate_Click(object sender, EventArgs e) =>
CreateObject(nameof(DrawingStormTrooper));
private void ButtonCreateSimple_Click(object sender, EventArgs e) =>
CreateObject(nameof(DrawingStormTrooperSimple));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingStormTrooper == null)
{
return;
}
private void StormTrooperForm_Load(object sender, EventArgs e)
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Up);
break;
case "buttonDown":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Down);
break;
case "buttonLeft":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Left);
break;
case "buttonRight":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Right);
break;
}
private void ButtonCreate_Click(object sender, EventArgs e)
if (result)
{
Random random = new();
_drawingStormTrooper = new DrawingStormTrooper();
_drawingStormTrooper.Init(Convert.ToBoolean(random.Next(0, 2)), 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)));
_drawingStormTrooper.SetPictureSize(pictureBox2.Width,
pictureBox2.Height);
_drawingStormTrooper.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
}
private void ButtonStrategy_Click(object sender, EventArgs e)
{
if (_drawingStormTrooper == null)
{
if (_drawingStormTrooper == null)
return;
}
if (comboBox1.Enabled)
{
_strategy = comboBox1.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(new MoveableStormTrooper((DrawingStormTrooper)_drawingStormTrooper),
pictureBox2.Width, pictureBox2.Height);
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Up);
break;
case "buttonDown":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Down);
break;
case "buttonLeft":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Left);
break;
case "buttonRight":
result =
_drawingStormTrooper.MoveStormTrooper(DirectionType.Right);
break;
}
if (_strategy == null)
{
return;
}
if (result)
{
Draw();
}
comboBox1.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == StrategyStatus.Finish)
{
comboBox1.Enabled = true;
_strategy = null;
}
}
}