Доработка логики, завершение первой лабораторной работы

This commit is contained in:
malimova 2023-10-02 20:28:53 +04:00
parent c9489b66f7
commit 6e1a5eb9c4
4 changed files with 14 additions and 57 deletions

View File

@ -12,26 +12,12 @@ namespace AirBomber
public EntityAirBomber? EntityAirBomber { get; private set; }
private int _pictureWidth;
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки бобмбардировщика
/// </summary>
private int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки бомбардировщика
/// </summary>
private int _startPosY;
/// <summary>
/// Ширина прорисовки бомбардировщика
/// </summary>
private readonly int _bomberWidth = 150;
/// <summary>
/// Высота прорисовки бомбардировщика
/// </summary>
private readonly int _bomberHeight = 120;
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
private readonly int _bomberWidth = 160;
private readonly int _bomberHeight = 118;
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height)
{
// TODO: Продумать проверки
_pictureWidth = width;
_pictureHeight = height;
if (width < _bomberWidth || height < _bomberHeight)
@ -42,28 +28,20 @@ namespace AirBomber
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, bombsColor, fuelTanks);
return true;
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if (x < 0 || x + _bomberWidth > _pictureWidth)
{
x = 15;
x = _pictureWidth - _bomberWidth;
}
if (y < 0 || y + _bomberHeight > _pictureHeight)
if (y < 0 || y + _bomberWidth > _pictureHeight)
{
y = 15;
y = _pictureHeight - _bomberHeight;
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (EntityAirBomber == null)
@ -109,16 +87,16 @@ namespace AirBomber
Brush bodyColor = new SolidBrush(EntityAirBomber.BodyColor);
Brush bombsColor = new SolidBrush(EntityAirBomber.BombsColor);
Brush wingsColor = new SolidBrush(Color.DeepPink);
// bombs
if (EntityAirBomber.Bombs)
{
g.FillEllipse(bombsColor, _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.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29);
g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15);
g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15);
}
//границы бомбера
g.FillPolygon(additionalBrush, new Point[] //nose
{
new Point(_startPosX + 19, _startPosY + 50),

View File

@ -8,7 +8,6 @@ namespace AirBomber
{
public class EntityAirBomber
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
@ -17,15 +16,6 @@ namespace AirBomber
public Color BombsColor { get; private set; }
public bool FuelTanks { get; private set; }
public double Step => (double)Speed * 100 / Weight;
/// <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>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bombs, Color bombsColor, bool fuelTanks)
{

View File

@ -2,11 +2,7 @@
{
public partial class FormAirBomber : Form
{
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningAirBomber? _drawningAirBomber;
public FormAirBomber()
{
InitializeComponent();
@ -22,11 +18,6 @@
_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();
@ -34,14 +25,11 @@
_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));
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)

View File

@ -7,6 +7,7 @@ namespace AirBomber
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.