DozorovaA.A_SecondLabWork #2
4
ArmoredVehicle/FormMap.Designer.cs
generated
4
ArmoredVehicle/FormMap.Designer.cs
generated
@ -159,7 +159,9 @@
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта"});
|
||||
"Простая карта",
|
||||
"Горизонтальная карта",
|
||||
"Вертикальная карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 321);
|
||||
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
|
@ -73,6 +73,12 @@
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Горизонтальная карта":
|
||||
_abstractMap = new HorizontalMap();
|
||||
break;
|
||||
case "Вертикальная карта":
|
||||
_abstractMap = new VerticalMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
63
ArmoredVehicle/HorizontalMap.cs
Normal file
63
ArmoredVehicle/HorizontalMap.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredVehicle
|
||||
{
|
||||
internal class HorizontalMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.BlueViolet);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.White);
|
||||
|
||||
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));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1));
|
||||
|
||||
}
|
||||
|
||||
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 < 5)
|
||||
{
|
||||
|
||||
int x1 = _random.Next(0, 12);
|
||||
int x2 = _random.Next(12, _map.GetLength(0));
|
||||
|
||||
int y1 = _random.Next(0, _map.GetLength(1));
|
||||
|
||||
for(int i = x1; i<x2; i++)
|
||||
{
|
||||
if (_map[i, y1] == _freeRoad)
|
||||
{
|
||||
_map[i, y1] = _barrier;
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
ArmoredVehicle/VerticalMAp.cs
Normal file
62
ArmoredVehicle/VerticalMAp.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredVehicle
|
||||
{
|
||||
internal class VerticalMap : AbstractMap
|
||||
{ /// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Brown);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightGray);
|
||||
|
||||
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));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1));
|
||||
|
||||
}
|
||||
|
||||
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 < 7)
|
||||
{
|
||||
|
||||
int x1 = _random.Next(0, 12);
|
||||
int x2 = _random.Next(12, _map.GetLength(0));
|
||||
|
||||
int y1 = _random.Next(0, _map.GetLength(1));
|
||||
|
||||
for (int i = x1; i < x2; i++)
|
||||
{
|
||||
if (_map[y1, i] == _freeRoad)
|
||||
{
|
||||
_map[y1, i] = _barrier;
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user