Две собственные реализации карты
This commit is contained in:
parent
f86df21cc2
commit
1e83e26657
73
ArmoredCar/ArmoredCar/MyMapLabirinth.cs
Normal file
73
ArmoredCar/ArmoredCar/MyMapLabirinth.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
internal class MyMapLabirinth : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierTreeColor = new SolidBrush(Color.Lime);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.SandyBrown);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierTreeColor, i * _size_x, j * _size_y, _size_x * 2, _size_y * 2);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x * 2, _size_y * 2);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[50, 50];
|
||||
_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 < 20)
|
||||
{
|
||||
int x = _random.Next(0, 50);
|
||||
int y = _random.Next(0, 50);
|
||||
int number = _random.Next(1, 15);
|
||||
if (counter < 5) {
|
||||
if (number + x > _map.GetLength(0))
|
||||
{
|
||||
number = _map.GetLength(0) - x - 1;
|
||||
}
|
||||
for (int i = x; i < x + number; ++i)
|
||||
{
|
||||
_map[i, y] = _barrier;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (number + y > _map.GetLength(1))
|
||||
{
|
||||
number = _map.GetLength(1) - y - 1;
|
||||
}
|
||||
for (int i = y; i < y + number; ++i)
|
||||
{
|
||||
_map[x, i] = _barrier;
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
ArmoredCar/ArmoredCar/MyMapWooden.cs
Normal file
54
ArmoredCar/ArmoredCar/MyMapWooden.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
internal class MyMapWooden : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierTreeColor = new SolidBrush(Color.LightGreen);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Brown);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierTreeColor, i * _size_x, j * _size_y, _size_x * 2, _size_y * 2);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x * 2, _size_y * 2 );
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[50, 50];
|
||||
_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 < 25)
|
||||
{
|
||||
int x = _random.Next(0, 50);
|
||||
int y = _random.Next(0, 50);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user