Новая карта "Океан"

This commit is contained in:
just1valery 2022-09-28 16:56:47 +04:00
parent 53c32e224f
commit f0dd67650a
5 changed files with 65 additions and 4 deletions

View File

@ -59,6 +59,7 @@ namespace WarmlyShip
_drawningObject.MoveObject(MoveObjectBack(direction));
}
return DrawMapWithObject();
}
private Direction MoveObjectBack(Direction direction)
{

View File

@ -163,11 +163,13 @@
//
this.ComboBoxSelectorMap.FormattingEnabled = true;
this.ComboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта"});
"Простая карта",
"Океан"});
this.ComboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(182, 28);
this.ComboBoxSelectorMap.TabIndex = 8;
this.ComboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// FormMap
//

View File

@ -81,8 +81,12 @@ namespace WarmlyShip
switch (ComboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
_abstractMap = new SimpleMap();
break;
case "Îęĺŕí":
_abstractMap = new OceanMap();
break;
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal class OceanMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Gray);
private readonly Brush roadColor = new SolidBrush(Color.DeepSkyBlue);
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));
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[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 < 15)
{
int x = _random.Next(0, 95);
int y = _random.Next(0, 95);
if (_map[x, y] == _freeRoad)
{
_map[x, y + 1] = _barrier;
_map[x, y + 2] = _barrier;
_map[x + 1, y + 1] = _barrier;
_map[x + 2, y + 1] = _barrier;
_map[x + 1, y] = _barrier;
_map[x + 2, y] = _barrier;
counter++;
}
}
}
}
}

View File

@ -38,7 +38,7 @@ namespace WarmlyShip
_map[i, j] = _freeRoad;
}
}
while (counter < 50)
while (counter < 25)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);