Добавлена новая карта со стенами

This commit is contained in:
Данияр Аглиуллов 2022-09-15 18:02:00 +04:00
parent 020c73c4d1
commit 7df4ed00ce
3 changed files with 70 additions and 1 deletions

View File

@ -158,7 +158,8 @@
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта"}); "Простая карта",
"Карта со стенами"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);

View File

@ -87,6 +87,9 @@ namespace AirBomber
case "Простая карта": case "Простая карта":
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
break; break;
case "Карта со стенами":
_abstractMap = new WallMap();
break;
} }
} }
} }

View File

@ -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
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Brown);
/// <summary>
/// Цвет участка открытого
/// </summary>
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;
}
}
}
}
}