Compare commits

..

10 Commits
main ... lab_8

Author SHA1 Message Date
b1be9c302d lab_8 2023-12-29 21:02:13 +04:00
ff8cbd3ea6 lab_8 2023-12-29 20:42:01 +04:00
faa1e41ee0 lab_8 2023-12-29 20:32:17 +04:00
c156ce7b1f lab_7 2023-12-29 19:55:03 +04:00
f33c17eade lab_6 2023-12-13 03:15:53 +04:00
34e4d490c0 lab_5 2023-12-13 03:10:36 +04:00
4de997dcb5 lab_4 2023-12-13 02:57:47 +04:00
ce8e5ace33 lab_3 2023-12-13 02:54:38 +04:00
e40ae5a4ee lab_2 2023-12-13 02:50:15 +04:00
80c26c1b12 lab_1 2023-12-10 22:46:36 +04:00
43 changed files with 3222 additions and 77 deletions

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirFighter.Drawnings;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace AirFighter.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(DirectionAirFighter.Left);
protected bool MoveRight() => MoveTo(DirectionAirFighter.Right);
protected bool MoveUp() => MoveTo(DirectionAirFighter.Up);
protected bool MoveDown() => MoveTo(DirectionAirFighter.Down);
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionAirFighter directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -8,4 +8,14 @@
<ImplicitUsings>enable</ImplicitUsings>
</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.7" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.Generics
{
internal class AirFighterCollectionInfo : IEquatable<AirFighterCollectionInfo>
{
public string Name { get; private set; }
public string Description { get; private set; }
public AirFighterCollectionInfo(string name, string description)
{
Name = name;
Description = description;
}
public bool Equals(AirFighterCollectionInfo? other)
{
return Name == other.Name;
}
public override int GetHashCode()
{
return this.Name.GetHashCode();
}
}
}

View File

@ -0,0 +1,57 @@
using AirFighter.DrawningObjects;
using AirFighter.Entities;
using AirFighter.Generics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class fighterCompareByColor : IComparer<DrawningAirFighter?>
{
public int Compare(DrawningAirFighter? x, DrawningAirFighter? y)
{
if (x == null || x.EntityAirFighter == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityAirFighter == null)
{
throw new ArgumentNullException(nameof(y));
}
var bodyColorCompare = x.EntityAirFighter.BodyColor.Name.CompareTo(y.EntityAirFighter.BodyColor.Name);
if (bodyColorCompare != 0)
{
return bodyColorCompare;
}
if (x.EntityAirFighter is EntityAirFighterMilitary xEntitySailCatamaran && y.EntityAirFighter is EntityAirFighterMilitary yEntitySailCatamaran)
{
var BodyColorCompare = xEntitySailCatamaran.BodyColor.Name.CompareTo(yEntitySailCatamaran.BodyColor.Name);
if (BodyColorCompare != 0)
{
return BodyColorCompare;
}
var AdditionalColorCompare = xEntitySailCatamaran.AdditionalColor.Name.CompareTo(yEntitySailCatamaran.AdditionalColor.Name);
if (AdditionalColorCompare != 0)
{
return AdditionalColorCompare;
}
}
var speedCompare = x.EntityAirFighter.Speed.CompareTo(y.EntityAirFighter.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityAirFighter.Weight.CompareTo(y.EntityAirFighter.Weight);
}
}
}

View File

@ -0,0 +1,32 @@
using AirFighter.DrawningObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class AirFighterCompareByType : IComparer<DrawningAirFighter?>
{
public int Compare(DrawningAirFighter? x, DrawningAirFighter? y)
{
if (x == null || x.EntityAirFighter == null)
throw new ArgumentNullException(nameof(x));
if (y == null || y.EntityAirFighter == null)
throw new ArgumentNullException(nameof(y));
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityAirFighter.Speed.CompareTo(y.EntityAirFighter.Speed);
if (speedCompare != 0)
return speedCompare;
return x.EntityAirFighter.Weight.CompareTo(y.EntityAirFighter.Weight);
}
}
}

View File

@ -0,0 +1,99 @@
using AirFighter.Drawnings;
using AirFighter.MovementStrategy;
using AirFighter.DrawningObjects;
using AirFighter.Generics;
using AirFighter.MovementStrategy;
namespace AirFighter.Generics
{
internal class AirFighterGenericCollection<T, U>
where T : DrawningAirFighter
where U : IMoveableObject
{
public IEnumerable<T?> GetAirFighter => _collection.GetAirFighter();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 180;
private readonly SetGeneric<T> _collection;
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
public AirFighterGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static bool operator +(AirFighterGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return false;
}
return collect?._collection.Insert(obj, new DrawningAirFighterEqutables()) ?? false;
}
public static T operator -(AirFighterGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect?._collection.Remove(pos);
}
return obj;
}
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowAirFighter()
{
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, 2);
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, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _collection.Count; i++)
foreach (var airfighter in _collection.GetAirFighter())
{
if (airfighter != null)
{
T? fighter = _collection[i];
if (fighter == null)
continue;
int row = height - 1 - (i / width);
int col = width - 1 - (i % width);
fighter.SetPosition(col * _placeSizeWidth + 10, row * _placeSizeHeight + 5);
fighter.DrawTransport(g);
}
}
}
}
}

View File

@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirFighter.DrawningObjects;
using AirFighter.MovementStrategy;
using AirFighter.Generics;
using System.IO;
using AirFighter.Exceptions;
namespace AirFighter.Generics
{
internal class AirFighterGenericStorage
{
readonly Dictionary<AirFighterCollectionInfo, AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>> _fighterStorages;
public List<AirFighterCollectionInfo> Keys => _fighterStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public AirFighterGenericStorage(int pictureWidth, int pictureHeight)
{
_fighterStorages = new Dictionary<AirFighterCollectionInfo, AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
// TODO Прописать логику для добавления
if (!_fighterStorages.ContainsKey(new AirFighterCollectionInfo(name, string.Empty)))
{
var fighterCollection = new AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>(_pictureWidth, _pictureHeight);
_fighterStorages.Add(new AirFighterCollectionInfo(name, string.Empty), fighterCollection);
}
}
public void DelSet(string name)
{
// TODO Прописать логику для удаления
if (_fighterStorages.ContainsKey(new AirFighterCollectionInfo(name, string.Empty)))
{
_fighterStorages.Remove(new AirFighterCollectionInfo(name, string.Empty));
}
}
public AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>?
this[string ind]
{
get
{
AirFighterCollectionInfo indObj = new AirFighterCollectionInfo(ind, string.Empty);
// TODO Продумать логику получения набора
if (_fighterStorages.ContainsKey(indObj))
{
return _fighterStorages[indObj];
}
return null;
}
}
private static readonly char _separatorForKeyValue = '|';
private readonly char _separatorRecords = ';';
private static readonly char _separatorForObject = ':';
public void SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<AirFighterCollectionInfo, AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>> record in _fighterStorages)
{
StringBuilder records = new();
foreach (DrawningAirFighter? elem in record.Value.GetAirFighter)
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
}
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
throw new Exception("Невалидная операция, нет данных для сохранения");
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write($"shipStorage{Environment.NewLine}{data}");
}
}
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
throw new Exception("Файл не найден");
}
using (StreamReader reader = new StreamReader(filename))
{
string cheker = reader.ReadLine();
if (cheker == null)
{
throw new Exception("Нет данных для загрузки");
}
if (!cheker.StartsWith("fighterStorage"))
{
throw new Exception("Неверный формат ввода");
}
_fighterStorages.Clear();
string strs;
bool firstinit = true;
while ((strs = reader.ReadLine()) != null)
{
if (strs == null && firstinit)
{
throw new Exception("Нет данных для загрузки");
}
if (strs == null)
{
break;
}
firstinit = false;
string name = strs.Split(_separatorForKeyValue)[0];
AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter> collection = new(_pictureWidth, _pictureHeight);
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
{
DrawningAirFighter? fighter =
data?.CreateDrawningAirFighter(_separatorForObject, _pictureWidth, _pictureHeight);
if (fighter != null)
{
try { _ = collection + fighter; }
catch (AirFighterNotFoundException e)
{
throw e;
}
catch (StorageOverflowException e)
{
throw e;
}
}
}
_fighterStorages.Add(new AirFighterCollectionInfo(name, string.Empty), collection);
}
}
}
}
}

View File

@ -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 AirFighter
{
[Serializable] internal class AirFighterNotFoundException : ApplicationException
{
public AirFighterNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
public AirFighterNotFoundException() : base() { }
public AirFighterNotFoundException(string message) : base(message) { }
public AirFighterNotFoundException(string message, Exception exception) : base(message, exception) { }
protected AirFighterNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.Drawnings
{
public enum DirectionAirFighter
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using AirFighter.Entities;
using AirFighter.Drawnings;
using System.Drawing.Drawing2D;
using AirFighter.MovementStrategy;
namespace AirFighter.DrawningObjects
{
public class DrawningAirFighter
{
public EntityAirFighter? EntityAirFighter { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _fighterWidth = 195;
protected readonly int _fighterHeight = 166;
public DrawningAirFighter(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _fighterWidth || height < _fighterHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityAirFighter = new EntityAirFighter(speed, weight, bodyColor);
}
protected DrawningAirFighter(int speed, double weight, Color bodyColor, int
width, int height, int fighterWidth, int fighterHeight)
{
if (width <= _pictureWidth || height <= _pictureHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_fighterWidth = fighterWidth;
_fighterHeight = fighterHeight;
EntityAirFighter = new EntityAirFighter(speed, weight, bodyColor);
}
public void SetPosition(int x, int y)
{
if ((x > 0) && (x < _pictureWidth))
_startPosX = x;
else _startPosX = 0;
if ((y > 0) && (y < _pictureHeight))
_startPosY = y;
else _startPosY = 0;
_startPosX = x;
_startPosY = y;
}
public IMoveableObject GetMoveableObject => new DrawningObjectAirFighter(this);
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _fighterWidth;
public int GetHeight => _fighterHeight;
public bool CanMove(DirectionAirFighter direction)
{
if (EntityAirFighter == null)
{
return false;
}
return direction switch
{
DirectionAirFighter.Left => _startPosX - EntityAirFighter.Step > 0,
DirectionAirFighter.Up => _startPosY - EntityAirFighter.Step > 7,
DirectionAirFighter.Right => _startPosX + EntityAirFighter.Step + _fighterWidth < _pictureWidth,// TODO: Продумать логику
DirectionAirFighter.Down => _startPosY + EntityAirFighter.Step + _fighterHeight < _pictureHeight,// TODO: Продумать логику
_ => false,
};
}
public void MoveTransport(DirectionAirFighter direction)
{
if (!CanMove(direction) || EntityAirFighter == null)
{
return;
}
switch (direction)
{
case DirectionAirFighter.Left:
_startPosX -= (int)EntityAirFighter.Step;
break;
case DirectionAirFighter.Up:
_startPosY -= (int)EntityAirFighter.Step;
break;
case DirectionAirFighter.Right:
_startPosX += (int)EntityAirFighter.Step;
break;
case DirectionAirFighter.Down:
_startPosY += (int)EntityAirFighter.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (EntityAirFighter == null)
{
return;
}
Pen pen = new(EntityAirFighter.BodyColor, 2);
Brush brushBlack = new SolidBrush(EntityAirFighter.BodyColor);
PointF[] front = {
new(_startPosX + 160, _startPosY + 69),
new(_startPosX + 195, _startPosY + 83),
new(_startPosX + 160, _startPosY + 97)
};
PointF[] tailTop = {
new(_startPosX, _startPosY + 30),
new(_startPosX, _startPosY + 70),
new(_startPosX + 25, _startPosY + 70),
new(_startPosX + 25, _startPosY + 55)
};
PointF[] tailBottom = {
new(_startPosX, _startPosY + 96),
new(_startPosX, _startPosY + 136),
new(_startPosX + 25, _startPosY + 111),
new(_startPosX + 25, _startPosY + 96)
};
PointF[] wingTop =
{
new(_startPosX + 100, _startPosY),
new(_startPosX + 100, _startPosY + 70),
new(_startPosX + 75, _startPosY + 70),
new(_startPosX + 90, _startPosY),
};
PointF[] wingBottom =
{
new(_startPosX + 100, _startPosY + 96),
new(_startPosX + 100, _startPosY + 166),
new(_startPosX + 90, _startPosY + 166),
new(_startPosX + 75, _startPosY + 96),
};
g.DrawPolygon(pen, tailTop);
g.DrawPolygon(pen, tailBottom);
g.DrawPolygon(pen, wingTop);
g.DrawPolygon(pen, wingBottom);
g.DrawRectangle(pen, _startPosX, _startPosY + 70, 160, 26);
g.FillPolygon(brushBlack, front);
}
}
}

View File

@ -0,0 +1,59 @@
using AirFighter.DrawningObjects;
using AirFighter.Entities;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class DrawningAirFighterEqutables : IEqualityComparer<DrawningAirFighter?>
{
public bool Equals(DrawningAirFighter? x, DrawningAirFighter? y)
{
if (x == null || x.EntityAirFighter == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityAirFighter == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityAirFighter.Speed != y.EntityAirFighter.Speed)
{
return false;
}
if (x.EntityAirFighter.Weight != y.EntityAirFighter.Weight)
{
return false;
}
if (x.EntityAirFighter.BodyColor != y.EntityAirFighter.BodyColor)
{
return false;
}
if (x is EntityAirFighterMilitary && y is EntityAirFighterMilitary)
{
EntityAirFighterMilitary EntityX = (EntityAirFighterMilitary)x.EntityAirFighter;
EntityAirFighterMilitary EntityY = (EntityAirFighterMilitary)y.EntityAirFighter;
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
return false;
if (EntityX.Wing != EntityY.Wing)
return false;
if (EntityX.Rocket != EntityY.Rocket)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawningAirFighter obj)
{
return obj.GetHashCode();
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirFighter.Drawnings;
using AirFighter.Entities;
namespace AirFighter.DrawningObjects
{
public class DrawningAirFighterMilitary : DrawningAirFighter
{
public DrawningAirFighterMilitary(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool wing, int width, int height) :
base(speed, weight, bodyColor, width, height, 195, 166)
{
if (EntityAirFighter != null)
{
EntityAirFighter = new EntityAirFighterMilitary(speed, weight, bodyColor,
additionalColor, rocket, wing);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityAirFighter is not EntityAirFighterMilitary fighterMilitary)
{
return;
}
Brush additionalBrush = new SolidBrush(fighterMilitary.AdditionalColor);
if (fighterMilitary.Wing)
{
PointF[] topDopWing =
{
new(_startPosX + 78, _startPosY + 56),
new(_startPosX + 75, _startPosY + 70),
new(_startPosX + 55, _startPosY + 50),
new(_startPosX + 60, _startPosY + 45),
};
PointF[] bottomDopWing =
{
new(_startPosX + 78, _startPosY + 110),
new(_startPosX + 75, _startPosY + 96),
new(_startPosX + 55, _startPosY + 116),
new(_startPosX + 60, _startPosY + 121),
};
g.FillPolygon(additionalBrush, topDopWing);
g.FillPolygon(additionalBrush, bottomDopWing);
}
base.DrawTransport(g);
if (fighterMilitary.Rocket)
{
PointF[] topRocket1 =
{
new(_startPosX + 100, _startPosY + 20),
new(_startPosX + 100, _startPosY + 30),
new(_startPosX + 112, _startPosY + 30),
new(_startPosX + 120, _startPosY + 25),
new(_startPosX + 112, _startPosY + 20)
};
PointF[] topRocket2 =
{
new(_startPosX + 100, _startPosY + 35),
new(_startPosX + 100, _startPosY + 45),
new(_startPosX + 112, _startPosY + 45),
new(_startPosX + 120, _startPosY + 40),
new(_startPosX + 112, _startPosY + 35)
};
PointF[] bottomRocket1 =
{
new(_startPosX + 100, _startPosY + 146),
new(_startPosX + 100, _startPosY + 136),
new(_startPosX + 112, _startPosY + 136),
new(_startPosX + 120, _startPosY + 141),
new(_startPosX + 112, _startPosY + 146)
};
PointF[] bottomRocket2 =
{
new(_startPosX + 100, _startPosY + 131),
new(_startPosX + 100, _startPosY + 121),
new(_startPosX + 112, _startPosY + 121),
new(_startPosX + 120, _startPosY + 126),
new(_startPosX + 112, _startPosY + 131)
};
g.FillPolygon(additionalBrush, topRocket1);
g.FillPolygon(additionalBrush, topRocket2);
g.FillPolygon(additionalBrush, bottomRocket1);
g.FillPolygon(additionalBrush, bottomRocket2);
}
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.Entities
{
public class EntityAirFighter
{
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 EntityAirFighter(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.Entities
{
public class EntityAirFighterMilitary : EntityAirFighter
{
public Color AdditionalColor { get; set; }
public bool Rocket { get; private set; }
public bool Wing { get; private set; }
public EntityAirFighterMilitary(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool wing)
: base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Rocket = rocket;
Wing = wing;
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirFighter.Entities;
namespace AirFighter.DrawningObjects
{
public static class ExtentionDrawningAirFighter
{
public static DrawningAirFighter? CreateDrawningAirFighter(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawningAirFighter(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
else if (strs.Length == 6)
{
return new DrawningAirFighterMilitary(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 DrawningAirFighter drawningAirFighter,
char separatorForObject)
{
var fighter = drawningAirFighter.EntityAirFighter;
if (fighter == null)
{
return string.Empty;
}
var str =
$"{fighter.Speed}{separatorForObject}{fighter.Weight}{separatorForObject}{fighter.BodyColor.Name}";
if (fighter is not EntityAirFighterMilitary fighterMilitary)
{
return str;
}
return
$"{str}{separatorForObject}{fighterMilitary.AdditionalColor.Name}{separatorForObject}{fighterMilitary.Wing}{separatorForObject}{fighterMilitary.Rocket}";
}
}
}

View File

@ -1,39 +0,0 @@
namespace AirFighter
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace AirFighter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,193 @@
namespace AirFighter
{
partial class FormAirFighter
{
/// <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()
{
pictureBoxAirFighter = new PictureBox();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonCreate = new Button();
ButtonStep = new Button();
comboBoxStrategy = new ComboBox();
ButtonCreateFighter = new Button();
buttonSelectFighter = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit();
SuspendLayout();
//
// pictureBoxAirFighter
//
pictureBoxAirFighter.Dock = DockStyle.Fill;
pictureBoxAirFighter.Location = new Point(0, 0);
pictureBoxAirFighter.Name = "pictureBoxAirFighter";
pictureBoxAirFighter.Size = new Size(800, 450);
pictureBoxAirFighter.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxAirFighter.TabIndex = 0;
pictureBoxAirFighter.TabStop = false;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.__png_3;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(686, 370);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 1;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.__png_2;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(722, 407);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 2;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.__png_1;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(758, 370);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.__png_4;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(722, 370);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
//
// buttonCreate
//
buttonCreate.BackColor = SystemColors.Control;
buttonCreate.Font = new Font("Times New Roman", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonCreate.Location = new Point(12, 390);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(164, 48);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать истребитель с ракетами\r\n\r\n";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreateAirFighterMilitary_Click;
//
// ButtonStep
//
ButtonStep.BackColor = Color.Azure;
ButtonStep.Font = new Font("Times New Roman", 9.75F, FontStyle.Bold, GraphicsUnit.Point);
ButtonStep.Location = new Point(713, 57);
ButtonStep.Name = "ButtonStep";
ButtonStep.Size = new Size(75, 23);
ButtonStep.TabIndex = 3;
ButtonStep.Text = "Шаг";
ButtonStep.UseVisualStyleBackColor = true;
ButtonStep.Click += ButtonStep_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder", "-" });
comboBoxStrategy.Location = new Point(667, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.TabIndex = 6;
//
// ButtonCreateFighter
//
ButtonCreateFighter.Font = new Font("Times New Roman", 12F, FontStyle.Regular, GraphicsUnit.Point);
ButtonCreateFighter.Location = new Point(182, 390);
ButtonCreateFighter.Name = "ButtonCreateFighter";
ButtonCreateFighter.Size = new Size(164, 47);
ButtonCreateFighter.TabIndex = 2;
ButtonCreateFighter.Text = "Создаать истребитель";
ButtonCreateFighter.UseVisualStyleBackColor = true;
ButtonCreateFighter.Click += ButtonCreateFighter_Click;
//
// buttonSelectFighter
//
buttonSelectFighter.Font = new Font("Times New Roman", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSelectFighter.Location = new Point(352, 390);
buttonSelectFighter.Name = "buttonSelectFighter";
buttonSelectFighter.Size = new Size(164, 47);
buttonSelectFighter.TabIndex = 7;
buttonSelectFighter.Text = "Выбор";
buttonSelectFighter.UseVisualStyleBackColor = true;
buttonSelectFighter.Click += ButtonSelectAirFighter_Click;
//
// FormAirFighter
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonSelectFighter);
Controls.Add(ButtonCreateFighter);
Controls.Add(comboBoxStrategy);
Controls.Add(ButtonStep);
Controls.Add(buttonCreate);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(pictureBoxAirFighter);
Name = "FormAirFighter";
Text = "AirFighter";
((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox pictureBoxAirFighter;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreate;
private Button ButtonStep;
private ComboBox comboBoxStrategy;
private Button ButtonCreateFighter;
private Button buttonSelectFighter;
}
}

View File

@ -0,0 +1,148 @@
using AirFighter.DrawningObjects;
using AirFighter.Drawnings;
using AirFighter.MovementStrategy;
namespace AirFighter
{
public partial class FormAirFighter : Form
{
private DrawningAirFighter? _drawningAirFighter;
private AbstractStrategy? _abstractStrategy;
public DrawningAirFighter? SelectedAirFighter { get; private set; }
public FormAirFighter()
{
InitializeComponent();
_abstractStrategy = null;
SelectedAirFighter = null;
}
private void Draw()
{
if (_drawningAirFighter == null)
{
return;
}
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningAirFighter.DrawTransport(gr);
pictureBoxAirFighter.Image = bmp;
}
private void buttonCreateAirFighterMilitary_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO âûáîð îñíîâíîãî öâåòà
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO âûáîð äîïîëíèòåëüíîãî öâåòà
ColorDialog dialog_dop = new();
if (dialog_dop.ShowDialog() == DialogResult.OK)
{
dopColor = dialog_dop.Color;
}
_drawningAirFighter = new DrawningAirFighterMilitary(random.Next(100, 300),
random.Next(1000, 3000),
color,
dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void ButtonCreateFighter_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;
}
_drawningAirFighter = new DrawningAirFighter(random.Next(100, 300),
random.Next(1000, 3000),
color,
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningAirFighter == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningAirFighter.MoveTransport(DirectionAirFighter.Up);
break;
case "buttonDown":
_drawningAirFighter.MoveTransport(DirectionAirFighter.Down);
break;
case "buttonLeft":
_drawningAirFighter.MoveTransport(DirectionAirFighter.Left);
break;
case "buttonRight":
_drawningAirFighter.MoveTransport(DirectionAirFighter.Right);
break;
}
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningAirFighter == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectAirFighter(_drawningAirFighter), pictureBoxAirFighter.Width,
pictureBoxAirFighter.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy != null)
{
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
private void ButtonSelectAirFighter_Click(object sender, EventArgs e)
{
SelectedAirFighter = _drawningAirFighter;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -1,24 +1,24 @@
<?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
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="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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,274 @@
namespace AirFighter
{
partial class FormAirFighterCollection
{
/// <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()
{
groupBox1 = new GroupBox();
ButtonSortByType = new Button();
ButtonSortByColor = new Button();
groupBox2 = new GroupBox();
buttonDelObject = new Button();
listBoxStorage = new ListBox();
buttonAddObject = new Button();
textBoxStorageName = new TextBox();
maskedTextBoxNumber = new MaskedTextBox();
buttonRemoveFighter = new Button();
buttonRefreshCollection = new Button();
buttonAddFighter = new Button();
pictureBoxCollection = new PictureBox();
menuStrip1 = new MenuStrip();
fileToolStripMenuItem = new ToolStripMenuItem();
SaveToolStripMenuItem = new ToolStripMenuItem();
LoadToolStripMenuItem = new ToolStripMenuItem();
openFileDialog1 = new OpenFileDialog();
saveFileDialog1 = new SaveFileDialog();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(ButtonSortByType);
groupBox1.Controls.Add(ButtonSortByColor);
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(maskedTextBoxNumber);
groupBox1.Controls.Add(buttonRemoveFighter);
groupBox1.Controls.Add(buttonRefreshCollection);
groupBox1.Controls.Add(buttonAddFighter);
groupBox1.Location = new Point(740, 0);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(213, 448);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
// ButtonSortByType
//
ButtonSortByType.Location = new Point(17, 251);
ButtonSortByType.Name = "ButtonSortByType";
ButtonSortByType.Size = new Size(166, 23);
ButtonSortByType.TabIndex = 3;
ButtonSortByType.Text = "Сортировка по типу";
ButtonSortByType.UseVisualStyleBackColor = true;
ButtonSortByType.Click += ButtonSortByType_Click;
//
// ButtonSortByColor
//
ButtonSortByColor.Location = new Point(17, 280);
ButtonSortByColor.Name = "ButtonSortByColor";
ButtonSortByColor.Size = new Size(166, 23);
ButtonSortByColor.TabIndex = 4;
ButtonSortByColor.Text = "Сортировка по цвету";
ButtonSortByColor.UseVisualStyleBackColor = true;
ButtonSortByColor.Click += ButtonSortByColor_Click;
//
// groupBox2
//
groupBox2.Controls.Add(buttonDelObject);
groupBox2.Controls.Add(listBoxStorage);
groupBox2.Controls.Add(buttonAddObject);
groupBox2.Controls.Add(textBoxStorageName);
groupBox2.Location = new Point(3, 19);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(200, 226);
groupBox2.TabIndex = 6;
groupBox2.TabStop = false;
groupBox2.Text = "Наборы";
//
// buttonDelObject
//
buttonDelObject.Location = new Point(18, 188);
buttonDelObject.Name = "buttonDelObject";
buttonDelObject.Size = new Size(159, 34);
buttonDelObject.TabIndex = 2;
buttonDelObject.Text = "Удалить набор";
buttonDelObject.UseVisualStyleBackColor = true;
buttonDelObject.Click += ButtonDelObject_Click;
//
// listBoxStorage
//
listBoxStorage.FormattingEnabled = true;
listBoxStorage.ItemHeight = 15;
listBoxStorage.Location = new Point(15, 88);
listBoxStorage.Name = "listBoxStorage";
listBoxStorage.Size = new Size(162, 94);
listBoxStorage.TabIndex = 2;
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
//
// buttonAddObject
//
buttonAddObject.Location = new Point(18, 48);
buttonAddObject.Name = "buttonAddObject";
buttonAddObject.Size = new Size(159, 34);
buttonAddObject.TabIndex = 1;
buttonAddObject.Text = "Добавить набор";
buttonAddObject.UseVisualStyleBackColor = true;
buttonAddObject.Click += ButtonAddObject_Click;
//
// textBoxStorageName
//
textBoxStorageName.Location = new Point(3, 19);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(191, 23);
textBoxStorageName.TabIndex = 0;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
maskedTextBoxNumber.Location = new Point(39, 346);
maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(100, 22);
maskedTextBoxNumber.TabIndex = 5;
//
// buttonRemoveFighter
//
buttonRemoveFighter.Location = new Point(17, 374);
buttonRemoveFighter.Name = "buttonRemoveFighter";
buttonRemoveFighter.Size = new Size(166, 31);
buttonRemoveFighter.TabIndex = 3;
buttonRemoveFighter.Text = "Удалить истребитель";
buttonRemoveFighter.UseVisualStyleBackColor = true;
buttonRemoveFighter.Click += ButtonRemoveAirFighter_Click;
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(17, 411);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(166, 31);
buttonRefreshCollection.TabIndex = 4;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// buttonAddFighter
//
buttonAddFighter.Location = new Point(17, 309);
buttonAddFighter.Name = "buttonAddFighter";
buttonAddFighter.Size = new Size(166, 31);
buttonAddFighter.TabIndex = 2;
buttonAddFighter.Text = "Добавить истребитель ";
buttonAddFighter.UseVisualStyleBackColor = true;
buttonAddFighter.Click += ButtonAddAirFighter_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 27);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(734, 421);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
pictureBoxCollection.Click += ButtonAddAirFighter_Click;
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(953, 24);
menuStrip1.TabIndex = 2;
menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
fileToolStripMenuItem.Size = new Size(48, 20);
fileToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
SaveToolStripMenuItem.Size = new Size(133, 22);
SaveToolStripMenuItem.Text = "Сохранить";
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
// LoadToolStripMenuItem
//
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
LoadToolStripMenuItem.Size = new Size(133, 22);
LoadToolStripMenuItem.Text = "Загрузить";
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// openFileDialog1
//
openFileDialog1.FileName = "openFileDialog1";
openFileDialog1.Filter = "txt file | *.txt";
//
// saveFileDialog1
//
saveFileDialog1.Filter = "txt file | *.txt";
//
// FormAirFighterCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(953, 448);
Controls.Add(pictureBoxCollection);
Controls.Add(groupBox1);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "FormAirFighterCollection";
Text = "Набор истребителя";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private GroupBox groupBox1;
private PictureBox pictureBoxCollection;
private Button buttonRemoveFighter;
private Button buttonRefreshCollection;
private Button buttonAddFighter;
private MaskedTextBox maskedTextBoxNumber;
private GroupBox groupBox2;
private TextBox textBoxStorageName;
private Button buttonDelObject;
private ListBox listBoxStorage;
private Button buttonAddObject;
private MenuStrip menuStrip1;
private ToolStripMenuItem fileToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog1;
private SaveFileDialog saveFileDialog1;
private Button ButtonSortByType;
private Button ButtonSortByColor;
}
}

View File

@ -0,0 +1,260 @@

using AirFighter.DrawningObjects;
using AirFighter.Drawnings;
using AirFighter.Generics;
using AirFighter.MovementStrategy;
using Microsoft.Extensions.Logging;
namespace AirFighter
{
/// <summary>
/// Форма для работы с набором объектов класса DrawningAirFighter
/// </summary>
public partial class FormAirFighterCollection : Form
{
/// <summary>
/// Набор объектов
/// </summary>
private readonly AirFighterGenericStorage _storage;
private readonly ILogger _logger;
/// <summary>
/// Конструктор
/// </summary>
public FormAirFighterCollection(ILogger<FormAirFighterCollection> logger)
{
InitializeComponent();
_storage = new AirFighterGenericStorage(pictureBoxCollection.Width,
pictureBoxCollection.Height);
_logger = logger;
}
/// <summary>
/// Заполнение listBoxObjects
/// </summary>
private void ReloadObjects()
{
int index = listBoxStorage.SelectedIndex;
listBoxStorage.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorage.Items.Add(_storage.Keys[i].Name);
}
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
>= listBoxStorage.Items.Count))
{
listBoxStorage.SelectedIndex = 0;
}
else if (listBoxStorage.Items.Count > 0 && index > -1 &&
index < listBoxStorage.Items.Count)
{
listBoxStorage.SelectedIndex = index;
}
}
/// <summary>
/// Добавление набора в коллекцию
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("Пустое название набора");
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
_logger.LogInformation($"Добавлен набор:{textBoxStorageName.Text}");
}
/// <summary>
/// Выбор набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void listBoxStorage_SelectedIndexChanged(object sender,
EventArgs e)
{
pictureBoxCollection.Image =
_storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowAirFighter();
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
_logger.LogWarning("Удаление невыбранного набора");
return;
}
string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
_logger.LogInformation($"Удален набор: {name}");
}
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddAirFighter_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var formAirFighterConfig = new FormAirFighterConfig();
formAirFighterConfig.AddEvent(fighter =>
{
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
_logger.LogWarning("Добавление пустого объекта");
return;
}
try
{
_ = obj + fighter;
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowAirFighter();
_logger.LogInformation($"Добавлен объект в набор {listBoxStorage.SelectedItem.ToString()}");
}
catch (Exception ex)
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorage.SelectedItem.ToString()}");
}
});
formAirFighterConfig.Show();
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveAirFighter_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
_logger.LogWarning("Удаление объекта из несуществующего набора");
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowAirFighter();
_logger.LogInformation($"Удален объект из набора {listBoxStorage.SelectedItem.ToString()}");
}
else
{
MessageBox.Show("Не удалось удалить объект"); _logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefreshCollection_Click(object sender, EventArgs
e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowAirFighter();
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
_storage.SaveData(saveFileDialog1.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Сохранение наборов в файл {saveFileDialog1.FileName}");
}
catch (Exception ex)
{
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
_storage.LoadData(openFileDialog1.FileName);
ReloadObjects();
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Загрузились наборы из файла {openFileDialog1.FileName}");
}
catch (Exception ex)
{
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось загрузить наборы с ошибкой: {ex.Message}");
}
}
}
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareAirFighter(new AirFighterCompareByType());
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareAirFighter(new fighterCompareByColor());
//сортировка
private void CompareAirFighter(IComparer<DrawningAirFighter?> comparer)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
obj.Sort(comparer);
pictureBoxCollection.Image = obj.ShowAirFighter();
}
}
}

View File

@ -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="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>272, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,361 @@
namespace AirFighter
{
partial class FormAirFighterConfig
{
/// <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()
{
groupBox1 = new GroupBox();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
groupBox2 = new GroupBox();
panelPurple = new Panel();
panelYellow = new Panel();
panelBlack = new Panel();
panelBlue = new Panel();
panelGray = new Panel();
panelGreen = new Panel();
panelWhite = new Panel();
panelRed = new Panel();
checkBoxWing = new CheckBox();
checkBoxRocket = new CheckBox();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
label2 = new Label();
label1 = new Label();
panelColor = new Panel();
labelDopColor = new Label();
labelBaseColor = new Label();
pictureBoxObject = new PictureBox();
ButtonOk = new Button();
buttonCancel = new Button();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
panelColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(labelModifiedObject);
groupBox1.Controls.Add(labelSimpleObject);
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(checkBoxWing);
groupBox1.Controls.Add(checkBoxRocket);
groupBox1.Controls.Add(numericUpDownWeight);
groupBox1.Controls.Add(numericUpDownSpeed);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Location = new Point(12, 12);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(454, 228);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Параметры";
//
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(313, 146);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(87, 27);
labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(215, 146);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(87, 27);
labelSimpleObject.TabIndex = 7;
labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
//
// groupBox2
//
groupBox2.Controls.Add(panelPurple);
groupBox2.Controls.Add(panelYellow);
groupBox2.Controls.Add(panelBlack);
groupBox2.Controls.Add(panelBlue);
groupBox2.Controls.Add(panelGray);
groupBox2.Controls.Add(panelGreen);
groupBox2.Controls.Add(panelWhite);
groupBox2.Controls.Add(panelRed);
groupBox2.Location = new Point(215, 32);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(185, 106);
groupBox2.TabIndex = 6;
groupBox2.TabStop = false;
groupBox2.Text = "Цвета";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(139, 63);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(35, 30);
panelPurple.TabIndex = 7;
panelPurple.MouseDown += panelColor_MouseDown;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(139, 22);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(35, 30);
panelYellow.TabIndex = 3;
panelYellow.MouseDown += panelColor_MouseDown;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(98, 63);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(35, 30);
panelBlack.TabIndex = 6;
panelBlack.MouseDown += panelColor_MouseDown;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(98, 22);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(35, 30);
panelBlue.TabIndex = 2;
panelBlue.MouseDown += panelColor_MouseDown;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(57, 63);
panelGray.Name = "panelGray";
panelGray.Size = new Size(35, 30);
panelGray.TabIndex = 5;
panelGray.MouseDown += panelColor_MouseDown;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(57, 22);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(35, 30);
panelGreen.TabIndex = 1;
panelGreen.MouseDown += panelColor_MouseDown;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(16, 63);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(35, 30);
panelWhite.TabIndex = 4;
panelWhite.MouseDown += panelColor_MouseDown;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(16, 22);
panelRed.Name = "panelRed";
panelRed.Size = new Size(35, 30);
panelRed.TabIndex = 0;
panelRed.MouseDown += panelColor_MouseDown;
//
// checkBoxWing
//
checkBoxWing.AutoSize = true;
checkBoxWing.Location = new Point(10, 154);
checkBoxWing.Name = "checkBoxWing";
checkBoxWing.Size = new Size(199, 19);
checkBoxWing.TabIndex = 5;
checkBoxWing.Text = "Признак наличия доп. крыльев";
checkBoxWing.UseVisualStyleBackColor = true;
//
// checkBoxRocket
//
checkBoxRocket.AutoSize = true;
checkBoxRocket.Location = new Point(10, 119);
checkBoxRocket.Name = "checkBoxRocket";
checkBoxRocket.Size = new Size(156, 19);
checkBoxRocket.TabIndex = 4;
checkBoxRocket.Text = "Признак наличия ракет";
checkBoxRocket.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(76, 60);
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(73, 23);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(76, 31);
numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(73, 23);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(10, 62);
label2.Name = "label2";
label2.Size = new Size(29, 15);
label2.TabIndex = 1;
label2.Text = "Вес:";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(10, 33);
label1.Name = "label1";
label1.Size = new Size(62, 15);
label1.TabIndex = 0;
label1.Text = "Скорость:";
//
// panelColor
//
panelColor.AllowDrop = true;
panelColor.Controls.Add(labelDopColor);
panelColor.Controls.Add(labelBaseColor);
panelColor.Controls.Add(pictureBoxObject);
panelColor.Location = new Point(472, 12);
panelColor.Name = "panelColor";
panelColor.Size = new Size(276, 257);
panelColor.TabIndex = 1;
panelColor.DragDrop += PanelObject_DragDrop;
panelColor.DragEnter += PanelObject_DragEnter;
//
// labelDopColor
//
labelDopColor.AllowDrop = true;
labelDopColor.BorderStyle = BorderStyle.FixedSingle;
labelDopColor.Location = new Point(164, 10);
labelDopColor.Name = "labelDopColor";
labelDopColor.Size = new Size(100, 29);
labelDopColor.TabIndex = 2;
labelDopColor.Text = "Доп. цвет";
labelDopColor.TextAlign = ContentAlignment.MiddleCenter;
labelDopColor.DragDrop += LabelDopColor_DragDrop;
labelDopColor.DragEnter += LabelColor_DragEnter;
labelDopColor.MouseDown += LabelObject_MouseDown;
//
// labelBaseColor
//
labelBaseColor.AllowDrop = true;
labelBaseColor.BorderStyle = BorderStyle.FixedSingle;
labelBaseColor.Location = new Point(12, 10);
labelBaseColor.Name = "labelBaseColor";
labelBaseColor.Size = new Size(100, 29);
labelBaseColor.TabIndex = 2;
labelBaseColor.Text = "Цвет";
labelBaseColor.TextAlign = ContentAlignment.MiddleCenter;
labelBaseColor.DragDrop += LabelBaseColor_DragDrop;
labelBaseColor.DragEnter += LabelColor_DragEnter;
labelBaseColor.MouseDown += LabelObject_MouseDown;
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(12, 46);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(252, 182);
pictureBoxObject.TabIndex = 0;
pictureBoxObject.TabStop = false;
//
// ButtonOk
//
ButtonOk.Location = new Point(484, 275);
ButtonOk.Name = "ButtonOk";
ButtonOk.Size = new Size(100, 32);
ButtonOk.TabIndex = 2;
ButtonOk.Text = "Добавить";
ButtonOk.UseVisualStyleBackColor = true;
ButtonOk.Click += ButtonOk_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(636, 275);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(100, 32);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// FormAirFighterConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 388);
Controls.Add(buttonCancel);
Controls.Add(ButtonOk);
Controls.Add(panelColor);
Controls.Add(groupBox1);
Name = "FormAirFighterConfig";
Text = "FormFighterConfig";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
panelColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label label2;
private Label label1;
private GroupBox groupBox2;
private CheckBox checkBoxWing;
private CheckBox checkBoxRocket;
private Panel panelPurple;
private Panel panelYellow;
private Panel panelBlack;
private Panel panelBlue;
private Panel panelGray;
private Panel panelGreen;
private Panel panelWhite;
private Panel panelRed;
private Label labelSimpleObject;
private Label labelModifiedObject;
private Panel panelColor;
private PictureBox pictureBoxObject;
private Label labelDopColor;
private Label labelBaseColor;
private Button ButtonOk;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,180 @@

using AirFighter.Drawnings;
using AirFighter.Entities;
using AirFighter;
using AirFighter.DrawningObjects;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
namespace AirFighter
{
/// <summary>
/// Форма создания объекта
/// </summary>
public partial class FormAirFighterConfig : Form
{
/// <summary>
/// Переменная-выбранная установка
/// </summary>
DrawningAirFighter? _fighter = null;
/// <summary>
/// Событие
/// </summary>
private event Action<DrawningAirFighter> EventAddAirFighter;
/// <summary>
/// Конструктор
/// </summary>
public FormAirFighterConfig()
{
InitializeComponent();
panelBlack.MouseDown += panelColor_MouseDown;
panelPurple.MouseDown += panelColor_MouseDown;
panelGray.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelWhite.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
// TODO buttonCancel.Click with lambda
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Отрисовать установку
/// </summary>
private void DrawAirFighter()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_fighter?.SetPosition(5, 5);
_fighter?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawningAirFighter> ev)
{
if (EventAddAirFighter == null)
{
EventAddAirFighter = new Action<DrawningAirFighter>(ev);
}
else
{
EventAddAirFighter += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_fighter = new DrawningAirFighter((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
_fighter = new DrawningAirFighterMilitary((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxWing.Checked,
checkBoxRocket.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
break;
}
DrawAirFighter();
}
/// <summary>
/// Отправляем цвет с панели
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
if (_fighter != null)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
_fighter.EntityAirFighter.BodyColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAirFighter();
}
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (_fighter != null && _fighter.EntityAirFighter is EntityAirFighterMilitary entityustabat)
{
labelDopColor.AllowDrop = true;
}
else
labelDopColor.AllowDrop = false;
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (_fighter != null && _fighter.EntityAirFighter is EntityAirFighterMilitary entityAirFighterMilitary)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
entityAirFighterMilitary.AdditionalColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAirFighter();
}
}
/// <summary>
/// Добавление установки
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddAirFighter?.Invoke(_fighter);
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirFighter.Drawnings;
namespace AirFighter.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionAirFighter direction);
void MoveObject(DirectionAirFighter direction);
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirFighter.DrawningObjects;
using AirFighter.Drawnings;
namespace AirFighter.MovementStrategy
{
public class DrawningObjectAirFighter : IMoveableObject
{
private readonly DrawningAirFighter? _drawningAirFighter = null;
public DrawningObjectAirFighter(DrawningAirFighter drawningAirFighter)
{
_drawningAirFighter = drawningAirFighter;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningAirFighter == null || _drawningAirFighter.EntityAirFighter ==
null)
{
return null;
}
return new ObjectParameters(_drawningAirFighter.GetPosX, _drawningAirFighter.GetPosY, _drawningAirFighter.GetWidth, _drawningAirFighter.GetHeight);
}
}
public int GetStep => (int)(_drawningAirFighter?.EntityAirFighter?.Step ?? 0);
public bool CheckCanMove(DirectionAirFighter direction) =>
_drawningAirFighter?.CanMove(direction) ?? false;
public void MoveObject(DirectionAirFighter direction) =>
_drawningAirFighter?.MoveTransport(direction);
public void SetPosition(int x, int y)
{
if (_drawningAirFighter != null)
{
_drawningAirFighter.SetPosition(x, y);
}
}
public void Draw(Graphics g)
{
if (_drawningAirFighter != null)
{
_drawningAirFighter.DrawTransport(g);
}
}
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.MovementStrategy
{
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.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;
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffX) > GetStep() || Math.Abs(diffY) > GetStep())
{
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -1,3 +1,12 @@
using AirFighter;
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Serilog;
using AirFighter;
namespace AirFighter
{
internal static class Program
@ -11,7 +20,31 @@ namespace AirFighter
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormAirFighterCollection>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormAirFighterCollection>().AddLogging(option =>
{
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();
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
}
}
}

View File

@ -0,0 +1,113 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AirFighter.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AirFighter.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap @__png_1 {
get {
object obj = ResourceManager.GetObject("--png-1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap @__png_2 {
get {
object obj = ResourceManager.GetObject("--png-2", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap @__png_3 {
get {
object obj = ResourceManager.GetObject("--png-3", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap @__png_31 {
get {
object obj = ResourceManager.GetObject("--png-31", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap @__png_4 {
get {
object obj = ResourceManager.GetObject("--png-4", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,136 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="--png-3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\--png-3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="--png-31" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\--png-31.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="--png-1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\--png-1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="--png-2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\--png-2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="--png-4" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\--png-4.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,78 @@
using System.Numerics;
using AirFighter.Exceptions;
namespace AirFighter.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 fighter, IEqualityComparer<T>? equal = null)
{
Insert(fighter, 0, equal);
return true;
}
public bool Insert(T fighter, int position, IEqualityComparer<T>? equal = null)
{
if (position < 0 || position >= _maxCount)
throw new AirFighterNotFoundException(position);
if (Count >= _maxCount)
throw new StorageOverflowException(position);
if (equal != null)
{
if (_places.Contains(fighter, equal))
throw new ArgumentException(nameof(fighter));
}
_places.Insert(position, fighter);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position > _maxCount || position >= Count)
throw new AirFighterNotFoundException();
if (_places[position] == null)
{
throw new AirFighterNotFoundException();
}
_places[position] = null;
return true;
}
public T? this[int position]
{
get
{
if (position < 0 || position > _maxCount)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
_places[position] = value;
}
}
public IEnumerable<T?> GetAirFighter(int? maxAirFighter = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxAirFighter.HasValue && i == maxAirFighter.Value)
{
yield break;
}
}
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.MovementStrategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter.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 contex) : base(info, contex) { }
}
}

View File

@ -0,0 +1,20 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/log_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext", "WithShipName", "WithThreadId" ],
"Properties": {
"Application": "AirFighter"
}
}
}