Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be33c0e4bc | ||
|
|
62a7064012 | ||
|
|
8c293b6d5c | ||
|
|
71fca0840e | ||
|
|
735492bfe2 | ||
|
|
842e5a8ca4 | ||
|
|
f5d9e89692 | ||
|
|
1bacab8f18 | ||
|
|
f08466a718 | ||
|
|
065b937d2c | ||
|
|
db85af0a99 | ||
|
|
feeea2ef58 | ||
|
|
5309de6c2f | ||
|
|
5543d1951e | ||
|
|
929e314196 | ||
|
|
4d583a149b | ||
|
|
3f9f29c8b8 |
84
Cruiser/Cruiser/AbstractStrategy.cs
Normal file
84
Cruiser/Cruiser/AbstractStrategy.cs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
using Monorail.DrawningObjects;
|
||||||
|
|
||||||
|
namespace Monorail.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||||
|
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||||
|
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||||
|
|
||||||
|
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||||
|
|
||||||
|
protected ObjectParameters? GetObjectParameters =>
|
||||||
|
_moveableObject?.GetObjectPosition;
|
||||||
|
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
|
||||||
|
private bool MoveTo(DirectionType directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Cruiser/Cruiser/ClassDelegate.cs
Normal file
14
Cruiser/Cruiser/ClassDelegate.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Cruiser
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Делегат для передачи объекта
|
||||||
|
/// </summary>
|
||||||
|
public delegate void PlaneDelegate(DrawingPlane plane);
|
||||||
|
}
|
||||||
@@ -1,49 +1,31 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Cruiser
|
namespace Monorail.Entities
|
||||||
{
|
{
|
||||||
public class Cruiser
|
public class EntityPlane
|
||||||
{
|
{
|
||||||
|
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public double Weight { get; private set; }
|
public double Weight { get; private set; }
|
||||||
|
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; set; }
|
||||||
|
|
||||||
public Color AdditionalColor { get; private set; }
|
|
||||||
|
|
||||||
|
|
||||||
public bool Headlights { get; private set; }
|
|
||||||
public bool HelicopterPad { get; private set; }
|
|
||||||
|
|
||||||
public bool Coating { get; private set; }
|
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
|
||||||
/// <param name="speed">Скорость</param>
|
public EntityPlane(int speed, double weight, Color bodyColor)
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="headlights">Признак наличия передних фар</param>
|
|
||||||
/// <param name="helicopterPad">Признак наличия площадки для вертолета</param>
|
|
||||||
/// <param name="coating">Признак наличия покрытия</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, bool headlights, bool helicopterPad, bool coating)
|
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
}
|
||||||
|
public void setBodyColor(Color color)
|
||||||
Headlights = headlights;
|
{
|
||||||
HelicopterPad = helicopterPad;
|
BodyColor = color;
|
||||||
Coating = coating;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
137
Cruiser/Cruiser/CruiserGenericCollection.cs
Normal file
137
Cruiser/Cruiser/CruiserGenericCollection.cs
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
using Monorail.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class PlanesGenericCollection<T, U>
|
||||||
|
where T : DrawingPlane
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
|
||||||
|
/// <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 bool operator +(PlanesGenericCollection<T, U>? collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null || collect == null)
|
||||||
|
return false;
|
||||||
|
return collect._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// <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(_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(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||||
|
1; ++j)
|
||||||
|
{//линия разметки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||||
|
_placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||||
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
foreach (var plane in _collection.GetPlanes())
|
||||||
|
{
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
int inRow = _pictureWidth / _placeSizeWidth;
|
||||||
|
plane.SetPosition((i % inRow) * (_placeSizeWidth) + _placeSizeWidth / 20, _placeSizeHeight * (i / inRow) + _placeSizeHeight / 20);
|
||||||
|
plane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
147
Cruiser/Cruiser/CruiserGenericStorage.cs
Normal file
147
Cruiser/Cruiser/CruiserGenericStorage.cs
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
using Cruiser;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.Generics;
|
||||||
|
using Monorail.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class PlanesGenericStorage
|
||||||
|
{
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по самолетам в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка сохранении данных</returns>
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> record in _planeStorage)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawingPlane? elem in record.Value.GetPlanes)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (StreamWriter sw = new(filename))
|
||||||
|
{
|
||||||
|
sw.WriteLine($"PlaneStorage{Environment.NewLine}{data}");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка информации по автомобилям в хранилище из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (StreamReader sr = new(filename))
|
||||||
|
{
|
||||||
|
string str = sr.ReadLine();
|
||||||
|
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (strs == null || strs.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!strs[0].StartsWith("PlaneStorage"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_planeStorage.Clear();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
str = sr.ReadLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords,
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawingPlane? plane =
|
||||||
|
elem?.CreateDrawingPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
if (!(collection + plane))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_planeStorage.Add(record[0], collection);
|
||||||
|
str = sr.ReadLine();
|
||||||
|
} while (str != null);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly Dictionary<string, PlanesGenericCollection<DrawingPlane,
|
||||||
|
DrawingObjectPlane>> _planeStorage;
|
||||||
|
public List<string> Keys => _planeStorage.Keys.ToList();
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_planeStorage = new Dictionary<string, PlanesGenericCollection<DrawingPlane,
|
||||||
|
DrawingObjectPlane>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
_planeStorage.Add(name,
|
||||||
|
new PlanesGenericCollection<DrawingPlane,
|
||||||
|
DrawingObjectPlane>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_planeStorage.ContainsKey(name))
|
||||||
|
return;
|
||||||
|
_planeStorage.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_planeStorage.ContainsKey(ind))
|
||||||
|
return _planeStorage[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,27 +4,14 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Cruiser
|
namespace Monorail
|
||||||
{
|
{
|
||||||
public enum Direction
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
/// Вверх
|
|
||||||
|
|
||||||
/// </summary>
|
|
||||||
Up = 1,
|
Up = 1,
|
||||||
/// <summary>
|
|
||||||
/// Вниз
|
|
||||||
/// </summary>
|
|
||||||
Down = 2,
|
Down = 2,
|
||||||
/// <summary>
|
|
||||||
/// Влево
|
|
||||||
/// </summary>
|
|
||||||
Left = 3,
|
Left = 3,
|
||||||
/// <summary>
|
|
||||||
/// Вправо
|
|
||||||
/// </summary>
|
|
||||||
Right = 4
|
Right = 4
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,161 +1,143 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Cruiser;
|
||||||
|
using Monorail.Entities;
|
||||||
|
using Monorail.MovementStrategy;
|
||||||
|
|
||||||
namespace Cruiser
|
namespace Monorail.DrawningObjects
|
||||||
{
|
{
|
||||||
public class DrawningCruiser
|
public class DrawingPlane
|
||||||
{
|
{
|
||||||
|
public EntityPlane? EntityPlane { get; protected set; }
|
||||||
public Cruiser? Cruiser { get; private set; }
|
|
||||||
|
|
||||||
private int _pictureWidth;
|
private int _pictureWidth;
|
||||||
|
|
||||||
private int _pictureHeight;
|
private int _pictureHeight;
|
||||||
|
|
||||||
private int _startPosX;
|
protected int _startPosX;
|
||||||
|
|
||||||
private int _startPosY;
|
protected int _startPosY;
|
||||||
|
|
||||||
private readonly int _cruiserWidth = 150;
|
protected readonly int _planeWidth = 160;
|
||||||
|
|
||||||
|
protected readonly int _planeHeight = 160;
|
||||||
|
|
||||||
private readonly int _cruiserHeight = 50;
|
public int GetPosX => _startPosX;
|
||||||
|
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
|
||||||
|
public int GetWidth => _planeWidth;
|
||||||
|
|
||||||
/// <param name="speed">Скорость</param>
|
public int GetHeight => _planeHeight;
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="headlights">Признак наличия фар</param>
|
|
||||||
/// <param name="helicopterPad">Признак наличия антикрыла</param>
|
|
||||||
/// <param name="coating">Признак наличия гоночной полосы</param>
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
|
||||||
/// <param name="height">Высота картинки</param>
|
|
||||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
|
||||||
|
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height)
|
||||||
additionalColor, bool headlights, bool helicopterPad, bool coating, int width, int height)
|
|
||||||
{
|
{
|
||||||
|
if (_planeWidth > width || _planeHeight > height)
|
||||||
|
return;
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
if (_pictureHeight > _cruiserWidth && _pictureWidth > _cruiserHeight)
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||||
{
|
}
|
||||||
Cruiser = new Cruiser();
|
public void ChangeColor(Color col)
|
||||||
Cruiser.Init(speed, weight, bodyColor, additionalColor,
|
{
|
||||||
headlights, helicopterPad, coating);
|
if (EntityPlane == null)
|
||||||
return true;
|
return;
|
||||||
}
|
EntityPlane.BodyColor = col;
|
||||||
return false;
|
}
|
||||||
|
protected DrawingPlane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
|
||||||
|
{
|
||||||
|
if (_planeWidth > width || _planeHeight > height)
|
||||||
|
return;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_planeWidth = planeWidth;
|
||||||
|
_planeHeight = planeHeight;
|
||||||
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="x">Координата X</param>
|
public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
if (Cruiser == null) return;
|
if (x < 0 || y < 0 || x + _planeWidth >= _pictureWidth || y + _planeHeight >= _pictureHeight)
|
||||||
while (x + _cruiserWidth > _pictureWidth)
|
x = y = 2;
|
||||||
{
|
|
||||||
x -= (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
while (x < 0)
|
|
||||||
{
|
|
||||||
x += (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
while (y + _cruiserHeight > _pictureHeight)
|
|
||||||
{
|
|
||||||
y -= (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
while (y < 0)
|
|
||||||
{
|
|
||||||
y += (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
|
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка, что объект может переместится по указанному направлению
|
||||||
|
/// </summary>
|
||||||
/// <param name="direction">Направление</param>
|
/// <param name="direction">Направление</param>
|
||||||
public void MoveTransport(Direction direction)
|
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (Cruiser == null)
|
if (EntityPlane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DirectionType.Left => _startPosX - EntityPlane.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DirectionType.Up => _startPosY - EntityPlane.Step > 0,
|
||||||
|
// вправо
|
||||||
|
DirectionType.Right => _startPosX + EntityPlane.Step + _planeWidth < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
DirectionType.Down => _startPosY + EntityPlane.Step + _planeHeight < _pictureHeight,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
public void MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
|
//влево
|
||||||
case Direction.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX - Cruiser.Step > 0)
|
_startPosX -= (int)EntityPlane.Step;
|
||||||
{
|
|
||||||
_startPosX -= (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
//вверх
|
||||||
case Direction.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY - Cruiser.Step > 0)
|
_startPosY -= (int)EntityPlane.Step;
|
||||||
{
|
|
||||||
_startPosY -= (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
// вправо
|
||||||
case Direction.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX + Cruiser.Step + _cruiserWidth < _pictureWidth)
|
_startPosX += (int)EntityPlane.Step;
|
||||||
{
|
|
||||||
_startPosX += (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
//вниз
|
||||||
case Direction.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY + Cruiser.Step + _cruiserHeight < _pictureHeight)
|
_startPosY += (int)EntityPlane.Step;
|
||||||
{
|
|
||||||
_startPosY += (int)Cruiser.Step;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="g"></param>
|
public virtual void DrawTransport(Graphics g)
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
{
|
||||||
if (Cruiser == null)
|
if (EntityPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new Pen(Color.Black, 2);
|
||||||
Brush additionalBrush = new
|
|
||||||
SolidBrush(Cruiser.AdditionalColor);
|
|
||||||
|
|
||||||
|
|
||||||
//границы автомобиля
|
|
||||||
|
|
||||||
|
|
||||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
|
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
|
||||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
|
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
|
||||||
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
||||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
|
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
|
||||||
30);
|
30);
|
||||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
||||||
|
Brush br = new SolidBrush(EntityPlane.BodyColor);
|
||||||
//если есть доп.фонари
|
|
||||||
if (Cruiser.Headlights)
|
|
||||||
{
|
|
||||||
|
|
||||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
|
|
||||||
20);
|
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
|
||||||
20);
|
|
||||||
}
|
|
||||||
//основание лодки!!!
|
|
||||||
Brush br = new SolidBrush(Cruiser.BodyColor);
|
|
||||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
||||||
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
|
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
|
||||||
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
||||||
@@ -179,22 +161,9 @@ additionalColor, bool headlights, bool helicopterPad, bool coating, int width, i
|
|||||||
g.DrawRectangle(Pens.Black, _startPosX + 50,
|
g.DrawRectangle(Pens.Black, _startPosX + 50,
|
||||||
_startPosY + 19, 30, 25);
|
_startPosY + 19, 30, 25);
|
||||||
|
|
||||||
if (Cruiser.HelicopterPad)
|
|
||||||
{
|
|
||||||
//если есть площадка под вертолет
|
|
||||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 20, 20);
|
|
||||||
}
|
|
||||||
if (Cruiser.Coating)
|
|
||||||
{
|
|
||||||
//если есть спец покрытие для площадки под вертолет
|
|
||||||
g.FillEllipse(Brushes.Red, _startPosX + 90, _startPosY + 20, 20, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
37
Cruiser/Cruiser/DrawningObjectCar.cs
Normal file
37
Cruiser/Cruiser/DrawningObjectCar.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Cruiser;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
|
||||||
|
namespace Monorail.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawingObjectPlane : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawingPlane? _drawningPlane = null;
|
||||||
|
public DrawingObjectPlane(DrawingPlane drawingPlane)
|
||||||
|
{
|
||||||
|
_drawningPlane = drawingPlane;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningPlane == null || _drawningPlane.EntityPlane ==
|
||||||
|
null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningPlane.GetPosX,
|
||||||
|
_drawningPlane.GetPosY, _drawningPlane.GetWidth, _drawningPlane.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningPlane?.EntityPlane?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionType direction) =>
|
||||||
|
_drawningPlane?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionType direction) =>
|
||||||
|
_drawningPlane?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
Cruiser/Cruiser/DrawningPro.cs
Normal file
59
Cruiser/Cruiser/DrawningPro.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Monorail.Entities;
|
||||||
|
|
||||||
|
namespace Monorail.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawingAirBomber : DrawingPlane
|
||||||
|
{
|
||||||
|
public DrawingAirBomber(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool bombs, bool wing, int width, int height)
|
||||||
|
: base(speed, width, bodyColor, width, height, 160, 160)
|
||||||
|
{
|
||||||
|
if (EntityPlane != null)
|
||||||
|
{
|
||||||
|
EntityPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, wing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityPlane is not EntityAirBomber airBomber)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
Pen pen = new Pen(Color.Black, 2);
|
||||||
|
Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor);
|
||||||
|
|
||||||
|
if (airBomber.Fuel)
|
||||||
|
{
|
||||||
|
Point[] trianglePoints1 =
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 20, _startPosY + 5),
|
||||||
|
new Point(_startPosX + 40, _startPosY + 25),
|
||||||
|
new Point(_startPosX + 60, _startPosY + 5)
|
||||||
|
};
|
||||||
|
|
||||||
|
Point[] trianglePoints2 =
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 20, _startPosY + 55),
|
||||||
|
new Point(_startPosX + 40, _startPosY + 35),
|
||||||
|
new Point(_startPosX + 60, _startPosY + 55)
|
||||||
|
};
|
||||||
|
|
||||||
|
g.FillPolygon(additionalBrush, trianglePoints1);
|
||||||
|
g.FillPolygon(additionalBrush, trianglePoints2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (airBomber.Bombs)
|
||||||
|
{
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
Cruiser/Cruiser/ExtentionDrawingCruiser.cs
Normal file
56
Cruiser/Cruiser/ExtentionDrawingCruiser.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Cruiser
|
||||||
|
{
|
||||||
|
public static class ExtentionDrawingPlane
|
||||||
|
{
|
||||||
|
public static DrawingPlane? CreateDrawingPlane(this string info, char
|
||||||
|
separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingPlane(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingAirBomber(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]), width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawingPlane">Сохраняемый объект</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawingPlane drawingPlane,
|
||||||
|
char separatorForObject)
|
||||||
|
{
|
||||||
|
var plane = drawingPlane.EntityPlane;
|
||||||
|
if (plane == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
|
||||||
|
if (plane is not EntityAirBomber airBomber)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return
|
||||||
|
$"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.Fuel}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
128
Cruiser/Cruiser/Form1.Designer.cs
generated
128
Cruiser/Cruiser/Form1.Designer.cs
generated
@@ -28,6 +28,10 @@
|
|||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonCreate = new System.Windows.Forms.Button();
|
this.buttonCreate = new System.Windows.Forms.Button();
|
||||||
|
this.button2 = new System.Windows.Forms.Button();
|
||||||
|
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
||||||
|
this.ButtonStep = new System.Windows.Forms.Button();
|
||||||
|
this.SelectedCruiser = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -49,6 +53,7 @@
|
|||||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBox1.TabIndex = 0;
|
this.pictureBox1.TabIndex = 0;
|
||||||
this.pictureBox1.TabStop = false;
|
this.pictureBox1.TabStop = false;
|
||||||
|
this.pictureBox1.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@@ -60,7 +65,7 @@
|
|||||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonDown.TabIndex = 1;
|
this.buttonDown.TabIndex = 1;
|
||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@@ -72,7 +77,7 @@
|
|||||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonLeft.TabIndex = 2;
|
this.buttonLeft.TabIndex = 2;
|
||||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
@@ -84,7 +89,7 @@
|
|||||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonRight.TabIndex = 3;
|
this.buttonRight.TabIndex = 3;
|
||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
@@ -96,22 +101,70 @@
|
|||||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonUp.TabIndex = 4;
|
this.buttonUp.TabIndex = 4;
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
//
|
||||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
this.buttonCreate.Location = new System.Drawing.Point(36, 302);
|
this.buttonCreate.Location = new System.Drawing.Point(0, 302);
|
||||||
this.buttonCreate.Name = "buttonCreate";
|
this.buttonCreate.Name = "buttonCreate";
|
||||||
this.buttonCreate.Size = new System.Drawing.Size(112, 34);
|
this.buttonCreate.Size = new System.Drawing.Size(218, 34);
|
||||||
this.buttonCreate.TabIndex = 5;
|
this.buttonCreate.TabIndex = 5;
|
||||||
this.buttonCreate.Text = "Создать";
|
this.buttonCreate.Text = "Создать простую";
|
||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreateSportCar_Click);
|
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||||
|
//
|
||||||
|
// button2
|
||||||
|
//
|
||||||
|
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.button2.Location = new System.Drawing.Point(210, 301);
|
||||||
|
this.button2.Name = "button2";
|
||||||
|
this.button2.Size = new System.Drawing.Size(251, 37);
|
||||||
|
this.button2.TabIndex = 6;
|
||||||
|
this.button2.Text = "Создать про версию";
|
||||||
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
|
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||||
|
//
|
||||||
|
// comboBox1
|
||||||
|
//
|
||||||
|
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBox1.FormattingEnabled = true;
|
||||||
|
this.comboBox1.Items.AddRange(new object[] {
|
||||||
|
"Центр",
|
||||||
|
"Угол"});
|
||||||
|
this.comboBox1.Location = new System.Drawing.Point(415, 22);
|
||||||
|
this.comboBox1.Name = "comboBox1";
|
||||||
|
this.comboBox1.Size = new System.Drawing.Size(182, 33);
|
||||||
|
this.comboBox1.TabIndex = 7;
|
||||||
|
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// ButtonStep
|
||||||
|
//
|
||||||
|
this.ButtonStep.Location = new System.Drawing.Point(485, 70);
|
||||||
|
this.ButtonStep.Name = "ButtonStep";
|
||||||
|
this.ButtonStep.Size = new System.Drawing.Size(112, 34);
|
||||||
|
this.ButtonStep.TabIndex = 8;
|
||||||
|
this.ButtonStep.Text = "Шаг";
|
||||||
|
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||||
|
//
|
||||||
|
// SelectedCruiser
|
||||||
|
//
|
||||||
|
this.SelectedCruiser.Location = new System.Drawing.Point(210, 261);
|
||||||
|
this.SelectedCruiser.Name = "SelectedCruiser";
|
||||||
|
this.SelectedCruiser.Size = new System.Drawing.Size(112, 34);
|
||||||
|
this.SelectedCruiser.TabIndex = 9;
|
||||||
|
this.SelectedCruiser.Text = "Выбрать";
|
||||||
|
this.SelectedCruiser.UseVisualStyleBackColor = true;
|
||||||
|
this.SelectedCruiser.Click += new System.EventHandler(this.SelectedCruiser_Click);
|
||||||
//
|
//
|
||||||
// CruiserForm
|
// CruiserForm
|
||||||
//
|
//
|
||||||
this.ClientSize = new System.Drawing.Size(667, 358);
|
this.ClientSize = new System.Drawing.Size(667, 358);
|
||||||
|
this.Controls.Add(this.SelectedCruiser);
|
||||||
|
this.Controls.Add(this.ButtonStep);
|
||||||
|
this.Controls.Add(this.comboBox1);
|
||||||
|
this.Controls.Add(this.button2);
|
||||||
this.Controls.Add(this.buttonCreate);
|
this.Controls.Add(this.buttonCreate);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
@@ -125,61 +178,6 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonCreateSportCar_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
_drawningCruiser = new DrawningCruiser();
|
|
||||||
_drawningCruiser.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)), pictureBox1.Width, pictureBox1.Height);
|
|
||||||
_drawningCruiser.SetPosition(random.Next(10, 100),
|
|
||||||
random.Next(10, 100));
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawningCruiser == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
||||||
switch (name)
|
|
||||||
{
|
|
||||||
case "buttonUp":
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Up);
|
|
||||||
break;
|
|
||||||
case "buttonDown":
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Down);
|
|
||||||
break;
|
|
||||||
case "buttonLeft":
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Left);
|
|
||||||
break;
|
|
||||||
case "buttonRight":
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Right);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Draw()
|
|
||||||
{
|
|
||||||
if (_drawningCruiser == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bitmap bmp = new(pictureBox1.Width,
|
|
||||||
pictureBox1.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
|
||||||
_drawningCruiser.DrawTransport(gr);
|
|
||||||
pictureBox1.Image = bmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -190,5 +188,9 @@ private Button button1;
|
|||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonCreate;
|
private Button buttonCreate;
|
||||||
|
private Button button2;
|
||||||
|
private ComboBox comboBox1;
|
||||||
|
private Button ButtonStep;
|
||||||
|
private Button SelectedCruiser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,162 @@
|
|||||||
|
using System;
|
||||||
|
using Cruiser;
|
||||||
|
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 System.Windows.Forms;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.MovementStrategy;
|
||||||
|
using Monorail;
|
||||||
|
|
||||||
|
|
||||||
namespace Cruiser
|
namespace Cruiser
|
||||||
{
|
{
|
||||||
|
|
||||||
public partial class CruiserForm : Form
|
public partial class CruiserForm : Form
|
||||||
{
|
{
|
||||||
private DrawningCruiser? _drawningCruiser;
|
private DrawingPlane? _drawingPlane;
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
public DrawingPlane? SelectedPlane { get; private set; }
|
||||||
|
|
||||||
public CruiserForm()
|
public CruiserForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
|
SelectedPlane = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawingPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawingPlane.DrawTransport(gr);
|
||||||
|
pictureBox1.Image = bmp;
|
||||||
|
}
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawingPlane.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawingPlane.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawingPlane.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawingPlane.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button2_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color mainColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
Color additColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
mainColor = dialog.Color;
|
||||||
|
}
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
additColor = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingPlane = new DrawingAirBomber(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
pictureBox1.Width, pictureBox1.Height);
|
||||||
|
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void ButtonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingPlane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBox1.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBox1.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToEdge(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new
|
||||||
|
DrawingObjectPlane(_drawingPlane), pictureBox1.Width,
|
||||||
|
pictureBox1.Height);
|
||||||
|
comboBox1.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_strategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBox1.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingPlane = new DrawingPlane(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), color,
|
||||||
|
pictureBox1.Width, pictureBox1.Height);
|
||||||
|
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SelectedCruiser_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedPlane = _drawingPlane;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,3 +165,4 @@ namespace Cruiser
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
383
Cruiser/Cruiser/Form2.Designer.cs
generated
Normal file
383
Cruiser/Cruiser/Form2.Designer.cs
generated
Normal file
@@ -0,0 +1,383 @@
|
|||||||
|
namespace Cruiser
|
||||||
|
{
|
||||||
|
partial class Form2
|
||||||
|
{
|
||||||
|
/// <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.checkBox2 = new System.Windows.Forms.CheckBox();
|
||||||
|
this.button2 = new System.Windows.Forms.Button();
|
||||||
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.panel3 = new System.Windows.Forms.Panel();
|
||||||
|
this.label_addit_color = new System.Windows.Forms.Label();
|
||||||
|
this.label_color = new System.Windows.Forms.Label();
|
||||||
|
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||||
|
this.labelAdvanced = new System.Windows.Forms.Label();
|
||||||
|
this.labelBasic = new System.Windows.Forms.Label();
|
||||||
|
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.panel9 = new System.Windows.Forms.Panel();
|
||||||
|
this.panel8 = new System.Windows.Forms.Panel();
|
||||||
|
this.panel7 = new System.Windows.Forms.Panel();
|
||||||
|
this.panel6 = new System.Windows.Forms.Panel();
|
||||||
|
this.panel5 = new System.Windows.Forms.Panel();
|
||||||
|
this.panel4 = new System.Windows.Forms.Panel();
|
||||||
|
this.panel2 = new System.Windows.Forms.Panel();
|
||||||
|
this.panel1 = new System.Windows.Forms.Panel();
|
||||||
|
this.checkBox1 = new System.Windows.Forms.CheckBox();
|
||||||
|
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
this.panel3.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||||
|
this.groupBox2.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.checkBox2);
|
||||||
|
this.groupBox1.Controls.Add(this.button2);
|
||||||
|
this.groupBox1.Controls.Add(this.button1);
|
||||||
|
this.groupBox1.Controls.Add(this.panel3);
|
||||||
|
this.groupBox1.Controls.Add(this.labelAdvanced);
|
||||||
|
this.groupBox1.Controls.Add(this.labelBasic);
|
||||||
|
this.groupBox1.Controls.Add(this.groupBox2);
|
||||||
|
this.groupBox1.Controls.Add(this.checkBox1);
|
||||||
|
this.groupBox1.Controls.Add(this.numericUpDown2);
|
||||||
|
this.groupBox1.Controls.Add(this.numericUpDown1);
|
||||||
|
this.groupBox1.Controls.Add(this.label2);
|
||||||
|
this.groupBox1.Controls.Add(this.label1);
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(57, 43);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(1163, 391);
|
||||||
|
this.groupBox1.TabIndex = 0;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// checkBox2
|
||||||
|
//
|
||||||
|
this.checkBox2.AutoSize = true;
|
||||||
|
this.checkBox2.Location = new System.Drawing.Point(33, 277);
|
||||||
|
this.checkBox2.Name = "checkBox2";
|
||||||
|
this.checkBox2.Size = new System.Drawing.Size(232, 29);
|
||||||
|
this.checkBox2.TabIndex = 12;
|
||||||
|
this.checkBox2.Text = "Наличие ракетных шахт";
|
||||||
|
this.checkBox2.UseVisualStyleBackColor = true;
|
||||||
|
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
|
||||||
|
//
|
||||||
|
// button2
|
||||||
|
//
|
||||||
|
this.button2.Location = new System.Drawing.Point(991, 321);
|
||||||
|
this.button2.Name = "button2";
|
||||||
|
this.button2.Size = new System.Drawing.Size(127, 38);
|
||||||
|
this.button2.TabIndex = 11;
|
||||||
|
this.button2.Text = "Отмена";
|
||||||
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
this.button1.Location = new System.Drawing.Point(838, 321);
|
||||||
|
this.button1.Name = "button1";
|
||||||
|
this.button1.Size = new System.Drawing.Size(136, 38);
|
||||||
|
this.button1.TabIndex = 10;
|
||||||
|
this.button1.Text = "Добавить";
|
||||||
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// panel3
|
||||||
|
//
|
||||||
|
this.panel3.AllowDrop = true;
|
||||||
|
this.panel3.Controls.Add(this.label_addit_color);
|
||||||
|
this.panel3.Controls.Add(this.label_color);
|
||||||
|
this.panel3.Controls.Add(this.pictureBox1);
|
||||||
|
this.panel3.Location = new System.Drawing.Point(822, 45);
|
||||||
|
this.panel3.Name = "panel3";
|
||||||
|
this.panel3.Size = new System.Drawing.Size(312, 261);
|
||||||
|
this.panel3.TabIndex = 9;
|
||||||
|
this.panel3.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||||
|
this.panel3.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||||
|
//
|
||||||
|
// label_addit_color
|
||||||
|
//
|
||||||
|
this.label_addit_color.AllowDrop = true;
|
||||||
|
this.label_addit_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.label_addit_color.Location = new System.Drawing.Point(169, 23);
|
||||||
|
this.label_addit_color.Name = "label_addit_color";
|
||||||
|
this.label_addit_color.Size = new System.Drawing.Size(117, 38);
|
||||||
|
this.label_addit_color.TabIndex = 10;
|
||||||
|
this.label_addit_color.Text = "Доп.цвет";
|
||||||
|
this.label_addit_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.label_addit_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelAddColor_DragDrop);
|
||||||
|
this.label_addit_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelAddColor_DragEnter);
|
||||||
|
//
|
||||||
|
// label_color
|
||||||
|
//
|
||||||
|
this.label_color.AllowDrop = true;
|
||||||
|
this.label_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.label_color.Location = new System.Drawing.Point(30, 23);
|
||||||
|
this.label_color.Name = "label_color";
|
||||||
|
this.label_color.Size = new System.Drawing.Size(110, 38);
|
||||||
|
this.label_color.TabIndex = 9;
|
||||||
|
this.label_color.Text = "Цвет";
|
||||||
|
this.label_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.label_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
|
||||||
|
this.label_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
|
||||||
|
//
|
||||||
|
// pictureBox1
|
||||||
|
//
|
||||||
|
this.pictureBox1.Location = new System.Drawing.Point(76, 64);
|
||||||
|
this.pictureBox1.Name = "pictureBox1";
|
||||||
|
this.pictureBox1.Size = new System.Drawing.Size(163, 178);
|
||||||
|
this.pictureBox1.TabIndex = 8;
|
||||||
|
this.pictureBox1.TabStop = false;
|
||||||
|
//
|
||||||
|
// labelAdvanced
|
||||||
|
//
|
||||||
|
this.labelAdvanced.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelAdvanced.Location = new System.Drawing.Point(521, 293);
|
||||||
|
this.labelAdvanced.Name = "labelAdvanced";
|
||||||
|
this.labelAdvanced.Size = new System.Drawing.Size(141, 47);
|
||||||
|
this.labelAdvanced.TabIndex = 7;
|
||||||
|
this.labelAdvanced.Text = "Продвинутый";
|
||||||
|
this.labelAdvanced.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelAdvanced.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// labelBasic
|
||||||
|
//
|
||||||
|
this.labelBasic.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelBasic.Location = new System.Drawing.Point(369, 293);
|
||||||
|
this.labelBasic.Name = "labelBasic";
|
||||||
|
this.labelBasic.Size = new System.Drawing.Size(131, 47);
|
||||||
|
this.labelBasic.TabIndex = 6;
|
||||||
|
this.labelBasic.Text = "Простой";
|
||||||
|
this.labelBasic.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelBasic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// groupBox2
|
||||||
|
//
|
||||||
|
this.groupBox2.Controls.Add(this.panel9);
|
||||||
|
this.groupBox2.Controls.Add(this.panel8);
|
||||||
|
this.groupBox2.Controls.Add(this.panel7);
|
||||||
|
this.groupBox2.Controls.Add(this.panel6);
|
||||||
|
this.groupBox2.Controls.Add(this.panel5);
|
||||||
|
this.groupBox2.Controls.Add(this.panel4);
|
||||||
|
this.groupBox2.Controls.Add(this.panel2);
|
||||||
|
this.groupBox2.Controls.Add(this.panel1);
|
||||||
|
this.groupBox2.Location = new System.Drawing.Point(335, 40);
|
||||||
|
this.groupBox2.Name = "groupBox2";
|
||||||
|
this.groupBox2.Size = new System.Drawing.Size(357, 231);
|
||||||
|
this.groupBox2.TabIndex = 5;
|
||||||
|
this.groupBox2.TabStop = false;
|
||||||
|
this.groupBox2.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// panel9
|
||||||
|
//
|
||||||
|
this.panel9.BackColor = System.Drawing.Color.Fuchsia;
|
||||||
|
this.panel9.Location = new System.Drawing.Point(264, 153);
|
||||||
|
this.panel9.Name = "panel9";
|
||||||
|
this.panel9.Size = new System.Drawing.Size(53, 49);
|
||||||
|
this.panel9.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// panel8
|
||||||
|
//
|
||||||
|
this.panel8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
|
||||||
|
this.panel8.Location = new System.Drawing.Point(180, 153);
|
||||||
|
this.panel8.Name = "panel8";
|
||||||
|
this.panel8.Size = new System.Drawing.Size(53, 49);
|
||||||
|
this.panel8.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// panel7
|
||||||
|
//
|
||||||
|
this.panel7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
|
||||||
|
this.panel7.Location = new System.Drawing.Point(108, 153);
|
||||||
|
this.panel7.Name = "panel7";
|
||||||
|
this.panel7.Size = new System.Drawing.Size(53, 49);
|
||||||
|
this.panel7.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// panel6
|
||||||
|
//
|
||||||
|
this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
|
||||||
|
this.panel6.Location = new System.Drawing.Point(34, 153);
|
||||||
|
this.panel6.Name = "panel6";
|
||||||
|
this.panel6.Size = new System.Drawing.Size(53, 49);
|
||||||
|
this.panel6.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// panel5
|
||||||
|
//
|
||||||
|
this.panel5.BackColor = System.Drawing.Color.Purple;
|
||||||
|
this.panel5.Location = new System.Drawing.Point(264, 44);
|
||||||
|
this.panel5.Name = "panel5";
|
||||||
|
this.panel5.Size = new System.Drawing.Size(53, 49);
|
||||||
|
this.panel5.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// panel4
|
||||||
|
//
|
||||||
|
this.panel4.BackColor = System.Drawing.Color.DarkOrchid;
|
||||||
|
this.panel4.Location = new System.Drawing.Point(186, 44);
|
||||||
|
this.panel4.Name = "panel4";
|
||||||
|
this.panel4.Size = new System.Drawing.Size(53, 49);
|
||||||
|
this.panel4.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panel2
|
||||||
|
//
|
||||||
|
this.panel2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
|
||||||
|
this.panel2.Location = new System.Drawing.Point(108, 44);
|
||||||
|
this.panel2.Name = "panel2";
|
||||||
|
this.panel2.Size = new System.Drawing.Size(53, 49);
|
||||||
|
this.panel2.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panel1
|
||||||
|
//
|
||||||
|
this.panel1.BackColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||||
|
this.panel1.Location = new System.Drawing.Point(32, 44);
|
||||||
|
this.panel1.Name = "panel1";
|
||||||
|
this.panel1.Size = new System.Drawing.Size(55, 49);
|
||||||
|
this.panel1.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// checkBox1
|
||||||
|
//
|
||||||
|
this.checkBox1.AutoSize = true;
|
||||||
|
this.checkBox1.Location = new System.Drawing.Point(33, 213);
|
||||||
|
this.checkBox1.Name = "checkBox1";
|
||||||
|
this.checkBox1.Size = new System.Drawing.Size(310, 29);
|
||||||
|
this.checkBox1.TabIndex = 4;
|
||||||
|
this.checkBox1.Text = "Наличие площадки под вертолет";
|
||||||
|
this.checkBox1.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDown2
|
||||||
|
//
|
||||||
|
this.numericUpDown2.Location = new System.Drawing.Point(128, 143);
|
||||||
|
this.numericUpDown2.Maximum = new decimal(new int[] {
|
||||||
|
1000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDown2.Minimum = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDown2.Name = "numericUpDown2";
|
||||||
|
this.numericUpDown2.Size = new System.Drawing.Size(84, 31);
|
||||||
|
this.numericUpDown2.TabIndex = 3;
|
||||||
|
this.numericUpDown2.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// numericUpDown1
|
||||||
|
//
|
||||||
|
this.numericUpDown1.Location = new System.Drawing.Point(128, 75);
|
||||||
|
this.numericUpDown1.Maximum = new decimal(new int[] {
|
||||||
|
1000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDown1.Minimum = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDown1.Name = "numericUpDown1";
|
||||||
|
this.numericUpDown1.Size = new System.Drawing.Size(74, 31);
|
||||||
|
this.numericUpDown1.TabIndex = 2;
|
||||||
|
this.numericUpDown1.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(33, 145);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(43, 25);
|
||||||
|
this.label2.TabIndex = 1;
|
||||||
|
this.label2.Text = "Вес:";
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(33, 75);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(93, 25);
|
||||||
|
this.label1.TabIndex = 0;
|
||||||
|
this.label1.Text = "Скорость:";
|
||||||
|
//
|
||||||
|
// Form2
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1279, 552);
|
||||||
|
this.Controls.Add(this.groupBox1);
|
||||||
|
this.Name = "Form2";
|
||||||
|
this.Text = "Создание объекта";
|
||||||
|
this.Load += new System.EventHandler(this.Form2_Load);
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
|
this.panel3.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||||
|
this.groupBox2.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private Button button2;
|
||||||
|
private Button button1;
|
||||||
|
private Panel panel3;
|
||||||
|
private Label label_addit_color;
|
||||||
|
private Label label_color;
|
||||||
|
private PictureBox pictureBox1;
|
||||||
|
private Label labelAdvanced;
|
||||||
|
private Label labelBasic;
|
||||||
|
private GroupBox groupBox2;
|
||||||
|
private Panel panel2;
|
||||||
|
private Panel panel1;
|
||||||
|
private CheckBox checkBox1;
|
||||||
|
private NumericUpDown numericUpDown2;
|
||||||
|
private NumericUpDown numericUpDown1;
|
||||||
|
private Label label2;
|
||||||
|
private Label label1;
|
||||||
|
private CheckBox checkBox2;
|
||||||
|
private Panel panel9;
|
||||||
|
private Panel panel8;
|
||||||
|
private Panel panel7;
|
||||||
|
private Panel panel6;
|
||||||
|
private Panel panel5;
|
||||||
|
private Panel panel4;
|
||||||
|
}
|
||||||
|
}
|
||||||
214
Cruiser/Cruiser/Form2.cs
Normal file
214
Cruiser/Cruiser/Form2.cs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
namespace Cruiser
|
||||||
|
{
|
||||||
|
public partial class Form2 : Form
|
||||||
|
{
|
||||||
|
public int _pictureWidth { get; private set; }
|
||||||
|
public int _pictureHeight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Переменная
|
||||||
|
/// </summary>
|
||||||
|
DrawingPlane? _plane = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Событие
|
||||||
|
/// </summary>
|
||||||
|
public event Action<DrawingPlane>? EventAddPlane;
|
||||||
|
|
||||||
|
|
||||||
|
public Form2(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
InitializeComponent();
|
||||||
|
panel1.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel2.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel3.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel4.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel5.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel6.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel7.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel8.MouseDown += PanelColor_MouseDown;
|
||||||
|
panel9.MouseDown += PanelColor_MouseDown;
|
||||||
|
button2.Click += (s, e) => Close();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void DrawPlane()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_plane?.SetPosition(5, 5);
|
||||||
|
_plane?.DrawTransport(gr);
|
||||||
|
pictureBox1.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddEvent(Action<DrawingPlane> ev)
|
||||||
|
{
|
||||||
|
if (EventAddPlane == null)
|
||||||
|
{
|
||||||
|
EventAddPlane = ev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddPlane += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 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 "labelBasic":
|
||||||
|
_plane = new DrawingPlane((int)numericUpDown1.Value,
|
||||||
|
(int)numericUpDown2.Value, Color.White, _pictureWidth, _pictureHeight);
|
||||||
|
break;
|
||||||
|
case "labelAdvanced":
|
||||||
|
_plane = new DrawingAirBomber((int)numericUpDown1.Value,
|
||||||
|
(int)numericUpDown2.Value, Color.White, Color.Black, checkBox1.Checked,
|
||||||
|
checkBox2.Checked, _pictureWidth, _pictureHeight);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawPlane();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
||||||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_plane == null)
|
||||||
|
return;
|
||||||
|
EventAddPlane?.Invoke(_plane);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_plane?.EntityPlane == null)
|
||||||
|
return;
|
||||||
|
switch (((Label)sender).Name)
|
||||||
|
{
|
||||||
|
case "label_color":
|
||||||
|
_plane?.EntityPlane?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||||
|
break;
|
||||||
|
case "label_addit_color":
|
||||||
|
if (!(_plane is DrawingAirBomber))
|
||||||
|
return;
|
||||||
|
(_plane.EntityPlane as EntityAirBomber)?.setAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
//на всякий случай
|
||||||
|
Color bodyColor = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
if (_plane is DrawingAirBomber)
|
||||||
|
{
|
||||||
|
_plane = new DrawingAirBomber((int)numericUpDown1.Value,
|
||||||
|
(int)numericUpDown2.Value, bodyColor, ((EntityAirBomber)_plane.EntityPlane).AdditionalColor, checkBox1.Checked,
|
||||||
|
checkBox2.Checked, _pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_plane = new DrawingPlane((int)numericUpDown1.Value,
|
||||||
|
(int)numericUpDown2.Value, bodyColor, _pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
DrawPlane();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelAddColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if ((_plane?.EntityPlane == null) || (_plane is DrawingAirBomber == false))
|
||||||
|
return;
|
||||||
|
Color additionalColor = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
_plane = new DrawingAirBomber((int)numericUpDown1.Value,
|
||||||
|
(int)numericUpDown1.Value, _plane.EntityPlane.BodyColor, additionalColor, checkBox1.Checked,
|
||||||
|
checkBox2.Checked, _pictureWidth, _pictureHeight);
|
||||||
|
DrawPlane();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelAddColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAddCruiser()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
private void Form2_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox2_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
60
Cruiser/Cruiser/Form2.resx
Normal file
60
Cruiser/Cruiser/Form2.resx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
237
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
Normal file
237
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Cruiser
|
||||||
|
{
|
||||||
|
partial class FormCruiserCollection
|
||||||
|
{
|
||||||
|
/// <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.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||||
|
this.panel1 = new System.Windows.Forms.Panel();
|
||||||
|
this.textBox2 = new System.Windows.Forms.TextBox();
|
||||||
|
this.addStorageButton = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||||
|
this.button2 = new System.Windows.Forms.Button();
|
||||||
|
this.updateCollectionButton = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonRemoveCar = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonAddCruiser = new System.Windows.Forms.Button();
|
||||||
|
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||||
|
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||||
|
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
|
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||||
|
this.panel1.SuspendLayout();
|
||||||
|
this.menuStrip.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBox1
|
||||||
|
//
|
||||||
|
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBox1.Location = new System.Drawing.Point(0, 33);
|
||||||
|
this.pictureBox1.Name = "pictureBox1";
|
||||||
|
this.pictureBox1.Size = new System.Drawing.Size(971, 511);
|
||||||
|
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
|
this.pictureBox1.TabIndex = 0;
|
||||||
|
this.pictureBox1.TabStop = false;
|
||||||
|
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
|
||||||
|
//
|
||||||
|
// panel1
|
||||||
|
//
|
||||||
|
this.panel1.Controls.Add(this.textBox2);
|
||||||
|
this.panel1.Controls.Add(this.addStorageButton);
|
||||||
|
this.panel1.Controls.Add(this.listBoxStorages);
|
||||||
|
this.panel1.Controls.Add(this.button2);
|
||||||
|
this.panel1.Controls.Add(this.updateCollectionButton);
|
||||||
|
this.panel1.Controls.Add(this.ButtonRemoveCar);
|
||||||
|
this.panel1.Controls.Add(this.ButtonAddCruiser);
|
||||||
|
this.panel1.Controls.Add(this.textBox1);
|
||||||
|
this.panel1.Location = new System.Drawing.Point(692, 12);
|
||||||
|
this.panel1.Name = "panel1";
|
||||||
|
this.panel1.Size = new System.Drawing.Size(267, 520);
|
||||||
|
this.panel1.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// textBox2
|
||||||
|
//
|
||||||
|
this.textBox2.Location = new System.Drawing.Point(60, 36);
|
||||||
|
this.textBox2.Name = "textBox2";
|
||||||
|
this.textBox2.Size = new System.Drawing.Size(150, 31);
|
||||||
|
this.textBox2.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// addStorageButton
|
||||||
|
//
|
||||||
|
this.addStorageButton.Location = new System.Drawing.Point(79, 88);
|
||||||
|
this.addStorageButton.Name = "addStorageButton";
|
||||||
|
this.addStorageButton.Size = new System.Drawing.Size(112, 34);
|
||||||
|
this.addStorageButton.TabIndex = 2;
|
||||||
|
this.addStorageButton.Text = "Добавить";
|
||||||
|
this.addStorageButton.UseVisualStyleBackColor = true;
|
||||||
|
this.addStorageButton.Click += new System.EventHandler(this.addStorageButton_Click);
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
this.listBoxStorages.FormattingEnabled = true;
|
||||||
|
this.listBoxStorages.ItemHeight = 25;
|
||||||
|
this.listBoxStorages.Location = new System.Drawing.Point(60, 128);
|
||||||
|
this.listBoxStorages.Name = "listBoxStorages";
|
||||||
|
this.listBoxStorages.Size = new System.Drawing.Size(152, 104);
|
||||||
|
this.listBoxStorages.TabIndex = 4;
|
||||||
|
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// button2
|
||||||
|
//
|
||||||
|
this.button2.Location = new System.Drawing.Point(60, 264);
|
||||||
|
this.button2.Name = "button2";
|
||||||
|
this.button2.Size = new System.Drawing.Size(159, 36);
|
||||||
|
this.button2.TabIndex = 2;
|
||||||
|
this.button2.Text = "Удалить набор";
|
||||||
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
|
this.button2.Click += new System.EventHandler(this.delStorageButton_Click);
|
||||||
|
//
|
||||||
|
// updateCollectionButton
|
||||||
|
//
|
||||||
|
this.updateCollectionButton.Location = new System.Drawing.Point(79, 469);
|
||||||
|
this.updateCollectionButton.Name = "updateCollectionButton";
|
||||||
|
this.updateCollectionButton.Size = new System.Drawing.Size(112, 34);
|
||||||
|
this.updateCollectionButton.TabIndex = 2;
|
||||||
|
this.updateCollectionButton.Text = "Обновить";
|
||||||
|
this.updateCollectionButton.UseVisualStyleBackColor = true;
|
||||||
|
this.updateCollectionButton.Click += new System.EventHandler(this.button1_Click);
|
||||||
|
//
|
||||||
|
// ButtonRemoveCar
|
||||||
|
//
|
||||||
|
this.ButtonRemoveCar.Location = new System.Drawing.Point(60, 429);
|
||||||
|
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
|
||||||
|
this.ButtonRemoveCar.Size = new System.Drawing.Size(150, 34);
|
||||||
|
this.ButtonRemoveCar.TabIndex = 2;
|
||||||
|
this.ButtonRemoveCar.Text = "Удалить";
|
||||||
|
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
||||||
|
//
|
||||||
|
// ButtonAddCruiser
|
||||||
|
//
|
||||||
|
this.ButtonAddCruiser.Location = new System.Drawing.Point(60, 317);
|
||||||
|
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
|
||||||
|
this.ButtonAddCruiser.Size = new System.Drawing.Size(150, 34);
|
||||||
|
this.ButtonAddCruiser.TabIndex = 3;
|
||||||
|
this.ButtonAddCruiser.Text = "Добавить";
|
||||||
|
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
|
||||||
|
//
|
||||||
|
// textBox1
|
||||||
|
//
|
||||||
|
this.textBox1.Location = new System.Drawing.Point(60, 381);
|
||||||
|
this.textBox1.Name = "textBox1";
|
||||||
|
this.textBox1.Size = new System.Drawing.Size(150, 31);
|
||||||
|
this.textBox1.TabIndex = 2;
|
||||||
|
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
this.saveFileDialog.FileName = "PlanesStorage";
|
||||||
|
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
this.openFileDialog.FileName = "openFileDialog1";
|
||||||
|
this.openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||||
|
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.ToolStripMenuItem,
|
||||||
|
this.SaveToolStripMenuItem,
|
||||||
|
this.LoadToolStripMenuItem});
|
||||||
|
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.menuStrip.Name = "menuStrip";
|
||||||
|
this.menuStrip.Size = new System.Drawing.Size(971, 33);
|
||||||
|
this.menuStrip.TabIndex = 2;
|
||||||
|
this.menuStrip.Text = "menuStrip";
|
||||||
|
//
|
||||||
|
// ToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
|
||||||
|
this.ToolStripMenuItem.Size = new System.Drawing.Size(69, 29);
|
||||||
|
this.ToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(114, 29);
|
||||||
|
this.SaveToolStripMenuItem.Text = "Сохранить";
|
||||||
|
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// LoadToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
|
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(108, 29);
|
||||||
|
this.LoadToolStripMenuItem.Text = "Загрузить";
|
||||||
|
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// FormCruiserCollection
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(971, 544);
|
||||||
|
this.Controls.Add(this.panel1);
|
||||||
|
this.Controls.Add(this.pictureBox1);
|
||||||
|
this.Controls.Add(this.menuStrip);
|
||||||
|
this.Name = "FormCruiserCollection";
|
||||||
|
this.Text = "FormCruiserCollection";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||||
|
this.panel1.ResumeLayout(false);
|
||||||
|
this.panel1.PerformLayout();
|
||||||
|
this.menuStrip.ResumeLayout(false);
|
||||||
|
this.menuStrip.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBox1;
|
||||||
|
private Panel panel1;
|
||||||
|
private Button ButtonRemoveCar;
|
||||||
|
private Button ButtonAddCruiser;
|
||||||
|
private TextBox textBox1;
|
||||||
|
private Button updateCollectionButton;
|
||||||
|
private TextBox textBox2;
|
||||||
|
private Button addStorageButton;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button button2;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem ToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
229
Cruiser/Cruiser/FormCruiserCollection.cs
Normal file
229
Cruiser/Cruiser/FormCruiserCollection.cs
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.Generics;
|
||||||
|
using Monorail.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Cruiser
|
||||||
|
{
|
||||||
|
public partial class FormCruiserCollection : Form
|
||||||
|
{
|
||||||
|
private readonly PlanesGenericStorage _storage;
|
||||||
|
|
||||||
|
public FormCruiserCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new PlanesGenericStorage(pictureBox1.Width, pictureBox1.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pictureBox1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.SaveData(saveFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Сохранение прошло успешно",
|
||||||
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не сохранилось", "Результат",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Загрузка"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.LoadData(openFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Загрузка прошла успешно",
|
||||||
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
foreach (var collection in _storage.Keys)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось загрузить", "Результат",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ButtonAddCruiser_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Form2 form = new Form2(pictureBox1.Width, pictureBox1.Height);
|
||||||
|
form.Show();
|
||||||
|
Action<DrawingPlane>? planeDelegate = new((m) => {
|
||||||
|
bool q = (obj + m);
|
||||||
|
if (q)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox1.Image = obj.ShowPlanes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
form.AddEvent(planeDelegate);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRemoveCar_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;
|
||||||
|
if (textBox1.Text == null || !int.TryParse(textBox1.Text, out pos))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Введите номер парковочного места");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox1.Image = obj.ShowPlanes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void maskedTextBoxNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox1.Image = obj.ShowPlanes();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBox1.Image =
|
||||||
|
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void delStorageButton_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 addStorageButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBox2.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBox2.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
69
Cruiser/Cruiser/FormCruiserCollection.resx
Normal file
69
Cruiser/Cruiser/FormCruiserCollection.resx
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>28, 24</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>216, 24</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>400, 24</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
||||||
17
Cruiser/Cruiser/IMoveableObject.cs
Normal file
17
Cruiser/Cruiser/IMoveableObject.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using Cruiser;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
|
||||||
|
namespace Monorail.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
bool CheckCanMove(DirectionType direction);
|
||||||
|
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
49
Cruiser/Cruiser/MoveToBorder.cs
Normal file
49
Cruiser/Cruiser/MoveToBorder.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
using Monorail.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToEdge : 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 = objParams.RightBorder - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX < 0)
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY < 0)
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
59
Cruiser/Cruiser/MoveToCenter.cs
Normal file
59
Cruiser/Cruiser/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 Monorail.MovementStrategy
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Cruiser/Cruiser/ObjectParameters.cs
Normal file
32
Cruiser/Cruiser/ObjectParameters.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
namespace Monorail.MovementStrategy
|
||||||
|
{
|
||||||
|
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
|
||||||
|
public int TopBorder => _y;
|
||||||
|
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Cruiser/Cruiser/Pro.cs
Normal file
29
Cruiser/Cruiser/Pro.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail.Entities
|
||||||
|
{
|
||||||
|
public class EntityAirBomber : EntityPlane
|
||||||
|
{
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
public bool Bombs { get; private set; }
|
||||||
|
public bool Fuel { get; private set; }
|
||||||
|
|
||||||
|
public EntityAirBomber(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool bombs, bool fuel)
|
||||||
|
: base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Bombs = bombs;
|
||||||
|
Fuel = fuel;
|
||||||
|
}
|
||||||
|
public void setAdditionalColor(Color color)
|
||||||
|
{
|
||||||
|
AdditionalColor = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
namespace Cruiser
|
namespace Cruiser
|
||||||
{
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -11,7 +12,7 @@ namespace Cruiser
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new CruiserForm());
|
Application.Run(new FormCruiserCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
72
Cruiser/Cruiser/SetGeneric.cs
Normal file
72
Cruiser/Cruiser/SetGeneric.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly List<T?> _places;
|
||||||
|
|
||||||
|
public int Count => _places.Count;
|
||||||
|
|
||||||
|
private readonly int _maxCount;
|
||||||
|
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Insert(T plane)
|
||||||
|
{
|
||||||
|
if (_places.Count == _maxCount)
|
||||||
|
return false;
|
||||||
|
Insert(plane, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Insert(T plane, int position)
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||||
|
return false;
|
||||||
|
_places.Insert(position, plane);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position < Count))
|
||||||
|
return false;
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position <= Count))
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position <= Count))
|
||||||
|
return;
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Cruiser/Cruiser/Status.cs
Normal file
15
Cruiser/Cruiser/Status.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit = 1,
|
||||||
|
InProgress = 2,
|
||||||
|
Finish = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user