Malin D.V. Lab work 2 #2

Merged
eegov merged 7 commits from LabWork_02 into LabWork_01 2022-10-07 08:52:07 +04:00
6 changed files with 142 additions and 4 deletions
Showing only changes of commit 954aa17666 - Show all commits

View File

@ -31,7 +31,6 @@ namespace WarmlyLocomotive
}
public Bitmap MoveObject(Direction direction)
{
// TODO проверка, что объект может переместится в требуемом направлении
(float leftX, float topY, float rightX, float bottomY) = _drawningObject.GetCurrentPosition();
for (int i = 0; i < _map.GetLength(0); ++i)
{
@ -107,7 +106,6 @@ namespace WarmlyLocomotive
}
}
_drawningObject.SetObject(x, y, _width, _height);
// TODO првоерка, что объект не "накладывается" на закрытые участки
return true;
}
private Bitmap DrawMapWithObject()

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive
{
internal class BigBarriersMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.SandyBrown);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.LightCyan);
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()
{
_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, 100);
int y = _random.Next(0, 100);
if (x + 2 < 100 && y + 2 < 100)
{
if (_map[x, y] == _freeRoad && _map[x, y + 1] == _freeRoad && _map[x, y + 2] == _freeRoad && _map[x + 1, y] == _freeRoad && _map[x + 1, y + 1] == _freeRoad
&& _map[x + 1, y + 2] == _freeRoad && _map[x + 2, y] == _freeRoad && _map[x + 2, y + 1] == _freeRoad && _map[x + 2, y + 2] == _freeRoad)
{
_map[x, y] = _barrier;
_map[x, y + 1] = _barrier;
_map[x, y + 2] = _barrier;
_map[x + 1, y] = _barrier;
_map[x + 1, y + 1] = _barrier;
_map[x + 1, y + 2] = _barrier;
_map[x + 2, y] = _barrier;
_map[x + 2, y + 1] = _barrier;
_map[x + 2, y + 2] = _barrier;
counter++;
}
}
}
}
}
}

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive
{
internal class CirclesMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Red);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.LightCoral);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
if (i - 1 >= 0 && j - 1 >= 0)
{
if (_map[i - 1, j - 1] == _barrier && _map[i - 1, j] == _barrier && _map[i, j - 1] == _barrier)
{
g.FillEllipse(barrierColor, (i-1) * _size_x, (j-1) * _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, _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] = _freeRoad;
}
}
while (counter < 20)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (x + 1 < 100 && y + 1 < 100)
{
if (_map[x, y] == _freeRoad && _map[x, y + 1] == _freeRoad && _map[x + 1, y] == _freeRoad && _map[x + 1, y + 1] == _freeRoad)
{
_map[x, y] = _barrier;
_map[x + 1, y] = _barrier;
_map[x + 1, y + 1] = _barrier;
_map[x, y + 1] = _barrier;
counter++;
}
}
}
}
}
}

View File

@ -16,7 +16,6 @@ namespace WarmlyLocomotive
}
public void DrawningObject(Graphics g)
{
//ToDo
_locomotive?.DrawTransport(g);
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()

View File

@ -158,7 +158,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(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);

View File

@ -78,6 +78,12 @@ namespace WarmlyLocomotive
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Карта с большими барьерами":
_abstractMap = new BigBarriersMap();
break;
case "Карта с барьерами-кругами":
_abstractMap = new CirclesMap();
break;
}
}
}