Новая логика формы FormSportCar

This commit is contained in:
malimova 2023-10-15 21:45:37 +04:00
parent b2213886a7
commit 442ea73375
4 changed files with 64 additions and 43 deletions

View File

@ -22,12 +22,12 @@ namespace AirBomber
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningAirBomber(int speed, double weight, Color bodyColor, Color
additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) :
additionalColor, bool bombs, bool fuelTanks, int width, int height) :
base(speed, weight, bodyColor, width, height, 160, 118)
{
if (EntityAirPlane != null)
{
EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, bombsColor, fuelTanks);
EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks);
}
}
public override void DrawPlane(Graphics g)
@ -38,14 +38,13 @@ namespace AirBomber
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor);
Brush bombsColor = new SolidBrush(airBomber.BombsColor);
base.DrawPlane(g);
// обвесы
g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29);
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 15, 29);
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29);
g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29);
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 70, 15, 29);
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29);
g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15);
g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15);
g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15);
// fueltanks
g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15);

View File

@ -14,11 +14,10 @@ namespace AirBomber
public Color BombsColor { get; private set; }
public bool FuelTanks { get; private set; }
public EntityAirBomber(int speed, double weight, Color bodyColor, Color
additionalColor, bool bombs, Color bombsColor, bool fuelTanks) : base(speed, weight, bodyColor)
additionalColor, bool bombs, bool fuelTanks) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Bombs = bombs;
BombsColor = bombsColor;
FuelTanks = fuelTanks;
}
}

View File

@ -36,7 +36,7 @@
pictureBoxAirBomber = new PictureBox();
comboBoxStrategy = new ComboBox();
buttonCreateAirPlane = new Button();
buttonStep = new Button();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
SuspendLayout();
//
@ -131,23 +131,23 @@
buttonCreateAirPlane.UseVisualStyleBackColor = true;
buttonCreateAirPlane.Click += buttonCreateAirPlane_Click;
//
// buttonStep
// buttonStrategyStep
//
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStep.Location = new Point(862, 77);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(112, 49);
buttonStep.TabIndex = 8;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click;
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStrategyStep.Location = new Point(862, 77);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(112, 49);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
buttonStrategyStep.Click += buttonStrategyStep_Click;
//
// FormAirBomber
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(986, 540);
Controls.Add(buttonStep);
Controls.Add(buttonStrategyStep);
Controls.Add(buttonCreateAirPlane);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonUp);
@ -172,6 +172,6 @@
private PictureBox pictureBoxAirBomber;
private ComboBox comboBoxStrategy;
private Button buttonCreateAirPlane;
private Button buttonStep;
private Button buttonStrategyStep;
}
}

View File

@ -6,10 +6,17 @@
/// <summary>
/// Стратегия перемещения
/// </summary>
private AbstractStrategy? _abstractStrategy;
private AbstractStrategy? _strategy;
/// <summary>
/// Выбранный самолет
/// </summary>
public DrawningAirPlane? SelectedPlane { get; private set; }
public FormAirBomber()
{
InitializeComponent();
_strategy = null;
SelectedPlane = null;
}
private void Draw()
{
@ -25,25 +32,33 @@
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)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO выбор основного цвета
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO выбор дополнительного цвета
_drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
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 buttonCreateAirPlane_Click(object sender, EventArgs e)
{
Random random = new();
_drawningAirPlane = new DrawningAirPlane(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 color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
@ -69,7 +84,7 @@
}
Draw();
}
private void buttonStep_Click(object sender, EventArgs e)
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawningAirPlane == null)
{
@ -77,34 +92,42 @@
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_strategy.SetData(_drawningAirPlane.GetMoveableObject,
pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
}
if (_strategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width,
pictureBoxAirBomber.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
_strategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
if (_strategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
_strategy = null;
}
}
/// <summary>
/// Выбор самолета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectPlane_Click(object sender, EventArgs e)
{
SelectedPlane = _drawningAirPlane;
DialogResult = DialogResult.OK;
}
}
}
}