Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
fb148d0831 | |||
|
ed7cfe6354 | ||
|
477c7c1500 | ||
|
5ac86cbb43 | ||
|
928fa3a1df | ||
|
dd086e5c0b | ||
|
f81a857f68 |
124
Airbus/Airbus/AbstractMap.cs
Normal file
124
Airbus/Airbus/AbstractMap.cs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
internal abstract class AbstractMap
|
||||||
|
{
|
||||||
|
private IDrawningObject _drawningObject = null;
|
||||||
|
protected int[,] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected readonly Random _random = new();
|
||||||
|
protected readonly int _freeRoad = 0;
|
||||||
|
protected readonly int _barrier = 1;
|
||||||
|
public Bitmap CreateMap(int width, int height, IDrawningObject
|
||||||
|
drawningObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawningObject = drawningObject;
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckBarriers(float topOffset, float rightOffset, float leftOffset, float bottomOffset)
|
||||||
|
{
|
||||||
|
int top = Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + topOffset) / _size_y);
|
||||||
|
int right = Convert.ToInt32((_drawningObject.GetCurrentPosition().Right + rightOffset) / _size_x);
|
||||||
|
int left = Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + leftOffset) / _size_x);
|
||||||
|
int bottom = Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + bottomOffset) / _size_y);
|
||||||
|
if (top < 0 || left < 0 || right >= _map.GetLength(1) || bottom >= _map.GetLength(0)) return false;
|
||||||
|
for (int i = top; i <= bottom; i++)
|
||||||
|
{
|
||||||
|
for (int j = left; j <= right; j++)
|
||||||
|
{
|
||||||
|
if (_map[j, i] == _barrier) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
// TODO проверка, что объект может переместится в требуемом направлении
|
||||||
|
if (_drawningObject == null) return DrawMapWithObject();
|
||||||
|
bool isTrue = true;
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Direction.Left:
|
||||||
|
if (!CheckBarriers(0, -1 * _drawningObject.Step, -1 * _drawningObject.Step, 0)) isTrue = false;
|
||||||
|
break;
|
||||||
|
case Direction.Right:
|
||||||
|
if (!CheckBarriers(0, _drawningObject.Step, _drawningObject.Step, 0)) isTrue = false;
|
||||||
|
break;
|
||||||
|
case Direction.Up:
|
||||||
|
if (!CheckBarriers(-1 * _drawningObject.Step, 0, 0, -1 * _drawningObject.Step)) isTrue = false;
|
||||||
|
break;
|
||||||
|
case Direction.Down:
|
||||||
|
if (!CheckBarriers(_drawningObject.Step, 0, 0, _drawningObject.Step)) isTrue = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (isTrue)
|
||||||
|
{
|
||||||
|
_drawningObject.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int x = _random.Next(0, 10);
|
||||||
|
int y = _random.Next(0, 10);
|
||||||
|
_drawningObject.SetObject(x, y, _width, _height);
|
||||||
|
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||||
|
if (!CheckBarriers(0, 0, 0, 0)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Bitmap DrawMapWithObject()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_width, _height);
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _freeRoad)
|
||||||
|
{
|
||||||
|
DrawRoadPart(gr, i, j);
|
||||||
|
}
|
||||||
|
else if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
DrawBarrierPart(gr, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawningObject.DrawningObject(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ namespace Airbus
|
|||||||
{
|
{
|
||||||
internal enum Direction
|
internal enum Direction
|
||||||
{
|
{
|
||||||
|
None = 0,
|
||||||
Up = 1,
|
Up = 1,
|
||||||
Down = 2,
|
Down = 2,
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
@ -6,172 +6,78 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Airbus
|
namespace Airbus
|
||||||
{
|
{
|
||||||
internal class DrawningAirbus
|
internal class DrawningAirbus : DrawningPlane
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность
|
|
||||||
/// </summary>
|
|
||||||
public EntityAirbus Airbus { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Левая координата отрисовки самолета
|
|
||||||
/// </summary>
|
|
||||||
private float _startPosX;
|
|
||||||
/// <summary>
|
|
||||||
/// Верхняя кооридната отрисовки самолета
|
|
||||||
/// </summary>
|
|
||||||
private float _startPosY;
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина окна отрисовки
|
|
||||||
/// </summary>
|
|
||||||
private int? _pictureWidth = null;
|
|
||||||
/// <summary>
|
|
||||||
/// Высота окна отрисовки
|
|
||||||
/// </summary>
|
|
||||||
private int? _pictureHeight = null;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина отрисовки самолета
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _AirbusWidth = 130;
|
|
||||||
/// <summary>
|
|
||||||
/// Высота отрисовки самолета
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _AirbusHeight = 70;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес самолета</param>
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
public void Init(EntityAirbus Airbus)
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||||
|
/// <param name="wing">Признак наличия антикрыла</param>
|
||||||
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
|
public DrawningAirbus(int speed, float weight, Color bodyColor, Color
|
||||||
|
dopColor, bool bodyKit, bool wing, bool sportLine) :
|
||||||
|
base(speed, weight, bodyColor, 140, 70)
|
||||||
{
|
{
|
||||||
this.Airbus = Airbus;
|
Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
|
||||||
}
|
}
|
||||||
/// <summary>
|
public override void DrawTransport(Graphics g)
|
||||||
/// Установка позиции самолета
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Координата X</param>
|
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
|
||||||
/// <param name="height">Высота картинки</param>
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
|
||||||
{
|
{
|
||||||
if (x >= 0 && x + _AirbusWidth <= width && y >= 0 && y + _AirbusHeight <= height)
|
if (Plane is not EntityAirbus Airbus)
|
||||||
{
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Изменение направления пермещения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
public void MoveTransport(Direction direction)
|
|
||||||
{
|
|
||||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
// вправо
|
|
||||||
case Direction.Right:
|
|
||||||
if (_startPosX + _AirbusWidth + Airbus.Step < _pictureWidth)
|
|
||||||
{
|
|
||||||
_startPosX += Airbus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//влево
|
|
||||||
case Direction.Left:
|
|
||||||
if (_startPosX - Airbus.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosX -= Airbus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вверх
|
|
||||||
case Direction.Up:
|
|
||||||
if (_startPosY - Airbus.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosY -= Airbus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вниз
|
|
||||||
case Direction.Down:
|
|
||||||
if (_startPosY + _AirbusHeight + Airbus.Step < _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY += Airbus.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Отрисовка самолета
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
//границы самолета
|
Brush dopBrush = new SolidBrush(Airbus.DopColor);
|
||||||
g.DrawEllipse(pen, _startPosX, _startPosY + 30, 20, 20);
|
Brush fireBrush = new SolidBrush(Color.Red);
|
||||||
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 30, 100, 20);
|
Brush WindowBrush = new SolidBrush(Color.Blue);
|
||||||
|
|
||||||
g.DrawLine(pen, _startPosX + 110, _startPosY + 30, _startPosX + 130, _startPosY+40);
|
_startPosX += 10;
|
||||||
g.DrawLine(pen, _startPosX + 110, _startPosY+50, _startPosX + 130, _startPosY+40);
|
_startPosY += 5;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosX -= 10;
|
||||||
g.DrawLine(pen, _startPosX, _startPosY, _startPosX, _startPosY+40);
|
_startPosY -= 5;
|
||||||
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 30, _startPosY+30);
|
if (Airbus.BodyKit)
|
||||||
|
|
||||||
|
|
||||||
g.DrawLine(pen, _startPosX + 40, _startPosY + 50, _startPosX + 40, _startPosY+55);
|
|
||||||
g.DrawLine(pen, _startPosX + 100, _startPosY + 50, _startPosX + 100, _startPosY+55);
|
|
||||||
|
|
||||||
g.DrawEllipse(pen, _startPosX + 95, _startPosY + 55, 10, 10);
|
|
||||||
g.DrawEllipse(pen, _startPosX + 29, _startPosY + 55, 10, 10);
|
|
||||||
g.DrawEllipse(pen, _startPosX + 41, _startPosY + 55, 10, 10);
|
|
||||||
|
|
||||||
Brush br = new SolidBrush(Airbus?.BodyColor ?? Color.Black);
|
|
||||||
g.FillEllipse(br, _startPosX, _startPosY + 31, 20, 19);
|
|
||||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 31, 100, 19);
|
|
||||||
|
|
||||||
//илюминатор
|
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
|
||||||
g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 35, 60, 5);
|
|
||||||
g.FillEllipse(brBlack, _startPosX - 5, _startPosY + 25, 30, 10);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Смена границ формы отрисовки
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
|
||||||
/// <param name="height">Высота картинки</param>
|
|
||||||
public void ChangeBorders(int width, int height)
|
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
//1 реактор
|
||||||
_pictureHeight = height;
|
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 50, 22, 16);
|
||||||
if (_pictureWidth <= _AirbusWidth || _pictureHeight <= _AirbusHeight)
|
g.FillRectangle(dopBrush, _startPosX + 70, _startPosY + 50, 22, 16);
|
||||||
|
|
||||||
|
g.FillEllipse(dopBrush, _startPosX + 84, _startPosY + 50, 16, 16);
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, _startPosX + 62, _startPosY + 50, 16, 16);
|
||||||
|
g.FillEllipse(fireBrush, _startPosX + 62, _startPosY + 50, 16, 16);
|
||||||
|
|
||||||
|
//2 реактор
|
||||||
|
|
||||||
|
g.DrawRectangle(pen, _startPosX + 8, _startPosY + 18, 22, 16);
|
||||||
|
g.FillRectangle(dopBrush, _startPosX + 8, _startPosY + 18, 22, 16);
|
||||||
|
|
||||||
|
g.FillEllipse(dopBrush, _startPosX + 24, _startPosY + 18, 16, 16);
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, _startPosX, _startPosY + 18, 16, 16);
|
||||||
|
g.FillEllipse(fireBrush, _startPosX, _startPosY + 18, 16, 16);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (Airbus.Wing)
|
||||||
{
|
{
|
||||||
_pictureWidth = null;
|
|
||||||
_pictureHeight = null;
|
g.DrawLine(pen, _startPosX + 70, _startPosY + 20, _startPosX + 70, _startPosY + 35);
|
||||||
return;
|
g.DrawLine(pen, _startPosX + 70, _startPosY + 20, _startPosX + 90, _startPosY + 35);
|
||||||
}
|
}
|
||||||
if (_startPosX + _AirbusWidth > _pictureWidth)
|
if (Airbus.SportLine)
|
||||||
{
|
{
|
||||||
_startPosX = _pictureWidth.Value - _AirbusWidth;
|
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 40, 9, 9);
|
||||||
}
|
g.FillEllipse(WindowBrush, _startPosX + 110, _startPosY + 40, 9, 9);
|
||||||
if (_startPosY + _AirbusHeight > _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY = _pictureHeight.Value - _AirbusHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
Airbus/Airbus/DrawningObjectPlane.cs
Normal file
35
Airbus/Airbus/DrawningObjectPlane.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
internal class DrawningObjectPlane : IDrawningObject
|
||||||
|
{
|
||||||
|
private DrawningPlane _plane = null;
|
||||||
|
public DrawningObjectPlane(DrawningPlane plane)
|
||||||
|
{
|
||||||
|
_plane = plane;
|
||||||
|
}
|
||||||
|
public float Step => _plane?.Plane?.Step ?? 0;
|
||||||
|
public (float Left, float Top, float Right, float Bottom)
|
||||||
|
GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return _plane?.GetCurrentPosition() ?? default;
|
||||||
|
}
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_plane?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_plane.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
public void DrawningObject(Graphics g)
|
||||||
|
{
|
||||||
|
_plane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
189
Airbus/Airbus/DrawningPlane.cs
Normal file
189
Airbus/Airbus/DrawningPlane.cs
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
internal class DrawningPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityPlane Plane { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Левая координата отрисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
protected float _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя кооридната отрисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
protected float _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private int? _pictureWidth = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private int? _pictureHeight = null;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина отрисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _PlaneWidth = 130;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота отрисовки самолета
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _PlaneHeight = 70;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес самолета</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
public DrawningPlane(int speed, float weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Plane = new EntityPlane(speed, weight, bodyColor);
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции самолета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
if (x >= 0 && x + _PlaneWidth <= width && y >= 0 && y + _PlaneHeight <= height)
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления пермещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
public void MoveTransport(Direction direction)
|
||||||
|
{
|
||||||
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
// вправо
|
||||||
|
case Direction.Right:
|
||||||
|
if (_startPosX + _PlaneWidth + Plane.Step < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += Plane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//влево
|
||||||
|
case Direction.Left:
|
||||||
|
if (_startPosX - Plane.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= Plane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case Direction.Up:
|
||||||
|
if (_startPosY - Plane.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= Plane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case Direction.Down:
|
||||||
|
if (_startPosY + _PlaneHeight + Plane.Step < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += Plane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовка самолета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
///
|
||||||
|
protected DrawningPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight) : this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_PlaneWidth = planeWidth;
|
||||||
|
_PlaneHeight = planeHeight;
|
||||||
|
}
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
//границы самолета
|
||||||
|
g.DrawEllipse(pen, _startPosX, _startPosY + 30, 20, 20);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 30, 100, 20);
|
||||||
|
|
||||||
|
g.DrawLine(pen, _startPosX + 110, _startPosY + 30, _startPosX + 130, _startPosY+40);
|
||||||
|
g.DrawLine(pen, _startPosX + 110, _startPosY+50, _startPosX + 130, _startPosY+40);
|
||||||
|
|
||||||
|
|
||||||
|
g.DrawLine(pen, _startPosX, _startPosY, _startPosX, _startPosY+40);
|
||||||
|
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 30, _startPosY+30);
|
||||||
|
|
||||||
|
|
||||||
|
g.DrawLine(pen, _startPosX + 40, _startPosY + 50, _startPosX + 40, _startPosY+55);
|
||||||
|
g.DrawLine(pen, _startPosX + 100, _startPosY + 50, _startPosX + 100, _startPosY+55);
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, _startPosX + 95, _startPosY + 55, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 29, _startPosY + 55, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 41, _startPosY + 55, 10, 10);
|
||||||
|
|
||||||
|
Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black);
|
||||||
|
g.FillEllipse(br, _startPosX, _startPosY + 31, 20, 19);
|
||||||
|
g.FillRectangle(br, _startPosX + 10, _startPosY + 31, 100, 19);
|
||||||
|
|
||||||
|
//илюминатор
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 35, 60, 5);
|
||||||
|
g.FillEllipse(brBlack, _startPosX - 5, _startPosY + 25, 30, 10);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Смена границ формы отрисовки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
public void ChangeBorders(int width, int height)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
if (_pictureWidth <= _PlaneWidth || _pictureHeight <= _PlaneHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_startPosX + _PlaneWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth.Value - _PlaneWidth;
|
||||||
|
}
|
||||||
|
if (_startPosY + _PlaneHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight.Value - _PlaneHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return (_startPosX, _startPosY, _startPosX + _PlaneWidth, _startPosY + _PlaneHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,39 +6,41 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Airbus
|
namespace Airbus
|
||||||
{
|
{
|
||||||
internal class EntityAirbus
|
internal class EntityAirbus : EntityPlane
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Дополнительный цвет
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Speed { get; private set; }
|
public Color DopColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вес
|
/// Признак наличия обвеса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Weight { get; private set; }
|
public bool BodyKit { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Цвет кузова
|
/// Признак наличия антикрыла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; private set; }
|
public bool Wing { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения автомобиля
|
/// Признак наличия гоночной полосы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Step => Speed * 100 / Weight;
|
public bool SportLine { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса автомобиля
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed"></param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight"></param>
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
/// <param name="bodyColor"></param>
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
/// <returns></returns>
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||||
|
/// <param name="wing">Признак наличия антикрыла</param>
|
||||||
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
|
public EntityAirbus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
DopColor = dopColor;
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
BodyKit = bodyKit;
|
||||||
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
|
Wing = wing;
|
||||||
BodyColor = bodyColor;
|
SportLine = sportLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
44
Airbus/Airbus/EntityPlane.cs
Normal file
44
Airbus/Airbus/EntityPlane.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
internal class EntityPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public float Weight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет кузова
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения автомобиля
|
||||||
|
/// </summary>
|
||||||
|
public float Step => Speed * 100 / Weight;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей объекта-класса автомобиля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"></param>
|
||||||
|
/// <param name="weight"></param>
|
||||||
|
/// <param name="bodyColor"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public EntityPlane(int speed, float weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
216
Airbus/Airbus/FormMap.Designer.cs
generated
Normal file
216
Airbus/Airbus/FormMap.Designer.cs
generated
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
partial class FormMap
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.pictureBoxPlane = new System.Windows.Forms.PictureBox();
|
||||||
|
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||||
|
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
|
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
|
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
|
this.buttonCreate = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxSelector = new System.Windows.Forms.ComboBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).BeginInit();
|
||||||
|
this.statusStrip1.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxPlane
|
||||||
|
//
|
||||||
|
this.pictureBoxPlane.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBoxPlane.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBoxPlane.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.pictureBoxPlane.Name = "pictureBoxPlane";
|
||||||
|
this.pictureBoxPlane.Size = new System.Drawing.Size(700, 338);
|
||||||
|
this.pictureBoxPlane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
|
this.pictureBoxPlane.TabIndex = 0;
|
||||||
|
this.pictureBoxPlane.TabStop = false;
|
||||||
|
//
|
||||||
|
// statusStrip1
|
||||||
|
//
|
||||||
|
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.toolStripStatusLabelSpeed,
|
||||||
|
this.toolStripStatusLabelWeight,
|
||||||
|
this.toolStripStatusLabelBodyColor});
|
||||||
|
this.statusStrip1.Location = new System.Drawing.Point(0, 316);
|
||||||
|
this.statusStrip1.Name = "statusStrip1";
|
||||||
|
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
|
||||||
|
this.statusStrip1.Size = new System.Drawing.Size(700, 22);
|
||||||
|
this.statusStrip1.TabIndex = 1;
|
||||||
|
this.statusStrip1.Text = "statusStrip1";
|
||||||
|
//
|
||||||
|
// toolStripStatusLabelSpeed
|
||||||
|
//
|
||||||
|
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||||
|
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17);
|
||||||
|
this.toolStripStatusLabelSpeed.Text = "Скорость";
|
||||||
|
//
|
||||||
|
// toolStripStatusLabelWeight
|
||||||
|
//
|
||||||
|
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||||
|
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17);
|
||||||
|
this.toolStripStatusLabelWeight.Text = "Вес";
|
||||||
|
//
|
||||||
|
// toolStripStatusLabelBodyColor
|
||||||
|
//
|
||||||
|
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||||
|
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(33, 17);
|
||||||
|
this.toolStripStatusLabelBodyColor.Text = "Цвет";
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonCreate.Location = new System.Drawing.Point(10, 286);
|
||||||
|
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonCreate.Name = "buttonCreate";
|
||||||
|
this.buttonCreate.Size = new System.Drawing.Size(82, 22);
|
||||||
|
this.buttonCreate.TabIndex = 2;
|
||||||
|
this.buttonCreate.Text = "Создать";
|
||||||
|
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight;
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(658, 286);
|
||||||
|
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(26, 22);
|
||||||
|
this.buttonRight.TabIndex = 3;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft;
|
||||||
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(595, 286);
|
||||||
|
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(26, 22);
|
||||||
|
this.buttonLeft.TabIndex = 4;
|
||||||
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp;
|
||||||
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(626, 260);
|
||||||
|
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(26, 22);
|
||||||
|
this.buttonUp.TabIndex = 5;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown;
|
||||||
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(626, 286);
|
||||||
|
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(26, 22);
|
||||||
|
this.buttonDown.TabIndex = 6;
|
||||||
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(98, 285);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(99, 23);
|
||||||
|
this.buttonCreateModif.TabIndex = 7;
|
||||||
|
this.buttonCreateModif.Text = "Модификация";
|
||||||
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||||
|
//
|
||||||
|
// comboBoxSelector
|
||||||
|
//
|
||||||
|
this.comboBoxSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxSelector.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelector.Items.AddRange(new object[] {
|
||||||
|
"Простая карта",
|
||||||
|
"Вторая карта"});
|
||||||
|
this.comboBoxSelector.Location = new System.Drawing.Point(8, 8);
|
||||||
|
this.comboBoxSelector.Name = "comboBoxSelector";
|
||||||
|
this.comboBoxSelector.Size = new System.Drawing.Size(121, 23);
|
||||||
|
this.comboBoxSelector.TabIndex = 8;
|
||||||
|
this.comboBoxSelector.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelector_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// FormMap
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(700, 338);
|
||||||
|
this.Controls.Add(this.comboBoxSelector);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
|
this.Controls.Add(this.buttonDown);
|
||||||
|
this.Controls.Add(this.buttonUp);
|
||||||
|
this.Controls.Add(this.buttonLeft);
|
||||||
|
this.Controls.Add(this.buttonRight);
|
||||||
|
this.Controls.Add(this.buttonCreate);
|
||||||
|
this.Controls.Add(this.statusStrip1);
|
||||||
|
this.Controls.Add(this.pictureBoxPlane);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.Name = "FormMap";
|
||||||
|
this.Text = "Карта";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).EndInit();
|
||||||
|
this.statusStrip1.ResumeLayout(false);
|
||||||
|
this.statusStrip1.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private PictureBox pictureBoxPlane;
|
||||||
|
private StatusStrip statusStrip1;
|
||||||
|
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||||
|
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||||
|
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonCreateModif;
|
||||||
|
private ComboBox comboBoxSelector;
|
||||||
|
}
|
||||||
|
}
|
114
Airbus/Airbus/FormMap.cs
Normal file
114
Airbus/Airbus/FormMap.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
public partial class FormMap : Form
|
||||||
|
{
|
||||||
|
private AbstractMap _abstractMap;
|
||||||
|
public FormMap()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение информации по объекту
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane"></param>
|
||||||
|
private void SetData(DrawningPlane plane)
|
||||||
|
{
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Скорость: {plane.Plane.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Вес: {plane.Plane.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Цвет: {plane.Plane.BodyColor.Name}";
|
||||||
|
pictureBoxPlane.Image = _abstractMap.CreateMap(pictureBoxPlane.Width, pictureBoxPlane.Height, new DrawningObjectPlane(plane));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
var plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
|
SetData(plane);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение размеров формы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//получаем имя кнопки
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
Direction dir = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
dir = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
dir = Direction.Down;
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
dir = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
dir = Direction.Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pictureBoxPlane.Image = _abstractMap?.MoveObject(dir);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Модификация"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
var plane = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000,
|
||||||
|
2000),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
|
||||||
|
256)),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
|
||||||
|
256)),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
|
||||||
|
2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
|
SetData(plane);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Смена карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void comboBoxSelector_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelector.Text)
|
||||||
|
{
|
||||||
|
case "Простая карта":
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Вторая карта":
|
||||||
|
_abstractMap = new MyMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
namespace Airbus
|
namespace Airbus
|
||||||
{
|
{
|
||||||
partial class FormAirbus
|
partial class FormPlane
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -38,6 +38,7 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -149,11 +150,22 @@
|
|||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// FormAirbus
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(98, 285);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(99, 23);
|
||||||
|
this.buttonCreateModif.TabIndex = 7;
|
||||||
|
this.buttonCreateModif.Text = "Модификация";
|
||||||
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||||
|
//
|
||||||
|
// FormPlane
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(700, 338);
|
this.ClientSize = new System.Drawing.Size(700, 338);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -162,7 +174,7 @@
|
|||||||
this.Controls.Add(this.statusStrip1);
|
this.Controls.Add(this.statusStrip1);
|
||||||
this.Controls.Add(this.pictureBoxAirbus);
|
this.Controls.Add(this.pictureBoxAirbus);
|
||||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
this.Name = "FormAirbus";
|
this.Name = "FormPlane";
|
||||||
this.Text = "Самолет";
|
this.Text = "Самолет";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).EndInit();
|
||||||
this.statusStrip1.ResumeLayout(false);
|
this.statusStrip1.ResumeLayout(false);
|
||||||
@ -184,5 +196,6 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
private Button buttonCreateModif;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,11 +10,11 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace Airbus
|
namespace Airbus
|
||||||
{
|
{
|
||||||
public partial class FormAirbus : Form
|
public partial class FormPlane : Form
|
||||||
{
|
{
|
||||||
private DrawningAirbus _airbus;
|
private DrawningPlane _plane;
|
||||||
|
|
||||||
public FormAirbus()
|
public FormPlane()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
@ -25,9 +25,18 @@ namespace Airbus
|
|||||||
{
|
{
|
||||||
Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_airbus?.DrawTransport(gr);
|
_plane?.DrawTransport(gr);
|
||||||
pictureBoxAirbus.Image = bmp;
|
pictureBoxAirbus.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}";
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Обработка нажатия кнопки "Создать"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -36,14 +45,8 @@ namespace Airbus
|
|||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_airbus = new DrawningAirbus();
|
_plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
EntityAirbus Airbus = new EntityAirbus();
|
SetData();
|
||||||
Airbus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
_airbus.Init(Airbus);
|
|
||||||
_airbus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
|
||||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_airbus.Airbus.Speed}";
|
|
||||||
toolStripStatusLabelWeight.Text = $"Вес: {_airbus.Airbus.Weight}";
|
|
||||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_airbus.Airbus.BodyColor.Name}";
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,16 +61,16 @@ namespace Airbus
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_airbus?.MoveTransport(Direction.Up);
|
_plane?.MoveTransport(Direction.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_airbus?.MoveTransport(Direction.Down);
|
_plane?.MoveTransport(Direction.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_airbus?.MoveTransport(Direction.Left);
|
_plane?.MoveTransport(Direction.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_airbus?.MoveTransport(Direction.Right);
|
_plane?.MoveTransport(Direction.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
@ -79,11 +82,17 @@ namespace Airbus
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void PictureBoxAirbus_Resize(object sender, EventArgs e)
|
private void PictureBoxAirbus_Resize(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
_plane?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_plane = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
63
Airbus/Airbus/FormPlane.resx
Normal file
63
Airbus/Airbus/FormPlane.resx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
40
Airbus/Airbus/IDrawningObject.cs
Normal file
40
Airbus/Airbus/IDrawningObject.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
internal interface IDrawningObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения объекта
|
||||||
|
/// </summary>
|
||||||
|
public float Step { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width">Ширина полотна</param>
|
||||||
|
/// <param name="height">Высота полотна</param>
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления пермещения объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
void DrawningObject(Graphics g);
|
||||||
|
/// <summary>
|
||||||
|
/// Получение текущей позиции объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
(float Left, float Top, float Right, float Bottom)
|
||||||
|
GetCurrentPosition();
|
||||||
|
}
|
||||||
|
}
|
48
Airbus/Airbus/MyMap.cs
Normal file
48
Airbus/Airbus/MyMap.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
internal class MyMap : AbstractMap
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.SkyBlue);
|
||||||
|
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 < 25)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace Airbus
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormAirbus());
|
Application.Run(new FormMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
53
Airbus/Airbus/SimpleMap.cs
Normal file
53
Airbus/Airbus/SimpleMap.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
internal class SimpleMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка открытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
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 < 50)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user