ISEbd-21_Tomasheva_RoadTrai.../RoadTrain/RoadTrain/RoadMap.cs
2022-12-07 12:13:11 +04:00

56 lines
1.7 KiB
C#

namespace RoadTrain
{
internal class RoadMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Green);
/// <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, 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[50, 50];
_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 < 20)
{
int x = _random.Next(0, 48);
int y = _random.Next(1, 49);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
_map[x+1, y-1] = _barrier;
_map[x + 1, y] = _barrier;
_map[x + 2, y] = _barrier;
counter = counter + 4;
}
}
}
}
}