Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8647cc572a | ||
|
|
592059a118 | ||
|
|
4beddff8a2 | ||
|
|
4b4f3eed79 | ||
|
|
35feab6891 |
133
ProjectBomber/ProjectBomber/AbstractStrategy.cs
Normal file
133
ProjectBomber/ProjectBomber/AbstractStrategy.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectBomber.Entities;
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
@@ -6,66 +8,136 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber
|
||||
namespace ProjectBomber.DrawningObjects
|
||||
{
|
||||
internal class DrawningBomber
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBomber EntityBomber { get; private set; }
|
||||
public EntityBomber EntityBomber { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private int _bomberWidth = 50;
|
||||
protected readonly int _bomberWidth = 60;
|
||||
/// <summary>
|
||||
/// Высота прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private int _bomberHeight = 110;
|
||||
protected readonly int _bomberHeight = 55;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет крыльев</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
/// <param name="fuelTanks">Признак наличия топливных баков</param>
|
||||
/// <param name="line">Признак наличия полосы</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, bool line, int width, int height, int bomberwidth, int bomberheight)
|
||||
public DrawningBomber(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_bomberWidth = bomberwidth;
|
||||
_bomberHeight = bomberheight;
|
||||
EntityBomber = new EntityBomber();
|
||||
EntityBomber.Init(speed, weight, bodyColor, additionalColor, bombs, fuelTanks, line);
|
||||
EntityBomber = new EntityBomber(speed, weight, bodyColor);
|
||||
if ((_bomberWidth >= _pictureWidth) || (_bomberHeight >= _pictureHeight))
|
||||
{
|
||||
Console.WriteLine("Объект не прошел проверку");
|
||||
Console.WriteLine("Проверка не пройдена, нельзя создать объект в этих размерах");
|
||||
if (_bomberWidth >= _pictureWidth)
|
||||
{
|
||||
_bomberWidth = _pictureWidth - _bomberWidth;
|
||||
}
|
||||
if (_bomberHeight >= _pictureHeight)
|
||||
{
|
||||
_bomberHeight = _pictureHeight - _bomberHeight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Объект создан");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="bomberWidth">Ширина прорисовки бомбардировщика</param>
|
||||
/// <param name="bomberHeight">Высота прорисовки бомбардировщика</param>
|
||||
protected DrawningBomber(int speed, double weight, Color bodyColor, int width, int height, int bomberWidth, int bomberHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_bomberWidth = bomberWidth;
|
||||
_bomberHeight = bomberHeight;
|
||||
EntityBomber = new EntityBomber(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _bomberWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _bomberHeight;
|
||||
/// <summary>
|
||||
/// Проверка, что объект может переместится по указанному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityBomber == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (direction == DirectionType.Left)
|
||||
{
|
||||
return _startPosX - EntityBomber.Step > 0;
|
||||
}
|
||||
else if (direction == DirectionType.Up)
|
||||
{
|
||||
return _startPosY - EntityBomber.Step > 0;
|
||||
}
|
||||
else if (direction == DirectionType.Down)
|
||||
{
|
||||
return _startPosY + EntityBomber.Step < _pictureHeight;
|
||||
}
|
||||
else if (direction == DirectionType.Right)
|
||||
{
|
||||
return _startPosX + EntityBomber.Step < _pictureWidth;
|
||||
}
|
||||
|
||||
return false; // Возвращаем false в случае неподдерживаемого направления
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
@@ -73,6 +145,7 @@ namespace ProjectBomber
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// TODO: Изменение x, y, если при установке объект выходит за границы
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
// если выходит за границы, возвращаем на форму
|
||||
@@ -136,24 +209,18 @@ namespace ProjectBomber
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public IMoveableObject GetMoveableObject => new
|
||||
DrawningObjectBomber(this);
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityBomber.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityBomber.BodyColor);
|
||||
// Бомбы
|
||||
if (EntityBomber.Bombs)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 18, 18, 4);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 48, 18, 4);
|
||||
}
|
||||
// крыло 1
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
path.StartFigure();
|
||||
@@ -212,17 +279,10 @@ namespace ProjectBomber
|
||||
g.FillPath(brOrange, path1);
|
||||
// Рисуем контур линии
|
||||
g.DrawPath(pen, path1);
|
||||
// баки с топливом
|
||||
if (EntityBomber.FuelTanks)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 28, 10, 3);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 40, 10, 3);
|
||||
}
|
||||
// линия
|
||||
if (EntityBomber.Line)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 34, 50, 2);
|
||||
}
|
||||
}
|
||||
public void setColor(Color color)
|
||||
{
|
||||
EntityBomber.setColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
72
ProjectBomber/ProjectBomber/DrawningBomberAdvanced.cs
Normal file
72
ProjectBomber/ProjectBomber/DrawningBomberAdvanced.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.Entities;
|
||||
|
||||
namespace ProjectBomber.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningBomberAdvanced : DrawningBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bombs">Признак наличия обвеса</param>
|
||||
/// <param name="fuelTanks">Признак наличия антикрыла</param>
|
||||
/// <param name="line">Признак наличия гоночной полосы</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawningBomberAdvanced(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bombs, bool fuelTanks, bool line, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 60, 60)
|
||||
{
|
||||
if (EntityBomber != null)
|
||||
{
|
||||
EntityBomber = new EntityBomberAdvanced(speed, weight, bodyColor,
|
||||
additionalColor, bombs, fuelTanks, line);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBomber is EntityBomberAdvanced bomber)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(bomber.AdditionalColor);
|
||||
// Бомбы
|
||||
if (bomber.Bombs)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 18, 18, 4);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 48, 18, 4);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
// баки с топливом
|
||||
if (bomber.FuelTanks)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 28, 10, 3);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 40, 10, 3);
|
||||
}
|
||||
// линия
|
||||
if (bomber.Line)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 34, 50, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setAddColor(Color color)
|
||||
{
|
||||
if (EntityBomber is EntityBomberAdvanced bomber)
|
||||
{
|
||||
bomber.setAddColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
ProjectBomber/ProjectBomber/DrawningObjectBomber.cs
Normal file
38
ProjectBomber/ProjectBomber/DrawningObjectBomber.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawningObjectBomber : IMoveableObject
|
||||
{
|
||||
private readonly DrawningBomber _drawningBomber = null;
|
||||
public DrawningObjectBomber(DrawningBomber drawningBomber)
|
||||
{
|
||||
_drawningBomber = drawningBomber;
|
||||
}
|
||||
public ObjectParameters GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningBomber == null || _drawningBomber.EntityBomber == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningBomber.GetPosX,
|
||||
_drawningBomber.GetPosY, _drawningBomber.GetWidth, _drawningBomber.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningBomber?.EntityBomber?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningBomber?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningBomber?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber
|
||||
namespace ProjectBomber.Entities
|
||||
{
|
||||
internal class EntityBomber
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бомбардировщик"
|
||||
/// </summary>
|
||||
public class EntityBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@@ -22,45 +25,24 @@ namespace ProjectBomber
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия бомб
|
||||
/// </summary>
|
||||
public bool Bombs { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия топливных баков
|
||||
/// </summary>
|
||||
public bool FuelTanks { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия воздушного пространства
|
||||
/// </summary>
|
||||
public bool Line { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес бомбардировщика</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
/// <param name="fuelTanks">Признак наличия топливных баков</param>
|
||||
/// <param name="line">Признак наличия линии</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bombs, bool fuelTanks, bool line)
|
||||
public EntityBomber(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Bombs = bombs;
|
||||
FuelTanks = fuelTanks;
|
||||
Line = line;
|
||||
}
|
||||
public void setColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
55
ProjectBomber/ProjectBomber/EntityBomberAdvanced.cs
Normal file
55
ProjectBomber/ProjectBomber/EntityBomberAdvanced.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.Entities;
|
||||
|
||||
namespace ProjectBomber.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бомбардировщик"
|
||||
/// </summary>
|
||||
public class EntityBomberAdvanced : EntityBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия бомб
|
||||
/// </summary>
|
||||
public bool Bombs { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия топливных баков
|
||||
/// </summary>
|
||||
public bool FuelTanks { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия полосы
|
||||
/// </summary>
|
||||
public bool Line { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
/// <param name="fuelTanks">Признак наличия топливных баков</param>
|
||||
/// <param name="line">Признак наличия полосы</param>
|
||||
public EntityBomberAdvanced(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, bool line):
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Bombs = bombs;
|
||||
FuelTanks = fuelTanks;
|
||||
Line = line;
|
||||
}
|
||||
public void setAddColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
78
ProjectBomber/ProjectBomber/Form1.Designer.cs
generated
78
ProjectBomber/ProjectBomber/Form1.Designer.cs
generated
@@ -30,11 +30,15 @@
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBomber));
|
||||
this.pictureBoxBomber = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.ButtonCreateBomber = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.comboBox1Strategy = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonCreatePlane = new System.Windows.Forms.Button();
|
||||
this.ButtonStep = new System.Windows.Forms.Button();
|
||||
this.ButtonSelectPlane = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBomber)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -48,16 +52,16 @@
|
||||
this.pictureBoxBomber.TabIndex = 0;
|
||||
this.pictureBoxBomber.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// ButtonCreateBomber
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 422);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(87, 27);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
this.ButtonCreateBomber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreateBomber.Location = new System.Drawing.Point(12, 421);
|
||||
this.ButtonCreateBomber.Name = "ButtonCreateBomber";
|
||||
this.ButtonCreateBomber.Size = new System.Drawing.Size(150, 27);
|
||||
this.ButtonCreateBomber.TabIndex = 2;
|
||||
this.ButtonCreateBomber.Text = "Создать бомбардировщик";
|
||||
this.ButtonCreateBomber.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreateBomber.Click += new System.EventHandler(this.ButtonCreateBomber_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@@ -107,15 +111,61 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// comboBox1Strategy
|
||||
//
|
||||
this.comboBox1Strategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBox1Strategy.FormattingEnabled = true;
|
||||
this.comboBox1Strategy.Items.AddRange(new object[] {
|
||||
"_abstractStrategy",
|
||||
"_MyabstractStrategy"});
|
||||
this.comboBox1Strategy.Location = new System.Drawing.Point(712, 12);
|
||||
this.comboBox1Strategy.Name = "comboBox1Strategy";
|
||||
this.comboBox1Strategy.Size = new System.Drawing.Size(150, 21);
|
||||
this.comboBox1Strategy.TabIndex = 8;
|
||||
//
|
||||
// ButtonCreatePlane
|
||||
//
|
||||
this.ButtonCreatePlane.Location = new System.Drawing.Point(168, 421);
|
||||
this.ButtonCreatePlane.Name = "ButtonCreatePlane";
|
||||
this.ButtonCreatePlane.Size = new System.Drawing.Size(121, 27);
|
||||
this.ButtonCreatePlane.TabIndex = 9;
|
||||
this.ButtonCreatePlane.Text = "Создать самолет";
|
||||
this.ButtonCreatePlane.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreatePlane.Click += new System.EventHandler(this.ButtonCreatePlane_Click);
|
||||
//
|
||||
// ButtonStep
|
||||
//
|
||||
this.ButtonStep.Location = new System.Drawing.Point(712, 39);
|
||||
this.ButtonStep.Name = "ButtonStep";
|
||||
this.ButtonStep.Size = new System.Drawing.Size(150, 22);
|
||||
this.ButtonStep.TabIndex = 10;
|
||||
this.ButtonStep.Text = "Шаг";
|
||||
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||
//
|
||||
// ButtonSelectPlane
|
||||
//
|
||||
this.ButtonSelectPlane.Location = new System.Drawing.Point(295, 421);
|
||||
this.ButtonSelectPlane.Name = "ButtonSelectPlane";
|
||||
this.ButtonSelectPlane.Size = new System.Drawing.Size(101, 28);
|
||||
this.ButtonSelectPlane.TabIndex = 11;
|
||||
this.ButtonSelectPlane.Text = "Выбрать";
|
||||
this.ButtonSelectPlane.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectPlane.Click += new System.EventHandler(this.ButtonSelectPlane_Click);
|
||||
//
|
||||
// FormBomber
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.Controls.Add(this.ButtonSelectPlane);
|
||||
this.Controls.Add(this.ButtonStep);
|
||||
this.Controls.Add(this.ButtonCreatePlane);
|
||||
this.Controls.Add(this.comboBox1Strategy);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.ButtonCreateBomber);
|
||||
this.Controls.Add(this.pictureBoxBomber);
|
||||
this.Name = "FormBomber";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
@@ -129,11 +179,15 @@
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBoxBomber;
|
||||
private System.Windows.Forms.Button buttonCreate;
|
||||
private System.Windows.Forms.Button ButtonCreateBomber;
|
||||
private System.Windows.Forms.Button buttonUp;
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonDown;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.ComboBox comboBox1Strategy;
|
||||
private System.Windows.Forms.Button ButtonCreatePlane;
|
||||
private System.Windows.Forms.Button ButtonStep;
|
||||
private System.Windows.Forms.Button ButtonSelectPlane;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -12,10 +14,23 @@ namespace ProjectBomber
|
||||
{
|
||||
public partial class FormBomber : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningBomber _drawningBomber;
|
||||
/// <summary>
|
||||
/// Стратегии перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy _abstractStrategy;
|
||||
/// <summary>
|
||||
/// Выбранный автомобиль
|
||||
/// </summary>
|
||||
public DrawningBomber SelectedBomber { get; private set; }
|
||||
public FormBomber()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedBomber = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
@@ -29,20 +44,48 @@ namespace ProjectBomber
|
||||
pictureBoxBomber.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Обработка нажатия кнопки "Создать бомбардировщик"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
private void ButtonCreateBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_drawningBomber = new DrawningBomber();
|
||||
_drawningBomber.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxBomber.Width, pictureBoxBomber.Height, 60, 70);
|
||||
_drawningBomber.SetPosition(random.Next(0, 50),
|
||||
random.Next(0, 50));
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
//выбор основного цвета и дополнительного
|
||||
ColorDialog colorDialog = new ColorDialog();
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = colorDialog.Color;
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = colorDialog.Color;
|
||||
}
|
||||
}
|
||||
_drawningBomber = new DrawningBomberAdvanced(random.Next(100, 300), random.Next(1000, 3000),
|
||||
color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxBomber.Width, pictureBoxBomber.Height);
|
||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать самолёт"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreatePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog colorDialog = new ColorDialog();
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = colorDialog.Color;
|
||||
}
|
||||
_drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxBomber.Width, pictureBoxBomber.Height);
|
||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@@ -74,5 +117,52 @@ namespace ProjectBomber
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBox1Strategy.Enabled)
|
||||
{
|
||||
int selectedIndex = comboBox1Strategy.SelectedIndex;
|
||||
|
||||
if (selectedIndex == 0)
|
||||
{
|
||||
_abstractStrategy = new MoveToCenter();
|
||||
}
|
||||
else if (selectedIndex == 1)
|
||||
{
|
||||
_abstractStrategy = new MoveToBottomRight();
|
||||
}
|
||||
|
||||
if (_abstractStrategy != null)
|
||||
{
|
||||
_abstractStrategy.SetData(new DrawningObjectBomber(_drawningBomber), pictureBoxBomber.Width, pictureBoxBomber.Height);
|
||||
comboBox1Strategy.Enabled = false;
|
||||
}
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBox1Strategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор самолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSelectPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBomber = _drawningBomber;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
187
ProjectBomber/ProjectBomber/FormPlaneCollection.Designer.cs
generated
Normal file
187
ProjectBomber/ProjectBomber/FormPlaneCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,187 @@
|
||||
namespace ProjectBomber
|
||||
{
|
||||
partial class FormPlaneCollection
|
||||
{
|
||||
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.groupBoxSet = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||
this.ListBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.ButtonAddObject = new System.Windows.Forms.Button();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemovePlane = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddPlane = new System.Windows.Forms.Button();
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBoxSet.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.groupBoxSet);
|
||||
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.groupBox1.Controls.Add(this.ButtonRemovePlane);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddPlane);
|
||||
this.groupBox1.Location = new System.Drawing.Point(586, 2);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(216, 563);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// groupBoxSet
|
||||
//
|
||||
this.groupBoxSet.Controls.Add(this.ButtonDelObject);
|
||||
this.groupBoxSet.Controls.Add(this.ListBoxStorages);
|
||||
this.groupBoxSet.Controls.Add(this.ButtonAddObject);
|
||||
this.groupBoxSet.Controls.Add(this.textBoxStorageName);
|
||||
this.groupBoxSet.Location = new System.Drawing.Point(21, 25);
|
||||
this.groupBoxSet.Name = "groupBoxSet";
|
||||
this.groupBoxSet.Size = new System.Drawing.Size(180, 274);
|
||||
this.groupBoxSet.TabIndex = 4;
|
||||
this.groupBoxSet.TabStop = false;
|
||||
this.groupBoxSet.Text = "Наборы";
|
||||
//
|
||||
// ButtonDelObject
|
||||
//
|
||||
this.ButtonDelObject.Location = new System.Drawing.Point(7, 226);
|
||||
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||
this.ButtonDelObject.Size = new System.Drawing.Size(161, 37);
|
||||
this.ButtonDelObject.TabIndex = 3;
|
||||
this.ButtonDelObject.Text = "Удалить набор";
|
||||
this.ButtonDelObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||
//
|
||||
// ListBoxStorages
|
||||
//
|
||||
this.ListBoxStorages.FormattingEnabled = true;
|
||||
this.ListBoxStorages.Location = new System.Drawing.Point(9, 112);
|
||||
this.ListBoxStorages.Name = "ListBoxStorages";
|
||||
this.ListBoxStorages.Size = new System.Drawing.Size(162, 95);
|
||||
this.ListBoxStorages.TabIndex = 2;
|
||||
this.ListBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxStorages_SelectedIndexChanged);
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
this.ButtonAddObject.Location = new System.Drawing.Point(8, 61);
|
||||
this.ButtonAddObject.Name = "ButtonAddObject";
|
||||
this.ButtonAddObject.Size = new System.Drawing.Size(164, 34);
|
||||
this.ButtonAddObject.TabIndex = 1;
|
||||
this.ButtonAddObject.Text = "Добавить набор";
|
||||
this.ButtonAddObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(7, 21);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(166, 20);
|
||||
this.textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(18, 509);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(178, 41);
|
||||
this.ButtonRefreshCollection.TabIndex = 3;
|
||||
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// ButtonRemovePlane
|
||||
//
|
||||
this.ButtonRemovePlane.Location = new System.Drawing.Point(18, 430);
|
||||
this.ButtonRemovePlane.Name = "ButtonRemovePlane";
|
||||
this.ButtonRemovePlane.Size = new System.Drawing.Size(179, 41);
|
||||
this.ButtonRemovePlane.TabIndex = 2;
|
||||
this.ButtonRemovePlane.Text = "Удалить самолет";
|
||||
this.ButtonRemovePlane.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemovePlane.Click += new System.EventHandler(this.ButtonRemovePlane_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(18, 388);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(180, 20);
|
||||
this.maskedTextBoxNumber.TabIndex = 1;
|
||||
//
|
||||
// ButtonAddPlane
|
||||
//
|
||||
this.ButtonAddPlane.Location = new System.Drawing.Point(18, 327);
|
||||
this.ButtonAddPlane.Name = "ButtonAddPlane";
|
||||
this.ButtonAddPlane.Size = new System.Drawing.Size(185, 40);
|
||||
this.ButtonAddPlane.TabIndex = 0;
|
||||
this.ButtonAddPlane.Text = "Добавить самолет";
|
||||
this.ButtonAddPlane.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(-2, 2);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(600, 563);
|
||||
this.pictureBoxCollection.TabIndex = 1;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormPlaneCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 564);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormPlaneCollection";
|
||||
this.Text = "Набор самолетов";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBoxSet.ResumeLayout(false);
|
||||
this.groupBoxSet.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.Button ButtonRefreshCollection;
|
||||
private System.Windows.Forms.Button ButtonRemovePlane;
|
||||
private System.Windows.Forms.TextBox maskedTextBoxNumber;
|
||||
private System.Windows.Forms.Button ButtonAddPlane;
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.GroupBox groupBoxSet;
|
||||
private System.Windows.Forms.Button ButtonDelObject;
|
||||
private System.Windows.Forms.ListBox ListBoxStorages;
|
||||
private System.Windows.Forms.Button ButtonAddObject;
|
||||
private System.Windows.Forms.TextBox textBoxStorageName;
|
||||
}
|
||||
}
|
||||
192
ProjectBomber/ProjectBomber/FormPlaneCollection.cs
Normal file
192
ProjectBomber/ProjectBomber/FormPlaneCollection.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
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;
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using ProjectBomber.Generics;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма для работы с набором объектов класса DrawningBomber
|
||||
/// </summary>
|
||||
public partial class FormPlaneCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly PlanesGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormPlaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = ListBoxStorages.SelectedIndex;
|
||||
ListBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
ListBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (ListBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= ListBoxStorages.Items.Count))
|
||||
{
|
||||
ListBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (ListBoxStorages.Items.Count > 0 && index > -1 &&
|
||||
index < ListBoxStorages.Items.Count)
|
||||
{
|
||||
ListBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {ListBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(ListBoxStorages.SelectedItem.ToString()?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
private void AddPlane(DrawningBomber plane)
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((obj + plane) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var formPlaneConfig = new FormPlaneConfig();
|
||||
formPlaneConfig.Show();
|
||||
formPlaneConfig.AddEvent(AddPlane);
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
ProjectBomber/ProjectBomber/FormPlaneCollection.resx
Normal file
120
ProjectBomber/ProjectBomber/FormPlaneCollection.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
||||
382
ProjectBomber/ProjectBomber/FormPlaneConfig.Designer.cs
generated
Normal file
382
ProjectBomber/ProjectBomber/FormPlaneConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,382 @@
|
||||
namespace ProjectBomber
|
||||
{
|
||||
partial class FormPlaneConfig
|
||||
{
|
||||
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.panelGray = new System.Windows.Forms.Panel();
|
||||
this.panelWhite = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.checkBoxLine = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxFuelTanks = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.checkBoxBombs = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.panelObject = new System.Windows.Forms.Panel();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.labelAddColor = new System.Windows.Forms.Label();
|
||||
this.labelColor = new System.Windows.Forms.Label();
|
||||
this.ButtonOk = new System.Windows.Forms.Button();
|
||||
this.buttonCanel = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
this.panelObject.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.labelModifiedObject);
|
||||
this.groupBox1.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBox1.Controls.Add(this.groupBoxColors);
|
||||
this.groupBox1.Controls.Add(this.checkBoxLine);
|
||||
this.groupBox1.Controls.Add(this.checkBoxFuelTanks);
|
||||
this.groupBox1.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBox1.Controls.Add(this.checkBoxBombs);
|
||||
this.groupBox1.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(530, 225);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Параметры";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelModifiedObject.Location = new System.Drawing.Point(400, 183);
|
||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||
this.labelModifiedObject.Size = new System.Drawing.Size(93, 31);
|
||||
this.labelModifiedObject.TabIndex = 9;
|
||||
this.labelModifiedObject.Text = "Продвинутый";
|
||||
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(273, 183);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(99, 31);
|
||||
this.labelSimpleObject.TabIndex = 8;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||
this.groupBoxColors.Location = new System.Drawing.Point(273, 32);
|
||||
this.groupBoxColors.Name = "groupBoxColors";
|
||||
this.groupBoxColors.Size = new System.Drawing.Size(245, 120);
|
||||
this.groupBoxColors.TabIndex = 7;
|
||||
this.groupBoxColors.TabStop = false;
|
||||
this.groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(192, 73);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelPurple.TabIndex = 7;
|
||||
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(130, 73);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelBlack.TabIndex = 6;
|
||||
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||
this.panelGray.Location = new System.Drawing.Point(68, 73);
|
||||
this.panelGray.Name = "panelGray";
|
||||
this.panelGray.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelGray.TabIndex = 5;
|
||||
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(6, 73);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelWhite.TabIndex = 4;
|
||||
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Location = new System.Drawing.Point(192, 19);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelYellow.TabIndex = 3;
|
||||
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(130, 19);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelBlue.TabIndex = 2;
|
||||
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||
this.panelGreen.Location = new System.Drawing.Point(68, 19);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelGreen.TabIndex = 1;
|
||||
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(6, 19);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(45, 40);
|
||||
this.panelRed.TabIndex = 0;
|
||||
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// checkBoxLine
|
||||
//
|
||||
this.checkBoxLine.AutoSize = true;
|
||||
this.checkBoxLine.Location = new System.Drawing.Point(30, 183);
|
||||
this.checkBoxLine.Name = "checkBoxLine";
|
||||
this.checkBoxLine.Size = new System.Drawing.Size(155, 17);
|
||||
this.checkBoxLine.TabIndex = 6;
|
||||
this.checkBoxLine.Text = "Признак наличия полосы";
|
||||
this.checkBoxLine.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxFuelTanks
|
||||
//
|
||||
this.checkBoxFuelTanks.AutoSize = true;
|
||||
this.checkBoxFuelTanks.Location = new System.Drawing.Point(30, 149);
|
||||
this.checkBoxFuelTanks.Name = "checkBoxFuelTanks";
|
||||
this.checkBoxFuelTanks.Size = new System.Drawing.Size(204, 17);
|
||||
this.checkBoxFuelTanks.TabIndex = 5;
|
||||
this.checkBoxFuelTanks.Text = "Признак наличия топливных баков";
|
||||
this.checkBoxFuelTanks.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(91, 71);
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(75, 20);
|
||||
this.numericUpDownWeight.TabIndex = 4;
|
||||
//
|
||||
// checkBoxBombs
|
||||
//
|
||||
this.checkBoxBombs.AutoSize = true;
|
||||
this.checkBoxBombs.Location = new System.Drawing.Point(30, 116);
|
||||
this.checkBoxBombs.Name = "checkBoxBombs";
|
||||
this.checkBoxBombs.Size = new System.Drawing.Size(143, 17);
|
||||
this.checkBoxBombs.TabIndex = 3;
|
||||
this.checkBoxBombs.Text = "Признак наличия бомб";
|
||||
this.checkBoxBombs.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Increment = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(91, 32);
|
||||
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(75, 20);
|
||||
this.numericUpDownSpeed.TabIndex = 2;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(27, 73);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(29, 13);
|
||||
this.label2.TabIndex = 1;
|
||||
this.label2.Text = "Вес:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(27, 32);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(58, 13);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Скорость:";
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
this.panelObject.AllowDrop = true;
|
||||
this.panelObject.Controls.Add(this.pictureBoxObject);
|
||||
this.panelObject.Controls.Add(this.labelAddColor);
|
||||
this.panelObject.Controls.Add(this.labelColor);
|
||||
this.panelObject.Location = new System.Drawing.Point(558, 12);
|
||||
this.panelObject.Name = "panelObject";
|
||||
this.panelObject.Size = new System.Drawing.Size(230, 187);
|
||||
this.panelObject.TabIndex = 1;
|
||||
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(19, 48);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(190, 125);
|
||||
this.pictureBoxObject.TabIndex = 2;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// labelAddColor
|
||||
//
|
||||
this.labelAddColor.AllowDrop = true;
|
||||
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelAddColor.Location = new System.Drawing.Point(122, 18);
|
||||
this.labelAddColor.Name = "labelAddColor";
|
||||
this.labelAddColor.Size = new System.Drawing.Size(88, 27);
|
||||
this.labelAddColor.TabIndex = 1;
|
||||
this.labelAddColor.Text = "Доп. цвет";
|
||||
this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelAddColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAddColor_DragDrop);
|
||||
this.labelAddColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
this.labelColor.AllowDrop = true;
|
||||
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelColor.Location = new System.Drawing.Point(17, 18);
|
||||
this.labelColor.Name = "labelColor";
|
||||
this.labelColor.Size = new System.Drawing.Size(86, 27);
|
||||
this.labelColor.TabIndex = 0;
|
||||
this.labelColor.Text = "Цвет";
|
||||
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
|
||||
//
|
||||
// ButtonOk
|
||||
//
|
||||
this.ButtonOk.Location = new System.Drawing.Point(577, 210);
|
||||
this.ButtonOk.Name = "ButtonOk";
|
||||
this.ButtonOk.Size = new System.Drawing.Size(84, 27);
|
||||
this.ButtonOk.TabIndex = 2;
|
||||
this.ButtonOk.Text = "Добавить";
|
||||
this.ButtonOk.UseVisualStyleBackColor = true;
|
||||
this.ButtonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// buttonCanel
|
||||
//
|
||||
this.buttonCanel.Location = new System.Drawing.Point(683, 210);
|
||||
this.buttonCanel.Name = "buttonCanel";
|
||||
this.buttonCanel.Size = new System.Drawing.Size(84, 27);
|
||||
this.buttonCanel.TabIndex = 3;
|
||||
this.buttonCanel.Text = "Отмена";
|
||||
this.buttonCanel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormPlaneConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 243);
|
||||
this.Controls.Add(this.buttonCanel);
|
||||
this.Controls.Add(this.ButtonOk);
|
||||
this.Controls.Add(this.panelObject);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormPlaneConfig";
|
||||
this.Text = "FormPlaneConfig";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
this.panelObject.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.NumericUpDown numericUpDownWeight;
|
||||
private System.Windows.Forms.CheckBox checkBoxBombs;
|
||||
private System.Windows.Forms.NumericUpDown numericUpDownSpeed;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.CheckBox checkBoxFuelTanks;
|
||||
private System.Windows.Forms.Label labelModifiedObject;
|
||||
private System.Windows.Forms.Label labelSimpleObject;
|
||||
private System.Windows.Forms.GroupBox groupBoxColors;
|
||||
private System.Windows.Forms.Panel panelPurple;
|
||||
private System.Windows.Forms.Panel panelBlack;
|
||||
private System.Windows.Forms.Panel panelGray;
|
||||
private System.Windows.Forms.Panel panelWhite;
|
||||
private System.Windows.Forms.Panel panelYellow;
|
||||
private System.Windows.Forms.Panel panelBlue;
|
||||
private System.Windows.Forms.Panel panelGreen;
|
||||
private System.Windows.Forms.Panel panelRed;
|
||||
private System.Windows.Forms.CheckBox checkBoxLine;
|
||||
private System.Windows.Forms.Panel panelObject;
|
||||
private System.Windows.Forms.PictureBox pictureBoxObject;
|
||||
private System.Windows.Forms.Label labelAddColor;
|
||||
private System.Windows.Forms.Label labelColor;
|
||||
private System.Windows.Forms.Button ButtonOk;
|
||||
private System.Windows.Forms.Button buttonCanel;
|
||||
}
|
||||
}
|
||||
176
ProjectBomber/ProjectBomber/FormPlaneConfig.cs
Normal file
176
ProjectBomber/ProjectBomber/FormPlaneConfig.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
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;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using ProjectBomber.Entities;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
public partial class FormPlaneConfig : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная-выбранный самолет
|
||||
/// </summary>
|
||||
DrawningBomber _plane = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawningBomber> EventAddPlane;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormPlaneConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelGray.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
buttonCanel.Click += (s, e) => Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать самолет
|
||||
/// </summary>
|
||||
private void DrawPlane()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_plane?.SetPosition(5, 5);
|
||||
_plane?.DrawTransport(gr);
|
||||
if (_plane is DrawningBomber)
|
||||
(_plane as DrawningBomber).DrawTransport(gr);
|
||||
else
|
||||
_plane?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_plane = new DrawningBomber((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_plane = new DrawningBomberAdvanced((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBombs.Checked,
|
||||
checkBoxFuelTanks.Checked, checkBoxLine.Checked, pictureBoxObject.Width,
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawPlane();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
public void AddEvent(Action<DrawningBomber> ev)
|
||||
{
|
||||
if (EventAddPlane == null)
|
||||
{
|
||||
EventAddPlane = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddPlane += ev;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление машины
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddPlane?.Invoke(_plane);
|
||||
Close();
|
||||
}
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
||||
DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||
DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации об обычном цвете
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
|
||||
if (_plane is DrawningBomber plane)
|
||||
{
|
||||
labelColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
plane.setColor((Color)e.Data.GetData(typeof(Color)));
|
||||
}
|
||||
DrawPlane();
|
||||
}
|
||||
private void LabelAddColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_plane is DrawningBomberAdvanced bomber)
|
||||
{
|
||||
labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
bomber.setAddColor((Color)e.Data.GetData(typeof(Color)));
|
||||
}
|
||||
DrawPlane();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
ProjectBomber/ProjectBomber/FormPlaneConfig.resx
Normal file
120
ProjectBomber/ProjectBomber/FormPlaneConfig.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
||||
35
ProjectBomber/ProjectBomber/IMoveableObject.cs
Normal file
35
ProjectBomber/ProjectBomber/IMoveableObject.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
||||
43
ProjectBomber/ProjectBomber/MoveToBottomRight.cs
Normal file
43
ProjectBomber/ProjectBomber/MoveToBottomRight.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
public class MoveToBottomRight : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = FieldWidth - objParams.RightBorder;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
var diffY = FieldHeight - objParams.DownBorder;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
59
ProjectBomber/ProjectBomber/MoveToCenter.cs
Normal file
59
ProjectBomber/ProjectBomber/MoveToCenter.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
57
ProjectBomber/ProjectBomber/ObjectParameters.cs
Normal file
57
ProjectBomber/ProjectBomber/ObjectParameters.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
166
ProjectBomber/ProjectBomber/PlanesGenericCollection.cs
Normal file
166
ProjectBomber/ProjectBomber/PlanesGenericCollection.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using ProjectBomber.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный класс для набора объектов DrawningBomber
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class PlanesGenericCollection<T, U>
|
||||
where T : DrawningBomber
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 200;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
pictureWidth = picWidth;
|
||||
pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(PlanesGenericCollection<T, U> collect, T
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(PlanesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U GetU(int pos)
|
||||
{
|
||||
return (U)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowPlanes()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(pictureWidth, pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
int numColumns = pictureWidth / _placeSizeWidth;
|
||||
int numRows = pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i <= numColumns; i++)
|
||||
{
|
||||
for (int j = 0; j <= numRows; ++j)
|
||||
{
|
||||
// Линии разметки места
|
||||
int x = i * _placeSizeWidth;
|
||||
int y = j * _placeSizeHeight;
|
||||
g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, numRows * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int numColumns = pictureWidth / _placeSizeWidth;
|
||||
int column = numColumns - 1;
|
||||
int row = 0;
|
||||
foreach (var plane in _collection.GetPlanes())
|
||||
{
|
||||
plane._pictureHeight = pictureHeight;
|
||||
plane._pictureWidth = pictureWidth;
|
||||
// Установка позиции бомбардировщика
|
||||
int xPosition = column * _placeSizeWidth;
|
||||
int yPosition = row * _placeSizeHeight;
|
||||
if (plane != null)
|
||||
{
|
||||
// Перемещение по ячейкам влево, вниз
|
||||
column--;
|
||||
if (column < 0)
|
||||
{
|
||||
column = numColumns - 1;
|
||||
row++;
|
||||
}
|
||||
plane.SetPosition(xPosition, yPosition);
|
||||
plane.DrawTransport(g);
|
||||
}
|
||||
else
|
||||
{
|
||||
column--;
|
||||
if (column < 0)
|
||||
{
|
||||
column = numColumns - 1;
|
||||
row++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
97
ProjectBomber/ProjectBomber/PlanesGenericStorage.cs
Normal file
97
ProjectBomber/ProjectBomber/PlanesGenericStorage.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using ProjectBomber.MovementStrategy;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции
|
||||
/// </summary>
|
||||
internal class PlanesGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, PlanesGenericCollection<DrawningBomber,
|
||||
DrawningObjectBomber>> _planeStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _planeStorages.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 PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_planeStorages = new Dictionary<string,
|
||||
PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
// Создаем новый набор и добавляем его в словарь
|
||||
if (!_planeStorages.ContainsKey(name))
|
||||
{
|
||||
_planeStorages[name] = new PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Набор с таким именем уже существует");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// Удаляем набор из словаря по имени
|
||||
if (_planeStorages.ContainsKey(name))
|
||||
{
|
||||
_planeStorages.Remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Набор с таким именем не найден.");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public PlanesGenericCollection<DrawningBomber, DrawningObjectBomber> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_planeStorages.ContainsKey(ind))
|
||||
{
|
||||
return _planeStorages[ind];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new KeyNotFoundException($"Набор с именем '{ind}' не найден.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace ProjectBomber
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormBomber());
|
||||
Application.Run(new FormPlaneCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,21 @@
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -46,20 +61,50 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AbstractStrategy.cs" />
|
||||
<Compile Include="Direction.cs" />
|
||||
<Compile Include="DrawningBomber.cs" />
|
||||
<Compile Include="DrawningBomberAdvanced.cs" />
|
||||
<Compile Include="DrawningObjectBomber.cs" />
|
||||
<Compile Include="EntityBomber.cs" />
|
||||
<Compile Include="EntityBomberAdvanced.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FormPlaneCollection.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FormPlaneCollection.Designer.cs">
|
||||
<DependentUpon>FormPlaneCollection.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FormPlaneConfig.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FormPlaneConfig.Designer.cs">
|
||||
<DependentUpon>FormPlaneConfig.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IMoveableObject.cs" />
|
||||
<Compile Include="MoveToBottomRight.cs" />
|
||||
<Compile Include="MoveToCenter.cs" />
|
||||
<Compile Include="ObjectParameters.cs" />
|
||||
<Compile Include="PlanesGenericCollection.cs" />
|
||||
<Compile Include="PlanesGenericStorage.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SetGeneric.cs" />
|
||||
<Compile Include="Status.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FormPlaneCollection.resx">
|
||||
<DependentUpon>FormPlaneCollection.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FormPlaneConfig.resx">
|
||||
<DependentUpon>FormPlaneConfig.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
@@ -82,5 +127,17 @@
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 и x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
143
ProjectBomber/ProjectBomber/SetGeneric.cs
Normal file
143
ProjectBomber/ProjectBomber/SetGeneric.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемый самолет</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane)
|
||||
{
|
||||
if (_places.Count == 0)
|
||||
{
|
||||
_places.Add(plane);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(plane);
|
||||
for (int i = 0; i < _places.Count; i++)
|
||||
{
|
||||
T temp = _places[i];
|
||||
_places[i] = _places[_places.Count - 1];
|
||||
_places[_places.Count - 1] = temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемый самолет</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T plane, int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (position < _places.Count && _places[position] == null)
|
||||
{
|
||||
_places[position] = plane;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ищем первую пустую позицию и вставляем туда.
|
||||
for (int i = 0; i < _maxCount; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
_places[i] = plane;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position >= _maxCount || _places.Count >= _maxCount)
|
||||
return; // Неправильная позиция или нет места для вставки
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetPlanes(int? maxPlanes = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxPlanes.HasValue && i == maxPlanes.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ProjectBomber/ProjectBomber/Status.cs
Normal file
24
ProjectBomber/ProjectBomber/Status.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
NotInit = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
InProgress = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Finish = 3
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user