diff --git a/Locomotive/Locomotive/FormMap.Designer.cs b/Locomotive/Locomotive/FormMap.Designer.cs index 5447710..f3b9c62 100644 --- a/Locomotive/Locomotive/FormMap.Designer.cs +++ b/Locomotive/Locomotive/FormMap.Designer.cs @@ -159,11 +159,13 @@ 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); this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); // // FormMap // diff --git a/Locomotive/Locomotive/FormMap.cs b/Locomotive/Locomotive/FormMap.cs index 16d64d3..bfd3a2f 100644 --- a/Locomotive/Locomotive/FormMap.cs +++ b/Locomotive/Locomotive/FormMap.cs @@ -78,7 +78,7 @@ namespace Locomotive } /// Смена карты - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorMap.Text) @@ -86,6 +86,10 @@ namespace Locomotive case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Карта с шипами": + _abstractMap = new SpikeMap(); + break; + } } } diff --git a/Locomotive/Locomotive/SpikeMap.cs b/Locomotive/Locomotive/SpikeMap.cs new file mode 100644 index 0000000..8f03023 --- /dev/null +++ b/Locomotive/Locomotive/SpikeMap.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class SpikeMap : 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 < 15) + { + int x = _random.Next(1, 99); + int y = _random.Next(1, 99); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + + if (_map[x + 1, y] == _freeRoad) _map[x + 1, y] = _barrier; + if (_map[x - 1, y] == _freeRoad) _map[x - 1, y] = _barrier; + if (_map[x, y + 1] == _freeRoad) _map[x, y + 1] = _barrier; + if (_map[x, y - 1] == _freeRoad) _map[x, y - 1] = _barrier; + + counter++; + } + } + } + } +}