Pibd-13 Kadyshev M.I. LabWork02 Base #2

Closed
nezui wants to merge 4 commits from LabWork02 into LabWork01
7 changed files with 284 additions and 148 deletions
Showing only changes of commit 2f34b4bdcf - Show all commits

View File

@ -1,4 +1,4 @@
namespace ProjectAirFighter;
namespace ProjectAirFighter.Drawning;
/// <summary>
/// Направление перемещения
/// </summary>

View File

@ -0,0 +1,78 @@
using System.Net.NetworkInformation;
using System.Net.Sockets;
using ProjectAirFighter.Entities;
namespace ProjectAirFighter.Drawning;
/// <summary>
/// класс отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningAirFighter : DrawningWarPlane
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия корпуса</param>
/// <param name="rocket">Признак наличия рокет</param>
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
//public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing)
Review

Закомментированного кода быть не должно

Закомментированного кода быть не должно
public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing) : base(120,140)
{
EntityWarPlane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, rocket, additionalWing);
}
public override void DrawTransport(Graphics g)
{
if (EntityWarPlane == null || EntityWarPlane is not EntityAirFighter warPlane||!_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black, 3);
Pen pen_rocket = new(Color.Black);
Brush brAdd = new SolidBrush(warPlane.AdditionalColor);
//ракеты
if (warPlane.Rocket)
{
Point[] FirstRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 110), new Point(_startPosX.Value + 95, _startPosY.Value + 110),
new Point(_startPosX.Value + 105, _startPosY.Value + 115),new Point(_startPosX.Value + 95, _startPosY.Value + 120),
new Point(_startPosX.Value + 55, _startPosY.Value + 120) };
g.DrawPolygon(pen_rocket, FirstRocket);
Point[] SecondRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 30), new Point(_startPosX.Value + 95, _startPosY.Value + 30),
new Point(_startPosX.Value + 105, _startPosY.Value + 35),new Point(_startPosX.Value + 95, _startPosY.Value + 40),
new Point(_startPosX.Value + 55, _startPosY.Value + 40) };
g.DrawPolygon(pen_rocket, SecondRocket);
g.FillPolygon(brAdd, FirstRocket);
g.FillPolygon(brAdd, SecondRocket);
}
base.DrawTransport(g);
if (warPlane.AdditionalWing)
{
Point[] AddWingLower = { new Point(_startPosX.Value + 60, _startPosY.Value + 80),
new Point(_startPosX.Value + 60, _startPosY.Value + 140), new Point(_startPosX.Value + 50, _startPosY.Value + 140),
new Point(_startPosX.Value + 40, _startPosY.Value + 80) };
g.DrawPolygon(pen, AddWingLower);
Point[] AddWingUpper = { new Point(_startPosX.Value + 60, _startPosY.Value + 60), new Point(_startPosX.Value + 60, _startPosY.Value),
new Point(_startPosX.Value + 50, _startPosY.Value), new Point(_startPosX.Value + 40, _startPosY.Value + 60) };
g.DrawPolygon(pen, AddWingUpper);
g.FillPolygon(brAdd, AddWingUpper);
g.FillPolygon(brAdd, AddWingLower);
}
}
}

View File

@ -1,17 +1,18 @@
using System.Net.NetworkInformation;
using ProjectAirFighter.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirFighter;
namespace ProjectAirFighter.Drawning;
/// <summary>
/// класс отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningAirFighter
public class DrawningWarPlane
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityAirFighter? EntityAirFighter { get; private set; }
public EntityWarPlane? EntityWarPlane { get; protected set; }
/// <summary>
/// Ширина окна
@ -24,46 +25,54 @@ public class DrawningAirFighter
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки истребителя
/// Левая координата прорисовки самолета
/// </summary>
private int? _startPosX;
protected int? _startPosX;
/// <summary>
/// Верхняя координата прорисовки истребителя
/// Верхняя координата прорисовки самолета
/// </summary>
private int? _startPosY;
protected int? _startPosY;
/// <summary>
/// Ширина прорисовки истребителя
/// Ширина прорисовки самолета
/// </summary>
private int? _drawningAirFlighterWidth = 120;
private int? _drawningWarPlaneWidth = 120;
/// <summary>
/// Высота прорисовки истребителя
/// Высота прорисовки самолета
/// </summary>
private int? _drawningAirFlighterHeight = 140;
private int? _drawningWarPlaneHeight = 140;
/// <summary>
/// Иницифлизация полей объекта-класса истребителя
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия корпуса</param>
/// <param name="rocket">Признак наличия рокет</param>
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
//public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing)
public void Init(EntityAirFighter entityAirFighter)
{
EntityAirFighter = entityAirFighter;
//EntityAirFighter.Init(speed, weight, bodyColor, additionalColor, rocket, additionalWing);
private DrawningWarPlane() {
_pictureHeight = null;
_pictureWidth = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningWarPlane(int speed, double weight, Color bodyColor) : this()
{
EntityWarPlane = new EntityWarPlane(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наслдеников
/// </summary>
/// <param name="drawningWarPlaneHeight">Высота прорисовки самолета</param>
/// <param name="drawningWarPlaneWidth">Ширина прорисовки самолета</param>
public DrawningWarPlane(int drawningWarPlaneWidth,int drawningWarPlaneHeight) : this()
{
_drawningWarPlaneWidth = drawningWarPlaneWidth;
_drawningWarPlaneHeight = drawningWarPlaneHeight;
}
/// <summary>
/// Установка границ поля
@ -73,7 +82,7 @@ public class DrawningAirFighter
/// <returns></returns>
public bool SetPictureSize(int width, int height)
{
if (width > _drawningAirFlighterWidth && height > _drawningAirFlighterHeight)
if (width > _drawningWarPlaneWidth && height > _drawningWarPlaneHeight)
{
_pictureWidth = width;
_pictureHeight = height;
@ -87,13 +96,13 @@ public class DrawningAirFighter
{
_startPosY = 0;
}
if (_startPosX.Value + _drawningAirFlighterWidth > _pictureWidth)
if (_startPosX.Value + _drawningWarPlaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningAirFlighterWidth;
_startPosX = _pictureWidth - _drawningWarPlaneWidth;
}
if (_startPosY.Value + _drawningAirFlighterHeight > _pictureHeight)
if (_startPosY.Value + _drawningWarPlaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningAirFlighterHeight;
_startPosY = _pictureHeight - _drawningWarPlaneHeight;
}
}
@ -108,7 +117,7 @@ public class DrawningAirFighter
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
@ -126,13 +135,13 @@ public class DrawningAirFighter
{
_startPosY = 0;
}
if (_startPosX + _drawningAirFlighterWidth > _pictureWidth)
if (_startPosX + _drawningWarPlaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningAirFlighterWidth;
_startPosX = _pictureWidth - _drawningWarPlaneWidth;
}
if (_startPosY + _drawningAirFlighterHeight > _pictureHeight)
if (_startPosY + _drawningWarPlaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningAirFlighterHeight;
_startPosY = _pictureHeight - _drawningWarPlaneHeight;
}
}
@ -148,7 +157,7 @@ public class DrawningAirFighter
/// <returns>true - перемещение выполнено, false - перемещение невозможно </returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityAirFighter == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@ -156,30 +165,30 @@ public class DrawningAirFighter
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityAirFighter.Step > 0)
if (_startPosX.Value - EntityWarPlane.Step > 0)
{
_startPosX -= (int)EntityAirFighter.Step;
_startPosX -= (int)EntityWarPlane.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityAirFighter.Step > 0)
if (_startPosY.Value - EntityWarPlane.Step > 0)
{
_startPosY -= (int)EntityAirFighter.Step;
_startPosY -= (int)EntityWarPlane.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityAirFighter.Step + _drawningAirFlighterHeight < _pictureHeight)
if (_startPosY.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureHeight)
{
_startPosY += (int)EntityAirFighter.Step;
_startPosY += (int)EntityWarPlane.Step;
}
return true;
//вправо
case DirectionType.Right:
if (_startPosX.Value + EntityAirFighter.Step + _drawningAirFlighterWidth < _pictureWidth)
if (_startPosX.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureWidth)
{
_startPosX += (int)EntityAirFighter.Step;
_startPosX += (int)EntityWarPlane.Step;
}
return true;
default:
@ -187,37 +196,19 @@ public class DrawningAirFighter
}
}
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (EntityAirFighter == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black,3);
Pen pen = new(Color.Black, 3);
Pen pen_rocket = new(Color.Black);
Brush brAdd = new SolidBrush(EntityAirFighter.AdditionalColor);
//ракеты
if (EntityAirFighter.Rocket)
{
Point[] FirstRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 110), new Point(_startPosX.Value + 95, _startPosY.Value + 110),
new Point(_startPosX.Value + 105, _startPosY.Value + 115),new Point(_startPosX.Value + 95, _startPosY.Value + 120),
new Point(_startPosX.Value + 55, _startPosY.Value + 120) };
g.DrawPolygon(pen_rocket, FirstRocket);
Point[] SecondRocket = { new Point(_startPosX.Value + 55, _startPosY.Value + 30), new Point(_startPosX.Value + 95, _startPosY.Value + 30),
new Point(_startPosX.Value + 105, _startPosY.Value + 35),new Point(_startPosX.Value + 95, _startPosY.Value + 40),
new Point(_startPosX.Value + 55, _startPosY.Value + 40) };
g.DrawPolygon(pen_rocket, SecondRocket);
g.FillPolygon(brAdd, FirstRocket);
g.FillPolygon(brAdd, SecondRocket);
}
//корпус
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 100, 20);
Point[] body = { new Point(_startPosX.Value + 100, _startPosY.Value + 80),
Point[] body = { new Point(_startPosX.Value + 100, _startPosY.Value + 80),
new Point(_startPosX.Value + 120, _startPosY.Value + 70), new Point(_startPosX.Value + 100, _startPosY.Value + 60) };
g.DrawPolygon(pen, body);
//нижнее крыло
@ -226,7 +217,7 @@ public class DrawningAirFighter
new Point(_startPosX.Value + 60, _startPosY.Value + 80) };
g.DrawPolygon(pen, wingUpper);
//верхнее крыло
Point[] wingLower = { new Point(_startPosX.Value + 80, _startPosY.Value + 60), new Point(_startPosX.Value + 80, _startPosY.Value),
Point[] wingLower = { new Point(_startPosX.Value + 80, _startPosY.Value + 60), new Point(_startPosX.Value + 80, _startPosY.Value),
new Point(_startPosX.Value + 70, _startPosY.Value), new Point(_startPosX.Value + 60, _startPosY.Value + 60) };
g.DrawPolygon(pen, wingLower);
//задние крылья
@ -239,33 +230,20 @@ public class DrawningAirFighter
new Point(_startPosX.Value, _startPosY.Value + 110),new Point(_startPosX.Value + 25, _startPosY.Value + 90),
new Point(_startPosX.Value + 25, _startPosY.Value + 80) };
g.DrawPolygon(pen, rearWingLower);
//залив носа
Brush brBlack = new SolidBrush(Color.Black);
g.FillPolygon(brBlack, body);
//залив корпуса
Brush br = new SolidBrush(EntityAirFighter.BodyColor);
Brush br = new SolidBrush(EntityWarPlane.BodyColor);
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 100, 20);
g.FillPolygon(br, wingLower);
g.FillPolygon(br, wingUpper);
g.FillPolygon(br, rearWingUpper);
g.FillPolygon(br, rearWingLower);
if (EntityAirFighter.AdditionalWing)
{
Point[] AddWingLower = { new Point(_startPosX.Value + 60, _startPosY.Value + 80),
new Point(_startPosX.Value + 60, _startPosY.Value + 140), new Point(_startPosX.Value + 50, _startPosY.Value + 140),
new Point(_startPosX.Value + 40, _startPosY.Value + 80) };
g.DrawPolygon(pen, AddWingLower);
Point[] AddWingUpper = { new Point(_startPosX.Value + 60, _startPosY.Value + 60), new Point(_startPosX.Value + 60, _startPosY.Value),
new Point(_startPosX.Value + 50, _startPosY.Value), new Point(_startPosX.Value + 40, _startPosY.Value + 60) };
g.DrawPolygon(pen, AddWingUpper);
g.FillPolygon(brAdd, AddWingUpper);
g.FillPolygon(brAdd, AddWingLower);
}
}
}
}

View File

@ -1,8 +1,8 @@
namespace ProjectAirFighter;
namespace ProjectAirFighter.Entities;
/// <summary>
/// Класс-сущность "Истребитель"
/// </summary>
public class EntityAirFighter
public class EntityAirFighter : EntityWarPlane
{
/// <summary>
/// Скорость
@ -48,11 +48,9 @@ public class EntityAirFighter
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="rocket">Признак наличия рокет</param>
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing)
public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing) :base(speed, weight, bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Rocket = rocket;
AdditionalWing = additionalWing;
@ -60,4 +58,4 @@ public class EntityAirFighter
}
}

View File

@ -0,0 +1,43 @@
namespace ProjectAirFighter.Entities;
/// <summary>
/// Класс-сущность "Военный самолет"
/// </summary>
public class EntityWarPlane
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Конструктор сущности
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="rocket">Признак наличия рокет</param>
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
public EntityWarPlane(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@ -34,6 +34,7 @@
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonCreateWarPlane = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit();
SuspendLayout();
//
@ -41,22 +42,19 @@
//
pictureBoxAirFighter.Dock = DockStyle.Fill;
pictureBoxAirFighter.Location = new Point(0, 0);
pictureBoxAirFighter.Margin = new Padding(3, 4, 3, 4);
pictureBoxAirFighter.Name = "pictureBoxAirFighter";
pictureBoxAirFighter.Size = new Size(1056, 743);
pictureBoxAirFighter.Size = new Size(924, 557);
pictureBoxAirFighter.TabIndex = 0;
pictureBoxAirFighter.TabStop = false;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(14, 635);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Location = new Point(0, 522);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.Size = new Size(232, 23);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать";
buttonCreate.Text = "Создать истребитель";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
@ -65,10 +63,9 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(897, 680);
buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Location = new Point(785, 510);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(40, 47);
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.ClientSizeChanged += FormAirFighter_SizeChanged;
@ -79,10 +76,9 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.up;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(946, 625);
buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Location = new Point(828, 469);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(40, 47);
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.ClientSizeChanged += FormAirFighter_SizeChanged;
@ -93,10 +89,9 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(946, 680);
buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Location = new Point(828, 510);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(40, 47);
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.ClientSizeChanged += FormAirFighter_SizeChanged;
@ -107,27 +102,37 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(993, 680);
buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Location = new Point(869, 510);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(40, 47);
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.ClientSizeChanged += FormAirFighter_SizeChanged;
buttonRight.Click += ButtonMove_Click;
//
// buttonCreateWarPlane
//
buttonCreateWarPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateWarPlane.Location = new Point(238, 522);
buttonCreateWarPlane.Name = "buttonCreateWarPlane";
buttonCreateWarPlane.Size = new Size(232, 23);
buttonCreateWarPlane.TabIndex = 6;
buttonCreateWarPlane.Text = "Создать военный самолет";
buttonCreateWarPlane.UseVisualStyleBackColor = true;
buttonCreateWarPlane.Click += buttonCreateWarPlane_Click;
//
// FormAirFighter
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1056, 743);
ClientSize = new Size(924, 557);
Controls.Add(buttonCreateWarPlane);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxAirFighter);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAirFighter";
Text = "Истребитель";
SizeChanged += FormAirFighter_SizeChanged;
@ -143,5 +148,6 @@
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateWarPlane;
}
}

View File

@ -7,6 +7,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectAirFighter.Drawning;
using ProjectAirFighter.Entities;
namespace ProjectAirFighter
{
@ -14,43 +16,74 @@ namespace ProjectAirFighter
{
private DrawningAirFighter? _drawningAirFighter;
private DrawningWarPlane? _drawningWarPlane;
private EntityAirFighter? _entityAirFighter;
/// <summary>
/// Стратегия перемещения
/// </summary>
//private AbstractStrategy? _strategy;
/// <summary>
/// Конструктор формы
/// </summary>
public FormAirFighter()
{
InitializeComponent();
//_strategy = null;
}
/// <summary>
/// Метод прорисовки
/// </summary>
private void Draw()
{
if (_drawningAirFighter == null) return;
if (_drawningWarPlane == null) return;
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningAirFighter.DrawTransport(gr);
_drawningWarPlane.DrawTransport(gr);
pictureBoxAirFighter.Image = bmp;
}
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningWarPlane):
_drawningWarPlane = new DrawningWarPlane(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256)));
break;
case nameof(DrawningAirFighter):
_drawningWarPlane = new DrawningAirFighter(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)),
Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width,
pictureBoxAirFighter.Height);
_drawningWarPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningAirFighter = new DrawningAirFighter();
_entityAirFighter = new EntityAirFighter();
_entityAirFighter.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)), Convert.ToBoolean(random.Next(0, 2)));
_drawningAirFighter.Init(_entityAirFighter);
_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningAirFighter.SetPosition(random.Next(40, 100), random.Next(40, 100));
Draw();
CreateObject(nameof(DrawningAirFighter));
}
private void buttonCreateWarPlane_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningWarPlane));
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningAirFighter == null)
if (_drawningWarPlane == null)
{
return;
}
@ -60,16 +93,16 @@ namespace ProjectAirFighter
switch (name)
{
case "buttonUp":
result = _drawningAirFighter.MoveTransport(DirectionType.Up);
result = _drawningWarPlane.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningAirFighter.MoveTransport(DirectionType.Down);
result = _drawningWarPlane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningAirFighter.MoveTransport(DirectionType.Left);
result = _drawningWarPlane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningAirFighter.MoveTransport(DirectionType.Right);
result = _drawningWarPlane.MoveTransport(DirectionType.Right);
break;
}
if (result)
@ -81,13 +114,13 @@ namespace ProjectAirFighter
}
private void FormAirFighter_SizeChanged(object sender, EventArgs e)
{
if (_drawningAirFighter == null) return;
if (_drawningWarPlane == null) return;
_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
if (_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height))
if (_drawningWarPlane.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height))
{
Draw();
}