diff --git a/Airbus/Airbus/DrawningObjectAirbus.cs b/Airbus/Airbus/DrawningObjectAirbus.cs index a6636cb..c207cd7 100644 --- a/Airbus/Airbus/DrawningObjectAirbus.cs +++ b/Airbus/Airbus/DrawningObjectAirbus.cs @@ -19,7 +19,7 @@ namespace Airbus void IDrawningObject.DrawningObject(Graphics g) { - //ДОДУМАТЬ ЛОГИКУ ЭТОГО МЕТОДА + _airbus.DrawTransport(g); } public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() diff --git a/Airbus/Airbus/FormMap.Designer.cs b/Airbus/Airbus/FormMap.Designer.cs index bc610f1..3d2f24b 100644 --- a/Airbus/Airbus/FormMap.Designer.cs +++ b/Airbus/Airbus/FormMap.Designer.cs @@ -160,7 +160,9 @@ 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(151, 28); diff --git a/Airbus/Airbus/FormMap.cs b/Airbus/Airbus/FormMap.cs index 044f172..71768bd 100644 --- a/Airbus/Airbus/FormMap.cs +++ b/Airbus/Airbus/FormMap.cs @@ -13,11 +13,14 @@ namespace Airbus public partial class FormMap : Form { private AbstractMap _abstractMap; + private SecondVersionAbstractMap _secondAbstractMap; + private ThirdVersionAbstractMap _thirdVersionAbstractMap; public FormMap() { InitializeComponent(); _abstractMap = new SimpleMap(); + _secondAbstractMap = new SecondSimpleMap(); } //заполнение информации по объекту @@ -26,8 +29,22 @@ namespace Airbus toolStripStatusLabelSpeed.Text = $"Скорость: {airbus.Airbus?.Speed}"; toolStripStatusLabelWeight.Text = $"Вес: {airbus.Airbus?.Weight}"; toolStripStatusLabelCorpusColor.Text = $"Цвет: {airbus.Airbus?.CorpusColor.Name}"; - pictureBoxAirbus.Image = _abstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height, + + if (comboBoxSelectorMap.Text == "Простая карта") + { + pictureBoxAirbus.Image = _abstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height, new DrawningObjectAirbus(airbus)); + } + if (comboBoxSelectorMap.Text == "Буря в пустыне") + { + pictureBoxAirbus.Image = _secondAbstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height, + new DrawningObjectAirbus(airbus)); + } + if (comboBoxSelectorMap.Text == "Звёздные войны") + { + pictureBoxAirbus.Image = _thirdVersionAbstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height, + new DrawningObjectAirbus(airbus)); + } } //обработка нажатия кнопки "Создать" @@ -59,7 +76,19 @@ namespace Airbus dir = Direction.Right; break; } - pictureBoxAirbus.Image = _abstractMap?.MoveObject(dir); + + if (comboBoxSelectorMap.Text == "Простая карта") + { + pictureBoxAirbus.Image = _abstractMap?.MoveObject(dir); + } + if (comboBoxSelectorMap.Text == "Буря в пустыне") + { + pictureBoxAirbus.Image = _secondAbstractMap?.MoveObject(dir); + } + if (comboBoxSelectorMap.Text == "Звёздные войны") + { + pictureBoxAirbus.Image = _thirdVersionAbstractMap?.MoveObject(dir); + } } //обработка нажития кнопки "Модификация" @@ -80,6 +109,12 @@ namespace Airbus case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Буря в пустыне": + _secondAbstractMap = new SecondSimpleMap(); + break; + case "Звёздные войны": + _thirdVersionAbstractMap = new ThirdSimpleMap(); + break; } } } diff --git a/Airbus/Airbus/SecondSimpleMap.cs b/Airbus/Airbus/SecondSimpleMap.cs new file mode 100644 index 0000000..64266be --- /dev/null +++ b/Airbus/Airbus/SecondSimpleMap.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class SecondSimpleMap : SecondVersionAbstractMap + { + //цвет закрытого участка + Brush barriedColor = new SolidBrush(Color.DarkRed); + + //цвет открытого участка + Brush roadColor = new SolidBrush(Color.DarkOrange); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + //float _weightLength = i * (_size_x + 1) - i * _size_x; + //float _heightLength = j * (_size_y + 1) - j * _size_y; + + g.FillEllipse(barriedColor, i * _size_x, j * _size_y, 10, 10); + } + + protected override void DrawRoadPart(Graphics g, int i, int j) + { + float _weightLength = i * (_size_x + 1); + float _heightLength = j * (_size_y + 1); + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _weightLength, _heightLength); + } + + 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++; + } + } + } + } +} diff --git a/Airbus/Airbus/SecondVersionAbstractMap.cs b/Airbus/Airbus/SecondVersionAbstractMap.cs new file mode 100644 index 0000000..37449c5 --- /dev/null +++ b/Airbus/Airbus/SecondVersionAbstractMap.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal abstract class SecondVersionAbstractMap + { + private IDrawningObject _drawningObject = null; + 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) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + + return DrawMapWithObject(); + } + + public Bitmap MoveObject(Direction direction) + { + //Сделать проверку на то, что объект может поместиться в выбранном направлении + if (true) + { + _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); + //Сделать проверку на то, то объект не "накладывается" на закрытые участки + return true; + } + + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + + if (_drawningObject == null || _map == null) + { + return bmp; + } + + Graphics gr = Graphics.FromImage(bmp); + + 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); + } + } + } + + _drawningObject.DrawningObject(gr); + return bmp; + } + + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} diff --git a/Airbus/Airbus/SimpleMap.cs b/Airbus/Airbus/SimpleMap.cs index 5bb3fe3..f0a8f5e 100644 --- a/Airbus/Airbus/SimpleMap.cs +++ b/Airbus/Airbus/SimpleMap.cs @@ -8,7 +8,7 @@ namespace Airbus { internal class SimpleMap : AbstractMap { - //цвет закрытого уастка + //цвет закрытого участка Brush barriedColor = new SolidBrush(Color.Black); //цвет открытого участка diff --git a/Airbus/Airbus/ThirdSimpleMap.cs b/Airbus/Airbus/ThirdSimpleMap.cs new file mode 100644 index 0000000..a38a182 --- /dev/null +++ b/Airbus/Airbus/ThirdSimpleMap.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class ThirdSimpleMap : ThirdVersionAbstractMap + { + + Random rnd = new Random(); + + //цвет выстрела из лазера + Color randomColor = new Color(); + + //цвет закрытого участка + Brush barriedColor; + + //цвет открытого участка + Brush roadColor = new SolidBrush(Color.DarkBlue); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); + barriedColor = new SolidBrush(randomColor); + g.FillRectangle(barriedColor, i * _size_x, j * _size_y, i * (_size_x + 1) + 10, 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++; + } + } + } + } +} diff --git a/Airbus/Airbus/ThirdVersionAbstractMap.cs b/Airbus/Airbus/ThirdVersionAbstractMap.cs new file mode 100644 index 0000000..c42499b --- /dev/null +++ b/Airbus/Airbus/ThirdVersionAbstractMap.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal abstract class ThirdVersionAbstractMap + { + private IDrawningObject _drawningObject = null; + 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) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + + return DrawMapWithObject(); + } + + public Bitmap MoveObject(Direction direction) + { + //Сделать проверку на то, что объект может поместиться в выбранном направлении + if (true) + { + _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); + //Сделать проверку на то, то объект не "накладывается" на закрытые участки + return true; + } + + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + + if (_drawningObject == null || _map == null) + { + return bmp; + } + + Graphics gr = Graphics.FromImage(bmp); + + 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); + } + } + } + + _drawningObject.DrawningObject(gr); + return bmp; + } + + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +}