Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
687a08304f | ||
|
6e0bdadae6 | ||
|
dd84cb56bc | ||
|
8e29980e9f | ||
|
86aee47092 | ||
|
793ecd010e | ||
|
4d7de8d19c | ||
|
bcebb2297a | ||
|
4148c28d17 | ||
|
cf00e1bcc2 | ||
|
cd50b5bf7a | ||
|
1dedcb6bc1 | ||
|
6d0a86275c | ||
|
9d313781ba | ||
|
8daf34e524 | ||
|
633083e5de | ||
|
0df7ae5e02 | ||
|
e86d1515d9 | ||
|
080c6c4c23 | ||
|
7bfa7b0938 | ||
|
9406327348 | ||
|
21721ee795 | ||
|
826cc3be3b | ||
|
7cb5d815f7 | ||
|
d9cadbabc4 | ||
|
31671e87d0 | ||
|
3fc0d392b0 | ||
|
1d8824c3e4 | ||
|
2c1cedade6 | ||
|
aaa540c662 | ||
|
704a27c3aa | ||
|
3a34dff170 | ||
|
534e7be294 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -69,6 +69,8 @@ ScaffoldingReadMe.txt
|
|||||||
# StyleCop
|
# StyleCop
|
||||||
StyleCopReport.xml
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
/ProjectFlowerShop/ImplementationExtensions
|
||||||
|
|
||||||
# Files built by Visual Studio
|
# Files built by Visual Studio
|
||||||
*_i.c
|
*_i.c
|
||||||
*_p.c
|
*_p.c
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.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(Direction.Left);
|
||||||
|
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||||
|
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||||
|
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||||
|
protected ObjectParameteres? 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(Direction directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class AirplaneCollectionInfo : IEquatable<AirplaneCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public AirplaneCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public bool Equals(AirplaneCollectionInfo? other)
|
||||||
|
{
|
||||||
|
if (other != null)
|
||||||
|
{
|
||||||
|
return Name == other.Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return this.Name.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
using ProjectAirplaneWithRadar.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class AirplaneCompareByColor : IComparer<DrawningAirplane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirplane? x, DrawningAirplane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirplane == null)
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirplane == null)
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
|
||||||
|
if (x.EntityAirplane.BodyColor.Name != y.EntityAirplane.BodyColor.Name)
|
||||||
|
{
|
||||||
|
return x.EntityAirplane.BodyColor.Name.CompareTo(y.EntityAirplane.BodyColor.Name);
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityAirplane.Speed.CompareTo(y.EntityAirplane.Speed);
|
||||||
|
|
||||||
|
if (speedCompare != 0)
|
||||||
|
return speedCompare;
|
||||||
|
|
||||||
|
return x.EntityAirplane.Weight.CompareTo(y.EntityAirplane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
using ProjectAirplaneWithRadar.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class AirplaneCompareByType : IComparer<DrawningAirplane?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningAirplane? x, DrawningAirplane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirplane == null)
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
|
||||||
|
if (y == null || y.EntityAirplane == null)
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityAirplane.Speed.CompareTo(y.EntityAirplane.Speed);
|
||||||
|
|
||||||
|
if (speedCompare != 0)
|
||||||
|
return speedCompare;
|
||||||
|
|
||||||
|
return x.EntityAirplane.Weight.CompareTo(y.EntityAirplane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
using ProjectAirplaneWithRadar.Generics;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||||
|
namespace ProjectAirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class AirplanesGenericCollection<T, U>
|
||||||
|
where T : DrawningAirplane
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
private readonly int _placeSizeWidth = 215;
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||||
|
public AirplanesGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
public IEnumerable<T?> GetAirplanes => _collection.GetAirplanes();
|
||||||
|
public static bool operator +(AirplanesGenericCollection<T, U> collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null || collect == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return collect?._collection.Insert(obj, new DrawningAirplanesEqutables()) ?? false;
|
||||||
|
}
|
||||||
|
public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection[pos];
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
public Bitmap ShowAirplanes()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
foreach (var airplane in _collection.GetAirplanes())
|
||||||
|
{
|
||||||
|
if (airplane != null)
|
||||||
|
{
|
||||||
|
int inRow = _pictureWidth / _placeSizeWidth;
|
||||||
|
airplane.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight);
|
||||||
|
airplane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||||
|
using ProjectAirplaneWithRadar.Generics;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class AirplanesGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<AirplaneCollectionInfo, AirplanesGenericCollection<DrawningAirplane,DrawningObjectAirplane>> _airplanesStorages;
|
||||||
|
public List<AirplaneCollectionInfo> Keys => _airplanesStorages.Keys.ToList();
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
public AirplanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_airplanesStorages = new Dictionary<AirplaneCollectionInfo,AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<AirplaneCollectionInfo,
|
||||||
|
AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>> record in _airplanesStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawningAirplane? elem in record.Value.GetAirplanes)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||||
|
}
|
||||||
|
string toWrite = $"AirplanesStorage{Environment.NewLine}{data}";
|
||||||
|
var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
using (StreamWriter sw = new(filename))
|
||||||
|
{
|
||||||
|
foreach (var str in strs)
|
||||||
|
{
|
||||||
|
sw.WriteLine(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new IOException("Файл не найден");
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
throw new IOException("Нет данных для загрузки");
|
||||||
|
}
|
||||||
|
if (!strs[0].StartsWith("AirplanesStorage"))
|
||||||
|
{
|
||||||
|
throw new IOException("Неверный формат данных");
|
||||||
|
}
|
||||||
|
_airplanesStorages.Clear();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
str = sr.ReadLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>
|
||||||
|
collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawningAirplane? airplane =
|
||||||
|
elem?.CreateDrawningAirplane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (airplane != null)
|
||||||
|
{
|
||||||
|
if (!(collection + airplane))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_airplanesStorages.Add(new AirplaneCollectionInfo (record[0], string.Empty), collection);
|
||||||
|
str = sr.ReadLine();
|
||||||
|
} while (str != null);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
_airplanesStorages.Add(new AirplaneCollectionInfo(name, string.Empty), new AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_airplanesStorages.ContainsKey(new AirplaneCollectionInfo(name, string.Empty)))
|
||||||
|
return;
|
||||||
|
_airplanesStorages.Remove(new AirplaneCollectionInfo(name, string.Empty));
|
||||||
|
}
|
||||||
|
public AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>?this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
AirplaneCollectionInfo indObj = new AirplaneCollectionInfo(ind, string.Empty);
|
||||||
|
if (_airplanesStorages.ContainsKey(indObj))
|
||||||
|
return _airplanesStorages[indObj];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": { "path": "log.txt" }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "Sample"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,171 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAirplaneWithRadar.Entities;
|
||||||
|
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawningAirplane
|
||||||
|
{
|
||||||
|
public EntityAirplane? EntityAirplane { get; protected set; }
|
||||||
|
private int _pictureWidth;
|
||||||
|
private int _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
protected readonly int _airplaneWidth = 200;
|
||||||
|
protected readonly int _airplaneHeight = 78;
|
||||||
|
char separator = '|';
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
public int GetWidth => _airplaneWidth;
|
||||||
|
public int GetHeight => _airplaneHeight;
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectAirplane(this);
|
||||||
|
public DrawningAirplane(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height)
|
||||||
|
{
|
||||||
|
if (width < _airplaneWidth || height < _airplaneHeight)
|
||||||
|
return;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
protected DrawningAirplane(int speed, double weight, Color bodyColor, int
|
||||||
|
width, int height, int airplaneWidth, int airplaneHeight)
|
||||||
|
{
|
||||||
|
if (width < _airplaneWidth || height < _airplaneHeight)
|
||||||
|
return;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_airplaneWidth = airplaneWidth;
|
||||||
|
_airplaneHeight = airplaneHeight;
|
||||||
|
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (x < 0 || y < 0 || x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
|
||||||
|
{
|
||||||
|
x = y = 10;
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
public void ChangeColor(Color col)
|
||||||
|
{
|
||||||
|
if (EntityAirplane == null)
|
||||||
|
return;
|
||||||
|
EntityAirplane.BodyColor = col;
|
||||||
|
}
|
||||||
|
public bool CanMove(Direction direction)
|
||||||
|
{
|
||||||
|
if (EntityAirplane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Direction.Left:
|
||||||
|
return _startPosX - EntityAirplane.Step > 0;
|
||||||
|
break;
|
||||||
|
case Direction.Up:
|
||||||
|
return _startPosY - EntityAirplane.Step > 0;
|
||||||
|
break;
|
||||||
|
case Direction.Right:
|
||||||
|
return _startPosX + EntityAirplane.Step + _airplaneWidth < _pictureWidth;
|
||||||
|
break;
|
||||||
|
case Direction.Down:
|
||||||
|
return _startPosY + EntityAirplane.Step + _airplaneHeight < _pictureHeight;
|
||||||
|
break;
|
||||||
|
default:return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void MoveTransport(Direction direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction)||EntityAirplane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Direction.Left:
|
||||||
|
if (_startPosX - EntityAirplane.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityAirplane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Up:
|
||||||
|
if (_startPosY - EntityAirplane.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityAirplane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Right:
|
||||||
|
if (_startPosX + EntityAirplane.Step + _airplaneWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityAirplane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Down:
|
||||||
|
if (_startPosY + EntityAirplane.Step + _airplaneHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityAirplane.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAirplane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new Pen(Color.Black, 3);
|
||||||
|
// корпус
|
||||||
|
Brush br = new SolidBrush(EntityAirplane.BodyColor);
|
||||||
|
g.DrawEllipse(pen, _startPosX, _startPosY + 25, 180, 30);
|
||||||
|
g.FillEllipse(br, _startPosX, _startPosY + 25, 180, 30);
|
||||||
|
// крыло
|
||||||
|
Brush blackBrush = new SolidBrush(Color.Black);
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 70, _startPosY + 35, 80, 10);
|
||||||
|
// стекла
|
||||||
|
Pen blackPen = new Pen(Color.Black, 2);
|
||||||
|
Brush blueBrush = new SolidBrush(Color.LightBlue);
|
||||||
|
Point point1 = new Point(_startPosX + 170, _startPosY + 30);
|
||||||
|
Point point2 = new Point(_startPosX + 200, _startPosY + 40);
|
||||||
|
Point point3 = new Point(_startPosX + 170, _startPosY + 50);
|
||||||
|
Point[] curvePoints =
|
||||||
|
{
|
||||||
|
point1,
|
||||||
|
point2,
|
||||||
|
point3,
|
||||||
|
};
|
||||||
|
g.FillPolygon(blueBrush, curvePoints);
|
||||||
|
g.DrawPolygon(blackPen, curvePoints);
|
||||||
|
g.DrawLine(blackPen, _startPosX + 170, _startPosY + 40, _startPosX + 200, _startPosY + 40);
|
||||||
|
// хвост
|
||||||
|
Point point4 = new Point(_startPosX, _startPosY + 35);
|
||||||
|
Point point5 = new Point(_startPosX, _startPosY + 5);
|
||||||
|
Point point6 = new Point(_startPosX + 30, _startPosY + 35);
|
||||||
|
Point[] curvePoints2 =
|
||||||
|
{
|
||||||
|
point4,
|
||||||
|
point5,
|
||||||
|
point6,
|
||||||
|
};
|
||||||
|
g.FillPolygon(br, curvePoints2);
|
||||||
|
g.DrawPolygon(blackPen, curvePoints2);
|
||||||
|
// шасси
|
||||||
|
g.DrawLine(blackPen, _startPosX + 50, _startPosY + 55, _startPosX + 50, _startPosY + 70);
|
||||||
|
g.DrawLine(blackPen, _startPosX + 150, _startPosY + 51, _startPosX + 150, _startPosY + 70);
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 40, _startPosY + 65, 10, 10);
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 65, 10, 10);
|
||||||
|
g.FillEllipse(blackBrush, _startPosX + 145, _startPosY + 65, 10, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,130 +7,41 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using ProjectAirplaneWithRadar.Entities;
|
||||||
namespace ProjectAirplaneWithRadar
|
namespace ProjectAirplaneWithRadar.DrawningObjects
|
||||||
{
|
{
|
||||||
public class DrawningAirplaneWithRadar
|
public class DrawningAirplaneWithRadar : DrawningAirplane
|
||||||
{
|
{
|
||||||
public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; }
|
public DrawningAirplaneWithRadar(int speed, double weight, Color bodyColor, Color
|
||||||
public int _pictureWidth;
|
additionalColor, bool radar, bool dopbak, int width, int height) : base(speed, weight, bodyColor, width, height, 200, 78)
|
||||||
public int _pictureHeight;
|
|
||||||
public int _startPosX;
|
|
||||||
public int _startPosY;
|
|
||||||
private readonly int _airplaneWidth = 200;
|
|
||||||
private readonly int _airplaneHeight = 78;
|
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopbak, int width, int height)
|
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
if (EntityAirplane != null)
|
||||||
_pictureHeight = height;
|
|
||||||
if (_airplaneWidth > _pictureWidth || _airplaneHeight > _pictureHeight)
|
|
||||||
return false;
|
|
||||||
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
|
|
||||||
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, radar, dopbak);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public void SetPosition(int x, int y)
|
|
||||||
{
|
|
||||||
if(x < 0 || y < 0 ||x+_airplaneWidth >= _pictureWidth|| y + _airplaneHeight >= _pictureHeight)
|
|
||||||
{
|
{
|
||||||
x = y = 10;
|
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, radar, dopbak);
|
||||||
_startPosX = x;
|
}
|
||||||
_startPosY=y;
|
|
||||||
}
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
}
|
||||||
public void MoveTransport(Direction direction)
|
public void ChangeAddColor(Color col)
|
||||||
{
|
{
|
||||||
if (EntityAirplaneWithRadar == null)
|
((EntityAirplaneWithRadar)EntityAirplane).AdditionalColor = col;
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAirplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (direction)
|
base.DrawTransport(g);
|
||||||
{
|
|
||||||
case Direction.Left:
|
|
||||||
if (_startPosX - EntityAirplaneWithRadar.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosX -= (int)EntityAirplaneWithRadar.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction.Up:
|
|
||||||
if (_startPosY - EntityAirplaneWithRadar.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosY -= (int)EntityAirplaneWithRadar.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction.Right:
|
|
||||||
if (_startPosX + EntityAirplaneWithRadar.Step+_airplaneWidth < _pictureWidth)
|
|
||||||
{
|
|
||||||
_startPosX += (int)EntityAirplaneWithRadar.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction.Down:
|
|
||||||
if (_startPosY + EntityAirplaneWithRadar.Step+_airplaneHeight < _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosY += (int)EntityAirplaneWithRadar.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if(EntityAirplaneWithRadar == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pen pen = new Pen(Color.Black, 3);
|
|
||||||
Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor);
|
|
||||||
// корпус
|
|
||||||
Brush br = new SolidBrush(EntityAirplaneWithRadar.BodyColor);
|
|
||||||
g.DrawEllipse(pen, _startPosX, _startPosY+25,180, 30) ;
|
|
||||||
g.FillEllipse(br, _startPosX, _startPosY+25, 180, 30);
|
|
||||||
// крыло
|
|
||||||
Brush blackBrush = new SolidBrush(Color.Black);
|
|
||||||
g.FillEllipse(blackBrush, _startPosX + 70, _startPosY + 35, 80, 10);
|
|
||||||
// стекла
|
|
||||||
Pen blackPen = new Pen(Color.Black, 2);
|
Pen blackPen = new Pen(Color.Black, 2);
|
||||||
Brush blueBrush = new SolidBrush(Color.LightBlue);
|
Pen pen = new Pen(Color.Black);
|
||||||
Point point1 = new Point(_startPosX+170, _startPosY+30);
|
Brush additionalBrush = new
|
||||||
Point point2 = new Point(_startPosX+200, _startPosY+40);
|
SolidBrush(airplaneWithRadar.AdditionalColor);
|
||||||
Point point3 = new Point(_startPosX+170, _startPosY + 50);
|
if (airplaneWithRadar.DopBak)
|
||||||
Point[] curvePoints =
|
|
||||||
{
|
|
||||||
point1,
|
|
||||||
point2,
|
|
||||||
point3,
|
|
||||||
};
|
|
||||||
g.FillPolygon(blueBrush, curvePoints);
|
|
||||||
g.DrawPolygon(blackPen, curvePoints);
|
|
||||||
g.DrawLine(blackPen, _startPosX + 170, _startPosY + 40, _startPosX + 200, _startPosY + 40);
|
|
||||||
// хвост
|
|
||||||
Point point4 = new Point(_startPosX, _startPosY + 35);
|
|
||||||
Point point5 = new Point(_startPosX, _startPosY +5 );
|
|
||||||
Point point6 = new Point(_startPosX + 30, _startPosY + 35);
|
|
||||||
Point[] curvePoints2 =
|
|
||||||
{
|
|
||||||
point4,
|
|
||||||
point5,
|
|
||||||
point6,
|
|
||||||
};
|
|
||||||
g.FillPolygon(br, curvePoints2);
|
|
||||||
g.DrawPolygon(blackPen, curvePoints2);
|
|
||||||
// шасси
|
|
||||||
g.DrawLine(blackPen, _startPosX + 50, _startPosY + 55, _startPosX + 50, _startPosY + 70);
|
|
||||||
g.DrawLine(blackPen, _startPosX + 150, _startPosY + 51, _startPosX + 150, _startPosY + 70);
|
|
||||||
g.FillEllipse(blackBrush, _startPosX + 40, _startPosY + 65, 10, 10);
|
|
||||||
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 65, 10, 10);
|
|
||||||
g.FillEllipse(blackBrush, _startPosX + 145, _startPosY + 65, 10, 10);
|
|
||||||
if (EntityAirplaneWithRadar.DopBak)
|
|
||||||
{
|
{
|
||||||
//бак
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 45, 40, 20);
|
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 45, 40, 20);
|
||||||
g.DrawEllipse(blackPen, _startPosX, _startPosY + 45, 40, 20);
|
g.DrawEllipse(blackPen, _startPosX, _startPosY + 45, 40, 20);
|
||||||
}
|
}
|
||||||
if (EntityAirplaneWithRadar.Radar)
|
if (airplaneWithRadar.Radar)
|
||||||
{
|
{
|
||||||
//радар
|
|
||||||
g.DrawLine(blackPen, _startPosX + 60, _startPosY + 25, _startPosX + 60, _startPosY + 15);
|
g.DrawLine(blackPen, _startPosX + 60, _startPosY + 25, _startPosX + 60, _startPosY + 15);
|
||||||
g.DrawLine(blackPen, _startPosX + 60, _startPosY + 15, _startPosX + 67, _startPosY + 11);
|
g.DrawLine(blackPen, _startPosX + 60, _startPosY + 15, _startPosX + 67, _startPosY + 11);
|
||||||
Point point7 = new Point(_startPosX + 60, _startPosY + 15);
|
Point point7 = new Point(_startPosX + 60, _startPosY + 15);
|
||||||
@ -138,10 +49,10 @@ namespace ProjectAirplaneWithRadar
|
|||||||
Point point9 = new Point(_startPosX + 70, _startPosY + 25);
|
Point point9 = new Point(_startPosX + 70, _startPosY + 25);
|
||||||
Point[] curvePoints3 =
|
Point[] curvePoints3 =
|
||||||
{
|
{
|
||||||
point7,
|
point7,
|
||||||
point8,
|
point8,
|
||||||
point9,
|
point9,
|
||||||
};
|
};
|
||||||
g.FillPolygon(additionalBrush, curvePoints3);
|
g.FillPolygon(additionalBrush, curvePoints3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
using ProjectAirplaneWithRadar.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class DrawningAirplanesEqutables : IEqualityComparer<DrawningAirplane?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawningAirplane? x, DrawningAirplane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityAirplane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityAirplane == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityAirplane.Speed != y.EntityAirplane.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityAirplane.Weight != y.EntityAirplane.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityAirplane.BodyColor != y.EntityAirplane.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is DrawningAirplaneWithRadar && y is DrawningAirplaneWithRadar)
|
||||||
|
{
|
||||||
|
EntityAirplaneWithRadar EntityX = (EntityAirplaneWithRadar)x.EntityAirplane;
|
||||||
|
EntityAirplaneWithRadar EntityY = (EntityAirplaneWithRadar)y.EntityAirplane;
|
||||||
|
if (EntityX.Radar != EntityY.Radar)
|
||||||
|
return false;
|
||||||
|
if (EntityX.DopBak != EntityY.DopBak)
|
||||||
|
return false;
|
||||||
|
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode([DisallowNull] DrawningAirplane obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawningObjectAirplane : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawningAirplane? _drawningAirplane = null;
|
||||||
|
public DrawningObjectAirplane(DrawningAirplane drawningCar)
|
||||||
|
{
|
||||||
|
_drawningAirplane = drawningCar;
|
||||||
|
}
|
||||||
|
public ObjectParameteres? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningAirplane == null || _drawningAirplane.EntityAirplane ==null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameteres(_drawningAirplane.GetPosX,
|
||||||
|
_drawningAirplane.GetPosY, _drawningAirplane.GetWidth, _drawningAirplane.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningAirplane?.EntityAirplane?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(Direction direction) =>
|
||||||
|
_drawningAirplane?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(Direction direction) =>
|
||||||
|
_drawningAirplane?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Entities
|
||||||
|
{
|
||||||
|
public class EntityAirplane
|
||||||
|
{
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
public Color BodyColor { get; set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
public EntityAirplane(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -5,32 +5,18 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ProjectAirplaneWithRadar
|
namespace ProjectAirplaneWithRadar.Entities
|
||||||
{
|
{
|
||||||
public class EntityAirplaneWithRadar
|
public class EntityAirplaneWithRadar : EntityAirplane
|
||||||
{
|
{
|
||||||
//скорость
|
public Color AdditionalColor { get; set; }
|
||||||
public int Speed { get; private set; }
|
public bool Radar { get; private set; }
|
||||||
// вес
|
public bool DopBak { get; private set; }
|
||||||
public double Weight { get; private set; }
|
public EntityAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopbak) : base(speed, weight, bodyColor)
|
||||||
// основной цвет
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
// доп цвет
|
|
||||||
public Color AdditionalColor { get; private set; }
|
|
||||||
// наличие радара
|
|
||||||
public bool Radar{ get; private set; }
|
|
||||||
// наличие дополнительных топливных баков
|
|
||||||
public bool DopBak{ get; private set; }
|
|
||||||
//шаг перемещения самолета
|
|
||||||
public double Step => (double)Speed*100/Weight;
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopbak)
|
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Radar = radar;
|
Radar = radar;
|
||||||
DopBak = dopbak;
|
DopBak = dopbak;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class AirplaneNotFoundException :ApplicationException
|
||||||
|
{
|
||||||
|
public AirplaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public AirplaneNotFoundException() : base() { }
|
||||||
|
public AirplaneNotFoundException(string message) : base(message) { }
|
||||||
|
public AirplaneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected AirplaneNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class StorageOverflowException :ApplicationException
|
||||||
|
{
|
||||||
|
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||||
|
public StorageOverflowException() : base() { }
|
||||||
|
public StorageOverflowException(string message) : base(message) { }
|
||||||
|
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected StorageOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
using ProjectAirplaneWithRadar.Entities;
|
||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar
|
||||||
|
{
|
||||||
|
public static class ExtentionDrawningAirplane
|
||||||
|
{
|
||||||
|
public static DrawningAirplane? CreateDrawningAirplane(this string info, char separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawningAirplane(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawningAirplaneWithRadar(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;
|
||||||
|
}
|
||||||
|
public static string GetDataForSave(this DrawningAirplane drawningAirplane,char separatorForObject)
|
||||||
|
{
|
||||||
|
var airplane = drawningAirplane.EntityAirplane;
|
||||||
|
if (airplane == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{airplane.Speed}{separatorForObject}{airplane.Weight}{separatorForObject}{airplane.BodyColor.Name}";
|
||||||
|
if (airplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return
|
||||||
|
$"{str}{separatorForObject}{airplaneWithRadar.AdditionalColor.Name}" +
|
||||||
|
$"{separatorForObject}{airplaneWithRadar.Radar}" +
|
||||||
|
$"{separatorForObject}{airplaneWithRadar.DopBak}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
366
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneConfig.Designer.cs
generated
Normal file
366
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneConfig.Designer.cs
generated
Normal file
@ -0,0 +1,366 @@
|
|||||||
|
namespace ProjectAirplaneWithRadar
|
||||||
|
{
|
||||||
|
partial class FormAirplaneConfig
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
configGroupBox = new GroupBox();
|
||||||
|
colorGroupBox = new GroupBox();
|
||||||
|
yellowPanel = new Panel();
|
||||||
|
bluePanel = new Panel();
|
||||||
|
greenPanel = new Panel();
|
||||||
|
purplePanel = new Panel();
|
||||||
|
blackPanel = new Panel();
|
||||||
|
greyPanel = new Panel();
|
||||||
|
whitePanel = new Panel();
|
||||||
|
redPanel = new Panel();
|
||||||
|
airplaneWithRadarLabel = new Label();
|
||||||
|
airplaneLabel = new Label();
|
||||||
|
checkDopBak = new CheckBox();
|
||||||
|
checkRadar = new CheckBox();
|
||||||
|
numericWeight = new NumericUpDown();
|
||||||
|
numericSpeed = new NumericUpDown();
|
||||||
|
weightLabel = new Label();
|
||||||
|
speedLabel = new Label();
|
||||||
|
allowPanel = new Panel();
|
||||||
|
addColorLabel = new Label();
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
colorLabel = new Label();
|
||||||
|
addButton = new Button();
|
||||||
|
cancelButton = new Button();
|
||||||
|
configGroupBox.SuspendLayout();
|
||||||
|
colorGroupBox.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericWeight).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericSpeed).BeginInit();
|
||||||
|
allowPanel.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// configGroupBox
|
||||||
|
//
|
||||||
|
configGroupBox.Controls.Add(colorGroupBox);
|
||||||
|
configGroupBox.Controls.Add(airplaneWithRadarLabel);
|
||||||
|
configGroupBox.Controls.Add(airplaneLabel);
|
||||||
|
configGroupBox.Controls.Add(checkDopBak);
|
||||||
|
configGroupBox.Controls.Add(checkRadar);
|
||||||
|
configGroupBox.Controls.Add(numericWeight);
|
||||||
|
configGroupBox.Controls.Add(numericSpeed);
|
||||||
|
configGroupBox.Controls.Add(weightLabel);
|
||||||
|
configGroupBox.Controls.Add(speedLabel);
|
||||||
|
configGroupBox.Location = new Point(12, 12);
|
||||||
|
configGroupBox.Name = "configGroupBox";
|
||||||
|
configGroupBox.Size = new Size(511, 279);
|
||||||
|
configGroupBox.TabIndex = 0;
|
||||||
|
configGroupBox.TabStop = false;
|
||||||
|
configGroupBox.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// colorGroupBox
|
||||||
|
//
|
||||||
|
colorGroupBox.Controls.Add(yellowPanel);
|
||||||
|
colorGroupBox.Controls.Add(bluePanel);
|
||||||
|
colorGroupBox.Controls.Add(greenPanel);
|
||||||
|
colorGroupBox.Controls.Add(purplePanel);
|
||||||
|
colorGroupBox.Controls.Add(blackPanel);
|
||||||
|
colorGroupBox.Controls.Add(greyPanel);
|
||||||
|
colorGroupBox.Controls.Add(whitePanel);
|
||||||
|
colorGroupBox.Controls.Add(redPanel);
|
||||||
|
colorGroupBox.Location = new Point(171, 23);
|
||||||
|
colorGroupBox.Name = "colorGroupBox";
|
||||||
|
colorGroupBox.Size = new Size(234, 143);
|
||||||
|
colorGroupBox.TabIndex = 7;
|
||||||
|
colorGroupBox.TabStop = false;
|
||||||
|
colorGroupBox.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// yellowPanel
|
||||||
|
//
|
||||||
|
yellowPanel.AllowDrop = true;
|
||||||
|
yellowPanel.BackColor = Color.Yellow;
|
||||||
|
yellowPanel.Location = new Point(174, 27);
|
||||||
|
yellowPanel.Name = "yellowPanel";
|
||||||
|
yellowPanel.Size = new Size(50, 50);
|
||||||
|
yellowPanel.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// bluePanel
|
||||||
|
//
|
||||||
|
bluePanel.AllowDrop = true;
|
||||||
|
bluePanel.BackColor = Color.Blue;
|
||||||
|
bluePanel.Location = new Point(118, 27);
|
||||||
|
bluePanel.Name = "bluePanel";
|
||||||
|
bluePanel.Size = new Size(50, 50);
|
||||||
|
bluePanel.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// greenPanel
|
||||||
|
//
|
||||||
|
greenPanel.AllowDrop = true;
|
||||||
|
greenPanel.BackColor = Color.Green;
|
||||||
|
greenPanel.Location = new Point(62, 27);
|
||||||
|
greenPanel.Name = "greenPanel";
|
||||||
|
greenPanel.Size = new Size(50, 50);
|
||||||
|
greenPanel.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// purplePanel
|
||||||
|
//
|
||||||
|
purplePanel.AllowDrop = true;
|
||||||
|
purplePanel.BackColor = Color.Purple;
|
||||||
|
purplePanel.Location = new Point(174, 82);
|
||||||
|
purplePanel.Name = "purplePanel";
|
||||||
|
purplePanel.Size = new Size(50, 50);
|
||||||
|
purplePanel.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// blackPanel
|
||||||
|
//
|
||||||
|
blackPanel.AllowDrop = true;
|
||||||
|
blackPanel.BackColor = Color.Black;
|
||||||
|
blackPanel.Location = new Point(118, 83);
|
||||||
|
blackPanel.Name = "blackPanel";
|
||||||
|
blackPanel.Size = new Size(50, 50);
|
||||||
|
blackPanel.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// greyPanel
|
||||||
|
//
|
||||||
|
greyPanel.AllowDrop = true;
|
||||||
|
greyPanel.BackColor = Color.Silver;
|
||||||
|
greyPanel.Location = new Point(62, 83);
|
||||||
|
greyPanel.Name = "greyPanel";
|
||||||
|
greyPanel.Size = new Size(50, 50);
|
||||||
|
greyPanel.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// whitePanel
|
||||||
|
//
|
||||||
|
whitePanel.AllowDrop = true;
|
||||||
|
whitePanel.BackColor = Color.White;
|
||||||
|
whitePanel.Location = new Point(6, 83);
|
||||||
|
whitePanel.Name = "whitePanel";
|
||||||
|
whitePanel.Size = new Size(50, 50);
|
||||||
|
whitePanel.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// redPanel
|
||||||
|
//
|
||||||
|
redPanel.AllowDrop = true;
|
||||||
|
redPanel.BackColor = Color.Red;
|
||||||
|
redPanel.Location = new Point(6, 27);
|
||||||
|
redPanel.Name = "redPanel";
|
||||||
|
redPanel.Size = new Size(50, 50);
|
||||||
|
redPanel.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// airplaneWithRadarLabel
|
||||||
|
//
|
||||||
|
airplaneWithRadarLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
airplaneWithRadarLabel.Location = new Point(297, 169);
|
||||||
|
airplaneWithRadarLabel.Name = "airplaneWithRadarLabel";
|
||||||
|
airplaneWithRadarLabel.Size = new Size(120, 50);
|
||||||
|
airplaneWithRadarLabel.TabIndex = 9;
|
||||||
|
airplaneWithRadarLabel.Text = "Продвинутый";
|
||||||
|
airplaneWithRadarLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
//
|
||||||
|
// airplaneLabel
|
||||||
|
//
|
||||||
|
airplaneLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
airplaneLabel.Location = new Point(171, 169);
|
||||||
|
airplaneLabel.Name = "airplaneLabel";
|
||||||
|
airplaneLabel.Size = new Size(120, 50);
|
||||||
|
airplaneLabel.TabIndex = 8;
|
||||||
|
airplaneLabel.Text = "Простой";
|
||||||
|
airplaneLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
//
|
||||||
|
// checkDopBak
|
||||||
|
//
|
||||||
|
checkDopBak.AutoSize = true;
|
||||||
|
checkDopBak.Location = new Point(6, 162);
|
||||||
|
checkDopBak.Name = "checkDopBak";
|
||||||
|
checkDopBak.Size = new Size(159, 24);
|
||||||
|
checkDopBak.TabIndex = 5;
|
||||||
|
checkDopBak.Text = "наличие доп. бака";
|
||||||
|
checkDopBak.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkRadar
|
||||||
|
//
|
||||||
|
checkRadar.AutoSize = true;
|
||||||
|
checkRadar.Location = new Point(6, 132);
|
||||||
|
checkRadar.Name = "checkRadar";
|
||||||
|
checkRadar.Size = new Size(144, 24);
|
||||||
|
checkRadar.TabIndex = 4;
|
||||||
|
checkRadar.Text = "наличие радара";
|
||||||
|
checkRadar.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericWeight
|
||||||
|
//
|
||||||
|
numericWeight.Location = new Point(6, 99);
|
||||||
|
numericWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||||
|
numericWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
numericWeight.Name = "numericWeight";
|
||||||
|
numericWeight.Size = new Size(150, 27);
|
||||||
|
numericWeight.TabIndex = 3;
|
||||||
|
numericWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// numericSpeed
|
||||||
|
//
|
||||||
|
numericSpeed.Location = new Point(6, 46);
|
||||||
|
numericSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||||
|
numericSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
numericSpeed.Name = "numericSpeed";
|
||||||
|
numericSpeed.Size = new Size(150, 27);
|
||||||
|
numericSpeed.TabIndex = 2;
|
||||||
|
numericSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// weightLabel
|
||||||
|
//
|
||||||
|
weightLabel.AutoSize = true;
|
||||||
|
weightLabel.Location = new Point(6, 76);
|
||||||
|
weightLabel.Name = "weightLabel";
|
||||||
|
weightLabel.Size = new Size(33, 20);
|
||||||
|
weightLabel.TabIndex = 1;
|
||||||
|
weightLabel.Text = "Вес";
|
||||||
|
//
|
||||||
|
// speedLabel
|
||||||
|
//
|
||||||
|
speedLabel.AutoSize = true;
|
||||||
|
speedLabel.Location = new Point(6, 23);
|
||||||
|
speedLabel.Name = "speedLabel";
|
||||||
|
speedLabel.Size = new Size(73, 20);
|
||||||
|
speedLabel.TabIndex = 0;
|
||||||
|
speedLabel.Text = "Скорость";
|
||||||
|
//
|
||||||
|
// allowPanel
|
||||||
|
//
|
||||||
|
allowPanel.AllowDrop = true;
|
||||||
|
allowPanel.Controls.Add(addColorLabel);
|
||||||
|
allowPanel.Controls.Add(pictureBox);
|
||||||
|
allowPanel.Controls.Add(colorLabel);
|
||||||
|
allowPanel.Location = new Point(538, 12);
|
||||||
|
allowPanel.Name = "allowPanel";
|
||||||
|
allowPanel.Size = new Size(250, 247);
|
||||||
|
allowPanel.TabIndex = 1;
|
||||||
|
allowPanel.DragDrop += allowPanel_DragDrop;
|
||||||
|
allowPanel.DragEnter += allowPanel_DragEnter;
|
||||||
|
//
|
||||||
|
// addColorLabel
|
||||||
|
//
|
||||||
|
addColorLabel.AllowDrop = true;
|
||||||
|
addColorLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
addColorLabel.Location = new Point(141, 10);
|
||||||
|
addColorLabel.Name = "addColorLabel";
|
||||||
|
addColorLabel.Size = new Size(104, 33);
|
||||||
|
addColorLabel.TabIndex = 2;
|
||||||
|
addColorLabel.Text = "Доп. цвет";
|
||||||
|
addColorLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
addColorLabel.DragDrop += addColorLabel_DragDrop;
|
||||||
|
addColorLabel.DragEnter += addColorLabel_DragEnter;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Location = new Point(17, 50);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(218, 190);
|
||||||
|
pictureBox.TabIndex = 0;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// colorLabel
|
||||||
|
//
|
||||||
|
colorLabel.AllowDrop = true;
|
||||||
|
colorLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
colorLabel.Location = new Point(17, 10);
|
||||||
|
colorLabel.Name = "colorLabel";
|
||||||
|
colorLabel.Size = new Size(104, 33);
|
||||||
|
colorLabel.TabIndex = 1;
|
||||||
|
colorLabel.Text = "Цвет";
|
||||||
|
colorLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
colorLabel.DragDrop += colorLabel_DragDrop;
|
||||||
|
colorLabel.DragEnter += colorLabel_DragEnter;
|
||||||
|
//
|
||||||
|
// addButton
|
||||||
|
//
|
||||||
|
addButton.Location = new Point(555, 262);
|
||||||
|
addButton.Name = "addButton";
|
||||||
|
addButton.Size = new Size(94, 29);
|
||||||
|
addButton.TabIndex = 2;
|
||||||
|
addButton.Text = "Добавить";
|
||||||
|
addButton.UseVisualStyleBackColor = true;
|
||||||
|
addButton.Click += addButton_Click;
|
||||||
|
//
|
||||||
|
// cancelButton
|
||||||
|
//
|
||||||
|
cancelButton.Location = new Point(679, 262);
|
||||||
|
cancelButton.Name = "cancelButton";
|
||||||
|
cancelButton.Size = new Size(94, 29);
|
||||||
|
cancelButton.TabIndex = 3;
|
||||||
|
cancelButton.Text = "Отменить";
|
||||||
|
cancelButton.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormAirplaneConfig
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 303);
|
||||||
|
Controls.Add(cancelButton);
|
||||||
|
Controls.Add(addButton);
|
||||||
|
Controls.Add(allowPanel);
|
||||||
|
Controls.Add(configGroupBox);
|
||||||
|
Name = "FormAirplaneConfig";
|
||||||
|
Text = "FormAirplaneConfig";
|
||||||
|
configGroupBox.ResumeLayout(false);
|
||||||
|
configGroupBox.PerformLayout();
|
||||||
|
colorGroupBox.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericWeight).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericSpeed).EndInit();
|
||||||
|
allowPanel.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox configGroupBox;
|
||||||
|
private CheckBox checkRadar;
|
||||||
|
private NumericUpDown numericWeight;
|
||||||
|
private NumericUpDown numericSpeed;
|
||||||
|
private Label weightLabel;
|
||||||
|
private Label speedLabel;
|
||||||
|
private CheckBox checkDopBak;
|
||||||
|
private GroupBox colorGroupBox;
|
||||||
|
private Panel panel5;
|
||||||
|
private Panel panel4;
|
||||||
|
private Panel panel3;
|
||||||
|
private Panel panel2;
|
||||||
|
private Panel redPanel;
|
||||||
|
private Panel purplePanel;
|
||||||
|
private Panel blackPanel;
|
||||||
|
private Panel greyPanel;
|
||||||
|
private Panel whitePanel;
|
||||||
|
private Label airplaneWithRadarLabel;
|
||||||
|
private Label airplaneLabel;
|
||||||
|
private Panel yellowPanel;
|
||||||
|
private Panel bluePanel;
|
||||||
|
private Panel greenPanel;
|
||||||
|
private Panel allowPanel;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Label addColorLabel;
|
||||||
|
private Label colorLabel;
|
||||||
|
private Button addButton;
|
||||||
|
private Button cancelButton;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
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 ProjectAirplaneWithRadar
|
||||||
|
{
|
||||||
|
public partial class FormAirplaneConfig : Form
|
||||||
|
{
|
||||||
|
DrawningAirplane? _airplane = null;
|
||||||
|
Action<DrawningAirplane>? EventAddAirplane;
|
||||||
|
private readonly int PictureWidth;
|
||||||
|
private readonly int PictureHeight;
|
||||||
|
public void AddEvent(Action<DrawningAirplane>? ev)
|
||||||
|
{
|
||||||
|
if (EventAddAirplane == null)
|
||||||
|
{
|
||||||
|
EventAddAirplane = ev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddAirplane += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public FormAirplaneConfig(int width, int height)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
blackPanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
greenPanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
redPanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
bluePanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
greyPanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
yellowPanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
purplePanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
whitePanel.MouseDown += PanelColor_MouseDown;
|
||||||
|
airplaneLabel.MouseDown += LabelObject_MouseDown;
|
||||||
|
airplaneWithRadarLabel.MouseDown += LabelObject_MouseDown;
|
||||||
|
cancelButton.Click += (s, e) => Close();
|
||||||
|
PictureWidth = width;
|
||||||
|
PictureHeight = height;
|
||||||
|
}
|
||||||
|
public void DrawAirplane()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_airplane?.SetPosition(5, 5);
|
||||||
|
_airplane?.DrawTransport(gr);
|
||||||
|
pictureBox.Image = bmp;
|
||||||
|
}
|
||||||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
private void allowPanel_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "airplaneLabel":
|
||||||
|
_airplane = new DrawningAirplane((int)numericSpeed.Value,
|
||||||
|
(int)numericWeight.Value, Color.Silver, PictureWidth, PictureHeight);
|
||||||
|
break;
|
||||||
|
case "airplaneWithRadarLabel":
|
||||||
|
_airplane = new DrawningAirplaneWithRadar((int)numericSpeed.Value,
|
||||||
|
(int)numericWeight.Value, Color.Silver, Color.Black, checkRadar.Checked, checkDopBak.Checked, PictureWidth, PictureHeight);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
colorLabel.BackColor = Color.Empty;
|
||||||
|
addColorLabel.BackColor = Color.Empty;
|
||||||
|
DrawAirplane();
|
||||||
|
}
|
||||||
|
private void allowPanel_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void addButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddAirplane?.Invoke(_airplane);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
private void colorLabel_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_airplane == null)
|
||||||
|
return;
|
||||||
|
colorLabel.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
_airplane.ChangeColor(colorLabel.BackColor);
|
||||||
|
DrawAirplane();
|
||||||
|
}
|
||||||
|
private void colorLabel_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void addColorLabel_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if ((_airplane == null) || (_airplane is DrawningAirplaneWithRadar == false))
|
||||||
|
return;
|
||||||
|
addColorLabel.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
((DrawningAirplaneWithRadar)_airplane).ChangeAddColor(addColorLabel.BackColor);
|
||||||
|
DrawAirplane();
|
||||||
|
}
|
||||||
|
private void addColorLabel_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -3,12 +3,12 @@
|
|||||||
partial class FormAirplaneWithRadar
|
partial class FormAirplaneWithRadar
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
@ -23,17 +23,21 @@
|
|||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxAirplaneWithRadar = new PictureBox();
|
pictureBoxAirplaneWithRadar = new PictureBox();
|
||||||
buttonCreate = new Button();
|
buttonCreateAirplaneWithRadar = new Button();
|
||||||
buttonDown = new Button();
|
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
|
buttonCreateAirplane = new Button();
|
||||||
|
comboBoxAirplane = new ComboBox();
|
||||||
|
buttonStep = new Button();
|
||||||
|
buttonSelectAirplane = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -42,47 +46,50 @@
|
|||||||
pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill;
|
pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill;
|
||||||
pictureBoxAirplaneWithRadar.Location = new Point(0, 0);
|
pictureBoxAirplaneWithRadar.Location = new Point(0, 0);
|
||||||
pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar";
|
pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar";
|
||||||
pictureBoxAirplaneWithRadar.Size = new Size(882, 453);
|
pictureBoxAirplaneWithRadar.Size = new Size(887, 454);
|
||||||
pictureBoxAirplaneWithRadar.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxAirplaneWithRadar.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBoxAirplaneWithRadar.TabIndex = 0;
|
pictureBoxAirplaneWithRadar.TabIndex = 0;
|
||||||
pictureBoxAirplaneWithRadar.TabStop = false;
|
pictureBoxAirplaneWithRadar.TabStop = false;
|
||||||
pictureBoxAirplaneWithRadar.Click += buttonMove_Click;
|
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreateAirplaneWithRadar
|
||||||
//
|
//
|
||||||
buttonCreate.Location = new Point(12, 412);
|
buttonCreateAirplaneWithRadar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreateAirplaneWithRadar.Location = new Point(12, 387);
|
||||||
buttonCreate.Size = new Size(94, 29);
|
buttonCreateAirplaneWithRadar.Name = "buttonCreateAirplaneWithRadar";
|
||||||
buttonCreate.TabIndex = 1;
|
buttonCreateAirplaneWithRadar.Size = new Size(195, 55);
|
||||||
buttonCreate.Text = "Create";
|
buttonCreateAirplaneWithRadar.TabIndex = 1;
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreateAirplaneWithRadar.Text = "Create Airplane With Radar";
|
||||||
buttonCreate.Click += buttonCreate_Click;
|
buttonCreateAirplaneWithRadar.UseVisualStyleBackColor = true;
|
||||||
//
|
buttonCreateAirplaneWithRadar.Click += buttonCreateAirplaneWithRadar_Click;
|
||||||
// buttonDown
|
|
||||||
//
|
|
||||||
buttonDown.Location = new Point(766, 396);
|
|
||||||
buttonDown.Name = "buttonDown";
|
|
||||||
buttonDown.Size = new Size(49, 45);
|
|
||||||
buttonDown.TabIndex = 2;
|
|
||||||
buttonDown.Text = "↓";
|
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
|
||||||
buttonDown.Click += buttonMove_Click;
|
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
buttonRight.Location = new Point(821, 396);
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.Location = new Point(825, 402);
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
buttonRight.Size = new Size(49, 45);
|
buttonRight.Size = new Size(50, 40);
|
||||||
buttonRight.TabIndex = 3;
|
buttonRight.TabIndex = 2;
|
||||||
buttonRight.Text = "→";
|
buttonRight.Text = "→";
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += buttonMove_Click;
|
buttonRight.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.Location = new Point(769, 402);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(50, 40);
|
||||||
|
buttonDown.TabIndex = 3;
|
||||||
|
buttonDown.Text = "↓";
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
buttonLeft.Location = new Point(711, 396);
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.Location = new Point(713, 402);
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
buttonLeft.Size = new Size(49, 45);
|
buttonLeft.Size = new Size(50, 40);
|
||||||
buttonLeft.TabIndex = 4;
|
buttonLeft.TabIndex = 4;
|
||||||
buttonLeft.Text = "←";
|
buttonLeft.Text = "←";
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
@ -90,24 +97,72 @@
|
|||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
buttonUp.Location = new Point(766, 345);
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.Location = new Point(769, 356);
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
buttonUp.Size = new Size(49, 45);
|
buttonUp.Size = new Size(50, 40);
|
||||||
buttonUp.TabIndex = 5;
|
buttonUp.TabIndex = 5;
|
||||||
buttonUp.Text = "↑";
|
buttonUp.Text = "↑";
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += buttonMove_Click;
|
buttonUp.Click += buttonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateAirplane
|
||||||
|
//
|
||||||
|
buttonCreateAirplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateAirplane.Location = new Point(213, 387);
|
||||||
|
buttonCreateAirplane.Name = "buttonCreateAirplane";
|
||||||
|
buttonCreateAirplane.Size = new Size(203, 55);
|
||||||
|
buttonCreateAirplane.TabIndex = 6;
|
||||||
|
buttonCreateAirplane.Text = "Create Airplane";
|
||||||
|
buttonCreateAirplane.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateAirplane.Click += buttonCreateAirplane_Click;
|
||||||
|
//
|
||||||
|
// comboBoxAirplane
|
||||||
|
//
|
||||||
|
comboBoxAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxAirplane.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxAirplane.FormattingEnabled = true;
|
||||||
|
comboBoxAirplane.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||||
|
comboBoxAirplane.Location = new Point(724, 12);
|
||||||
|
comboBoxAirplane.Name = "comboBoxAirplane";
|
||||||
|
comboBoxAirplane.Size = new Size(151, 28);
|
||||||
|
comboBoxAirplane.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
buttonStep.Location = new Point(724, 46);
|
||||||
|
buttonStep.Name = "buttonStep";
|
||||||
|
buttonStep.Size = new Size(151, 29);
|
||||||
|
buttonStep.TabIndex = 8;
|
||||||
|
buttonStep.Text = "Step";
|
||||||
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStep.Click += buttonStep_Click;
|
||||||
|
//
|
||||||
|
// buttonSelectAirplane
|
||||||
|
//
|
||||||
|
buttonSelectAirplane.Location = new Point(724, 81);
|
||||||
|
buttonSelectAirplane.Name = "buttonSelectAirplane";
|
||||||
|
buttonSelectAirplane.Size = new Size(151, 29);
|
||||||
|
buttonSelectAirplane.TabIndex = 9;
|
||||||
|
buttonSelectAirplane.Text = "Select Airplane";
|
||||||
|
buttonSelectAirplane.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectAirplane.Click += buttonSelectAirplane_Click;
|
||||||
|
//
|
||||||
// FormAirplaneWithRadar
|
// FormAirplaneWithRadar
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(882, 453);
|
ClientSize = new Size(887, 454);
|
||||||
|
Controls.Add(buttonSelectAirplane);
|
||||||
|
Controls.Add(buttonStep);
|
||||||
|
Controls.Add(comboBoxAirplane);
|
||||||
|
Controls.Add(buttonCreateAirplane);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonRight);
|
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonCreate);
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(buttonCreateAirplaneWithRadar);
|
||||||
Controls.Add(pictureBoxAirplaneWithRadar);
|
Controls.Add(pictureBoxAirplaneWithRadar);
|
||||||
Name = "FormAirplaneWithRadar";
|
Name = "FormAirplaneWithRadar";
|
||||||
Text = "FormAirplaneWithRadar";
|
Text = "FormAirplaneWithRadar";
|
||||||
@ -119,10 +174,14 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxAirplaneWithRadar;
|
private PictureBox pictureBoxAirplaneWithRadar;
|
||||||
private Button buttonCreate;
|
private Button buttonCreateAirplaneWithRadar;
|
||||||
private Button buttonDown;
|
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonDown;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private Button buttonCreateAirplane;
|
||||||
|
private ComboBox comboBoxAirplane;
|
||||||
|
private Button buttonStep;
|
||||||
|
private Button buttonSelectAirplane;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,53 +1,31 @@
|
|||||||
using System;
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
using System.Collections.Generic;
|
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ProjectAirplaneWithRadar
|
namespace ProjectAirplaneWithRadar
|
||||||
{
|
{
|
||||||
public partial class FormAirplaneWithRadar : Form
|
public partial class FormAirplaneWithRadar : Form
|
||||||
{
|
{
|
||||||
private DrawningAirplaneWithRadar? _drawningAirplaneWithRadar;
|
private DrawningAirplane _drawningAirplane;
|
||||||
|
private AbstractStrategy _abstractStrategy;
|
||||||
|
public DrawningAirplane? SelectedAirplane { get; private set; }
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningAirplaneWithRadar == null)
|
if (_drawningAirplane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new Bitmap(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
Bitmap bmp = new Bitmap(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningAirplaneWithRadar.DrawTransport(gr);
|
_drawningAirplane.DrawTransport(gr);
|
||||||
pictureBoxAirplaneWithRadar.Image = bmp;
|
pictureBoxAirplaneWithRadar.Image = bmp;
|
||||||
}
|
}
|
||||||
public FormAirplaneWithRadar()
|
public FormAirplaneWithRadar()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random random = new Random();
|
|
||||||
_drawningAirplaneWithRadar = new DrawningAirplaneWithRadar();
|
|
||||||
if (_drawningAirplaneWithRadar.Init
|
|
||||||
(random.Next(100, 300), // speed
|
|
||||||
random.Next(1000, 3000),// weight
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),// bodycolor
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), //additionalColor
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), // radar
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), //dopbak
|
|
||||||
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height))
|
|
||||||
{
|
|
||||||
_drawningAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningAirplaneWithRadar == null)
|
if (_drawningAirplane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -55,19 +33,98 @@ namespace ProjectAirplaneWithRadar
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Up);
|
_drawningAirplane.MoveTransport(Direction.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Down);
|
_drawningAirplane.MoveTransport(Direction.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Left);
|
_drawningAirplane.MoveTransport(Direction.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Right);
|
_drawningAirplane.MoveTransport(Direction.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
private void buttonCreateAirplaneWithRadar_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
bodyColor = dialog.Color;
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
additionalColor = dialog.Color;
|
||||||
|
|
||||||
|
_drawningAirplane = new DrawningAirplaneWithRadar(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
bodyColor, additionalColor, true, true,
|
||||||
|
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonCreateAirplane_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;
|
||||||
|
}
|
||||||
|
_drawningAirplane = new DrawningAirplane(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), color,
|
||||||
|
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||||
|
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningAirplane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxAirplane.Enabled)
|
||||||
|
{
|
||||||
|
switch (comboBoxAirplane.SelectedIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
_abstractStrategy = new MoveToCenter();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_abstractStrategy = new MoveToBorder();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new
|
||||||
|
DrawningObjectAirplane(_drawningAirplane), pictureBoxAirplaneWithRadar.Width,
|
||||||
|
pictureBoxAirplaneWithRadar.Height);
|
||||||
|
comboBoxAirplane.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxAirplane.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonSelectAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedAirplane = _drawningAirplane;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
267
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs
generated
Normal file
267
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs
generated
Normal file
@ -0,0 +1,267 @@
|
|||||||
|
namespace ProjectAirplaneWithRadar
|
||||||
|
{
|
||||||
|
partial class FormAirplanesCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBoxAirplanesCollection = new PictureBox();
|
||||||
|
groupBoxAirplaneWithRadar = new GroupBox();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
groupBoxCollection = new GroupBox();
|
||||||
|
buttonRemoveObject = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
buttonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
buttonUpdateCollection = new Button();
|
||||||
|
buttonDeleteAirplane = new Button();
|
||||||
|
buttonAddAirplane = new Button();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
menuStrip1 = new MenuStrip();
|
||||||
|
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirplanesCollection).BeginInit();
|
||||||
|
groupBoxAirplaneWithRadar.SuspendLayout();
|
||||||
|
groupBoxCollection.SuspendLayout();
|
||||||
|
menuStrip1.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxAirplanesCollection
|
||||||
|
//
|
||||||
|
pictureBoxAirplanesCollection.Location = new Point(0, 38);
|
||||||
|
pictureBoxAirplanesCollection.Name = "pictureBoxAirplanesCollection";
|
||||||
|
pictureBoxAirplanesCollection.Size = new Size(650, 454);
|
||||||
|
pictureBoxAirplanesCollection.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxAirplanesCollection.TabIndex = 0;
|
||||||
|
pictureBoxAirplanesCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// groupBoxAirplaneWithRadar
|
||||||
|
//
|
||||||
|
groupBoxAirplaneWithRadar.Controls.Add(buttonSortByColor);
|
||||||
|
groupBoxAirplaneWithRadar.Controls.Add(buttonSortByType);
|
||||||
|
groupBoxAirplaneWithRadar.Controls.Add(groupBoxCollection);
|
||||||
|
groupBoxAirplaneWithRadar.Controls.Add(buttonUpdateCollection);
|
||||||
|
groupBoxAirplaneWithRadar.Controls.Add(buttonDeleteAirplane);
|
||||||
|
groupBoxAirplaneWithRadar.Controls.Add(buttonAddAirplane);
|
||||||
|
groupBoxAirplaneWithRadar.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBoxAirplaneWithRadar.Dock = DockStyle.Right;
|
||||||
|
groupBoxAirplaneWithRadar.Location = new Point(650, 28);
|
||||||
|
groupBoxAirplaneWithRadar.Name = "groupBoxAirplaneWithRadar";
|
||||||
|
groupBoxAirplaneWithRadar.Size = new Size(251, 522);
|
||||||
|
groupBoxAirplaneWithRadar.TabIndex = 1;
|
||||||
|
groupBoxAirplaneWithRadar.TabStop = false;
|
||||||
|
groupBoxAirplaneWithRadar.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new Point(7, 487);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(238, 29);
|
||||||
|
buttonSortByColor.TabIndex = 6;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new Point(6, 453);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(238, 29);
|
||||||
|
buttonSortByType.TabIndex = 5;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
|
// groupBoxCollection
|
||||||
|
//
|
||||||
|
groupBoxCollection.Controls.Add(buttonRemoveObject);
|
||||||
|
groupBoxCollection.Controls.Add(listBoxStorages);
|
||||||
|
groupBoxCollection.Controls.Add(buttonAddObject);
|
||||||
|
groupBoxCollection.Controls.Add(textBoxStorageName);
|
||||||
|
groupBoxCollection.Location = new Point(7, 26);
|
||||||
|
groupBoxCollection.Name = "groupBoxCollection";
|
||||||
|
groupBoxCollection.Size = new Size(237, 271);
|
||||||
|
groupBoxCollection.TabIndex = 4;
|
||||||
|
groupBoxCollection.TabStop = false;
|
||||||
|
groupBoxCollection.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// buttonRemoveObject
|
||||||
|
//
|
||||||
|
buttonRemoveObject.Location = new Point(6, 225);
|
||||||
|
buttonRemoveObject.Name = "buttonRemoveObject";
|
||||||
|
buttonRemoveObject.Size = new Size(227, 32);
|
||||||
|
buttonRemoveObject.TabIndex = 3;
|
||||||
|
buttonRemoveObject.Text = "Удалить набор";
|
||||||
|
buttonRemoveObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveObject.Click += buttonRemoveObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 20;
|
||||||
|
listBoxStorages.Location = new Point(6, 95);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(227, 124);
|
||||||
|
listBoxStorages.TabIndex = 2;
|
||||||
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// buttonAddObject
|
||||||
|
//
|
||||||
|
buttonAddObject.Location = new Point(6, 59);
|
||||||
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
|
buttonAddObject.Size = new Size(226, 30);
|
||||||
|
buttonAddObject.TabIndex = 1;
|
||||||
|
buttonAddObject.Text = "Добавить набор";
|
||||||
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddObject.Click += buttonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(6, 26);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(225, 27);
|
||||||
|
textBoxStorageName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonUpdateCollection
|
||||||
|
//
|
||||||
|
buttonUpdateCollection.Location = new Point(6, 418);
|
||||||
|
buttonUpdateCollection.Name = "buttonUpdateCollection";
|
||||||
|
buttonUpdateCollection.Size = new Size(238, 29);
|
||||||
|
buttonUpdateCollection.TabIndex = 3;
|
||||||
|
buttonUpdateCollection.Text = "Обновить коллекцию";
|
||||||
|
buttonUpdateCollection.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdateCollection.Click += buttonUpdateCollection_Click;
|
||||||
|
//
|
||||||
|
// buttonDeleteAirplane
|
||||||
|
//
|
||||||
|
buttonDeleteAirplane.Location = new Point(7, 383);
|
||||||
|
buttonDeleteAirplane.Name = "buttonDeleteAirplane";
|
||||||
|
buttonDeleteAirplane.Size = new Size(238, 29);
|
||||||
|
buttonDeleteAirplane.TabIndex = 2;
|
||||||
|
buttonDeleteAirplane.Text = "Удалить самолет";
|
||||||
|
buttonDeleteAirplane.UseVisualStyleBackColor = true;
|
||||||
|
buttonDeleteAirplane.Click += buttonDeleteAirplane_Click;
|
||||||
|
//
|
||||||
|
// buttonAddAirplane
|
||||||
|
//
|
||||||
|
buttonAddAirplane.Location = new Point(6, 315);
|
||||||
|
buttonAddAirplane.Name = "buttonAddAirplane";
|
||||||
|
buttonAddAirplane.Size = new Size(238, 29);
|
||||||
|
buttonAddAirplane.TabIndex = 1;
|
||||||
|
buttonAddAirplane.Text = "Добавить самолет";
|
||||||
|
buttonAddAirplane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddAirplane.Click += buttonAddAirplane_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(64, 350);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||||
|
maskedTextBoxNumber.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// menuStrip1
|
||||||
|
//
|
||||||
|
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||||
|
menuStrip1.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||||
|
menuStrip1.Location = new Point(0, 0);
|
||||||
|
menuStrip1.Name = "menuStrip1";
|
||||||
|
menuStrip1.Size = new Size(901, 28);
|
||||||
|
menuStrip1.TabIndex = 2;
|
||||||
|
menuStrip1.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файлToolStripMenuItem
|
||||||
|
//
|
||||||
|
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||||
|
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
|
файлToolStripMenuItem.Size = new Size(59, 24);
|
||||||
|
файлToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
SaveToolStripMenuItem.Size = new Size(166, 26);
|
||||||
|
SaveToolStripMenuItem.Text = "Сохранить";
|
||||||
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click_1;
|
||||||
|
//
|
||||||
|
// LoadToolStripMenuItem
|
||||||
|
//
|
||||||
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
|
LoadToolStripMenuItem.Size = new Size(166, 26);
|
||||||
|
LoadToolStripMenuItem.Text = "Загрузить";
|
||||||
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.FileName = "openFileDialog1";
|
||||||
|
//
|
||||||
|
// FormAirplanesCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(901, 550);
|
||||||
|
Controls.Add(groupBoxAirplaneWithRadar);
|
||||||
|
Controls.Add(pictureBoxAirplanesCollection);
|
||||||
|
Controls.Add(menuStrip1);
|
||||||
|
Name = "FormAirplanesCollection";
|
||||||
|
Text = "FormAirplaneWithRadar";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirplanesCollection).EndInit();
|
||||||
|
groupBoxAirplaneWithRadar.ResumeLayout(false);
|
||||||
|
groupBoxAirplaneWithRadar.PerformLayout();
|
||||||
|
groupBoxCollection.ResumeLayout(false);
|
||||||
|
groupBoxCollection.PerformLayout();
|
||||||
|
menuStrip1.ResumeLayout(false);
|
||||||
|
menuStrip1.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxAirplanesCollection;
|
||||||
|
private GroupBox groupBoxAirplaneWithRadar;
|
||||||
|
private Button buttonDeleteAirplane;
|
||||||
|
private Button buttonAddAirplane;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private Button buttonUpdateCollection;
|
||||||
|
private GroupBox groupBoxCollection;
|
||||||
|
private Button buttonRemoveObject;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonAddObject;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private MenuStrip menuStrip1;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,222 @@
|
|||||||
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
|
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||||
|
using ProjectAirplaneWithRadar.Generics;
|
||||||
|
using ProjectAirplaneWithRadar.Exceptions;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Data;
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Serilog;
|
||||||
|
//using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar
|
||||||
|
{
|
||||||
|
public partial class FormAirplanesCollection : System.Windows.Forms.Form
|
||||||
|
{
|
||||||
|
private readonly AirplanesGenericStorage _storage;
|
||||||
|
public FormAirplanesCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new AirplanesGenericStorage(pictureBoxAirplanesCollection.Width, pictureBoxAirplanesCollection.Height);
|
||||||
|
|
||||||
|
}
|
||||||
|
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].Name);
|
||||||
|
}
|
||||||
|
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 buttonAddAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormAirplaneConfig form = new(pictureBoxAirplanesCollection.Width, pictureBoxAirplanesCollection.Height);
|
||||||
|
form.Show();
|
||||||
|
Action<DrawningAirplane>? airplaneDelegate = new((m) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool q = obj + m;
|
||||||
|
MessageBox.Show("Îáúåêò äîáàâëåí");
|
||||||
|
Log.Information($"Äîáàâëåí îáúåêò â êîëëåêöèþ {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||||
|
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
||||||
|
}
|
||||||
|
catch (StorageOverflowException ex)
|
||||||
|
{
|
||||||
|
Log.Warning($"Êîëëåêöèÿ {listBoxStorages.SelectedItem.ToString() ?? string.Empty} ïåðåïîëíåíà");
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
Log.Warning($"Äîáàâëÿåìûé îáúåêò óæå ñóùåñòâóåò â êîëëåêöèè {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||||
|
MessageBox.Show("Äîáàâëÿåìûé îáúåêò óæå ñóùåñâóåò â êîëëåêöèè");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
form.AddEvent(airplaneDelegate);
|
||||||
|
}
|
||||||
|
private void buttonDeleteAirplane_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;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
var q = obj - pos;
|
||||||
|
MessageBox.Show("Îáúåêò óäàëåí");
|
||||||
|
Log.Information($"Óäàëåí îáúåêò èç êîëëåêöèè {listBoxStorages.SelectedItem.ToString() ?? string.Empty} ïî íîìåðó {pos}");
|
||||||
|
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
||||||
|
}
|
||||||
|
catch (AirplaneNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Íå óäàëîñü óäàëèòü îáúåêò");
|
||||||
|
Log.Warning($"Íå ïîëó÷èëîñü óäàëèòü îáúåêò èç êîëëåêöèè {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
catch (FormatException ex)
|
||||||
|
{
|
||||||
|
Log.Warning($"Áûëî ââåäåíî íå ÷èñëî");
|
||||||
|
MessageBox.Show("Ââåäèòå ÷èñëî");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonUpdateCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
||||||
|
}
|
||||||
|
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Íå âñå äàííûå çàïîëíåíû", "Îøèáêà",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects(); Log.Information($"Äîáàâëåí íàáîð: {textBoxStorageName.Text}");
|
||||||
|
}
|
||||||
|
private void buttonRemoveObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Óäàëèòü îáúåêò {listBoxStorages.SelectedItem}?", "Óäàëåíèå", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||||
|
_storage.DelSet(name);
|
||||||
|
ReloadObjects();
|
||||||
|
Log.Information($"Óäàëåí íàáîð: {name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxAirplanesCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
|
||||||
|
}
|
||||||
|
private void SaveToolStripMenuItem_Click_1(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî",
|
||||||
|
"Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
Log.Information($"Ôàéë {saveFileDialog.FileName} óñïåøíî ñîõðàíåí");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning("Íå óäàëîñü ñîõðàíèòü");
|
||||||
|
MessageBox.Show($"Íå ñîõðàíèëîñü: {ex.Message}", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
|
MessageBox.Show("Çàãðóçêà ïðîøëà óñïåøíî",
|
||||||
|
"Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
Log.Information($"Ôàéë {openFileDialog.FileName} óñïåøíî çàãðóæåí");
|
||||||
|
foreach (var collection in _storage.Keys)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(collection);
|
||||||
|
}
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning("Íå óäàëîñü çàãðóçèòü");
|
||||||
|
MessageBox.Show($"Íå çàãðóçèëîñü: {ex.Message}", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e) => CompareAirplanes(new AirplaneCompareByType());
|
||||||
|
|
||||||
|
|
||||||
|
private void CompareAirplanes(IComparer<DrawningAirplane?> comparer)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
obj.Sort(comparer);
|
||||||
|
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e) => CompareAirplanes(new AirplaneCompareByColor());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>153, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>323, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
ObjectParameteres? GetObjectPosition { get; }
|
||||||
|
int GetStep { get; }
|
||||||
|
bool CheckCanMove(Direction direction);
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = FieldWidth - objParams.RightBorder;
|
||||||
|
if (diffX > GetStep())
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
var diffY = FieldHeight - objParams.DownBorder;
|
||||||
|
if (diffY > GetStep())
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameteres
|
||||||
|
{
|
||||||
|
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 ObjectParameteres(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,8 +1,18 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
|
using Serilog.Formatting.Json;
|
||||||
|
using Serilog.Configuration;
|
||||||
|
//using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
namespace ProjectAirplaneWithRadar
|
namespace ProjectAirplaneWithRadar
|
||||||
{
|
{
|
||||||
@ -14,9 +24,25 @@ namespace ProjectAirplaneWithRadar
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormAirplaneWithRadar());
|
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||||
|
string pathNeed = "";
|
||||||
|
for (int i = 0; i < path.Length - 3; i++)
|
||||||
|
{
|
||||||
|
pathNeed += path[i] + "\\";
|
||||||
|
}
|
||||||
|
var configuration = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile(path: $"{pathNeed}AppSettings.json", optional: false, reloadOnChange: true)
|
||||||
|
.Build();
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(configuration)
|
||||||
|
.CreateLogger();
|
||||||
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.Run(new FormAirplanesCollection());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,4 +8,21 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="AppSettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -0,0 +1,79 @@
|
|||||||
|
using ProjectAirplaneWithRadar.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.CodeDom;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Windows.Forms.VisualStyles;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.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 void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
|
public bool Insert(T airplane, IEqualityComparer<T>? equal = null)
|
||||||
|
{
|
||||||
|
if (_places.Count == _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
Insert(airplane, 0, equal);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Insert(T airplane, int position, IEqualityComparer<T>? equal = null)
|
||||||
|
{
|
||||||
|
if (_places.Count == _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
if (!(position >= 0 && position <= Count))
|
||||||
|
return false;
|
||||||
|
if (equal != null)
|
||||||
|
{
|
||||||
|
if (_places.Contains(airplane, equal))
|
||||||
|
throw new ArgumentException(nameof(airplane));
|
||||||
|
}
|
||||||
|
_places.Insert(position, airplane);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position < Count))
|
||||||
|
throw new AirplaneNotFoundException(position);
|
||||||
|
_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 && _places.Count < _maxCount))
|
||||||
|
return;
|
||||||
|
_places.Insert(position, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<T?> GetAirplanes(int? maxAirplanes = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxAirplanes.HasValue && i == maxAirplanes.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/Status.cs
Normal file
15
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/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 ProjectAirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
BIN
backup.zip
Normal file
BIN
backup.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user