93 lines
3.0 KiB
C#
93 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Boats
|
|
{
|
|
/// <summary>
|
|
/// Класс линейной карты
|
|
/// </summary>
|
|
internal class LineMap : AbstractMap
|
|
{
|
|
/// <summary>
|
|
/// Цвет участка закрытого
|
|
/// </summary>
|
|
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
|
/// <summary>
|
|
/// Цвет участка открытого
|
|
/// </summary>
|
|
private readonly Brush roadColor = new SolidBrush(Color.Black);
|
|
/// <summary>
|
|
/// Метод для отрисовки закрытого участка карты
|
|
/// </summary>
|
|
/// <param name="g"></param>
|
|
/// <param name="i"></param>
|
|
/// <param name="j"></param>
|
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
|
{
|
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
}
|
|
/// <summary>
|
|
/// Метод для отрисовки открытого участка карты
|
|
/// </summary>
|
|
/// <param name="g"></param>
|
|
/// <param name="i"></param>
|
|
/// <param name="j"></param>
|
|
protected override void DrawWaterPart(Graphics g, int i, int j)
|
|
{
|
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
}
|
|
/// <summary>
|
|
/// Метод генерации карты
|
|
/// </summary>
|
|
protected override void GenerateMap()
|
|
{
|
|
_map = new int[100, 100];
|
|
_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] = _freeWater;
|
|
}
|
|
}
|
|
// Будем рисовать линии
|
|
// из непроходимых блоков
|
|
int counter = 0;
|
|
while (counter < 20)
|
|
{
|
|
int x = _random.Next(0, 100);
|
|
int y = _random.Next(0, 100);
|
|
|
|
int lineLength = 5;
|
|
|
|
if (_map[x, y] == _freeWater)
|
|
{
|
|
int d = 0;
|
|
if (Convert.ToBoolean(_random.Next(0, 2)))
|
|
{
|
|
while (y + d < _map.GetLength(0) && d < lineLength * 2)
|
|
{
|
|
_map[x, y + d] = _barrier;
|
|
d++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while (x + d < _map.GetLength(1) && d < lineLength)
|
|
{
|
|
_map[x + d, y] = _barrier;
|
|
d++;
|
|
}
|
|
}
|
|
counter++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|