Финальные правки

This commit is contained in:
ShabOl 2023-11-19 00:10:06 +04:00
parent 530345052e
commit a768d109b5
2 changed files with 116 additions and 15 deletions

View File

@ -29,11 +29,14 @@
private void InitializeComponent() private void InitializeComponent()
{ {
BomberPictureBox = new PictureBox(); BomberPictureBox = new PictureBox();
CreateButton = new Button(); ButtonCreateBomberBase = new Button();
ButtonRight = new Button(); ButtonRight = new Button();
ButtonDown = new Button(); ButtonDown = new Button();
ButtonLeft = new Button(); ButtonLeft = new Button();
ButtonUp = new Button(); ButtonUp = new Button();
MovementStrategyComboBox = new ComboBox();
ButtonCreateBomber = new Button();
ButtonPerformMove = new Button();
((System.ComponentModel.ISupportInitialize)BomberPictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)BomberPictureBox).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -47,16 +50,16 @@
BomberPictureBox.TabIndex = 0; BomberPictureBox.TabIndex = 0;
BomberPictureBox.TabStop = false; BomberPictureBox.TabStop = false;
// //
// CreateButton // ButtonCreateBomberBase
// //
CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; ButtonCreateBomberBase.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
CreateButton.Location = new Point(12, 419); ButtonCreateBomberBase.Location = new Point(177, 407);
CreateButton.Name = "CreateButton"; ButtonCreateBomberBase.Name = "ButtonCreateBomberBase";
CreateButton.Size = new Size(75, 30); ButtonCreateBomberBase.Size = new Size(159, 42);
CreateButton.TabIndex = 1; ButtonCreateBomberBase.TabIndex = 1;
CreateButton.Text = "Создать"; ButtonCreateBomberBase.Text = "Создать бомбардировщик";
CreateButton.UseVisualStyleBackColor = true; ButtonCreateBomberBase.UseVisualStyleBackColor = true;
CreateButton.Click += ButtonCreate_Click; ButtonCreateBomberBase.Click += ButtonCreateBomberBase_Click;
// //
// ButtonRight // ButtonRight
// //
@ -106,16 +109,52 @@
ButtonUp.UseVisualStyleBackColor = true; ButtonUp.UseVisualStyleBackColor = true;
ButtonUp.Click += ButtonMove_Click; ButtonUp.Click += ButtonMove_Click;
// //
// MovementStrategyComboBox
//
MovementStrategyComboBox.Anchor = AnchorStyles.Top | AnchorStyles.Right;
MovementStrategyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
MovementStrategyComboBox.FormattingEnabled = true;
MovementStrategyComboBox.Items.AddRange(new object[] { "Перемещать в центр", "Перемещать вправо вниз" });
MovementStrategyComboBox.Location = new Point(706, 12);
MovementStrategyComboBox.Name = "MovementStrategyComboBox";
MovementStrategyComboBox.Size = new Size(166, 23);
MovementStrategyComboBox.TabIndex = 6;
//
// ButtonCreateBomber
//
ButtonCreateBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateBomber.Location = new Point(12, 407);
ButtonCreateBomber.Name = "ButtonCreateBomber";
ButtonCreateBomber.Size = new Size(159, 42);
ButtonCreateBomber.TabIndex = 7;
ButtonCreateBomber.Text = "Создать продвинутый бомбардировщик";
ButtonCreateBomber.UseVisualStyleBackColor = true;
ButtonCreateBomber.Click += ButtonCreateBomber_Click;
//
// ButtonPerformMove
//
ButtonPerformMove.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonPerformMove.Location = new Point(706, 50);
ButtonPerformMove.Name = "ButtonPerformMove";
ButtonPerformMove.Size = new Size(166, 31);
ButtonPerformMove.TabIndex = 8;
ButtonPerformMove.Text = "Сделать шаг";
ButtonPerformMove.UseVisualStyleBackColor = true;
ButtonPerformMove.Click += ButtonPerformStep_Click;
//
// BomberForm // BomberForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461); ClientSize = new Size(884, 461);
Controls.Add(ButtonPerformMove);
Controls.Add(ButtonCreateBomber);
Controls.Add(MovementStrategyComboBox);
Controls.Add(ButtonUp); Controls.Add(ButtonUp);
Controls.Add(ButtonLeft); Controls.Add(ButtonLeft);
Controls.Add(ButtonDown); Controls.Add(ButtonDown);
Controls.Add(ButtonRight); Controls.Add(ButtonRight);
Controls.Add(CreateButton); Controls.Add(ButtonCreateBomberBase);
Controls.Add(BomberPictureBox); Controls.Add(BomberPictureBox);
Name = "BomberForm"; Name = "BomberForm";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
@ -128,10 +167,13 @@
#endregion #endregion
private PictureBox BomberPictureBox; private PictureBox BomberPictureBox;
private Button CreateButton; private Button ButtonCreateBomberBase;
private Button ButtonRight; private Button ButtonRight;
private Button ButtonDown; private Button ButtonDown;
private Button ButtonLeft; private Button ButtonLeft;
private Button ButtonUp; private Button ButtonUp;
private ComboBox MovementStrategyComboBox;
private Button ButtonCreateBomber;
private Button ButtonPerformMove;
} }
} }

View File

@ -1,3 +1,4 @@
using AirBomber.MovementStrategy;
using AirBomber.Rendering; using AirBomber.Rendering;
namespace AirBomber namespace AirBomber
@ -5,6 +6,7 @@ namespace AirBomber
public partial class BomberForm : Form public partial class BomberForm : Form
{ {
private BomberRendererBase? _bomberRenderer; private BomberRendererBase? _bomberRenderer;
private AbstractStrategy? _strategy;
public BomberForm() public BomberForm()
{ {
@ -23,12 +25,11 @@ namespace AirBomber
BomberPictureBox.Image = bmp; BomberPictureBox.Image = bmp;
} }
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreateBomber_Click(object sender, EventArgs e)
{ {
Random random = new Random(); Random random = new Random();
_bomberRenderer = new BomberRendererBase();
_bomberRenderer.Init( _bomberRenderer = new BomberRenderer(
random.Next(100, 300), random.Next(100, 300),
random.Next(1000, 3000), 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)),
@ -38,8 +39,26 @@ namespace AirBomber
BomberPictureBox.Width, BomberPictureBox.Width,
BomberPictureBox.Height BomberPictureBox.Height
); );
_bomberRenderer.SetPosition(random.Next(10, 60), random.Next(10, 60));
MovementStrategyComboBox.Enabled = true;
Draw();
}
private void ButtonCreateBomberBase_Click(object sender, EventArgs e)
{
Random random = new Random();
_bomberRenderer = new BomberRendererBase(
random.Next(100, 200),
random.Next(1000, 1800),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
BomberPictureBox.Width,
BomberPictureBox.Height
);
_bomberRenderer.SetPosition(random.Next(20, 100), random.Next(20, 100)); _bomberRenderer.SetPosition(random.Next(20, 100), random.Next(20, 100));
MovementStrategyComboBox.Enabled = true;
Draw(); Draw();
} }
@ -71,5 +90,45 @@ namespace AirBomber
Draw(); Draw();
} }
private void ButtonPerformStep_Click(object sender, EventArgs e)
{
if (_bomberRenderer is null)
return;
if (MovementStrategyComboBox.Enabled)
{
_strategy = MovementStrategyComboBox.SelectedIndex switch
{
0 => new MoveToCenterStrategy(),
1 => new MoveToDownRightStrategy(),
_ => null,
};
if (_strategy is null)
return;
_strategy.SetData(
new ObjectEntityRenderer(_bomberRenderer),
BomberPictureBox.Width,
BomberPictureBox.Height
);
MovementStrategyComboBox.Enabled = false;
}
if (_strategy is null)
return;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == Status.Finish)
{
MovementStrategyComboBox.Enabled = true;
_strategy = null;
}
}
} }
} }