Заполнение класса DrawningAirBomber
This commit is contained in:
parent
ff4b2f7e71
commit
c9489b66f7
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -22,30 +23,23 @@ namespace AirBomber
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки бомбардировщика
|
/// Ширина прорисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _bomberWidth = 110;
|
private readonly int _bomberWidth = 150;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки бомбардировщика
|
/// Высота прорисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _bomberHeight = 60;
|
private readonly int _bomberHeight = 120;
|
||||||
/// <summary>
|
|
||||||
/// Инициализация свойств
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="bombs">Признак наличия бомб</param>
|
|
||||||
/// <param name="fuelTanks">Признак наличия топливных баков</param>
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
|
||||||
/// <param name="height">Высота картинки</param>
|
|
||||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int width, int height)
|
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height)
|
||||||
{
|
{
|
||||||
// TODO: Продумать проверки
|
// TODO: Продумать проверки
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
if (width < _bomberWidth || height < _bomberHeight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
EntityAirBomber = new EntityAirBomber();
|
EntityAirBomber = new EntityAirBomber();
|
||||||
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, fuelTanks);
|
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, bombsColor, fuelTanks);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -55,7 +49,14 @@ namespace AirBomber
|
|||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
// TODO: Изменение x, y
|
if (x < 0 || x + _bomberWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
x = 15;
|
||||||
|
}
|
||||||
|
if (y < 0 || y + _bomberHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y = 15;
|
||||||
|
}
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
@ -71,140 +72,140 @@ namespace AirBomber
|
|||||||
}
|
}
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
//влево
|
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX - EntityAirBomber.Step > 0)
|
if (_startPosX - EntityAirBomber.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityAirBomber.Step;
|
_startPosX -= (int)EntityAirBomber.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вверх
|
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY - EntityAirBomber.Step > 0)
|
if (_startPosY - EntityAirBomber.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityAirBomber.Step;
|
_startPosY -= (int)EntityAirBomber.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// вправо
|
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
// TODO: Продумать логику
|
if (_startPosX + EntityAirBomber.Step + _bomberWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityAirBomber.Step;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
//вниз
|
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
// TODO: Продумать логику
|
if (_startPosY + EntityAirBomber.Step + _bomberHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityAirBomber.Step;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
public void DrawBomber(Graphics g)
|
||||||
/// Прорисовка объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
{
|
||||||
if (EntityAirBomber == null)
|
if (EntityAirBomber == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new
|
Brush additionalBrush = new SolidBrush(EntityAirBomber.AdditionalColor);
|
||||||
SolidBrush(EntityAirBomber.AdditionalColor);
|
Brush bodyColor = new SolidBrush(EntityAirBomber.BodyColor);
|
||||||
// обвесы
|
Brush bombsColor = new SolidBrush(EntityAirBomber.BombsColor);
|
||||||
|
Brush wingsColor = new SolidBrush(Color.DeepPink);
|
||||||
|
// bombs
|
||||||
if (EntityAirBomber.Bombs)
|
if (EntityAirBomber.Bombs)
|
||||||
{
|
{
|
||||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
|
g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29);
|
||||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20,
|
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29);
|
||||||
20);
|
g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29);
|
||||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10,
|
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29);
|
||||||
20, 40);
|
|
||||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15,
|
|
||||||
15);
|
|
||||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45,
|
|
||||||
15, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX + 90,
|
|
||||||
_startPosY, 20, 20);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX + 90,
|
|
||||||
_startPosY + 40, 20, 20);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
|
||||||
_startPosY + 10, 20, 40);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY + 1, 15, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 90,
|
|
||||||
_startPosY + 45, 15, 15);
|
|
||||||
g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
|
|
||||||
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20);
|
|
||||||
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20,
|
|
||||||
40);
|
|
||||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14,
|
|
||||||
15);
|
|
||||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45,
|
|
||||||
14, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY,
|
|
||||||
20, 20);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY +
|
|
||||||
40, 20, 20);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 1,
|
|
||||||
_startPosY + 10, 25, 40);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 5,
|
|
||||||
_startPosY + 1, 15, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 5,
|
|
||||||
_startPosY + 45, 15, 15);
|
|
||||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39,
|
|
||||||
15);
|
|
||||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45,
|
|
||||||
39, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 35,
|
|
||||||
_startPosY + 1, 40, 15);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 35,
|
|
||||||
_startPosY + 45, 40, 15);
|
|
||||||
}
|
}
|
||||||
//границы автомобиля
|
//границы бомбера
|
||||||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20);
|
g.FillPolygon(additionalBrush, new Point[] //nose
|
||||||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20);
|
{
|
||||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20);
|
new Point(_startPosX + 19, _startPosY + 50),
|
||||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
|
new Point(_startPosX + 19, _startPosY + 69),
|
||||||
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
new Point(_startPosX + 1, _startPosY + 59),
|
||||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
|
}
|
||||||
30);
|
);
|
||||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 50, 120, 20); //korpus
|
||||||
//задние фары
|
g.FillPolygon(additionalBrush, new Point[] //up left wing
|
||||||
Brush brRed = new SolidBrush(Color.Red);
|
{
|
||||||
g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20);
|
new Point(_startPosX + 36, _startPosY + 49),
|
||||||
g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20,
|
new Point(_startPosX + 36, _startPosY + 1),
|
||||||
20);
|
new Point(_startPosX + 45, _startPosY + 1),
|
||||||
//передние фары
|
new Point(_startPosX + 55, _startPosY + 49),
|
||||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
}
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
|
);
|
||||||
20);
|
g.FillPolygon(additionalBrush, new Point[] //down left wing
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
{
|
||||||
20);
|
new Point(_startPosX + 36, _startPosY + 71),
|
||||||
//кузов
|
new Point(_startPosX + 36, _startPosY + 116),
|
||||||
Brush br = new SolidBrush(EntityAirBomber.BodyColor);
|
new Point(_startPosX + 45, _startPosY + 116),
|
||||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
new Point(_startPosX + 54, _startPosY + 71),
|
||||||
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
|
}
|
||||||
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
);
|
||||||
//стекла
|
g.FillPolygon(wingsColor, new Point[] //up right wing
|
||||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
{
|
||||||
g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5,
|
new Point(_startPosX + 120, _startPosY + 49),
|
||||||
40);
|
new Point(_startPosX + 120, _startPosY + 42),
|
||||||
g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5,
|
new Point(_startPosX + 140, _startPosY + 7),
|
||||||
40);
|
new Point(_startPosX + 140, _startPosY + 49),
|
||||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35,
|
}
|
||||||
2);
|
);
|
||||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35,
|
g.FillPolygon(wingsColor, new Point[] //down right wing
|
||||||
2);
|
{
|
||||||
//выделяем рамкой крышу
|
new Point(_startPosX + 120, _startPosY + 70),
|
||||||
g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35,
|
new Point(_startPosX + 120, _startPosY + 77),
|
||||||
40);
|
new Point(_startPosX + 140, _startPosY + 112),
|
||||||
g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25,
|
new Point(_startPosX + 140, _startPosY + 70),
|
||||||
30);
|
}
|
||||||
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15,
|
);
|
||||||
30);
|
|
||||||
// крыло
|
g.DrawPolygon(pen, new Point[] //nose
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 20, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 20, _startPosY + 70),
|
||||||
|
new Point(_startPosX, _startPosY + 59),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 19, _startPosY + 49, 121, 21); //корпус
|
||||||
|
g.DrawPolygon(pen, new Point[] //верхнее left крыло
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 35, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 35, _startPosY),
|
||||||
|
new Point(_startPosX + 45, _startPosY),
|
||||||
|
new Point(_startPosX + 55, _startPosY + 49),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawPolygon(pen, new Point[] //нижнее left крыло
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 36, _startPosY + 71),
|
||||||
|
new Point(_startPosX + 36, _startPosY + 116),
|
||||||
|
new Point(_startPosX + 45, _startPosY + 116),
|
||||||
|
new Point(_startPosX + 54, _startPosY + 71),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawPolygon(pen, new Point[] //up right крыло
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 120, _startPosY + 49),
|
||||||
|
new Point(_startPosX + 120, _startPosY + 42),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 7),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 49),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawPolygon(pen, new Point[] //down right крыло
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 120, _startPosY + 70),
|
||||||
|
new Point(_startPosX + 120, _startPosY + 77),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 112),
|
||||||
|
new Point(_startPosX + 140, _startPosY + 70),
|
||||||
|
}
|
||||||
|
);
|
||||||
if (EntityAirBomber.FuelTanks)
|
if (EntityAirBomber.FuelTanks)
|
||||||
{
|
{
|
||||||
g.FillRectangle(additionalBrush, _startPosX, _startPosY
|
g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15);
|
||||||
+ 5, 10, 50);
|
g.DrawRectangle(pen, _startPosX + 63, _startPosY + 34, 20, 15);
|
||||||
g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10,
|
g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 70, 20, 15);
|
||||||
50);
|
g.DrawRectangle(pen, _startPosX + 63, _startPosY + 70, 20, 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ namespace AirBomber
|
|||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
public bool Bombs { get; private set; }
|
public bool Bombs { get; private set; }
|
||||||
|
public Color BombsColor { get; private set; }
|
||||||
public bool FuelTanks { get; private set; }
|
public bool FuelTanks { get; private set; }
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -26,13 +27,14 @@ namespace AirBomber
|
|||||||
/// <param name="bombs">Признак наличия бомб</param>
|
/// <param name="bombs">Признак наличия бомб</param>
|
||||||
/// <param name="fuelTanks">Признак наличия топливных баков</param>
|
/// <param name="fuelTanks">Признак наличия топливных баков</param>
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
public void Init(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool bombs, bool fuelTanks)
|
additionalColor, bool bombs, Color bombsColor, bool fuelTanks)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Bombs = bombs;
|
Bombs = bombs;
|
||||||
|
BombsColor = bombsColor;
|
||||||
FuelTanks = fuelTanks;
|
FuelTanks = fuelTanks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
22
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
@ -33,6 +33,8 @@
|
|||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
|
pictureBoxAirBomber = new PictureBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreate
|
||||||
@ -44,6 +46,7 @@
|
|||||||
buttonCreate.TabIndex = 0;
|
buttonCreate.TabIndex = 0;
|
||||||
buttonCreate.Text = "Создать";
|
buttonCreate.Text = "Создать";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreate.Click += buttonCreate_Click;
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -55,6 +58,7 @@
|
|||||||
buttonDown.Size = new Size(30, 30);
|
buttonDown.Size = new Size(30, 30);
|
||||||
buttonDown.TabIndex = 1;
|
buttonDown.TabIndex = 1;
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -66,6 +70,7 @@
|
|||||||
buttonLeft.Size = new Size(30, 30);
|
buttonLeft.Size = new Size(30, 30);
|
||||||
buttonLeft.TabIndex = 2;
|
buttonLeft.TabIndex = 2;
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
@ -77,6 +82,7 @@
|
|||||||
buttonRight.Size = new Size(30, 30);
|
buttonRight.Size = new Size(30, 30);
|
||||||
buttonRight.TabIndex = 3;
|
buttonRight.TabIndex = 3;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
@ -88,6 +94,17 @@
|
|||||||
buttonUp.Size = new Size(30, 30);
|
buttonUp.Size = new Size(30, 30);
|
||||||
buttonUp.TabIndex = 4;
|
buttonUp.TabIndex = 4;
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxAirBomber
|
||||||
|
//
|
||||||
|
pictureBoxAirBomber.BackColor = SystemColors.Control;
|
||||||
|
pictureBoxAirBomber.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxAirBomber.Location = new Point(0, 0);
|
||||||
|
pictureBoxAirBomber.Name = "pictureBoxAirBomber";
|
||||||
|
pictureBoxAirBomber.Size = new Size(986, 540);
|
||||||
|
pictureBoxAirBomber.TabIndex = 5;
|
||||||
|
pictureBoxAirBomber.TabStop = false;
|
||||||
//
|
//
|
||||||
// FormAirBomber
|
// FormAirBomber
|
||||||
//
|
//
|
||||||
@ -99,8 +116,10 @@
|
|||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonCreate);
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(pictureBoxAirBomber);
|
||||||
Name = "FormAirBomber";
|
Name = "FormAirBomber";
|
||||||
Text = "Form1";
|
Text = "Бомбардировщик";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,5 +130,6 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private PictureBox pictureBoxAirBomber;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,70 @@
|
|||||||
namespace AirBomber
|
namespace AirBomber
|
||||||
{
|
{
|
||||||
public partial class FormAirBomber : Form
|
public partial class FormAirBomber : Form
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект для прорисовки объекта
|
||||||
|
/// </summary>
|
||||||
|
private DrawningAirBomber? _drawningAirBomber;
|
||||||
|
|
||||||
public FormAirBomber()
|
public FormAirBomber()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningAirBomber == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningAirBomber.DrawBomber(gr);
|
||||||
|
pictureBoxAirBomber.Image = bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_drawningAirBomber = new DrawningAirBomber();
|
||||||
|
_drawningAirBomber.Init(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); _drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение размеров формы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningAirBomber == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawningAirBomber.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawningAirBomber.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawningAirBomber.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawningAirBomber.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user