Compare commits
57 Commits
Author | SHA1 | Date | |
---|---|---|---|
d33dd81637 | |||
|
e0e3cfa6b3 | ||
|
adb9a6e567 | ||
|
58dca62ba7 | ||
|
e88bc4f57c | ||
|
2f1f850316 | ||
|
7e5c89d036 | ||
|
e31712ac6a | ||
|
56df1b9cb5 | ||
|
e4026d0b86 | ||
69db2652b3 | |||
17c69aebd7 | |||
63b72d2531 | |||
|
056cf6de2e | ||
|
edacc5498e | ||
|
5e0dfc5288 | ||
|
19eeb2b950 | ||
|
eace47e5ed | ||
|
7e3898123b | ||
|
d58705a5b2 | ||
|
20a73a199a | ||
|
bbbd2b794a | ||
|
74f5ddbdb8 | ||
|
beb0249392 | ||
|
e89afef208 | ||
|
29c3bb2f1d | ||
|
004ef856b9 | ||
|
c5f38eed07 | ||
|
81b1b26dc6 | ||
|
ad1b421aee | ||
|
9f549cc154 | ||
|
8a247dcc9a | ||
|
1d3cf33ca3 | ||
|
958cddcd6a | ||
|
70641cea7f | ||
|
340744510b | ||
|
92d046cc54 | ||
|
caacb5672f | ||
|
56c05a4d82 | ||
|
9d1f86bdd0 | ||
|
710e7086b9 | ||
|
b53a7d4689 | ||
|
32b7c9ecf7 | ||
|
97fda24a73 | ||
|
33525e1799 | ||
2b2d3903c2 | |||
|
2f87fa46bd | ||
|
c2c005c942 | ||
|
78c0f3880f | ||
|
7df4ed00ce | ||
|
020c73c4d1 | ||
|
7edfd49847 | ||
|
20b682b2ef | ||
|
7b58ed1f01 | ||
|
7f2ffe217c | ||
|
f5cb1bfbe2 | ||
|
5c1444b66c |
178
AirBomber/AirBomber/AbstractMap.cs
Normal file
178
AirBomber/AirBomber/AbstractMap.cs
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal abstract class AbstractMap
|
||||||
|
{
|
||||||
|
private IDrawningObject _drawningObject = null;
|
||||||
|
private Bitmap? _staticBitMap;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_staticBitMap = null;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawningObject = drawningObject;
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasMap => _map != null;
|
||||||
|
|
||||||
|
/// <summary>Проверяет наличие непроходимых участков в заданной области</summary>
|
||||||
|
/// <param name="area">Заданная область</param>
|
||||||
|
/// <param name="iBarrier">i-ый индекс первого барьера, который был найден в области</param>
|
||||||
|
/// <param name="jBarrier">j-ый индекс первого барьера, который был найден в области</param>
|
||||||
|
/// <returns>Есть ли барьеры</returns>
|
||||||
|
protected bool BarriersInArea(RectangleF area, ref int iBarrier, ref int jBarrier)
|
||||||
|
{
|
||||||
|
if (!(0 < area.Left && area.Right < _width && 0 < area.Top && area.Bottom < _height))
|
||||||
|
{
|
||||||
|
return true; // Если область попала за карту, считаем что она столкнулась с барьером
|
||||||
|
}
|
||||||
|
int rightArea = (int)Math.Ceiling(area.Right / _size_x);
|
||||||
|
int bottomArea = (int)Math.Ceiling(area.Bottom / _size_y);
|
||||||
|
for (int i = (int)(area.Left / _size_x); i < rightArea; i++)
|
||||||
|
{
|
||||||
|
for (int j = (int)(area.Top / _size_y); j < bottomArea; j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
iBarrier = i;
|
||||||
|
jBarrier = j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>Проверяет наличие непроходимых участков в заданной области</summary>
|
||||||
|
/// <param name="area">Заданная область</param>
|
||||||
|
/// <returns>Есть ли барьеры</returns>
|
||||||
|
protected bool BarriersInArea(RectangleF area)
|
||||||
|
{
|
||||||
|
int a = 0, b = 0;
|
||||||
|
return BarriersInArea(area, ref a, ref b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
var rect = _drawningObject.GetCurrentPosition();
|
||||||
|
var step = _drawningObject.Step;
|
||||||
|
// Вычисляем области смещения объекта
|
||||||
|
RectangleF? area = null;
|
||||||
|
if (direction == Direction.Left)
|
||||||
|
area = new(rect.Left - step, rect.Top, step, rect.Height);
|
||||||
|
else if (direction == Direction.Right)
|
||||||
|
area = new(rect.Right, rect.Top, step, rect.Height);
|
||||||
|
else if (direction == Direction.Up)
|
||||||
|
area = new(rect.Left, rect.Top - step, rect.Width, step);
|
||||||
|
else if (direction == Direction.Down)
|
||||||
|
area = new(rect.Left, rect.Bottom, rect.Width, step);
|
||||||
|
if (area.HasValue && !BarriersInArea(area.Value))
|
||||||
|
{
|
||||||
|
_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);
|
||||||
|
|
||||||
|
// Если натыкаемся на барьер помещаем левый верхний угол чуть ниже этого барьера
|
||||||
|
// если при этом выходим за карту, пермещаем правый нижный угол чуть выше этого барьера
|
||||||
|
// если объект выходит за карту, генирируем новые координаты рандомно
|
||||||
|
int currI = 0, currJ = 0;
|
||||||
|
var areaObject = _drawningObject.GetCurrentPosition();
|
||||||
|
int cntOut = 10000; // Количество итераций до выхода из цикла
|
||||||
|
while (BarriersInArea(areaObject, ref currI, ref currJ) && --cntOut >= 0)
|
||||||
|
{
|
||||||
|
if ((currJ + 1) * _size_y + areaObject.Height <= _height)
|
||||||
|
{
|
||||||
|
areaObject.Location = new PointF((currI + 1) * _size_x, (currJ + 1) * _size_y);
|
||||||
|
}
|
||||||
|
else if ((currI - 1) * _size_x - areaObject.Width >= 0)
|
||||||
|
{
|
||||||
|
areaObject = new((currI - 1) * _size_x - areaObject.Width, (currJ - 1) * _size_y - areaObject.Height, areaObject.Width, areaObject.Height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
areaObject.Location = new PointF(_random.Next(0, _width - (int)areaObject.Width),
|
||||||
|
_random.Next(0, _height - (int)areaObject.Height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawningObject.SetObject((int)areaObject.X, (int)areaObject.Y, _width, _height);
|
||||||
|
return cntOut >= 0;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполняет BitMap для отрисовки статичных объектов. Выполняется один раз при создании карты
|
||||||
|
/// </summary>
|
||||||
|
private void DrawMap()
|
||||||
|
{
|
||||||
|
if (_staticBitMap != null) return;
|
||||||
|
_staticBitMap = new(_width, _height);
|
||||||
|
Graphics gr = Graphics.FromImage(_staticBitMap);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap DrawMapWithObject()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_width, _height);
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
if (_staticBitMap == null)
|
||||||
|
DrawMap();
|
||||||
|
if (_staticBitMap != null)
|
||||||
|
gr.DrawImage(_staticBitMap, 0, 0);
|
||||||
|
_drawningObject.DrawObject(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Генерация карты. При перегрузки определить поля _map, _size_x, _size_y
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
}
|
||||||
|
}
|
@ -3,8 +3,9 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
|
None = 0,
|
||||||
Up = 1,
|
Up = 1,
|
||||||
Down = 2,
|
Down = 2,
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
67
AirBomber/AirBomber/DrawningAirBomber.cs
Normal file
67
AirBomber/AirBomber/DrawningAirBomber.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class DrawningAirBomber : DrawningAirplane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес самолета</param>
|
||||||
|
/// <param name="bodyColor">Цвет обшивки</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="hasBombs">Признак наличия бомб</param>
|
||||||
|
/// <param name="hasFuelTanks">Признак наличия топливных баков</param>
|
||||||
|
public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks)
|
||||||
|
: base(speed, weight, bodyColor, 95, 110)
|
||||||
|
{
|
||||||
|
Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Airplane is not EntityAirBomber airBomber)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var x = _startPosX;
|
||||||
|
var y = _startPosY;
|
||||||
|
var w = _airplaneWidth;
|
||||||
|
var h = _airplaneHeight;
|
||||||
|
Brush brush = new SolidBrush(airBomber.DopColor);
|
||||||
|
|
||||||
|
if (airBomber.HasBombs) // Бомбы снизу рисуются сначала
|
||||||
|
{
|
||||||
|
DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 - 19, 23, 10));
|
||||||
|
DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 + 9, 23, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
if (airBomber.HasFuelTanks)
|
||||||
|
{
|
||||||
|
g.FillEllipse(brush, new RectangleF(x + w / 4, y + h / 2 - 6, w / 2.5f, 12));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBomb(Graphics g, Color colorBomb, RectangleF r)
|
||||||
|
{
|
||||||
|
Pen pen = new(colorBomb);
|
||||||
|
pen.Width = r.Height / 3;
|
||||||
|
var widthTail = r.Width / 6;
|
||||||
|
g.FillEllipse(new SolidBrush(colorBomb), r.X, r.Y, r.Width - widthTail, r.Height); // Основание бомбы
|
||||||
|
// Хвост бомбы
|
||||||
|
var baseTail = new PointF(r.Right - widthTail, r.Y + r.Height / 2);
|
||||||
|
g.DrawLine(pen, baseTail, new PointF(r.Right, r.Top));
|
||||||
|
g.DrawLine(pen, baseTail, new PointF(r.Right, r.Bottom));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,46 +3,60 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DrawningAirplane
|
public class DrawningAirplane
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAirplane Airplane { get; private set; }
|
public EntityAirplane Airplane { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки самолета
|
/// Левая координата отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки самолета
|
/// Верхняя кооридната отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureWidth = null;
|
protected int? _pictureWidth = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureHeight = null;
|
protected int? _pictureHeight = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина отрисовки самолета
|
/// Ширина отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _airplaneWidth = 110;
|
protected readonly int _airplaneWidth = 80;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота отрисовки самолета
|
/// Высота отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _airplaneHeight = 140;
|
protected readonly int _airplaneHeight = 90;
|
||||||
/// <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(int speed, float weight, Color bodyColor)
|
public DrawningAirplane(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Airplane = new EntityAirplane();
|
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||||
Airplane.Init(speed, weight, bodyColor);
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес самолета</param>
|
||||||
|
/// <param name="bodyColor">Цвет обшивки</param>
|
||||||
|
/// <param name="airplaneWidth">Ширина отрисовки самолета</param>
|
||||||
|
/// <param name="airplaneHeight">Высота отрисовки самолета</param>
|
||||||
|
protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_airplaneWidth = airplaneWidth;
|
||||||
|
_airplaneHeight = airplaneHeight;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции самолета
|
/// Установка позиции самолета
|
||||||
@ -112,7 +126,7 @@
|
|||||||
/// Отрисовка самолета
|
/// Отрисовка самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
@ -192,5 +206,14 @@
|
|||||||
_startPosY = _pictureHeight.Value - _airplaneHeight;
|
_startPosY = _pictureHeight.Value - _airplaneHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение текущей позиции объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public RectangleF GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return new(_startPosX, _startPosY, _airplaneWidth, _airplaneHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
40
AirBomber/AirBomber/DrawningObject.cs
Normal file
40
AirBomber/AirBomber/DrawningObject.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class DrawningObject : IDrawningObject
|
||||||
|
{
|
||||||
|
private DrawningAirplane _airplane = null;
|
||||||
|
|
||||||
|
public DrawningObject(DrawningAirplane airplane)
|
||||||
|
{
|
||||||
|
_airplane = airplane;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Step => _airplane?.Airplane?.Step ?? 0;
|
||||||
|
|
||||||
|
public RectangleF GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return _airplane.GetCurrentPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_airplane?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_airplane?.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawObject(Graphics g)
|
||||||
|
{
|
||||||
|
_airplane?.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
AirBomber/AirBomber/EntityAirBomber.cs
Normal file
40
AirBomber/AirBomber/EntityAirBomber.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class EntityAirBomber : EntityAirplane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия бомб
|
||||||
|
/// </summary>
|
||||||
|
public bool HasBombs { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия топливных баков
|
||||||
|
/// </summary>
|
||||||
|
public bool HasFuelTanks { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес самолета</param>
|
||||||
|
/// <param name="bodyColor">Цвет обшивки самолета</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="hasBombs">Признак наличия бомб</param>
|
||||||
|
/// <param name="hasFuelTanks">Признак наличия топливных баков</param>
|
||||||
|
public EntityAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) :
|
||||||
|
base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
HasBombs = hasBombs;
|
||||||
|
HasFuelTanks = hasFuelTanks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Самолет"
|
/// Класс-сущность "Самолет"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class EntityAirplane
|
public class EntityAirplane
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Скорость
|
||||||
@ -28,7 +28,7 @@
|
|||||||
/// <param name="weight"></param>
|
/// <param name="weight"></param>
|
||||||
/// <param name="bodyColor"></param>
|
/// <param name="bodyColor"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityAirplane(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
28
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
28
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
@ -38,6 +38,8 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = 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();
|
||||||
|
this.buttonSelectAirplane = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -141,11 +143,35 @@
|
|||||||
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);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(93, 390);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(108, 23);
|
||||||
|
this.buttonCreateModif.TabIndex = 8;
|
||||||
|
this.buttonCreateModif.Text = "Модификация";
|
||||||
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||||
|
//
|
||||||
|
// buttonSelectAirplane
|
||||||
|
//
|
||||||
|
this.buttonSelectAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonSelectAirplane.Location = new System.Drawing.Point(577, 390);
|
||||||
|
this.buttonSelectAirplane.Name = "buttonSelectAirplane";
|
||||||
|
this.buttonSelectAirplane.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSelectAirplane.TabIndex = 8;
|
||||||
|
this.buttonSelectAirplane.Text = "Выбрать";
|
||||||
|
this.buttonSelectAirplane.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelectAirplane.Click += new System.EventHandler(this.ButtonSelectAirplane_Click);
|
||||||
|
//
|
||||||
// FormAirBomber
|
// FormAirBomber
|
||||||
//
|
//
|
||||||
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(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonSelectAirplane);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -175,5 +201,7 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
private Button buttonCreateModif;
|
||||||
|
private Button buttonSelectAirplane;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,11 @@ namespace AirBomber
|
|||||||
{
|
{
|
||||||
private DrawningAirplane _airplane;
|
private DrawningAirplane _airplane;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Âűáđŕííűé îáúĺęň
|
||||||
|
/// </summary>
|
||||||
|
public DrawningAirplane SelectedAirplane { get; private set; }
|
||||||
|
|
||||||
public FormAirBomber()
|
public FormAirBomber()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -19,6 +24,17 @@ namespace AirBomber
|
|||||||
pictureBoxAirplane.Image = bmp;
|
pictureBoxAirplane.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Ěĺňîä óńňŕíîâęč äŕííűő
|
||||||
|
/// </summary>
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Ńęîđîńňü: {_airplane.Airplane.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Âĺń: {_airplane.Airplane.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Öâĺň: {_airplane.Airplane.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
@ -26,12 +42,14 @@ namespace AirBomber
|
|||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_airplane = new DrawningAirplane();
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
_airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
ColorDialog dialog = new();
|
||||||
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
{
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
color = dialog.Color;
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
}
|
||||||
|
_airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||||
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -70,5 +88,41 @@ namespace AirBomber
|
|||||||
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Ěîäčôčęŕöč˙"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialogDop = new();
|
||||||
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDop.Color;
|
||||||
|
}
|
||||||
|
_airplane = new DrawningAirBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Âűáđŕňü"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonSelectAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedAirplane = _airplane;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
279
AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs
generated
Normal file
279
AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs
generated
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
partial class FormMapWithSetAirplanes
|
||||||
|
{
|
||||||
|
/// <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.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||||
|
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonRemoveAirplane = new System.Windows.Forms.Button();
|
||||||
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDown = 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.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAddAirplane = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
this.groupBoxMaps.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||||
|
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonAddAirplane);
|
||||||
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
||||||
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
|
this.groupBoxTools.Size = new System.Drawing.Size(204, 632);
|
||||||
|
this.groupBoxTools.TabIndex = 0;
|
||||||
|
this.groupBoxTools.TabStop = false;
|
||||||
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// groupBoxMaps
|
||||||
|
//
|
||||||
|
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||||
|
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
|
||||||
|
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||||
|
this.groupBoxMaps.Size = new System.Drawing.Size(192, 248);
|
||||||
|
this.groupBoxMaps.TabIndex = 0;
|
||||||
|
this.groupBoxMaps.TabStop = false;
|
||||||
|
this.groupBoxMaps.Text = "Карты";
|
||||||
|
//
|
||||||
|
// buttonAddMap
|
||||||
|
//
|
||||||
|
this.buttonAddMap.Location = new System.Drawing.Point(11, 80);
|
||||||
|
this.buttonAddMap.Name = "buttonAddMap";
|
||||||
|
this.buttonAddMap.Size = new System.Drawing.Size(175, 35);
|
||||||
|
this.buttonAddMap.TabIndex = 2;
|
||||||
|
this.buttonAddMap.Text = "Добавить карту";
|
||||||
|
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||||
|
//
|
||||||
|
// buttonDeleteMap
|
||||||
|
//
|
||||||
|
this.buttonDeleteMap.Location = new System.Drawing.Point(11, 206);
|
||||||
|
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||||
|
this.buttonDeleteMap.Size = new System.Drawing.Size(175, 35);
|
||||||
|
this.buttonDeleteMap.TabIndex = 4;
|
||||||
|
this.buttonDeleteMap.Text = "Удалить карту";
|
||||||
|
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||||
|
//
|
||||||
|
// listBoxMaps
|
||||||
|
//
|
||||||
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
|
this.listBoxMaps.ItemHeight = 15;
|
||||||
|
this.listBoxMaps.Location = new System.Drawing.Point(11, 121);
|
||||||
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
|
this.listBoxMaps.Size = new System.Drawing.Size(175, 79);
|
||||||
|
this.listBoxMaps.TabIndex = 3;
|
||||||
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// textBoxNewMapName
|
||||||
|
//
|
||||||
|
this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22);
|
||||||
|
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||||
|
this.textBoxNewMapName.Size = new System.Drawing.Size(175, 23);
|
||||||
|
this.textBoxNewMapName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
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(11, 51);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 355);
|
||||||
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||||
|
this.maskedTextBoxPosition.TabIndex = 2;
|
||||||
|
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonRemoveAirplane
|
||||||
|
//
|
||||||
|
this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 384);
|
||||||
|
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
||||||
|
this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35);
|
||||||
|
this.buttonRemoveAirplane.TabIndex = 3;
|
||||||
|
this.buttonRemoveAirplane.Text = "Удалить самолет";
|
||||||
|
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click);
|
||||||
|
//
|
||||||
|
// buttonShowStorage
|
||||||
|
//
|
||||||
|
this.buttonShowStorage.Location = new System.Drawing.Point(17, 437);
|
||||||
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
|
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||||
|
this.buttonShowStorage.TabIndex = 4;
|
||||||
|
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown;
|
||||||
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(91, 582);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonDown.TabIndex = 10;
|
||||||
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight;
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(127, 582);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonRight.TabIndex = 9;
|
||||||
|
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::AirBomber.Properties.Resources.arrowLeft;
|
||||||
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(55, 582);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonLeft.TabIndex = 8;
|
||||||
|
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::AirBomber.Properties.Resources.arrowUp;
|
||||||
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(91, 546);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonUp.TabIndex = 7;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonShowOnMap
|
||||||
|
//
|
||||||
|
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 487);
|
||||||
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
|
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||||
|
this.buttonShowOnMap.TabIndex = 5;
|
||||||
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||||
|
//
|
||||||
|
// buttonAddAirplane
|
||||||
|
//
|
||||||
|
this.buttonAddAirplane.Location = new System.Drawing.Point(17, 314);
|
||||||
|
this.buttonAddAirplane.Name = "buttonAddAirplane";
|
||||||
|
this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35);
|
||||||
|
this.buttonAddAirplane.TabIndex = 1;
|
||||||
|
this.buttonAddAirplane.Text = "Добавить самолет";
|
||||||
|
this.buttonAddAirplane.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click);
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBox.Name = "pictureBox";
|
||||||
|
this.pictureBox.Size = new System.Drawing.Size(811, 632);
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormMapWithSetAirplanes
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1015, 632);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Name = "FormMapWithSetAirplanes";
|
||||||
|
this.Text = "Карта с набором объектов";
|
||||||
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
|
this.groupBoxTools.PerformLayout();
|
||||||
|
this.groupBoxMaps.ResumeLayout(false);
|
||||||
|
this.groupBoxMaps.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
private Button buttonShowOnMap;
|
||||||
|
private Button buttonAddAirplane;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonShowStorage;
|
||||||
|
private Button buttonRemoveAirplane;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private GroupBox groupBoxMaps;
|
||||||
|
private Button buttonDeleteMap;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
private TextBox textBoxNewMapName;
|
||||||
|
private Button buttonAddMap;
|
||||||
|
}
|
||||||
|
}
|
206
AirBomber/AirBomber/FormMapWithSetAirplanes.cs
Normal file
206
AirBomber/AirBomber/FormMapWithSetAirplanes.cs
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public partial class FormMapWithSetAirplanes : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь для выпадающего списка
|
||||||
|
/// </summary>
|
||||||
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{ "Простая карта", new SimpleMap() },
|
||||||
|
{ "Карта со стенами", new WallMap() },
|
||||||
|
};
|
||||||
|
/// <summary>
|
||||||
|
/// Объект от коллекции карт
|
||||||
|
/// </summary>
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormMapWithSetAirplanes()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
|
comboBoxSelectorMap.Items.Clear();
|
||||||
|
foreach(var elem in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxMaps
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = listBoxMaps.SelectedIndex;
|
||||||
|
|
||||||
|
listBoxMaps.Items.Clear();
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormAirBomber form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
DrawningObject airplane = new(form.SelectedAirplane);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text) ||
|
||||||
|
MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//получаем имя кнопки
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AirBomber/AirBomber/FormMapWithSetAirplanes.resx
Normal file
60
AirBomber/AirBomber/FormMapWithSetAirplanes.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<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>
|
||||||
|
</root>
|
43
AirBomber/AirBomber/IDrawningObject.cs
Normal file
43
AirBomber/AirBomber/IDrawningObject.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||||
|
/// </summary>
|
||||||
|
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>
|
||||||
|
/// <returns></returns>
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
void DrawObject(Graphics g);
|
||||||
|
/// <summary>
|
||||||
|
/// Получение текущей позиции объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
RectangleF GetCurrentPosition();
|
||||||
|
}
|
||||||
|
}
|
186
AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs
Normal file
186
AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class MapWithSetAirplanesGeneric<T, U>
|
||||||
|
where T : class, IDrawningObject
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 190;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetAirplanesGeneric<T> _setAirplanes;
|
||||||
|
/// <summary>
|
||||||
|
/// Карта
|
||||||
|
/// </summary>
|
||||||
|
private readonly U _map;
|
||||||
|
|
||||||
|
public U Map => _map;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="map"></param>
|
||||||
|
public MapWithSetAirplanesGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setAirplanes = new SetAirplanesGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="map"></param>
|
||||||
|
/// <param name="airplane"></param>
|
||||||
|
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
|
||||||
|
public static int operator +(MapWithSetAirplanesGeneric<T, U> map, T airplane)
|
||||||
|
{
|
||||||
|
return map._setAirplanes.Insert(airplane);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="map"></param>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
|
||||||
|
public static T operator -(MapWithSetAirplanesGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setAirplanes.Remove(position);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawAirplanes(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Просмотр объекта на карте
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
for (int i = 0; i < _setAirplanes.Count; i++)
|
||||||
|
{
|
||||||
|
var airplane = _setAirplanes[i];
|
||||||
|
if (airplane != null)
|
||||||
|
{
|
||||||
|
return Map.CreateMap(_pictureWidth, _pictureHeight, airplane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение объекта по крате
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (Map != null)
|
||||||
|
{
|
||||||
|
return Map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||||
|
/// </summary>
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setAirplanes.Count - 1;
|
||||||
|
for (int i = 0; i < _setAirplanes.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setAirplanes[i] == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var airplane = _setAirplanes[j];
|
||||||
|
if (airplane != null)
|
||||||
|
{
|
||||||
|
_setAirplanes.Insert(airplane, i);
|
||||||
|
_setAirplanes.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
|
||||||
|
{
|
||||||
|
DrawHangar(g, pen, new RectangleF(i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth / 1.8F, _placeSizeHeight / 1.6F));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawHangar(Graphics g, Pen pen, RectangleF rect)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, rect.Left , rect.Top , rect.Right, rect.Top );
|
||||||
|
g.DrawLine(pen, rect.Right, rect.Top , rect.Right, rect.Bottom);
|
||||||
|
g.DrawLine(pen, rect.Right, rect.Bottom, rect.Left , rect.Bottom);
|
||||||
|
|
||||||
|
// Края ворот ангара
|
||||||
|
g.DrawLine(pen, rect.Left, rect.Top , rect.Left, rect.Top + rect.Height / 10);
|
||||||
|
g.DrawLine(pen, rect.Left, rect.Bottom, rect.Left, rect.Bottom - rect.Height / 10);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawAirplanes(Graphics g)
|
||||||
|
{
|
||||||
|
int countInLine = _pictureWidth / _placeSizeWidth;
|
||||||
|
int maxLeft = (countInLine - 1) * _placeSizeWidth;
|
||||||
|
for (int i = 0; i < _setAirplanes.Count; i++)
|
||||||
|
{
|
||||||
|
var airplane = _setAirplanes[i];
|
||||||
|
airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
|
||||||
|
airplane?.DrawObject(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
75
AirBomber/AirBomber/MapsCollection.cs
Normal file
75
AirBomber/AirBomber/MapsCollection.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using AirBomber;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс для хранения коллекции карт
|
||||||
|
/// </summary>
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище) с картами
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, MapWithSetAirplanesGeneric<DrawningObject,
|
||||||
|
AbstractMap>> _mapStorages;
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий карт
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pictureWidth"></param>
|
||||||
|
/// <param name="pictureHeight"></param>
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_mapStorages = new Dictionary<string,
|
||||||
|
MapWithSetAirplanesGeneric<DrawningObject, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название карты</param>
|
||||||
|
/// <param name="map">Карта</param>
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
_mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название карты</param>
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
_mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к аэродрому
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public MapWithSetAirplanesGeneric<DrawningObject, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
_mapStorages.TryGetValue(ind, out var mapWithSetAirplanesGeneric);
|
||||||
|
return mapWithSetAirplanesGeneric;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace AirBomber
|
|||||||
// 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 FormAirBomber());
|
Application.Run(new FormMapWithSetAirplanes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
113
AirBomber/AirBomber/SetAirplanesGeneric.cs
Normal file
113
AirBomber/AirBomber/SetAirplanesGeneric.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetAirplanesGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Список объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly List<T> _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Count;
|
||||||
|
|
||||||
|
private readonly int _maxcount;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetAirplanesGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxcount = count;
|
||||||
|
_places = new List<T>();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="airplane">Добавляемый самолет</param>
|
||||||
|
/// <returns>Возвращает позицию вставленного объекта, либо -1 если его не удалось вставить</returns>
|
||||||
|
public int Insert(T airplane)
|
||||||
|
{
|
||||||
|
return Insert(airplane, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool isCorrectPosition(int position)
|
||||||
|
{
|
||||||
|
return 0 <= position && position < _maxcount;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="airplane">Добавляемый самолет</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>Возвращает позицию вставленного объекта, либо -1 если его не удалось вставить</returns>
|
||||||
|
public int Insert(T airplane, int position)
|
||||||
|
{
|
||||||
|
if (!isCorrectPosition(position))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
_places.Insert(position, airplane);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (!isCorrectPosition(position))
|
||||||
|
return null;
|
||||||
|
var result = _places[position];
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return isCorrectPosition(position) && position < Count ? _places[position] : null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по набору до первого пустого
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T> GetAirplanes()
|
||||||
|
{
|
||||||
|
foreach (var airplane in _places)
|
||||||
|
{
|
||||||
|
if (airplane != null)
|
||||||
|
{
|
||||||
|
yield return airplane;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
AirBomber/AirBomber/SimpleMap.cs
Normal file
50
AirBomber/AirBomber/SimpleMap.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Простая реализация абсрактного класса AbstractMap
|
||||||
|
/// </summary>
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
AirBomber/AirBomber/WallMap.cs
Normal file
65
AirBomber/AirBomber/WallMap.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class WallMap : AbstractMap
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Brown);
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка открытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.LightPink);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillPolygon(barrierColor, new PointF[]
|
||||||
|
{
|
||||||
|
new PointF(i * _size_x, j * _size_y),
|
||||||
|
new PointF((i + 1) * _size_x, j * _size_y),
|
||||||
|
new PointF((i + 1) * _size_x - _size_x / 4, (j + 1) * _size_y - _size_y / 2),
|
||||||
|
new PointF((i + 1) * _size_x, (j + 1) * _size_y),
|
||||||
|
new PointF(i * _size_x, (j + 1) * _size_y),
|
||||||
|
new PointF(i * _size_x + _size_x / 4, (j + 1) * _size_y - _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[120, 120];
|
||||||
|
var minSize = Math.Min(_map.GetLength(0), _map.GetLength(1));
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
var lengthWall = _random.Next(3, minSize / 2);
|
||||||
|
var incX = _random.Next(0, 2);
|
||||||
|
var incY = 1 - incX;
|
||||||
|
var left = _random.Next(0, _map.GetLength(0) - lengthWall);
|
||||||
|
var top = _random.Next(0, _map.GetLength(1) - lengthWall);
|
||||||
|
for (var j = 0; j < lengthWall; j++)
|
||||||
|
{
|
||||||
|
_map[left + incX * j, top + incY * j] = _barrier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user