2022-10-18 12:05:10 +04:00

59 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class ModifyMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.WhiteSmoke);
private readonly Brush roadColor = new SolidBrush(Color.Blue);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _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()
{
Random random = new Random();
int firstPointX;
int secondPointX;
int pointY;
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int counter = 0;
while(counter < 15)
{
bool freePlace = true;
firstPointX = random.Next(0, _map.GetLength(0)-10);
secondPointX = random.Next(firstPointX, _map.GetLength(0)-10);
pointY = random.Next(0, _map.GetLength(1)-10);
for(int i = firstPointX; i <secondPointX; i++)
{
if (_map[i, pointY] == _barrier)
{
freePlace = false;
break;
}
_map[i, pointY] = _barrier;
}
if (freePlace)
{
counter++;
}
}
}
}
}