59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ContainerShip
|
|
{
|
|
internal class IslandsMap : AbstractMap
|
|
{
|
|
private readonly Brush islandColor = new SolidBrush(Color.Yellow);
|
|
|
|
private readonly Brush waterColor = new SolidBrush(Color.Aqua);
|
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
|
{
|
|
g.FillRectangle(islandColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
}
|
|
protected override void DrawWaterPart(Graphics g, int i, int j)
|
|
{
|
|
g.FillRectangle(waterColor, 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] = _water;
|
|
}
|
|
}
|
|
while (counter < 10)
|
|
{
|
|
int x = _random.Next(0, 100);
|
|
int y = _random.Next(0, 100);
|
|
if (_map[x, y] == _water && x < 97 && y < 97)
|
|
{
|
|
_map[x + 1, y] = _barrier;
|
|
_map[x + 2, y] = _barrier;
|
|
_map[x, y + 1] = _barrier;
|
|
_map[x + 1, y + 1] = _barrier;
|
|
_map[x + 2, y + 1] = _barrier;
|
|
_map[x + 3, y + 1] = _barrier;
|
|
_map[x, y + 2] = _barrier;
|
|
_map[x + 1, y + 2] = _barrier;
|
|
_map[x + 2, y + 2] = _barrier;
|
|
_map[x + 3, y + 2] = _barrier;
|
|
_map[x + 1, y + 3] = _barrier;
|
|
_map[x + 2, y + 3] = _barrier;
|
|
counter++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|