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

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()
{
BomberPictureBox = new PictureBox();
CreateButton = new Button();
ButtonCreateBomberBase = new Button();
ButtonRight = new Button();
ButtonDown = new Button();
ButtonLeft = new Button();
ButtonUp = new Button();
MovementStrategyComboBox = new ComboBox();
ButtonCreateBomber = new Button();
ButtonPerformMove = new Button();
((System.ComponentModel.ISupportInitialize)BomberPictureBox).BeginInit();
SuspendLayout();
//
@ -47,16 +50,16 @@
BomberPictureBox.TabIndex = 0;
BomberPictureBox.TabStop = false;
//
// CreateButton
// ButtonCreateBomberBase
//
CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
CreateButton.Location = new Point(12, 419);
CreateButton.Name = "CreateButton";
CreateButton.Size = new Size(75, 30);
CreateButton.TabIndex = 1;
CreateButton.Text = "Создать";
CreateButton.UseVisualStyleBackColor = true;
CreateButton.Click += ButtonCreate_Click;
ButtonCreateBomberBase.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateBomberBase.Location = new Point(177, 407);
ButtonCreateBomberBase.Name = "ButtonCreateBomberBase";
ButtonCreateBomberBase.Size = new Size(159, 42);
ButtonCreateBomberBase.TabIndex = 1;
ButtonCreateBomberBase.Text = "Создать бомбардировщик";
ButtonCreateBomberBase.UseVisualStyleBackColor = true;
ButtonCreateBomberBase.Click += ButtonCreateBomberBase_Click;
//
// ButtonRight
//
@ -106,16 +109,52 @@
ButtonUp.UseVisualStyleBackColor = true;
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
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461);
Controls.Add(ButtonPerformMove);
Controls.Add(ButtonCreateBomber);
Controls.Add(MovementStrategyComboBox);
Controls.Add(ButtonUp);
Controls.Add(ButtonLeft);
Controls.Add(ButtonDown);
Controls.Add(ButtonRight);
Controls.Add(CreateButton);
Controls.Add(ButtonCreateBomberBase);
Controls.Add(BomberPictureBox);
Name = "BomberForm";
StartPosition = FormStartPosition.CenterScreen;
@ -128,10 +167,13 @@
#endregion
private PictureBox BomberPictureBox;
private Button CreateButton;
private Button ButtonCreateBomberBase;
private Button ButtonRight;
private Button ButtonDown;
private Button ButtonLeft;
private Button ButtonUp;
private ComboBox MovementStrategyComboBox;
private Button ButtonCreateBomber;
private Button ButtonPerformMove;
}
}

View File

@ -1,3 +1,4 @@
using AirBomber.MovementStrategy;
using AirBomber.Rendering;
namespace AirBomber
@ -5,6 +6,7 @@ namespace AirBomber
public partial class BomberForm : Form
{
private BomberRendererBase? _bomberRenderer;
private AbstractStrategy? _strategy;
public BomberForm()
{
@ -23,12 +25,11 @@ namespace AirBomber
BomberPictureBox.Image = bmp;
}
private void ButtonCreate_Click(object sender, EventArgs e)
private void ButtonCreateBomber_Click(object sender, EventArgs e)
{
Random random = new Random();
_bomberRenderer = new BomberRendererBase();
_bomberRenderer.Init(
_bomberRenderer = new BomberRenderer(
random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
@ -38,8 +39,26 @@ namespace AirBomber
BomberPictureBox.Width,
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));
MovementStrategyComboBox.Enabled = true;
Draw();
}
@ -71,5 +90,45 @@ namespace AirBomber
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;
}
}
}
}