Добавление собственных карт

This commit is contained in:
Denis 2022-10-06 03:50:53 +04:00
parent a091ea799f
commit 93af5d6e5a
4 changed files with 128 additions and 1 deletions

View File

@ -166,7 +166,9 @@
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(14, 16); this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 16);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";

View File

@ -95,6 +95,12 @@ namespace AirplaneWithRadar
case "Простая карта": case "Простая карта":
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
break; break;
case "Карта неба с облаками":
_abstractMap = new SkyMap();
break;
case "Карта дождливого неба с грозой":
_abstractMap = new RainySkyMap();
break;
} }
} }
} }

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class RainySkyMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Blue);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.DarkGray);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
//g.DrawLine(barrierColor, i * _size_x, j * _size_y, i * _size_x + _size_x, j * _size_y + (1 / 3) * _size_y);
//g.DrawLine(barrierColor, i * _size_x + _size_x, j * _size_y + (1 / 3) * _size_y, i * _size_x, j * _size_y + (2 * 3) * _size_y);
//g.DrawLine(barrierColor, i * _size_x, j * _size_y + 2 * _size_y, i * _size_x + _size_x, j * _size_y + 3 * _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
}
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 < 12)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
if (y + 5 < 100 && x + 3 < 100)
{
_map[x, y] = _barrier;
_map[x + 1, y + 1] = _barrier;
_map[x + 2, y + 2] = _barrier;
_map[x + 1, y + 3] = _barrier;
_map[x + 2, y + 4] = _barrier;
_map[x + 3 , y + 5] = _barrier;
counter++;
}
}
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
/// <summary>
/// Простая реализация абсрактного класса AbstractMap
/// </summary>
internal class SkyMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Gray);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.LightBlue);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillEllipse(barrierColor, i * (_size_x - 1), j * (_size_y - 1), 40, 24);
}
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(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}