From cb68550a45e8391e2f2236f960610a7cf3780e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Thu, 22 Sep 2022 05:29:34 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=87=D0=B0=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractMap.cs | 170 ++++++++++++++++++ AirBomber/AirBomber/Direction.cs | 1 + AirBomber/AirBomber/DrawningAirBomber.cs | 67 ++++++++ AirBomber/AirBomber/DrawningAirplane.cs | 48 ++++-- AirBomber/AirBomber/DrawningObject.cs | 40 +++++ AirBomber/AirBomber/EntityAirBomber.cs | 40 +++++ AirBomber/AirBomber/EntityAirplane.cs | 2 +- AirBomber/AirBomber/FormAirBomber.cs | 3 +- AirBomber/AirBomber/FormMap.Designer.cs | 208 +++++++++++++++++++++++ AirBomber/AirBomber/FormMap.cs | 96 +++++++++++ AirBomber/AirBomber/FormMap.resx | 63 +++++++ AirBomber/AirBomber/IDrawningObject.cs | 43 +++++ AirBomber/AirBomber/Program.cs | 2 +- AirBomber/AirBomber/SimpleMap.cs | 50 ++++++ AirBomber/AirBomber/WallMap.cs | 65 +++++++ 15 files changed, 881 insertions(+), 17 deletions(-) create mode 100644 AirBomber/AirBomber/AbstractMap.cs create mode 100644 AirBomber/AirBomber/DrawningAirBomber.cs create mode 100644 AirBomber/AirBomber/DrawningObject.cs create mode 100644 AirBomber/AirBomber/EntityAirBomber.cs create mode 100644 AirBomber/AirBomber/FormMap.Designer.cs create mode 100644 AirBomber/AirBomber/FormMap.cs create mode 100644 AirBomber/AirBomber/FormMap.resx create mode 100644 AirBomber/AirBomber/IDrawningObject.cs create mode 100644 AirBomber/AirBomber/SimpleMap.cs create mode 100644 AirBomber/AirBomber/WallMap.cs diff --git a/AirBomber/AirBomber/AbstractMap.cs b/AirBomber/AirBomber/AbstractMap.cs new file mode 100644 index 0000000..260ad22 --- /dev/null +++ b/AirBomber/AirBomber/AbstractMap.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal abstract class AbstractMap + { + private IDrawningObject _drawningObject = null; + private Bitmap? _staticBitMap; + protected int[,] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected readonly Random _random = new(); + protected readonly int _freeRoad = 0; + protected readonly int _barrier = 1; + + public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject) + { + _staticBitMap = null; + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + + /// Проверяет наличие непроходимых участков в заданной области + /// Заданная область + /// i-ый индекс первого барьера, который был найден в области + /// j-ый индекс первого барьера, который был найден в области + /// Есть ли барьеры + protected bool BarriersInArea(RectangleF area, ref int iBarrier, ref int jBarrier) + { + if (!(0 < area.Left && area.Right < _width && 0 < area.Top && area.Bottom < _height)) + { + return true; // Если область попала за карту, считаем что она столкнулась с барьером + } + int rightArea = (int)Math.Ceiling(area.Right / _size_x); + int bottomArea = (int)Math.Ceiling(area.Bottom / _size_y); + for (int i = (int)(area.Left / _size_x); i < rightArea; i++) + { + for (int j = (int)(area.Top / _size_y); j < bottomArea; j++) + { + if (_map[i, j] == _barrier) + { + iBarrier = i; + jBarrier = j; + return true; + } + } + } + return false; + } + protected bool BarriersInArea(RectangleF area) + { + int a = 0, b = 0; + return BarriersInArea(area, ref a, ref b); + } + + + public Bitmap MoveObject(Direction direction) + { + var rect = _drawningObject.GetCurrentPosition(); + var step = _drawningObject.Step; + // Вычисляем области смещения объекта + RectangleF? area = null; + if (direction == Direction.Left) + area = new(rect.Left - step, rect.Top, step, rect.Height); + else if (direction == Direction.Right) + area = new(rect.Right, rect.Top, step, rect.Height); + else if (direction == Direction.Up) + area = new(rect.Left, rect.Top - step, rect.Width, step); + else if (direction == Direction.Down) + area = new(rect.Left, rect.Bottom, rect.Width, step); + if (area.HasValue && !BarriersInArea(area.Value)) + { + _drawningObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + private bool SetObjectOnMap() + { + if (_drawningObject == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawningObject.SetObject(x, y, _width, _height); + + // Если натыкаемся на барьер помещаем левый верхний угол чуть ниже этого барьера + // если при этом выходим за карту, пермещаем правый нижный угол чуть выше этого барьера + // если объект выходит за карту, генирируем новые координаты рандомно + int currI = 0, currJ = 0; + var areaObject = _drawningObject.GetCurrentPosition(); + int cntOut = 10000; // Количество итераций до выхода из цикла + while (BarriersInArea(areaObject, ref currI, ref currJ) && --cntOut >= 0) + { + if ((currJ + 1) * _size_y + areaObject.Height <= _height) + { + areaObject.Location = new PointF((currI + 1) * _size_x, (currJ + 1) * _size_y); + } + else if ((currI - 1) * _size_x - areaObject.Width >= 0) + { + areaObject = new((currI - 1) * _size_x - areaObject.Width, (currJ - 1) * _size_y - areaObject.Height, areaObject.Width, areaObject.Height); + } + else + { + areaObject.Location = new PointF(_random.Next(0, _width - (int)areaObject.Width), + _random.Next(0, _height - (int)areaObject.Height)); + } + } + _drawningObject.SetObject((int)areaObject.X, (int)areaObject.Y, _width, _height); + return cntOut >= 0; + } + private void DrawMap() + { + if (_staticBitMap != null) return; + _staticBitMap = new(_width, _height); + Graphics gr = Graphics.FromImage(_staticBitMap); + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (_map[i, j] == _freeRoad) + { + DrawRoadPart(gr, i, j); + } + else if (_map[i, j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + } + + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawningObject == null || _map == null) + { + return bmp; + } + Graphics gr = Graphics.FromImage(bmp); + if (_staticBitMap == null) + DrawMap(); + if (_staticBitMap != null) + gr.DrawImage(_staticBitMap, 0, 0); + _drawningObject.DrawningObject(gr); + return bmp; + } + + /// + /// Генерация карты. При перегрузки определить поля _map, _size_x, _size_y + /// + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/Direction.cs b/AirBomber/AirBomber/Direction.cs index 950a2d3..808d3d0 100644 --- a/AirBomber/AirBomber/Direction.cs +++ b/AirBomber/AirBomber/Direction.cs @@ -5,6 +5,7 @@ /// internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs new file mode 100644 index 0000000..2f5da52 --- /dev/null +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class DrawningAirBomber : DrawningAirplane + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолета + /// Цвет обшивки + /// Дополнительный цвет + /// Признак наличия бомб + /// Признак наличия топливных баков + public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) + : base(speed, weight, bodyColor, 115, 155) + { + Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks); + } + + public override void DrawTransport(Graphics g) + { + if (Airplane is not EntityAirBomber airBomber) + { + return; + } + + var x = _startPosX; + var y = _startPosY; + var w = _airplaneWidth; + var h = _airplaneHeight; + Brush brush = new SolidBrush(airBomber.DopColor); + + if (airBomber.HasBombs) // Бомбы снизу рисуются сначала + { + DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 - 19, 23, 10)); + DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 + 9, 23, 10)); + } + + base.DrawTransport(g); + + if (airBomber.HasFuelTanks) + { + g.FillEllipse(brush, new RectangleF(x + w / 4, y + h / 2 - 6, w / 2.5f, 12)); + } + } + + private void DrawBomb(Graphics g, Color colorBomb, RectangleF r) + { + Pen pen = new(colorBomb); + pen.Width = r.Height / 3; + var widthTail = r.Width / 6; + g.FillEllipse(new SolidBrush(colorBomb), r.X, r.Y, r.Width - widthTail, r.Height); // Основание бомбы + // Хвост бомбы + var baseTail = new PointF(r.Right - widthTail, r.Y + r.Height / 2); + g.DrawLine(pen, baseTail, new PointF(r.Right, r.Top)); + g.DrawLine(pen, baseTail, new PointF(r.Right, r.Bottom)); + } + } +} diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs index 3754ad5..cad66c4 100644 --- a/AirBomber/AirBomber/DrawningAirplane.cs +++ b/AirBomber/AirBomber/DrawningAirplane.cs @@ -8,45 +8,58 @@ /// /// Класс-сущность /// - public EntityAirplane Airplane { get; private set; } - + public EntityAirplane Airplane { get; protected set; } + public DrawningAirplaneEngines DrawningEngines { get; private set; } /// /// Левая координата отрисовки автомобиля /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки автомобиля /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// - private int? _pictureWidth = null; + protected int? _pictureWidth = null; /// /// Высота окна отрисовки /// - private int? _pictureHeight = null; + protected int? _pictureHeight = null; /// /// Ширина отрисовки автомобиля /// - private readonly int _airplaneWidth = 110; + protected readonly int _airplaneWidth = 80; /// /// Высота отрисовки автомобиля /// - private readonly int _airplaneHeight = 140; + protected readonly int _airplaneHeight = 90; /// /// Инициализация свойств /// /// Скорость /// Вес самолета /// Цвет обшивки - public void Init(int speed, float weight, Color bodyColor) + public DrawningAirplane(int speed, float weight, Color bodyColor) { - Airplane = new EntityAirplane(); - Airplane.Init(speed, weight, bodyColor); + Airplane = new EntityAirplane(speed, weight, bodyColor); DrawningEngines = new(); - DrawningEngines.CountEngines = 6; + } + + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолета + /// Цвет обшивки + /// Ширина отрисовки самолета + /// Высота отрисовки самолета + protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : + this(speed, weight, bodyColor) + { + _airplaneWidth = airplaneWidth; + _airplaneHeight = airplaneHeight; } /// /// Установка позиции самолета @@ -116,7 +129,7 @@ /// Отрисовка самолета /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -198,5 +211,14 @@ _startPosY = _pictureHeight.Value - _airplaneHeight; } } + + /// + /// Получение текущей позиции объекта + /// + /// + public RectangleF GetCurrentPosition() + { + return new(_startPosX, _startPosY, _airplaneWidth, _airplaneHeight); + } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs new file mode 100644 index 0000000..d79a291 --- /dev/null +++ b/AirBomber/AirBomber/DrawningObject.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class DrawningObject : IDrawningObject + { + private DrawningAirplane _airplane = null; + + public DrawningObject(DrawningAirplane airplane) + { + _airplane = airplane; + } + + public float Step => _airplane?.Airplane?.Step ?? 0; + + public RectangleF GetCurrentPosition() + { + return _airplane.GetCurrentPosition(); + } + + public void MoveObject(Direction direction) + { + _airplane?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _airplane.SetPosition(x, y, width, height); + } + + void IDrawningObject.DrawningObject(Graphics g) + { + _airplane.DrawTransport(g); + } + } +} diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs new file mode 100644 index 0000000..8e5ace5 --- /dev/null +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class EntityAirBomber : EntityAirplane + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия бомб + /// + public bool HasBombs { get; private set; } + /// + /// Признак наличия топливных баков + /// + public bool HasFuelTanks { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия бомб + /// Признак наличия топливных баков + public EntityAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + HasBombs = hasBombs; + HasFuelTanks = hasFuelTanks; + } + } +} diff --git a/AirBomber/AirBomber/EntityAirplane.cs b/AirBomber/AirBomber/EntityAirplane.cs index bd6810f..2869683 100644 --- a/AirBomber/AirBomber/EntityAirplane.cs +++ b/AirBomber/AirBomber/EntityAirplane.cs @@ -28,7 +28,7 @@ /// /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityAirplane(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 94c2e7c..d57444b 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -26,8 +26,7 @@ namespace AirBomber private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _airplane = new DrawningAirplane(); - _airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _airplane.DrawningEngines.CountEngines = (int)countEngineBox.Value; _airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}"; diff --git a/AirBomber/AirBomber/FormMap.Designer.cs b/AirBomber/AirBomber/FormMap.Designer.cs new file mode 100644 index 0000000..54ebe8b --- /dev/null +++ b/AirBomber/AirBomber/FormMap.Designer.cs @@ -0,0 +1,208 @@ +namespace AirBomber +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBoxCar = new System.Windows.Forms.PictureBox(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit(); + this.statusStrip.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxCar + // + this.pictureBoxCar.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxCar.Location = new System.Drawing.Point(0, 0); + this.pictureBoxCar.Name = "pictureBoxCar"; + this.pictureBoxCar.Size = new System.Drawing.Size(800, 428); + this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxCar.TabIndex = 0; + this.pictureBoxCar.TabStop = false; + // + // statusStrip + // + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip.Location = new System.Drawing.Point(0, 428); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(800, 22); + this.statusStrip.TabIndex = 1; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость:"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17); + this.toolStripStatusLabelWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + // + // buttonCreate + // + this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreate.Location = new System.Drawing.Point(12, 390); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(722, 350); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 3; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(686, 386); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(758, 386); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 5; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(722, 386); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 6; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonCreateModif + // + this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModif.Location = new System.Drawing.Point(104, 390); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Карта со стенами"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); + this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.buttonCreateModif); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxCar); + this.Controls.Add(this.statusStrip); + this.Name = "FormMap"; + this.Text = "Карта"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit(); + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxCar; + private StatusStrip statusStrip; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button buttonCreate; + private Button buttonUp; + private Button buttonLeft; + private Button buttonRight; + private Button buttonDown; + private Button buttonCreateModif; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMap.cs b/AirBomber/AirBomber/FormMap.cs new file mode 100644 index 0000000..c311927 --- /dev/null +++ b/AirBomber/AirBomber/FormMap.cs @@ -0,0 +1,96 @@ +using AirBomber; + +namespace AirBomber +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + /// + /// Заполнение информации по объекту + /// + /// + private void SetData(DrawningAirplane car) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {car.Airplane.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {car.Airplane.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {car.Airplane.BodyColor.Name}"; + pictureBoxCar.Image = _abstractMap.CreateMap(pictureBoxCar.Width, pictureBoxCar.Height, + new DrawningObject(car)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var car = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(car); + } + /// + /// Изменение размеров формы + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBoxCar.Image = _abstractMap?.MoveObject(dir); + } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + var car = new DrawningAirBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(car); + } + /// + /// Смена карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + case "Карта со стенами": + _abstractMap = new WallMap(); + break; + } + } + } +} diff --git a/AirBomber/AirBomber/FormMap.resx b/AirBomber/AirBomber/FormMap.resx new file mode 100644 index 0000000..2c0949d --- /dev/null +++ b/AirBomber/AirBomber/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/AirBomber/AirBomber/IDrawningObject.cs b/AirBomber/AirBomber/IDrawningObject.cs new file mode 100644 index 0000000..6077012 --- /dev/null +++ b/AirBomber/AirBomber/IDrawningObject.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawningObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + /// + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawningObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + RectangleF GetCurrentPosition(); + } +} diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index 76b85fe..e462fb5 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -11,7 +11,7 @@ namespace AirBomber // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirBomber()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/SimpleMap.cs b/AirBomber/AirBomber/SimpleMap.cs new file mode 100644 index 0000000..63bb878 --- /dev/null +++ b/AirBomber/AirBomber/SimpleMap.cs @@ -0,0 +1,50 @@ +namespace AirBomber +{ + /// + /// Простая реализация абсрактного класса AbstractMap + /// + internal class SimpleMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.Gray); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 50) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/WallMap.cs b/AirBomber/AirBomber/WallMap.cs new file mode 100644 index 0000000..8cb7989 --- /dev/null +++ b/AirBomber/AirBomber/WallMap.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class WallMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Brown); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.LightPink); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillPolygon(barrierColor, new PointF[] + { + new PointF(i * _size_x, j * _size_y), + new PointF((i + 1) * _size_x, j * _size_y), + new PointF((i + 1) * _size_x - _size_x / 4, (j + 1) * _size_y - _size_y / 2), + new PointF((i + 1) * _size_x, (j + 1) * _size_y), + new PointF(i * _size_x, (j + 1) * _size_y), + new PointF(i * _size_x + _size_x / 4, (j + 1) * _size_y - _size_y / 2), + }); + } + + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y); + } + + protected override void GenerateMap() + { + _map = new int[120, 120]; + var minSize = Math.Min(_map.GetLength(0), _map.GetLength(1)); + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + for (var i = 0; i < 10; i++) + { + var lengthWall = _random.Next(3, minSize / 2); + var incX = _random.Next(0, 2); + var incY = 1 - incX; + var left = _random.Next(0, _map.GetLength(0) - lengthWall); + var top = _random.Next(0, _map.GetLength(1) - lengthWall); + for (var j = 0; j < lengthWall; j++) + { + _map[left + incX * j, top + incY * j] = _barrier; + } + } + + } + } +} -- 2.25.1 From 8d19ef68902bcc0ff451dbb21c57794626c6eff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Thu, 22 Sep 2022 06:08:48 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20?= =?UTF-8?q?DrawningAirplaneEngines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirplane.cs | 4 ++-- .../AirBomber/DrawningAirplaneEngines.cs | 12 +--------- AirBomber/AirBomber/DrawningObject.cs | 2 +- AirBomber/AirBomber/IAirplaneEngines.cs | 24 +++++++++++++++++++ AirBomber/AirBomber/Program.cs | 2 +- 5 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 AirBomber/AirBomber/IAirplaneEngines.cs diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs index cad66c4..45e005b 100644 --- a/AirBomber/AirBomber/DrawningAirplane.cs +++ b/AirBomber/AirBomber/DrawningAirplane.cs @@ -10,7 +10,7 @@ /// public EntityAirplane Airplane { get; protected set; } - public DrawningAirplaneEngines DrawningEngines { get; private set; } + public IAirplaneEngines DrawningEngines { get; private set; } /// /// Левая координата отрисовки автомобиля /// @@ -44,7 +44,7 @@ public DrawningAirplane(int speed, float weight, Color bodyColor) { Airplane = new EntityAirplane(speed, weight, bodyColor); - DrawningEngines = new(); + DrawningEngines = new DrawningAirplaneEngines(); } /// diff --git a/AirBomber/AirBomber/DrawningAirplaneEngines.cs b/AirBomber/AirBomber/DrawningAirplaneEngines.cs index e8ac24b..2fe3e1b 100644 --- a/AirBomber/AirBomber/DrawningAirplaneEngines.cs +++ b/AirBomber/AirBomber/DrawningAirplaneEngines.cs @@ -9,13 +9,11 @@ namespace AirBomber /// /// Класс-дополнение к самолету отвечающий за число двигателей и их отрисовку /// - internal class DrawningAirplaneEngines + internal class DrawningAirplaneEngines : IAirplaneEngines { /// Приватное поле содержащие текущее количество двигателей самолета private CountEngines _countEngines; - /// Получение действительного количества двигателей или установка поддерживаемого числа двигателей - /// The count engines. public int CountEngines { get => (int)_countEngines; @@ -27,14 +25,6 @@ namespace AirBomber } } - - /// Отрисовывает все двигатели на обеих крыльях - /// The g. - /// Цвет двигателей. - /// Позиция крыльев по x. В этой координате будут центры двигателей - /// Крайняя левая позиция левого крыла по y - /// Крайняя правая позиция правого крыла по y - /// Ширина тела самолета, или расстояние между крыльями. public void DrawEngines(Graphics g, Color colorEngine, float wingPosX, float leftWingY, float rightWingY, int widthBodyAirplane) { float distanceBetweenEngines = (leftWingY - rightWingY - widthBodyAirplane) / 8.0f; diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs index d79a291..3b12ec9 100644 --- a/AirBomber/AirBomber/DrawningObject.cs +++ b/AirBomber/AirBomber/DrawningObject.cs @@ -8,7 +8,7 @@ namespace AirBomber { internal class DrawningObject : IDrawningObject { - private DrawningAirplane _airplane = null; + private DrawningAirplane _airplane; public DrawningObject(DrawningAirplane airplane) { diff --git a/AirBomber/AirBomber/IAirplaneEngines.cs b/AirBomber/AirBomber/IAirplaneEngines.cs new file mode 100644 index 0000000..ccbc860 --- /dev/null +++ b/AirBomber/AirBomber/IAirplaneEngines.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal interface IAirplaneEngines + { + /// Получение действительного количества двигателей или установка поддерживаемого числа двигателей + /// The count engines. + int CountEngines { get; set; } + + /// Отрисовывает все двигатели на обеих крыльях + /// The g. + /// Цвет двигателей. + /// Позиция крыльев по x. В этой координате будут центры двигателей + /// Крайняя левая позиция левого крыла по y + /// Крайняя правая позиция правого крыла по y + /// Ширина тела самолета, или расстояние между крыльями. + void DrawEngines(Graphics g, Color colorEngine, float wingPosX, float leftWingY, float rightWingY, int widthBodyAirplane); + } +} diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index e462fb5..76b85fe 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -11,7 +11,7 @@ namespace AirBomber // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormAirBomber()); } } } \ No newline at end of file -- 2.25.1 From 006cea0aca6c7abf524771dab51c9eba442f6cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Thu, 22 Sep 2022 07:02:39 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=82=D1=80=D0=B8=20=D1=80=D0=B5=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D1=80=D0=B0=D0=B7=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=84=D0=BE=D1=80=D0=BC=20=D0=B4=D0=B2=D0=B8?= =?UTF-8?q?=D0=B3=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AirplaneArrowEngines.cs | 26 +++++++++++++++++++ AirBomber/AirBomber/AirplaneRectEngines.cs | 18 +++++++++++++ .../AirBomber/DrawningAirplaneEngines.cs | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 AirBomber/AirBomber/AirplaneArrowEngines.cs create mode 100644 AirBomber/AirBomber/AirplaneRectEngines.cs diff --git a/AirBomber/AirBomber/AirplaneArrowEngines.cs b/AirBomber/AirBomber/AirplaneArrowEngines.cs new file mode 100644 index 0000000..3eba788 --- /dev/null +++ b/AirBomber/AirBomber/AirplaneArrowEngines.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class AirplaneArrowEngines : DrawningAirplaneEngines + { + protected override void DrawEngine(Graphics g, Color colorAirplane, RectangleF rectAroundEngine) + { + var x = rectAroundEngine.X + rectAroundEngine.Width / 4; + g.FillPolygon(new SolidBrush(colorAirplane), new PointF[] + { + new PointF(rectAroundEngine.Left, rectAroundEngine.Top + rectAroundEngine.Height / 2), + new PointF(x, rectAroundEngine.Top), + new PointF(x, rectAroundEngine.Bottom), + }); + int margin = 2; + g.FillRectangle(new SolidBrush(colorAirplane), + x , rectAroundEngine.Top + margin, + rectAroundEngine.Right - x, rectAroundEngine.Height - margin * 2); + } + } +} diff --git a/AirBomber/AirBomber/AirplaneRectEngines.cs b/AirBomber/AirBomber/AirplaneRectEngines.cs new file mode 100644 index 0000000..a23dd24 --- /dev/null +++ b/AirBomber/AirBomber/AirplaneRectEngines.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class AirplaneRectEngines : DrawningAirplaneEngines + { + protected override void DrawEngine(Graphics g, Color colorAirplane, RectangleF rectAroundEngine) + { + g.FillRectangle(new SolidBrush(colorAirplane), rectAroundEngine); + g.FillRectangle(new SolidBrush(Color.Black), + rectAroundEngine.Left, rectAroundEngine.Top, rectAroundEngine.Width / 4, rectAroundEngine.Height); + } + } +} diff --git a/AirBomber/AirBomber/DrawningAirplaneEngines.cs b/AirBomber/AirBomber/DrawningAirplaneEngines.cs index 2fe3e1b..23d5585 100644 --- a/AirBomber/AirBomber/DrawningAirplaneEngines.cs +++ b/AirBomber/AirBomber/DrawningAirplaneEngines.cs @@ -37,7 +37,7 @@ namespace AirBomber } } - private void DrawEngine(Graphics g, Color colorAirplane, RectangleF rectAroundEngine) + protected virtual void DrawEngine(Graphics g, Color colorAirplane, RectangleF rectAroundEngine) { g.FillEllipse(new SolidBrush(colorAirplane), rectAroundEngine); g.FillEllipse(new SolidBrush(Color.Black), -- 2.25.1 From a02a602dceeef2c38c2b81371b9448c42587856f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Thu, 22 Sep 2022 07:50:53 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=20?= =?UTF-8?q?=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BF=D0=BE=D0=B2=20=D0=B4=D0=B2=D0=B8=D0=B3=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 5 +-- AirBomber/AirBomber/DrawningAirplane.cs | 18 +++++----- AirBomber/AirBomber/FormAirBomber.Designer.cs | 34 ++++++++++++++----- AirBomber/AirBomber/FormAirBomber.cs | 17 +++++++++- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index 2f5da52..b17f7c4 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -19,8 +19,9 @@ namespace AirBomber /// Дополнительный цвет /// Признак наличия бомб /// Признак наличия топливных баков - public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) - : base(speed, weight, bodyColor, 115, 155) + /// Какой будет двигатель самолета. null - двигатели отсутствуют + public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks, IAirplaneEngines? typeAirplaneEngines = null) + : base(speed, weight, bodyColor, 115, 155, typeAirplaneEngines) { Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks); } diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs index 45e005b..754387a 100644 --- a/AirBomber/AirBomber/DrawningAirplane.cs +++ b/AirBomber/AirBomber/DrawningAirplane.cs @@ -10,7 +10,7 @@ /// public EntityAirplane Airplane { get; protected set; } - public IAirplaneEngines DrawningEngines { get; private set; } + public IAirplaneEngines? DrawningEngines { get; private set; } /// /// Левая координата отрисовки автомобиля /// @@ -30,21 +30,22 @@ /// /// Ширина отрисовки автомобиля /// - protected readonly int _airplaneWidth = 80; + protected readonly int _airplaneWidth = 90; /// /// Высота отрисовки автомобиля /// - protected readonly int _airplaneHeight = 90; + protected readonly int _airplaneHeight = 105; /// /// Инициализация свойств /// /// Скорость /// Вес самолета /// Цвет обшивки - public DrawningAirplane(int speed, float weight, Color bodyColor) + /// Какой будет двигатель самолета. null - двигатели отсутствуют + public DrawningAirplane(int speed, float weight, Color bodyColor, IAirplaneEngines? typeAirplaneEngines = null) { Airplane = new EntityAirplane(speed, weight, bodyColor); - DrawningEngines = new DrawningAirplaneEngines(); + DrawningEngines = typeAirplaneEngines; } /// @@ -55,8 +56,9 @@ /// Цвет обшивки /// Ширина отрисовки самолета /// Высота отрисовки самолета - protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : - this(speed, weight, bodyColor) + /// Какой будет двигатель самолета. null - двигатели отсутствуют + protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight, IAirplaneEngines? typeAirplaneEngines) : + this(speed, weight, bodyColor, typeAirplaneEngines) { _airplaneWidth = airplaneWidth; _airplaneHeight = airplaneHeight; @@ -169,7 +171,7 @@ // Конец хвоста g.FillRectangle(BodyColorBrush, x + w - 5, y + 15, 5, h - 30); // Двигатели - DrawningEngines.DrawEngines(g, Airplane.BodyColor, x + w / 2 - 20, y + h, y, 15); + DrawningEngines?.DrawEngines(g, Airplane.BodyColor, x + w / 2 - 20, y + h, y, 15); } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 52f71e3..e140578 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -33,6 +33,7 @@ this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusCountEngines = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonCreate = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); @@ -40,7 +41,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.countEngineBox = new System.Windows.Forms.NumericUpDown(); this.labelInformCountEngines = new System.Windows.Forms.Label(); - this.toolStripStatusCountEngines = new System.Windows.Forms.ToolStripStatusLabel(); + this.comboTypeEngines = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit(); this.statusStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).BeginInit(); @@ -87,10 +88,16 @@ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); this.toolStripStatusLabelBodyColor.Text = "Цвет:"; // + // toolStripStatusCountEngines + // + this.toolStripStatusCountEngines.Name = "toolStripStatusCountEngines"; + this.toolStripStatusCountEngines.Size = new System.Drawing.Size(139, 17); + this.toolStripStatusCountEngines.Text = "Количество двигателей:"; + // // buttonCreate // this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreate.Location = new System.Drawing.Point(244, 390); + this.buttonCreate.Location = new System.Drawing.Point(372, 390); this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.buttonCreate.TabIndex = 2; @@ -149,37 +156,45 @@ // countEngineBox // this.countEngineBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.countEngineBox.Location = new System.Drawing.Point(142, 390); + this.countEngineBox.Location = new System.Drawing.Point(306, 390); this.countEngineBox.Maximum = new decimal(new int[] { 10000, 0, 0, 0}); this.countEngineBox.Name = "countEngineBox"; - this.countEngineBox.Size = new System.Drawing.Size(96, 23); + this.countEngineBox.Size = new System.Drawing.Size(60, 23); this.countEngineBox.TabIndex = 7; // // labelInformCountEngines // this.labelInformCountEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelInformCountEngines.AutoSize = true; - this.labelInformCountEngines.Location = new System.Drawing.Point(0, 394); + this.labelInformCountEngines.Location = new System.Drawing.Point(161, 394); this.labelInformCountEngines.Name = "labelInformCountEngines"; this.labelInformCountEngines.Size = new System.Drawing.Size(139, 15); this.labelInformCountEngines.TabIndex = 8; this.labelInformCountEngines.Text = "Количество двигателей:"; // - // toolStripStatusCountEngines + // comboTypeEngines // - this.toolStripStatusCountEngines.Name = "toolStripStatusCountEngines"; - this.toolStripStatusCountEngines.Size = new System.Drawing.Size(139, 17); - this.toolStripStatusCountEngines.Text = "Количество двигателей:"; + this.comboTypeEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.comboTypeEngines.FormattingEnabled = true; + this.comboTypeEngines.Items.AddRange(new object[] { + "Закругленный", + "Квадратный", + "Стрелка"}); + this.comboTypeEngines.Location = new System.Drawing.Point(12, 390); + this.comboTypeEngines.Name = "comboTypeEngines"; + this.comboTypeEngines.Size = new System.Drawing.Size(143, 23); + this.comboTypeEngines.TabIndex = 9; // // FormAirBomber // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.comboTypeEngines); this.Controls.Add(this.labelInformCountEngines); this.Controls.Add(this.countEngineBox); this.Controls.Add(this.buttonDown); @@ -215,5 +230,6 @@ private NumericUpDown countEngineBox; private Label labelInformCountEngines; private ToolStripStatusLabel toolStripStatusCountEngines; + private ComboBox comboTypeEngines; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index d57444b..4302b71 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -25,8 +25,23 @@ namespace AirBomber /// private void ButtonCreate_Click(object sender, EventArgs e) { + IAirplaneEngines? typeAirplaneEngines = null; + switch (comboTypeEngines.Text) + { + case "": + typeAirplaneEngines = new AirplaneRectEngines(); + break; + case "": + typeAirplaneEngines = new AirplaneArrowEngines(); + break; + default: + typeAirplaneEngines = new DrawningAirplaneEngines(); + break; + } Random rnd = new(); - _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + typeAirplaneEngines); _airplane.DrawningEngines.CountEngines = (int)countEngineBox.Value; _airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}"; -- 2.25.1 From d5d6d4ecb226829f5d969e83fe9b7508dec972cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Fri, 23 Sep 2022 12:05:15 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D1=8F=D1=85=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=BE=D0=B1?= =?UTF-8?q?=D0=B8=D0=BB=D1=8F=20=D0=BD=D0=B0=20=D1=81=D0=B0=D0=BC=D0=BE?= =?UTF-8?q?=D0=BB=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirplane.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs index 754387a..cb5c3af 100644 --- a/AirBomber/AirBomber/DrawningAirplane.cs +++ b/AirBomber/AirBomber/DrawningAirplane.cs @@ -12,11 +12,11 @@ public IAirplaneEngines? DrawningEngines { get; private set; } /// - /// Левая координата отрисовки автомобиля + /// Левая координата отрисовки самолета /// protected float _startPosX; /// - /// Верхняя кооридната отрисовки автомобиля + /// Верхняя кооридната отрисовки самолета /// protected float _startPosY; /// @@ -28,11 +28,11 @@ /// protected int? _pictureHeight = null; /// - /// Ширина отрисовки автомобиля + /// Ширина отрисовки самолета /// protected readonly int _airplaneWidth = 90; /// - /// Высота отрисовки автомобиля + /// Высота отрисовки самолета /// protected readonly int _airplaneHeight = 105; /// -- 2.25.1 From f91c1d48c67247d345d5be41555f303a3fb6adfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Fri, 23 Sep 2022 12:22:40 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B5=D0=B2=20=D0=B2=20=D0=BA=D0=BE=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractMap.cs | 6 ++++++ AirBomber/AirBomber/EntityAirBomber.cs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AirBomber/AirBomber/AbstractMap.cs b/AirBomber/AirBomber/AbstractMap.cs index 260ad22..78425d8 100644 --- a/AirBomber/AirBomber/AbstractMap.cs +++ b/AirBomber/AirBomber/AbstractMap.cs @@ -61,6 +61,9 @@ namespace AirBomber } return false; } + /// Проверяет наличие непроходимых участков в заданной области + /// Заданная область + /// Есть ли барьеры protected bool BarriersInArea(RectangleF area) { int a = 0, b = 0; @@ -123,6 +126,9 @@ namespace AirBomber _drawningObject.SetObject((int)areaObject.X, (int)areaObject.Y, _width, _height); return cntOut >= 0; } + /// + /// Заполняет BitMap для отрисовки статичных объектов. Выполняется один раз при создании карты + /// private void DrawMap() { if (_staticBitMap != null) return; diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index 8e5ace5..727d7ff 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -24,8 +24,8 @@ namespace AirBomber /// Инициализация свойств /// /// Скорость - /// Вес автомобиля - /// Цвет кузова + /// Вес самолета + /// Цвет обшивки /// Дополнительный цвет /// Признак наличия бомб /// Признак наличия топливных баков -- 2.25.1