Обновлена форма для отображения

This commit is contained in:
Никита Потапов 2023-09-25 23:53:37 +04:00
parent 32c55d0b57
commit 18e8449fdf
3 changed files with 121 additions and 26 deletions

View File

@ -24,7 +24,7 @@ namespace ProjectStormtrooper
/// <param name="height">Высота картинки</param>
public DrawingStormtrooper(int speed, double weight, Color bodyColor,
Color additionalColor, bool rockets, bool bombs,
int width, int height) : base(speed, weight, bodyColor, width, height, 110, 110)
int width, int height) : base(speed, weight, bodyColor, width, height, 140, 90)
{
if (EntityPlane != null)
{

View File

@ -29,11 +29,14 @@
private void InitializeComponent()
{
pictureBoxStormtrooper = new PictureBox();
buttonCreate = new Button();
buttonCreateStormtrooper = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonCreatePlane = new Button();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
SuspendLayout();
//
@ -47,16 +50,16 @@
pictureBoxStormtrooper.TabIndex = 0;
pictureBoxStormtrooper.TabStop = false;
//
// buttonCreate
// buttonCreateStormtrooper
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 412);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(94, 29);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
buttonCreateStormtrooper.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateStormtrooper.Location = new Point(12, 412);
buttonCreateStormtrooper.Name = "buttonCreateStormtrooper";
buttonCreateStormtrooper.Size = new Size(201, 29);
buttonCreateStormtrooper.TabIndex = 1;
buttonCreateStormtrooper.Text = "Создать штурмовик";
buttonCreateStormtrooper.UseVisualStyleBackColor = true;
buttonCreateStormtrooper.Click += buttonCreateStormtrooper_Click;
//
// buttonUp
//
@ -106,16 +109,50 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// buttonCreatePlane
//
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreatePlane.Location = new Point(219, 412);
buttonCreatePlane.Name = "buttonCreatePlane";
buttonCreatePlane.Size = new Size(201, 29);
buttonCreatePlane.TabIndex = 6;
buttonCreatePlane.Text = "Создать самолет";
buttonCreatePlane.UseVisualStyleBackColor = true;
buttonCreatePlane.Click += buttonCreatePlane_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter" });
comboBoxStrategy.Location = new Point(719, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 7;
//
// buttonStep
//
buttonStep.Location = new Point(776, 46);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(94, 29);
buttonStep.TabIndex = 8;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click;
//
// FormStormtrooper
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 453);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreatePlane);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonCreate);
Controls.Add(buttonCreateStormtrooper);
Controls.Add(pictureBoxStormtrooper);
Name = "FormStormtrooper";
StartPosition = FormStartPosition.CenterScreen;
@ -128,10 +165,13 @@
#endregion
private PictureBox pictureBoxStormtrooper;
private Button buttonCreate;
private Button buttonCreateStormtrooper;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private Button buttonCreatePlane;
private ComboBox comboBoxStrategy;
private Button buttonStep;
}
}

View File

@ -8,7 +8,8 @@ namespace ProjectStormtrooper
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawingStormtrooper? _drawingStormtrooper;
private DrawingPlane? _drawingPlane;
private AbstractStrategy? _abstractStrategy;
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
@ -21,25 +22,24 @@ namespace ProjectStormtrooper
/// </summary>
private void Draw()
{
if (_drawingStormtrooper == null)
if (_drawingPlane == null)
{
return;
}
Bitmap bmp = new(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
Graphics g = Graphics.FromImage(bmp);
_drawingStormtrooper.DrawTransport(g);
_drawingPlane.DrawTransport(g);
pictureBoxStormtrooper.Image = bmp;
}
/// <summary>
/// Îáðàáîò÷èê íàæàòèÿ êíîïêè "Ñîçäàòü"
/// Îáðàáîò÷èê íàæàòèÿ êíîïêè "Ñîçäàòü øòóðìîâèê"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_Click(object sender, EventArgs e)
private void buttonCreateStormtrooper_Click(object sender, EventArgs e)
{
Random random = new();
_drawingStormtrooper = new DrawingStormtrooper();
_drawingStormtrooper.Init(
_drawingPlane = new DrawingStormtrooper(
random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
@ -49,7 +49,25 @@ namespace ProjectStormtrooper
pictureBoxStormtrooper.Width,
pictureBoxStormtrooper.Height
);
_drawingStormtrooper.SetPosition(random.Next(10, 100), random.Next(10, 100));
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// Îáðàáîò÷èê íàæàòèÿ êíîïêè "Ñîçäàòü ñàìîëåò"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreatePlane_Click(object sender, EventArgs e)
{
Random random = new();
_drawingPlane = new DrawingPlane(
random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
pictureBoxStormtrooper.Width,
pictureBoxStormtrooper.Height
);
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
@ -59,7 +77,7 @@ namespace ProjectStormtrooper
/// <param name="e"></param>
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingStormtrooper == null)
if (_drawingPlane == null)
{
return;
}
@ -67,19 +85,56 @@ namespace ProjectStormtrooper
switch (buttonName)
{
case "buttonUp":
_drawingStormtrooper.MoveTransport(DirectionType.Up);
_drawingPlane.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingStormtrooper.MoveTransport(DirectionType.Down);
_drawingPlane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingStormtrooper.MoveTransport(DirectionType.Left);
_drawingPlane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingStormtrooper.MoveTransport(DirectionType.Right);
_drawingPlane.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingPlane == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
}