PIbd-22_Bondarenko_M.S._War.../WarmlyShip/WarmlyShip/LastMap.cs
Макс Бондаренко cb66cd7938 Чупапи муняня
2022-10-18 20:34:50 +04:00

56 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal class LastMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Red);
private readonly Brush roadColor = new SolidBrush(Color.Green);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, j * _size_x, i * _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 < 45)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
if (x > 0 && y > 0 && x < _map.GetLength(0) - 1 && y < _map.GetLength(1) - 1)
{
_map[x - 1, y] = _barrier;
_map[x + 1, y] = _barrier;
_map[x, y - 1] = _barrier;
_map[x, y + 1] = _barrier;
}
counter++;
}
}
}
}
}