Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cd442a400d | ||
|
9df56cdb4d | ||
|
7e4fd641e7 | ||
|
d43966d9eb | ||
|
d2423b1bd3 | ||
|
1436165717 | ||
|
bdbb9bae60 | ||
|
a112213e0a | ||
|
dfdc51e414 | ||
|
1260b0dc88 | ||
|
2fc394b825 | ||
|
ae537a58ca | ||
|
7591ef9672 | ||
|
5fb60274de | ||
|
908ca82192 | ||
|
e9d0046f62 | ||
|
d9446d1c46 | ||
|
c60f61ba18 | ||
|
d229bc8f73 | ||
|
496f946e45 |
214
AirFighter/AirFighter/AbstractMap.cs
Normal file
214
AirFighter/AirFighter/AbstractMap.cs
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||||
|
{
|
||||||
|
private IDrawingObject _drawningObject = null;
|
||||||
|
protected int[,] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected readonly Random _random = new();
|
||||||
|
protected readonly int _freeRoad = 0;
|
||||||
|
protected readonly int _barrier = 1;
|
||||||
|
public Bitmap CreateMap(int width, int height, IDrawingObject drawningObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawningObject = drawningObject;
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect)
|
||||||
|
{
|
||||||
|
return checkBarrier(rect, false, false, true, false);
|
||||||
|
}
|
||||||
|
private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect, bool minLeft, bool maxLeft, bool isTop, bool isBottom)
|
||||||
|
{
|
||||||
|
(int mapI, int mapJ) res = (-1, -1);
|
||||||
|
|
||||||
|
for (int i = (int)(rect.Top / _size_y); i <= (int)(rect.Bottom / _size_y) && i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = (int)(rect.Left / _size_x); j <= (int)(rect.Right / _size_x) && j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
if (j < 0) j = 0;
|
||||||
|
if (i < 0) i = 0;
|
||||||
|
if (_map[i, j] != _barrier) continue;
|
||||||
|
|
||||||
|
if (res.mapI == -1) res = (i, j);
|
||||||
|
if (minLeft && res.mapJ > j) res = (i, j);
|
||||||
|
if (maxLeft && res.mapJ < j) res = (i, j);
|
||||||
|
if(isBottom) res = (i, j);
|
||||||
|
if (isTop) return (i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
// TODO проверка, что объект может переместится в требуемом
|
||||||
|
|
||||||
|
var position = _drawningObject.GetCurrentPosition();
|
||||||
|
|
||||||
|
float drawningWidth = position.Right - position.Left;
|
||||||
|
float drawningHeight = position.Bottom - position.Top;
|
||||||
|
|
||||||
|
bool minLeft = false;
|
||||||
|
bool maxLeft = false;
|
||||||
|
bool isTop = false;
|
||||||
|
bool isBottom = false;
|
||||||
|
|
||||||
|
if (direction == Direction.Left)
|
||||||
|
{
|
||||||
|
position.Left -= _drawningObject.Step;
|
||||||
|
maxLeft = true;
|
||||||
|
}
|
||||||
|
if (direction == Direction.Right)
|
||||||
|
{
|
||||||
|
position.Left += _drawningObject.Step;
|
||||||
|
minLeft = true;
|
||||||
|
}
|
||||||
|
if (direction == Direction.Up) {
|
||||||
|
position.Top -= _drawningObject.Step;
|
||||||
|
isTop = true;
|
||||||
|
}
|
||||||
|
if (direction == Direction.Down)
|
||||||
|
{
|
||||||
|
position.Top += _drawningObject.Step;
|
||||||
|
isBottom = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
position.Right = position.Left + drawningWidth;
|
||||||
|
position.Bottom = position.Top + drawningHeight;
|
||||||
|
|
||||||
|
var currentBarrier = checkBarrier(position, minLeft, maxLeft, isTop, isBottom);
|
||||||
|
|
||||||
|
if (currentBarrier.mapI == -1)
|
||||||
|
{
|
||||||
|
_drawningObject.MoveObject(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (direction == Direction.Left)
|
||||||
|
position.Left = (currentBarrier.mapJ + 1) * _size_x + 1;
|
||||||
|
|
||||||
|
else if (direction == Direction.Right)
|
||||||
|
position.Left = currentBarrier.mapJ * _size_x - drawningWidth - 1;
|
||||||
|
|
||||||
|
else if (direction == Direction.Up)
|
||||||
|
position.Top = (currentBarrier.mapI + 1) * _size_y + 1;
|
||||||
|
|
||||||
|
else if (direction == Direction.Down)
|
||||||
|
position.Top = currentBarrier.mapI * _size_y - drawningHeight - 1;
|
||||||
|
|
||||||
|
if (currentBarrier.mapI != -1)
|
||||||
|
_drawningObject.SetObject((int)position.Left, (int)position.Top, _width, _height);
|
||||||
|
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
private bool SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int x = _random.Next(0, 10);
|
||||||
|
int y = _random.Next(0, 10);
|
||||||
|
_drawningObject.SetObject(x, y, _width, _height);
|
||||||
|
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||||
|
|
||||||
|
var position = _drawningObject.GetCurrentPosition();
|
||||||
|
float drawningWidth = position.Right - position.Left;
|
||||||
|
float drawningHeight = position.Bottom - position.Top;
|
||||||
|
|
||||||
|
var currentBarrier = checkBarrier(position);
|
||||||
|
int minRowIndex = _map.GetLength(0);
|
||||||
|
|
||||||
|
while(currentBarrier.mapI != -1)
|
||||||
|
{
|
||||||
|
minRowIndex = currentBarrier.mapI < minRowIndex ? currentBarrier.mapI : minRowIndex;
|
||||||
|
|
||||||
|
position.Left = (currentBarrier.mapJ + 1) * _size_x + 1;
|
||||||
|
position.Right = position.Left + drawningWidth;
|
||||||
|
|
||||||
|
if(position.Right > _width)
|
||||||
|
{
|
||||||
|
position.Top = (minRowIndex + 1) * _size_y + 1;
|
||||||
|
position.Bottom = position.Top + drawningHeight;
|
||||||
|
|
||||||
|
position.Left = 0;
|
||||||
|
position.Right = drawningWidth;
|
||||||
|
|
||||||
|
minRowIndex = _map.GetLength(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (position.Bottom > _height) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentBarrier = checkBarrier(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawningObject.SetObject((int)position.Left, (int)position.Top, _width, _height);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private Bitmap DrawMapWithObject()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_width, _height);
|
||||||
|
if (_drawningObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _freeRoad)
|
||||||
|
{
|
||||||
|
DrawRoadPart(gr, i, j);
|
||||||
|
}
|
||||||
|
else if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
DrawBarrierPart(gr, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawningObject.DrawningObject(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
|
||||||
|
public bool Equals(AbstractMap? other)
|
||||||
|
{
|
||||||
|
if (_width != other._width || _height != other._height) return false;
|
||||||
|
if (_size_x != other._size_x || _size_y != other._size_y) return false;
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if(_map[i, j] != other._map[i, j]) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,19 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
@ -23,4 +36,10 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="loggerConfig.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
31
AirFighter/AirFighter/AircraftCompareByColor.cs
Normal file
31
AirFighter/AirFighter/AircraftCompareByColor.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class AircraftCompareByColor : IComparer<IDrawingObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawingObject? x, IDrawingObject? y)
|
||||||
|
{
|
||||||
|
var xAirFighter = x as DrawingObjectAirFighter;
|
||||||
|
var yAirFighter = y as DrawingObjectAirFighter;
|
||||||
|
|
||||||
|
if (xAirFighter == null && yAirFighter == null) return 0;
|
||||||
|
if (xAirFighter == null) return 1;
|
||||||
|
if (yAirFighter == null) return -1;
|
||||||
|
|
||||||
|
string xColor = xAirFighter.GetAirFighter.AirFighter.BodyColor.Name;
|
||||||
|
string yColor = yAirFighter.GetAirFighter.AirFighter.BodyColor.Name;
|
||||||
|
|
||||||
|
if (xColor != yColor) return xColor.CompareTo(yColor);
|
||||||
|
|
||||||
|
var speedCompare = xAirFighter.GetAirFighter.AirFighter.Speed.CompareTo(yAirFighter.GetAirFighter.AirFighter.Speed);
|
||||||
|
if (speedCompare != 0) return speedCompare;
|
||||||
|
|
||||||
|
return xAirFighter.GetAirFighter.AirFighter.Weight.CompareTo(yAirFighter.GetAirFighter.AirFighter.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
AirFighter/AirFighter/AircraftCompareByType.cs
Normal file
38
AirFighter/AirFighter/AircraftCompareByType.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class AircraftCompareByType : IComparer<IDrawingObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawingObject? x, IDrawingObject? y)
|
||||||
|
{
|
||||||
|
var xAirFighter = x as DrawingObjectAirFighter;
|
||||||
|
var yAirFighter = y as DrawingObjectAirFighter;
|
||||||
|
|
||||||
|
if (xAirFighter == null && yAirFighter == null) return 0;
|
||||||
|
if (xAirFighter == null) return 1;
|
||||||
|
if (yAirFighter == null) return -1;
|
||||||
|
|
||||||
|
|
||||||
|
if (xAirFighter.GetAirFighter.GetType().Name != yAirFighter.GetAirFighter.GetType().Name)
|
||||||
|
{
|
||||||
|
if (xAirFighter.GetAirFighter.GetType().Name == "DrawingAirFighter")
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = xAirFighter.GetAirFighter.AirFighter.Speed.CompareTo(yAirFighter.GetAirFighter.AirFighter.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xAirFighter.GetAirFighter.AirFighter.Weight.CompareTo(yAirFighter.GetAirFighter.AirFighter.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
AirFighter/AirFighter/AircraftNotFoundException.cs
Normal file
14
AirFighter/AirFighter/AircraftNotFoundException.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class AircraftNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public AircraftNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public AircraftNotFoundException() : base() { }
|
||||||
|
public AircraftNotFoundException(string message) : base(message) { }
|
||||||
|
public AircraftNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected AircraftNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
@ -6,8 +6,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirFighter
|
namespace AirFighter
|
||||||
{
|
{
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
|
None,
|
||||||
Up,
|
Up,
|
||||||
Right,
|
Right,
|
||||||
Left,
|
Left,
|
||||||
|
@ -6,12 +6,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirFighter
|
namespace AirFighter
|
||||||
{
|
{
|
||||||
internal class DrawingAirFighter
|
public class DrawingAirFighter
|
||||||
{
|
{
|
||||||
public EntityAirFighter AirFighter { get; private set; }
|
public EntityAirFighter AirFighter { get; protected set; }
|
||||||
|
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
|
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
private int? _pictureHeight = null;
|
private int? _pictureHeight = null;
|
||||||
@ -19,10 +19,20 @@ namespace AirFighter
|
|||||||
private readonly int _airFighterWidth = 195;
|
private readonly int _airFighterWidth = 195;
|
||||||
private readonly int _airFighterHeight = 166;
|
private readonly int _airFighterHeight = 166;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public DrawingAirFighter(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
AirFighter = new EntityAirFighter();
|
AirFighter = new EntityAirFighter(speed, weight, bodyColor);
|
||||||
AirFighter.Init(speed, weight, bodyColor);
|
}
|
||||||
|
public DrawingAirFighter(int speed, float weight, Color bodyColor, int airFighterWidth, int airFighterHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_airFighterWidth = airFighterWidth;
|
||||||
|
_airFighterHeight = airFighterHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingAirFighter Update(int? speed = null, float? weight = null, Color? bodyColor = null)
|
||||||
|
{
|
||||||
|
return new DrawingAirFighter(speed ?? AirFighter.Speed, weight ?? AirFighter.Weight, bodyColor ?? AirFighter.BodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
@ -77,20 +87,26 @@ namespace AirFighter
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return ( _startPosX, _startPosX + _airFighterWidth, _startPosY, _startPosY + _airFighterHeight );
|
||||||
|
}
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||||
{
|
{
|
||||||
|
MessageBox.Show("test");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(AirFighter.BodyColor);
|
Pen pen = new(AirFighter.BodyColor, 2);
|
||||||
Brush brushBlack = new SolidBrush(AirFighter.BodyColor);
|
Brush brushBlack = new SolidBrush(AirFighter.BodyColor);
|
||||||
|
|
||||||
PointF[] front = {
|
PointF[] front = {
|
||||||
new(_startPosX + 160, _startPosY + 70),
|
new(_startPosX + 160, _startPosY + 69),
|
||||||
new(_startPosX + 195, _startPosY + 83),
|
new(_startPosX + 195, _startPosY + 83),
|
||||||
new(_startPosX + 160, _startPosY + 96)
|
new(_startPosX + 160, _startPosY + 97)
|
||||||
};
|
};
|
||||||
|
|
||||||
PointF[] tailTop = {
|
PointF[] tailTop = {
|
||||||
@ -124,12 +140,12 @@ namespace AirFighter
|
|||||||
new(_startPosX + 75, _startPosY + 96),
|
new(_startPosX + 75, _startPosY + 96),
|
||||||
};
|
};
|
||||||
|
|
||||||
g.FillPolygon(brushBlack, front);
|
|
||||||
g.DrawPolygon(pen, tailTop);
|
g.DrawPolygon(pen, tailTop);
|
||||||
g.DrawPolygon(pen, tailBottom);
|
g.DrawPolygon(pen, tailBottom);
|
||||||
g.DrawPolygon(pen, wingTop);
|
g.DrawPolygon(pen, wingTop);
|
||||||
g.DrawPolygon(pen, wingBottom);
|
g.DrawPolygon(pen, wingBottom);
|
||||||
g.DrawRectangle(pen, _startPosX, _startPosY + 70, 160, 26);
|
g.DrawRectangle(pen, _startPosX, _startPosY + 70, 160, 26);
|
||||||
|
g.FillPolygon(brushBlack, front);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeBorders(int width, int height)
|
public void ChangeBorders(int width, int height)
|
||||||
|
107
AirFighter/AirFighter/DrawingModernAirFighter.cs
Normal file
107
AirFighter/AirFighter/DrawingModernAirFighter.cs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class DrawingModernAirFighter : DrawingAirFighter
|
||||||
|
{
|
||||||
|
public DrawingModernAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWings, bool rockets) :
|
||||||
|
base(speed, weight, bodyColor, 195, 166)
|
||||||
|
{
|
||||||
|
AirFighter = new EntityModernAirFighter(speed, weight, bodyColor, dopColor, dopWings, rockets);
|
||||||
|
}
|
||||||
|
public DrawingModernAirFighter Update(int? speed = null, float? weight = null, Color? bodyColor = null,
|
||||||
|
Color? dopColor = null, bool? dopWings = null, bool? rockets = null)
|
||||||
|
{
|
||||||
|
EntityModernAirFighter entity = (EntityModernAirFighter)AirFighter;
|
||||||
|
return new DrawingModernAirFighter(speed ?? entity.Speed, weight ?? entity.Weight, bodyColor ?? entity.BodyColor,
|
||||||
|
dopColor ?? entity.DopColor, dopWings ?? entity.DopWings, rockets ?? entity.Rockets);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (AirFighter is not EntityModernAirFighter modernAirFighter)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(modernAirFighter.DopColor);
|
||||||
|
Brush dopBrush = new SolidBrush(modernAirFighter.DopColor);
|
||||||
|
|
||||||
|
if (modernAirFighter.DopWings)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
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(dopBrush, topDopWing);
|
||||||
|
g.FillPolygon(dopBrush, bottomDopWing);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modernAirFighter.Rockets)
|
||||||
|
{
|
||||||
|
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(dopBrush, topRocket1);
|
||||||
|
g.FillPolygon(dopBrush, topRocket2);
|
||||||
|
g.FillPolygon(dopBrush, bottomRocket1);
|
||||||
|
g.FillPolygon(dopBrush, bottomRocket2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
AirFighter/AirFighter/DrawingObjectAirFighter.cs
Normal file
72
AirFighter/AirFighter/DrawingObjectAirFighter.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class DrawingObjectAirFighter : IDrawingObject
|
||||||
|
{
|
||||||
|
private DrawingAirFighter _airFighter = null;
|
||||||
|
public DrawingObjectAirFighter(DrawingAirFighter airFighter)
|
||||||
|
{
|
||||||
|
_airFighter = airFighter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingAirFighter GetAirFighter => _airFighter;
|
||||||
|
|
||||||
|
public float Step => _airFighter?.AirFighter?.Step ?? 0;
|
||||||
|
public (float Left, float Right, float Top, float Bottom)
|
||||||
|
GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return _airFighter?.GetCurrentPosition() ?? default;
|
||||||
|
}
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_airFighter?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_airFighter.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
public void DrawningObject(Graphics g)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
_airFighter.DrawTransport(g);
|
||||||
|
}
|
||||||
|
public string GetInfo() => _airFighter?.GetDataForSave();
|
||||||
|
public static IDrawingObject Create(string data) => new DrawingObjectAirFighter(data.CreateDrawingAirFighter());
|
||||||
|
|
||||||
|
public bool Equals(IDrawingObject? other)
|
||||||
|
{
|
||||||
|
var otherObj = other as DrawingObjectAirFighter;
|
||||||
|
if (otherObj == null) return false;
|
||||||
|
|
||||||
|
var airFighter = _airFighter.AirFighter;
|
||||||
|
var otherAirFighter = otherObj._airFighter.AirFighter;
|
||||||
|
|
||||||
|
if (airFighter.Speed != otherAirFighter.Speed) return false;
|
||||||
|
if (airFighter.Weight != otherAirFighter.Weight) return false;
|
||||||
|
if (airFighter.BodyColor != otherAirFighter.BodyColor) return false;
|
||||||
|
|
||||||
|
// TODO доделать проверки в случае продвинутого объекта
|
||||||
|
|
||||||
|
if(airFighter.GetType().Name != otherAirFighter.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(airFighter.GetType().Name == "EntityAirFighter") return true;
|
||||||
|
|
||||||
|
var modernEntity1 = (EntityModernAirFighter) airFighter;
|
||||||
|
var modernEntity2 = (EntityModernAirFighter) otherAirFighter;
|
||||||
|
|
||||||
|
if (modernEntity1.DopColor.Name != modernEntity2.DopColor.Name) return false;
|
||||||
|
if (modernEntity1.Rockets != modernEntity2.Rockets) return false;
|
||||||
|
if (modernEntity1.DopWings != modernEntity2.DopWings) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirFighter
|
namespace AirFighter
|
||||||
{
|
{
|
||||||
internal class EntityAirFighter
|
public class EntityAirFighter
|
||||||
{
|
{
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
public float Weight { get; private set; }
|
public float Weight { get; private set; }
|
||||||
@ -14,7 +14,7 @@ namespace AirFighter
|
|||||||
|
|
||||||
public float Step => Speed * 100 / Weight;
|
public float Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityAirFighter(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
|
|
||||||
|
27
AirFighter/AirFighter/EntityModernAirFighter.cs
Normal file
27
AirFighter/AirFighter/EntityModernAirFighter.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
// EntityModernAirFighter
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class EntityModernAirFighter : EntityAirFighter
|
||||||
|
{
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
public bool DopWings { get; private set; }
|
||||||
|
public bool Rockets { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
public EntityModernAirFighter(int speed, float weight, Color bodyColor, Color
|
||||||
|
dopColor, bool dopWings, bool rockets) :
|
||||||
|
base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
DopWings = dopWings;
|
||||||
|
Rockets = rockets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
AirFighter/AirFighter/ExtensionAircraft.cs
Normal file
39
AirFighter/AirFighter/ExtensionAircraft.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal static class ExtentionAircraft
|
||||||
|
{
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
public static DrawingAirFighter CreateDrawingAirFighter(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingAirFighter(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingModernAirFighter(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static string GetDataForSave(this DrawingAirFighter drawningAircraft)
|
||||||
|
{
|
||||||
|
var aircraft = drawningAircraft.AirFighter;
|
||||||
|
var str =
|
||||||
|
$"{aircraft.Speed}{_separatorForObject}{aircraft.Weight}{_separatorForObject}" +
|
||||||
|
$"{aircraft.BodyColor.Name}";
|
||||||
|
|
||||||
|
if (aircraft is not EntityModernAirFighter modernAircraft)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return
|
||||||
|
$"{str}{_separatorForObject}{modernAircraft.DopColor.Name}{_separatorForObject}" +
|
||||||
|
$"{modernAircraft.Rockets}{_separatorForObject}{modernAircraft.DopWings}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
30
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
@ -38,6 +38,8 @@
|
|||||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSelect = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -49,7 +51,7 @@
|
|||||||
this.CreateButton.Name = "CreateButton";
|
this.CreateButton.Name = "CreateButton";
|
||||||
this.CreateButton.Size = new System.Drawing.Size(94, 29);
|
this.CreateButton.Size = new System.Drawing.Size(94, 29);
|
||||||
this.CreateButton.TabIndex = 0;
|
this.CreateButton.TabIndex = 0;
|
||||||
this.CreateButton.Text = "создать";
|
this.CreateButton.Text = "создание";
|
||||||
this.CreateButton.UseVisualStyleBackColor = true;
|
this.CreateButton.UseVisualStyleBackColor = true;
|
||||||
this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click);
|
this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click);
|
||||||
//
|
//
|
||||||
@ -147,11 +149,35 @@
|
|||||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20);
|
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20);
|
||||||
this.toolStripStatusLabelBodyColor.Text = "цвет:";
|
this.toolStripStatusLabelBodyColor.Text = "цвет:";
|
||||||
//
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.button1.Location = new System.Drawing.Point(121, 389);
|
||||||
|
this.button1.Name = "button1";
|
||||||
|
this.button1.Size = new System.Drawing.Size(148, 29);
|
||||||
|
this.button1.TabIndex = 7;
|
||||||
|
this.button1.Text = "модификация";
|
||||||
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.CreateModernButton_Click);
|
||||||
|
//
|
||||||
|
// buttonSelect
|
||||||
|
//
|
||||||
|
this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonSelect.Location = new System.Drawing.Point(558, 389);
|
||||||
|
this.buttonSelect.Name = "buttonSelect";
|
||||||
|
this.buttonSelect.Size = new System.Drawing.Size(115, 29);
|
||||||
|
this.buttonSelect.TabIndex = 8;
|
||||||
|
this.buttonSelect.Text = "выбрать";
|
||||||
|
this.buttonSelect.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_Click);
|
||||||
|
//
|
||||||
// FormAirFighter
|
// FormAirFighter
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.buttonSelect);
|
||||||
|
this.Controls.Add(this.button1);
|
||||||
this.Controls.Add(this.statusStrip1);
|
this.Controls.Add(this.statusStrip1);
|
||||||
this.Controls.Add(this.RightButton);
|
this.Controls.Add(this.RightButton);
|
||||||
this.Controls.Add(this.LeftButton);
|
this.Controls.Add(this.LeftButton);
|
||||||
@ -181,5 +207,7 @@
|
|||||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||||
|
private Button button1;
|
||||||
|
private Button buttonSelect;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,26 +4,60 @@ namespace AirFighter
|
|||||||
{
|
{
|
||||||
private DrawingAirFighter _airFighter;
|
private DrawingAirFighter _airFighter;
|
||||||
|
|
||||||
|
public DrawingAirFighter SelectedAirFighter { get; private set; }
|
||||||
|
|
||||||
public FormAirFighter()
|
public FormAirFighter()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetData(DrawingAirFighter airFighter)
|
||||||
|
{
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: { _airFighter.AirFighter.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateButton_Click(object sender, EventArgs e)
|
private void CreateButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
|
||||||
_airFighter = new DrawingAirFighter();
|
rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
_airFighter.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_airFighter = new DrawingAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||||
|
|
||||||
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
|
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
|
||||||
|
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter.Speed}";
|
SetData(_airFighter);
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter.Weight}";
|
Draw();
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: { _airFighter.AirFighter.BodyColor.Name}";
|
}
|
||||||
|
|
||||||
|
private void CreateModernButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialogDop = new();
|
||||||
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDop.Color;
|
||||||
|
}
|
||||||
|
_airFighter = new DrawingModernAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
color, dopColor,
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,2)));
|
||||||
|
|
||||||
|
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
|
||||||
|
|
||||||
|
SetData(_airFighter);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +93,11 @@ namespace AirFighter
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelect_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedAirFighter = _airFighter;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
|
362
AirFighter/AirFighter/FormAircraftConfig.Designer.cs
generated
Normal file
362
AirFighter/AirFighter/FormAircraftConfig.Designer.cs
generated
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
partial class FormAircraftConfig
|
||||||
|
{
|
||||||
|
/// <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.groupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||||
|
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||||
|
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||||
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.panelGray = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlack = new System.Windows.Forms.Panel();
|
||||||
|
this.panelPurple = new System.Windows.Forms.Panel();
|
||||||
|
this.panelWhite = new System.Windows.Forms.Panel();
|
||||||
|
this.panelBlue = new System.Windows.Forms.Panel();
|
||||||
|
this.panelGreen = new System.Windows.Forms.Panel();
|
||||||
|
this.panelYellow = new System.Windows.Forms.Panel();
|
||||||
|
this.panelRed = new System.Windows.Forms.Panel();
|
||||||
|
this.checkBoxRockets = new System.Windows.Forms.CheckBox();
|
||||||
|
this.checkBoxDopWings = new System.Windows.Forms.CheckBox();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.panel8 = new System.Windows.Forms.Panel();
|
||||||
|
this.label6 = new System.Windows.Forms.Label();
|
||||||
|
this.label5 = new System.Windows.Forms.Label();
|
||||||
|
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||||
|
this.buttonOk = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.groupBoxConfig.SuspendLayout();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||||
|
this.panel8.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxConfig
|
||||||
|
//
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.groupBox1);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxRockets);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.checkBoxDopWings);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.label2);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.label1);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||||
|
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||||
|
this.groupBoxConfig.Location = new System.Drawing.Point(12, 23);
|
||||||
|
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||||
|
this.groupBoxConfig.Size = new System.Drawing.Size(581, 307);
|
||||||
|
this.groupBoxConfig.TabIndex = 0;
|
||||||
|
this.groupBoxConfig.TabStop = false;
|
||||||
|
this.groupBoxConfig.Text = "Параметры";
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelModifiedObject.Location = new System.Drawing.Point(410, 240);
|
||||||
|
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
this.labelModifiedObject.Size = new System.Drawing.Size(117, 43);
|
||||||
|
this.labelModifiedObject.TabIndex = 9;
|
||||||
|
this.labelModifiedObject.Text = "Продвинутый";
|
||||||
|
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.labelSimpleObject.Location = new System.Drawing.Point(276, 240);
|
||||||
|
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
this.labelSimpleObject.Size = new System.Drawing.Size(117, 43);
|
||||||
|
this.labelSimpleObject.TabIndex = 8;
|
||||||
|
this.labelSimpleObject.Text = "Простой";
|
||||||
|
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.panelGray);
|
||||||
|
this.groupBox1.Controls.Add(this.panelBlack);
|
||||||
|
this.groupBox1.Controls.Add(this.panelPurple);
|
||||||
|
this.groupBox1.Controls.Add(this.panelWhite);
|
||||||
|
this.groupBox1.Controls.Add(this.panelBlue);
|
||||||
|
this.groupBox1.Controls.Add(this.panelGreen);
|
||||||
|
this.groupBox1.Controls.Add(this.panelYellow);
|
||||||
|
this.groupBox1.Controls.Add(this.panelRed);
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(262, 54);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(280, 165);
|
||||||
|
this.groupBox1.TabIndex = 7;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Цвета";
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||||
|
this.panelGray.Location = new System.Drawing.Point(81, 100);
|
||||||
|
this.panelGray.Name = "panelGray";
|
||||||
|
this.panelGray.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelGray.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||||
|
this.panelBlack.Location = new System.Drawing.Point(148, 100);
|
||||||
|
this.panelBlack.Name = "panelBlack";
|
||||||
|
this.panelBlack.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelBlack.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||||
|
this.panelPurple.Location = new System.Drawing.Point(215, 100);
|
||||||
|
this.panelPurple.Name = "panelPurple";
|
||||||
|
this.panelPurple.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelPurple.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||||
|
this.panelWhite.Location = new System.Drawing.Point(14, 100);
|
||||||
|
this.panelWhite.Name = "panelWhite";
|
||||||
|
this.panelWhite.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelWhite.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||||
|
this.panelBlue.Location = new System.Drawing.Point(215, 31);
|
||||||
|
this.panelBlue.Name = "panelBlue";
|
||||||
|
this.panelBlue.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelBlue.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
this.panelGreen.BackColor = System.Drawing.Color.Lime;
|
||||||
|
this.panelGreen.Location = new System.Drawing.Point(148, 31);
|
||||||
|
this.panelGreen.Name = "panelGreen";
|
||||||
|
this.panelGreen.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelGreen.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||||
|
this.panelYellow.Location = new System.Drawing.Point(81, 31);
|
||||||
|
this.panelYellow.Name = "panelYellow";
|
||||||
|
this.panelYellow.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelYellow.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||||
|
this.panelRed.Location = new System.Drawing.Point(14, 31);
|
||||||
|
this.panelRed.Name = "panelRed";
|
||||||
|
this.panelRed.Size = new System.Drawing.Size(50, 50);
|
||||||
|
this.panelRed.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// checkBoxRockets
|
||||||
|
//
|
||||||
|
this.checkBoxRockets.AutoSize = true;
|
||||||
|
this.checkBoxRockets.Location = new System.Drawing.Point(22, 222);
|
||||||
|
this.checkBoxRockets.Name = "checkBoxRockets";
|
||||||
|
this.checkBoxRockets.Size = new System.Drawing.Size(79, 24);
|
||||||
|
this.checkBoxRockets.TabIndex = 5;
|
||||||
|
this.checkBoxRockets.Text = "Ракеты";
|
||||||
|
this.checkBoxRockets.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxDopWings
|
||||||
|
//
|
||||||
|
this.checkBoxDopWings.AutoSize = true;
|
||||||
|
this.checkBoxDopWings.Location = new System.Drawing.Point(22, 182);
|
||||||
|
this.checkBoxDopWings.Name = "checkBoxDopWings";
|
||||||
|
this.checkBoxDopWings.Size = new System.Drawing.Size(207, 24);
|
||||||
|
this.checkBoxDopWings.TabIndex = 4;
|
||||||
|
this.checkBoxDopWings.Text = "Дополнительные крылья";
|
||||||
|
this.checkBoxDopWings.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(22, 105);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(36, 20);
|
||||||
|
this.label2.TabIndex = 3;
|
||||||
|
this.label2.Text = "Вес:";
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(22, 56);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(76, 20);
|
||||||
|
this.label1.TabIndex = 2;
|
||||||
|
this.label1.Text = "Скорость:";
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
this.numericUpDownWeight.Location = new System.Drawing.Point(119, 105);
|
||||||
|
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||||
|
this.numericUpDownWeight.Size = new System.Drawing.Size(90, 27);
|
||||||
|
this.numericUpDownWeight.TabIndex = 1;
|
||||||
|
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
this.numericUpDownSpeed.Location = new System.Drawing.Point(119, 54);
|
||||||
|
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||||
|
this.numericUpDownSpeed.Size = new System.Drawing.Size(90, 27);
|
||||||
|
this.numericUpDownSpeed.TabIndex = 0;
|
||||||
|
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// panel8
|
||||||
|
//
|
||||||
|
this.panel8.AllowDrop = true;
|
||||||
|
this.panel8.Controls.Add(this.label6);
|
||||||
|
this.panel8.Controls.Add(this.label5);
|
||||||
|
this.panel8.Controls.Add(this.pictureBoxObject);
|
||||||
|
this.panel8.Location = new System.Drawing.Point(682, 23);
|
||||||
|
this.panel8.Name = "panel8";
|
||||||
|
this.panel8.Size = new System.Drawing.Size(329, 263);
|
||||||
|
this.panel8.TabIndex = 1;
|
||||||
|
this.panel8.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||||
|
this.panel8.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||||
|
//
|
||||||
|
// label6
|
||||||
|
//
|
||||||
|
this.label6.AllowDrop = true;
|
||||||
|
this.label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.label6.Location = new System.Drawing.Point(171, 24);
|
||||||
|
this.label6.Name = "label6";
|
||||||
|
this.label6.Size = new System.Drawing.Size(143, 43);
|
||||||
|
this.label6.TabIndex = 11;
|
||||||
|
this.label6.Text = "Доп. цвет";
|
||||||
|
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.label6.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
|
||||||
|
this.label6.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
//
|
||||||
|
// label5
|
||||||
|
//
|
||||||
|
this.label5.AllowDrop = true;
|
||||||
|
this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.label5.Location = new System.Drawing.Point(13, 24);
|
||||||
|
this.label5.Name = "label5";
|
||||||
|
this.label5.Size = new System.Drawing.Size(143, 43);
|
||||||
|
this.label5.TabIndex = 10;
|
||||||
|
this.label5.Text = "Цвет";
|
||||||
|
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
this.label5.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||||
|
this.label5.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
this.pictureBoxObject.Location = new System.Drawing.Point(13, 70);
|
||||||
|
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
this.pictureBoxObject.Size = new System.Drawing.Size(301, 176);
|
||||||
|
this.pictureBoxObject.TabIndex = 0;
|
||||||
|
this.pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonOk
|
||||||
|
//
|
||||||
|
this.buttonOk.Location = new System.Drawing.Point(695, 308);
|
||||||
|
this.buttonOk.Name = "buttonOk";
|
||||||
|
this.buttonOk.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.buttonOk.Size = new System.Drawing.Size(110, 31);
|
||||||
|
this.buttonOk.TabIndex = 2;
|
||||||
|
this.buttonOk.Text = "Добавить";
|
||||||
|
this.buttonOk.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(886, 308);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(110, 31);
|
||||||
|
this.buttonCancel.TabIndex = 3;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormAircraftConfig
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1040, 351);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonOk);
|
||||||
|
this.Controls.Add(this.panel8);
|
||||||
|
this.Controls.Add(this.groupBoxConfig);
|
||||||
|
this.Name = "FormAircraftConfig";
|
||||||
|
this.Text = "FormAircraftConfig";
|
||||||
|
this.groupBoxConfig.ResumeLayout(false);
|
||||||
|
this.groupBoxConfig.PerformLayout();
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||||
|
this.panel8.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxConfig;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private CheckBox checkBoxRockets;
|
||||||
|
private CheckBox checkBoxDopWings;
|
||||||
|
private Label label2;
|
||||||
|
private Label label1;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelRed;
|
||||||
|
private Panel panel8;
|
||||||
|
private Label label6;
|
||||||
|
private Label label5;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Button buttonOk;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
191
AirFighter/AirFighter/FormAircraftConfig.cs
Normal file
191
AirFighter/AirFighter/FormAircraftConfig.cs
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма создания объекта
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormAircraftConfig : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Переменная-выбранная машина
|
||||||
|
/// </summary>
|
||||||
|
DrawingAirFighter _car = null;
|
||||||
|
|
||||||
|
private Action<DrawingAirFighter> EventAddCar = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Событие
|
||||||
|
/// </summary>
|
||||||
|
// private event CarDelegate EventAddCar;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormAircraftConfig()
|
||||||
|
{
|
||||||
|
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 += (s, e) => Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовать машину
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public void AddEvent(Action<DrawingAirFighter> ev)
|
||||||
|
{
|
||||||
|
if(EventAddCar == null)
|
||||||
|
{
|
||||||
|
EventAddCar = ev;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventAddCar += ev;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawCar()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_car?.SetPosition(5, 5, pictureBoxObject.Width,
|
||||||
|
pictureBoxObject.Height);
|
||||||
|
_car?.DrawTransport(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление события
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ev"></param>
|
||||||
|
/* public void AddEvent(CarDelegate ev)
|
||||||
|
{
|
||||||
|
if (EventAddCar == null)
|
||||||
|
{
|
||||||
|
EventAddCar = new CarDelegate(ev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddCar += 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))
|
||||||
|
{
|
||||||
|
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":
|
||||||
|
_car = new DrawingAirFighter((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_car = new DrawingModernAirFighter((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||||
|
checkBoxDopWings.Checked, checkBoxRockets.Checked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawCar();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Отправляем цвет с панели
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Control).DoDragDrop((sender as Control).BackColor,
|
||||||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(typeof(Color)))
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Принимаем основной цвет
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_car == null) return;
|
||||||
|
Color color = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
|
||||||
|
if(_car is DrawingModernAirFighter)
|
||||||
|
{
|
||||||
|
_car = ((DrawingModernAirFighter)_car).Update(bodyColor: color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_car = _car.Update(bodyColor: color);
|
||||||
|
}
|
||||||
|
DrawCar();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Принимаем дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
var car = _car as DrawingModernAirFighter;
|
||||||
|
if (car == null) return;
|
||||||
|
|
||||||
|
Color color = (Color)e.Data.GetData(typeof(Color));
|
||||||
|
_car = car.Update(dopColor: color);
|
||||||
|
DrawCar();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление машины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonOk_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddCar?.Invoke(_car);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
AirFighter/AirFighter/FormAircraftConfig.resx
Normal file
60
AirFighter/AirFighter/FormAircraftConfig.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
215
AirFighter/AirFighter/FormMap.Designer.cs
generated
Normal file
215
AirFighter/AirFighter/FormMap.Designer.cs
generated
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
partial class FormMap
|
||||||
|
{
|
||||||
|
/// <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.CreateButton = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.DownButton = new System.Windows.Forms.Button();
|
||||||
|
this.UpButton = new System.Windows.Forms.Button();
|
||||||
|
this.LeftButton = new System.Windows.Forms.Button();
|
||||||
|
this.RightButton = new System.Windows.Forms.Button();
|
||||||
|
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||||
|
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
|
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
|
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.statusStrip1.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// CreateButton
|
||||||
|
//
|
||||||
|
this.CreateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.CreateButton.Location = new System.Drawing.Point(12, 390);
|
||||||
|
this.CreateButton.Name = "CreateButton";
|
||||||
|
this.CreateButton.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.CreateButton.TabIndex = 0;
|
||||||
|
this.CreateButton.Text = "создание";
|
||||||
|
this.CreateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click);
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.pictureBox.Name = "pictureBox";
|
||||||
|
this.pictureBox.Size = new System.Drawing.Size(800, 450);
|
||||||
|
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
this.pictureBox.Resize += new System.EventHandler(this.PictureBox_Resize);
|
||||||
|
//
|
||||||
|
// DownButton
|
||||||
|
//
|
||||||
|
this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down;
|
||||||
|
this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.DownButton.Location = new System.Drawing.Point(727, 389);
|
||||||
|
this.DownButton.Name = "DownButton";
|
||||||
|
this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.DownButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.DownButton.TabIndex = 2;
|
||||||
|
this.DownButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DownButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// UpButton
|
||||||
|
//
|
||||||
|
this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up;
|
||||||
|
this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.UpButton.Location = new System.Drawing.Point(727, 354);
|
||||||
|
this.UpButton.Name = "UpButton";
|
||||||
|
this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.UpButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.UpButton.TabIndex = 3;
|
||||||
|
this.UpButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// LeftButton
|
||||||
|
//
|
||||||
|
this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left;
|
||||||
|
this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.LeftButton.Location = new System.Drawing.Point(691, 389);
|
||||||
|
this.LeftButton.Name = "LeftButton";
|
||||||
|
this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.LeftButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.LeftButton.TabIndex = 4;
|
||||||
|
this.LeftButton.UseVisualStyleBackColor = true;
|
||||||
|
this.LeftButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// RightButton
|
||||||
|
//
|
||||||
|
this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right;
|
||||||
|
this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.RightButton.Location = new System.Drawing.Point(763, 389);
|
||||||
|
this.RightButton.Name = "RightButton";
|
||||||
|
this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.RightButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.RightButton.TabIndex = 5;
|
||||||
|
this.RightButton.UseVisualStyleBackColor = true;
|
||||||
|
this.RightButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// statusStrip1
|
||||||
|
//
|
||||||
|
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.toolStripStatusLabelSpeed,
|
||||||
|
this.toolStripStatusLabelWeight,
|
||||||
|
this.toolStripStatusLabelBodyColor});
|
||||||
|
this.statusStrip1.Location = new System.Drawing.Point(0, 424);
|
||||||
|
this.statusStrip1.Name = "statusStrip1";
|
||||||
|
this.statusStrip1.Size = new System.Drawing.Size(800, 26);
|
||||||
|
this.statusStrip1.TabIndex = 6;
|
||||||
|
this.statusStrip1.Text = "statusStrip1";
|
||||||
|
//
|
||||||
|
// toolStripStatusLabelSpeed
|
||||||
|
//
|
||||||
|
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||||
|
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(74, 20);
|
||||||
|
this.toolStripStatusLabelSpeed.Text = "скорость:";
|
||||||
|
//
|
||||||
|
// toolStripStatusLabelWeight
|
||||||
|
//
|
||||||
|
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||||
|
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(35, 20);
|
||||||
|
this.toolStripStatusLabelWeight.Text = "вес:";
|
||||||
|
//
|
||||||
|
// toolStripStatusLabelBodyColor
|
||||||
|
//
|
||||||
|
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||||
|
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20);
|
||||||
|
this.toolStripStatusLabelBodyColor.Text = "цвет:";
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.button1.Location = new System.Drawing.Point(121, 389);
|
||||||
|
this.button1.Name = "button1";
|
||||||
|
this.button1.Size = new System.Drawing.Size(148, 29);
|
||||||
|
this.button1.TabIndex = 7;
|
||||||
|
this.button1.Text = "модификация";
|
||||||
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.CreateModernButton_Click);
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
|
"простая карта",
|
||||||
|
"моя карта"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(150, 28);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 8;
|
||||||
|
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// FormMap
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.Controls.Add(this.button1);
|
||||||
|
this.Controls.Add(this.statusStrip1);
|
||||||
|
this.Controls.Add(this.RightButton);
|
||||||
|
this.Controls.Add(this.LeftButton);
|
||||||
|
this.Controls.Add(this.UpButton);
|
||||||
|
this.Controls.Add(this.DownButton);
|
||||||
|
this.Controls.Add(this.CreateButton);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Name = "FormMap";
|
||||||
|
this.Text = "Form1";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.statusStrip1.ResumeLayout(false);
|
||||||
|
this.statusStrip1.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button CreateButton;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button DownButton;
|
||||||
|
private Button UpButton;
|
||||||
|
private Button LeftButton;
|
||||||
|
private Button RightButton;
|
||||||
|
private StatusStrip statusStrip1;
|
||||||
|
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||||
|
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||||
|
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||||
|
private Button button1;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
}
|
||||||
|
}
|
110
AirFighter/AirFighter/FormMap.cs
Normal file
110
AirFighter/AirFighter/FormMap.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
public partial class FormMap : Form
|
||||||
|
{
|
||||||
|
private DrawingAirFighter _airFighter;
|
||||||
|
private AbstractMap _abstractMap;
|
||||||
|
|
||||||
|
public FormMap()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void SetData(DrawingAirFighter airFighter)
|
||||||
|
{
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Скорость: {_airFighter.AirFighter.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Вес: {_airFighter.AirFighter.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Цвет: { _airFighter.AirFighter.BodyColor.Name}";
|
||||||
|
|
||||||
|
pictureBox.Image = _abstractMap.CreateMap(pictureBox.Width, pictureBox.Height, new DrawingObjectAirFighter(_airFighter));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
|
||||||
|
_airFighter = new DrawingAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
|
|
||||||
|
SetData(_airFighter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateModernButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
|
||||||
|
_airFighter = new DrawingModernAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
|
|
||||||
|
|
||||||
|
SetData(_airFighter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
Direction dir = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "UpButton":
|
||||||
|
dir = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "DownButton":
|
||||||
|
dir = Direction.Down;
|
||||||
|
break;
|
||||||
|
case "LeftButton":
|
||||||
|
dir = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "RightButton":
|
||||||
|
dir = Direction.Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _abstractMap?.MoveObject(dir);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PictureBox_Resize(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_airFighter?.ChangeBorders(pictureBox.Width, pictureBox.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Draw()
|
||||||
|
{
|
||||||
|
if (pictureBox.Width == 0 || pictureBox.Height == 0) return;
|
||||||
|
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_airFighter?.DrawTransport(gr);
|
||||||
|
pictureBox.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelectorMap.Text)
|
||||||
|
{
|
||||||
|
case "простая карта":
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "моя карта":
|
||||||
|
_abstractMap = new MyMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
63
AirFighter/AirFighter/FormMap.resx
Normal file
63
AirFighter/AirFighter/FormMap.resx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
370
AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
generated
Normal file
370
AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
generated
Normal file
@ -0,0 +1,370 @@
|
|||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
partial class FormMapWithSetCars
|
||||||
|
{
|
||||||
|
/// <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.tools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||||
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||||
|
this.RightButton = new System.Windows.Forms.Button();
|
||||||
|
this.LeftButton = new System.Windows.Forms.Button();
|
||||||
|
this.UpButton = new System.Windows.Forms.Button();
|
||||||
|
this.DownButton = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonRemove = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonShowOnMap = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonShowStorage = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
|
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||||
|
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||||
|
this.tools.SuspendLayout();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.menuStrip1.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// tools
|
||||||
|
//
|
||||||
|
this.tools.Controls.Add(this.buttonSortByColor);
|
||||||
|
this.tools.Controls.Add(this.buttonSortByType);
|
||||||
|
this.tools.Controls.Add(this.groupBox1);
|
||||||
|
this.tools.Controls.Add(this.RightButton);
|
||||||
|
this.tools.Controls.Add(this.LeftButton);
|
||||||
|
this.tools.Controls.Add(this.UpButton);
|
||||||
|
this.tools.Controls.Add(this.DownButton);
|
||||||
|
this.tools.Controls.Add(this.maskedTextBoxPosition);
|
||||||
|
this.tools.Controls.Add(this.buttonRemove);
|
||||||
|
this.tools.Controls.Add(this.ButtonShowOnMap);
|
||||||
|
this.tools.Controls.Add(this.ButtonShowStorage);
|
||||||
|
this.tools.Controls.Add(this.buttonAdd);
|
||||||
|
this.tools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.tools.Location = new System.Drawing.Point(940, 28);
|
||||||
|
this.tools.Name = "tools";
|
||||||
|
this.tools.Size = new System.Drawing.Size(250, 697);
|
||||||
|
this.tools.TabIndex = 0;
|
||||||
|
this.tools.TabStop = false;
|
||||||
|
this.tools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.buttonDeleteMap);
|
||||||
|
this.groupBox1.Controls.Add(this.listBoxMaps);
|
||||||
|
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||||
|
this.groupBox1.Controls.Add(this.buttonAddMap);
|
||||||
|
this.groupBox1.Controls.Add(this.textBoxNewMapName);
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(12, 33);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(226, 286);
|
||||||
|
this.groupBox1.TabIndex = 0;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "карты";
|
||||||
|
//
|
||||||
|
// buttonDeleteMap
|
||||||
|
//
|
||||||
|
this.buttonDeleteMap.Location = new System.Drawing.Point(12, 243);
|
||||||
|
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||||
|
this.buttonDeleteMap.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonDeleteMap.TabIndex = 13;
|
||||||
|
this.buttonDeleteMap.Text = "Удалить карту";
|
||||||
|
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||||
|
//
|
||||||
|
// listBoxMaps
|
||||||
|
//
|
||||||
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
|
this.listBoxMaps.ItemHeight = 20;
|
||||||
|
this.listBoxMaps.Location = new System.Drawing.Point(12, 133);
|
||||||
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
|
this.listBoxMaps.Size = new System.Drawing.Size(196, 104);
|
||||||
|
this.listBoxMaps.TabIndex = 12;
|
||||||
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// comboBoxSelectorMap
|
||||||
|
//
|
||||||
|
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
|
"Простая карта",
|
||||||
|
"Моя карта"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 59);
|
||||||
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(196, 28);
|
||||||
|
this.comboBoxSelectorMap.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAddMap
|
||||||
|
//
|
||||||
|
this.buttonAddMap.Location = new System.Drawing.Point(12, 93);
|
||||||
|
this.buttonAddMap.Name = "buttonAddMap";
|
||||||
|
this.buttonAddMap.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonAddMap.TabIndex = 11;
|
||||||
|
this.buttonAddMap.Text = "Добавить карту";
|
||||||
|
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||||
|
//
|
||||||
|
// textBoxNewMapName
|
||||||
|
//
|
||||||
|
this.textBoxNewMapName.Location = new System.Drawing.Point(12, 26);
|
||||||
|
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||||
|
this.textBoxNewMapName.Size = new System.Drawing.Size(196, 27);
|
||||||
|
this.textBoxNewMapName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// RightButton
|
||||||
|
//
|
||||||
|
this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right;
|
||||||
|
this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.RightButton.Location = new System.Drawing.Point(148, 655);
|
||||||
|
this.RightButton.Name = "RightButton";
|
||||||
|
this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.RightButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.RightButton.TabIndex = 9;
|
||||||
|
this.RightButton.UseVisualStyleBackColor = true;
|
||||||
|
this.RightButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// LeftButton
|
||||||
|
//
|
||||||
|
this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left;
|
||||||
|
this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.LeftButton.Location = new System.Drawing.Point(76, 655);
|
||||||
|
this.LeftButton.Name = "LeftButton";
|
||||||
|
this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.LeftButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.LeftButton.TabIndex = 8;
|
||||||
|
this.LeftButton.UseVisualStyleBackColor = true;
|
||||||
|
this.LeftButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// UpButton
|
||||||
|
//
|
||||||
|
this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up;
|
||||||
|
this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.UpButton.Location = new System.Drawing.Point(112, 620);
|
||||||
|
this.UpButton.Name = "UpButton";
|
||||||
|
this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.UpButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.UpButton.TabIndex = 7;
|
||||||
|
this.UpButton.UseVisualStyleBackColor = true;
|
||||||
|
this.UpButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// DownButton
|
||||||
|
//
|
||||||
|
this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down;
|
||||||
|
this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.DownButton.Location = new System.Drawing.Point(112, 655);
|
||||||
|
this.DownButton.Name = "DownButton";
|
||||||
|
this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.DownButton.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.DownButton.TabIndex = 6;
|
||||||
|
this.DownButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DownButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 449);
|
||||||
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(196, 27);
|
||||||
|
this.maskedTextBoxPosition.TabIndex = 5;
|
||||||
|
this.maskedTextBoxPosition.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.maskedTextBoxPosition_MaskInputRejected);
|
||||||
|
//
|
||||||
|
// buttonRemove
|
||||||
|
//
|
||||||
|
this.buttonRemove.Location = new System.Drawing.Point(24, 482);
|
||||||
|
this.buttonRemove.Name = "buttonRemove";
|
||||||
|
this.buttonRemove.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonRemove.TabIndex = 4;
|
||||||
|
this.buttonRemove.Text = "Удалить";
|
||||||
|
this.buttonRemove.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
||||||
|
//
|
||||||
|
// ButtonShowOnMap
|
||||||
|
//
|
||||||
|
this.ButtonShowOnMap.Location = new System.Drawing.Point(24, 552);
|
||||||
|
this.ButtonShowOnMap.Name = "ButtonShowOnMap";
|
||||||
|
this.ButtonShowOnMap.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.ButtonShowOnMap.TabIndex = 3;
|
||||||
|
this.ButtonShowOnMap.Text = "Посмотреть карту";
|
||||||
|
this.ButtonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||||
|
//
|
||||||
|
// ButtonShowStorage
|
||||||
|
//
|
||||||
|
this.ButtonShowStorage.Location = new System.Drawing.Point(24, 517);
|
||||||
|
this.ButtonShowStorage.Name = "ButtonShowStorage";
|
||||||
|
this.ButtonShowStorage.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.ButtonShowStorage.TabIndex = 2;
|
||||||
|
this.ButtonShowStorage.Text = "Посмотреть хранилище";
|
||||||
|
this.ButtonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(24, 414);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddCar_Click);
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||||
|
this.pictureBox.Name = "pictureBox";
|
||||||
|
this.pictureBox.Size = new System.Drawing.Size(940, 697);
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// menuStrip1
|
||||||
|
//
|
||||||
|
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.файлToolStripMenuItem});
|
||||||
|
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.menuStrip1.Name = "menuStrip1";
|
||||||
|
this.menuStrip1.Size = new System.Drawing.Size(1190, 28);
|
||||||
|
this.menuStrip1.TabIndex = 2;
|
||||||
|
this.menuStrip1.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файлToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.saveToolStripMenuItem,
|
||||||
|
this.loadToolStripMenuItem});
|
||||||
|
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
|
this.файлToolStripMenuItem.Size = new System.Drawing.Size(58, 24);
|
||||||
|
this.файлToolStripMenuItem.Text = "файл";
|
||||||
|
//
|
||||||
|
// saveToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
|
this.saveToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||||
|
this.saveToolStripMenuItem.Text = "Сохранение";
|
||||||
|
this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// loadToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||||
|
this.loadToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||||
|
this.loadToolStripMenuItem.Text = "Загрузка";
|
||||||
|
this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
this.openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
this.buttonSortByType.Location = new System.Drawing.Point(27, 325);
|
||||||
|
this.buttonSortByType.Name = "buttonSortByType";
|
||||||
|
this.buttonSortByType.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonSortByType.TabIndex = 10;
|
||||||
|
this.buttonSortByType.Text = "Сортировать по типу";
|
||||||
|
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
this.buttonSortByColor.Location = new System.Drawing.Point(27, 360);
|
||||||
|
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
this.buttonSortByColor.Size = new System.Drawing.Size(196, 29);
|
||||||
|
this.buttonSortByColor.TabIndex = 11;
|
||||||
|
this.buttonSortByColor.Text = "Сортировать по цвету";
|
||||||
|
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||||
|
//
|
||||||
|
// FormMapWithSetCars
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1190, 725);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.tools);
|
||||||
|
this.Controls.Add(this.menuStrip1);
|
||||||
|
this.MainMenuStrip = this.menuStrip1;
|
||||||
|
this.Name = "FormMapWithSetCars";
|
||||||
|
this.Text = "FormMapWithSetCars";
|
||||||
|
this.tools.ResumeLayout(false);
|
||||||
|
this.tools.PerformLayout();
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.menuStrip1.ResumeLayout(false);
|
||||||
|
this.menuStrip1.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox tools;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private Button buttonRemove;
|
||||||
|
private Button ButtonShowOnMap;
|
||||||
|
private Button ButtonShowStorage;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private ComboBox comboBoxSelectorMap;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button RightButton;
|
||||||
|
private Button LeftButton;
|
||||||
|
private Button UpButton;
|
||||||
|
private Button DownButton;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private Button buttonDeleteMap;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
private Button buttonAddMap;
|
||||||
|
private TextBox textBoxNewMapName;
|
||||||
|
private MenuStrip menuStrip1;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem saveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
}
|
||||||
|
}
|
321
AirFighter/AirFighter/FormMapWithSetCars.cs
Normal file
321
AirFighter/AirFighter/FormMapWithSetCars.cs
Normal file
@ -0,0 +1,321 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
public partial class FormMapWithSetCars : Form
|
||||||
|
{
|
||||||
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{ "Простая карта", new SimpleMap() },
|
||||||
|
{ "Моя карта", new MyMap() }
|
||||||
|
};
|
||||||
|
/// <summary>
|
||||||
|
/// Объект от коллекции карт
|
||||||
|
/// </summary>
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public FormMapWithSetCars(ILogger<FormMapWithSetCars> logger)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width,
|
||||||
|
pictureBox.Height);
|
||||||
|
comboBoxSelectorMap.Items.Clear();
|
||||||
|
foreach (var elem in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
///
|
||||||
|
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = listBoxMaps.SelectedIndex;
|
||||||
|
listBoxMaps.Items.Clear();
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxMaps.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("При попытке создания карты не все данные заполнены");
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogInformation($"Нет карты с названием {comboBoxSelectorMap.Text}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(textBoxNewMapName.Text,
|
||||||
|
_mapsDict[comboBoxSelectorMap.Text]);
|
||||||
|
_logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_logger?.LogInformation($"Переход на карту {listBoxMaps.SelectedItem?.ToString()}");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ??
|
||||||
|
string.Empty);
|
||||||
|
_logger.LogInformation($"Удаление карты {listBoxMaps.SelectedItem}");
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AircraftAddCallback(DrawingAirFighter aircraft)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectAirFighter(aircraft) != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image =
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
_logger.LogInformation("На карту добавлен новый объект");
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Такой объект уже существует");
|
||||||
|
}
|
||||||
|
} catch (StorageOverflowException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Ошибка переполнения: {ex.Message}");
|
||||||
|
_logger.LogWarning($"Ошибка переполнения: {ex.Message}");
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||||
|
_logger.LogWarning($"Неизвестная ошибка: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ButtonAddCar_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormAircraftConfig form = new();
|
||||||
|
form.AddEvent(AircraftAddCallback);
|
||||||
|
form.Show();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image =
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
_logger.LogInformation($"Удален объект на позиции {pos}");
|
||||||
|
}
|
||||||
|
} catch (AircraftNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||||
|
_logger.LogWarning($"Ошибка при удалении объекта на позиции {pos}: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||||
|
_logger.LogWarning($"Неизвестная ошибка при удалении объекта на позиции {pos}: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
_logger.LogInformation("Показ хранилища");
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image =_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||||
|
_logger.LogInformation("Просмотр карты");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AircraftCompareByType());
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по цвету
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AircraftCompareByColor());
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//получаем имя кнопки
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
Direction dir = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "UpButton":
|
||||||
|
dir = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "DownButton":
|
||||||
|
dir = Direction.Down;
|
||||||
|
break;
|
||||||
|
case "LeftButton":
|
||||||
|
dir = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "RightButton":
|
||||||
|
dir = Direction.Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation($"Успешное сохранение в файл {saveFileDialog.FileName}");
|
||||||
|
} catch(Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning($"Ошибка при сохранении в файл {saveFileDialog.FileName}: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||||
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
_logger.LogInformation($"Успешная загрузка из файла {openFileDialog.FileName}");
|
||||||
|
ReloadMaps();
|
||||||
|
} catch(Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning($"Ошибка при загрузке из файла {openFileDialog.FileName}: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
AirFighter/AirFighter/FormMapWithSetCars.resx
Normal file
72
AirFighter/AirFighter/FormMapWithSetCars.resx
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>152, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>319, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>54</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
19
AirFighter/AirFighter/IDrawingObject.cs
Normal file
19
AirFighter/AirFighter/IDrawingObject.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||||
|
{
|
||||||
|
public float Step { get; }
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
void DrawningObject(Graphics g);
|
||||||
|
string GetInfo();
|
||||||
|
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
215
AirFighter/AirFighter/MapWithSetCarsGeneric.cs
Normal file
215
AirFighter/AirFighter/MapWithSetCarsGeneric.cs
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class MapWithSetCarsGeneric<T, U>
|
||||||
|
where T : class, IDrawingObject, IEquatable<T>
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 170;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetCarsGeneric<T> _setCars;
|
||||||
|
/// <summary>
|
||||||
|
/// Карта
|
||||||
|
/// </summary>
|
||||||
|
private readonly U _map;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="map"></param>
|
||||||
|
public MapWithSetCarsGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setCars = new SetCarsGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="map"></param>
|
||||||
|
/// <param name="car"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(MapWithSetCarsGeneric<T, U> map, T car)
|
||||||
|
{
|
||||||
|
return map._setCars.Insert(car);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="map"></param>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static T operator -(MapWithSetCarsGeneric<T, U> map, int
|
||||||
|
position)
|
||||||
|
{
|
||||||
|
return map._setCars.Remove(position);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawCars(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Просмотр объекта на карте
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
|
||||||
|
foreach(var car in _setCars.GetCars())
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение объекта по крате
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetData(char separatorType, char separatorData)
|
||||||
|
{
|
||||||
|
string data = $"{_map.GetType().Name}{separatorType}";
|
||||||
|
foreach (var car in _setCars.GetCars())
|
||||||
|
{
|
||||||
|
data += $"{car.GetInfo()}{separatorData}";
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
public void LoadData(string[] records)
|
||||||
|
{
|
||||||
|
foreach (var rec in records)
|
||||||
|
{
|
||||||
|
_setCars.Insert(DrawingObjectAirFighter.Create(rec) as T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setCars.Count - 1;
|
||||||
|
for (int i = 0; i < _setCars.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setCars[i] == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var car = _setCars[j];
|
||||||
|
if (car != null)
|
||||||
|
{
|
||||||
|
_setCars.Insert(car, i);
|
||||||
|
_setCars.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Sort(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
_setCars.SortSet(comparer);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
Brush brownBrush = new SolidBrush(Color.FromArgb(255, 211, 136, 84));
|
||||||
|
Brush greyBrush = new SolidBrush(Color.FromArgb(255, 160, 160, 160));
|
||||||
|
|
||||||
|
Point[] angar =
|
||||||
|
{
|
||||||
|
new(0, _pictureHeight ),
|
||||||
|
new(0, _pictureHeight / 4 ),
|
||||||
|
new(_pictureWidth / 2 , 9),
|
||||||
|
new(_pictureWidth, _pictureHeight / 4 ),
|
||||||
|
new(_pictureWidth, _pictureHeight ),
|
||||||
|
};
|
||||||
|
|
||||||
|
g.FillPolygon(brownBrush, angar);
|
||||||
|
g.FillRectangle(greyBrush, _pictureWidth / 6, (_pictureHeight * 5) / 12, (_pictureWidth * 2) / 3, (_pictureHeight * 7) / 12);
|
||||||
|
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{//линия рамзетки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
|
||||||
|
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||||
|
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawCars(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
foreach(var car in _setCars.GetCars())
|
||||||
|
{
|
||||||
|
int x = i % width;
|
||||||
|
int y = i / width;
|
||||||
|
|
||||||
|
car.SetObject((width - x - 1) * _placeSizeWidth, (height - y - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||||
|
car.DrawningObject(g);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
112
AirFighter/AirFighter/MapsCollection.cs
Normal file
112
AirFighter/AirFighter/MapsCollection.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, MapWithSetCarsGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||||
|
|
||||||
|
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
private char separatorDict = '|';
|
||||||
|
private char separatorData = ';';
|
||||||
|
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_mapStorages = new Dictionary<string, MapWithSetCarsGeneric<IDrawingObject, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название карты</param>
|
||||||
|
/// <param name="map">Карта</param>
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
bool check = _mapStorages.TryGetValue(name, out var value);
|
||||||
|
if (check) return;
|
||||||
|
|
||||||
|
_mapStorages[name] = new(_pictureWidth, _pictureHeight, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления
|
||||||
|
_mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
using (StreamWriter fs = new(filename))
|
||||||
|
{
|
||||||
|
fs.Write($"MapsCollection{Environment.NewLine}");
|
||||||
|
foreach (var storage in _mapStorages)
|
||||||
|
{
|
||||||
|
|
||||||
|
fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Файл не найден");
|
||||||
|
}
|
||||||
|
using (StreamReader fs = new(filename))
|
||||||
|
{
|
||||||
|
string current = fs.ReadLine();
|
||||||
|
if (!current.Contains("MapsCollection"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
throw new FileFormatException("Не правильный формат данных");
|
||||||
|
}
|
||||||
|
|
||||||
|
_mapStorages.Clear();
|
||||||
|
|
||||||
|
while ((current = fs.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
var elem = current.Split(separatorDict);
|
||||||
|
AbstractMap map = null;
|
||||||
|
switch (elem[1])
|
||||||
|
{
|
||||||
|
case "SimpleMap":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "MyMap":
|
||||||
|
map = new MyMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_mapStorages.Add(elem[0], new MapWithSetCarsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public MapWithSetCarsGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения объекта
|
||||||
|
bool check = _mapStorages.TryGetValue(ind, out var mapWithSet);
|
||||||
|
return mapWithSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
AirFighter/AirFighter/MyMap.cs
Normal file
79
AirFighter/AirFighter/MyMap.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class MyMap : AbstractMap
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка открытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < 20; ++i)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
|
||||||
|
GenerateMap(x, y, _random.Next(13, 23));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateMap(int x, int y, int depth)
|
||||||
|
{
|
||||||
|
if (depth <= 0) return;
|
||||||
|
bool check = false;
|
||||||
|
|
||||||
|
while (!check)
|
||||||
|
{
|
||||||
|
int deltaX = _random.Next(-1, 2);
|
||||||
|
int deltaY = _random.Next(-1, 2);
|
||||||
|
|
||||||
|
if (x + deltaX < 0 || x + deltaX >= 100) continue;
|
||||||
|
if (y + deltaY < 0 || y + deltaY >= 100) continue;
|
||||||
|
|
||||||
|
if (_map[y + deltaY, x + deltaX] == _barrier) depth--;
|
||||||
|
x += deltaX;
|
||||||
|
y += deltaY;
|
||||||
|
|
||||||
|
_map[y, x] = _barrier;
|
||||||
|
|
||||||
|
check = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GenerateMap(x, y, depth - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,8 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace AirFighter
|
namespace AirFighter
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -8,10 +13,30 @@ namespace AirFighter
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormAirFighter());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||||
|
{
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetCars>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<FormMapWithSetCars>()
|
||||||
|
.AddLogging(option =>
|
||||||
|
{
|
||||||
|
var config = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("loggerConfig.json")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(config).CreateLogger();
|
||||||
|
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
105
AirFighter/AirFighter/SetCarsGeneric.cs
Normal file
105
AirFighter/AirFighter/SetCarsGeneric.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class SetCarsGeneric<T>
|
||||||
|
where T : class, IEquatable<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Список объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly List<T> _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Count;
|
||||||
|
private readonly int _maxCount;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetCarsGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T>();
|
||||||
|
}
|
||||||
|
public int Insert(T car)
|
||||||
|
{
|
||||||
|
if (_places.Contains(car)) return -1;
|
||||||
|
// TODO вставка в начало набора
|
||||||
|
if (_places.Count == _maxCount) throw new StorageOverflowException(_maxCount);
|
||||||
|
_places.Insert(0, car);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
public int Insert(T car, int position)
|
||||||
|
{
|
||||||
|
if (_places.Contains(car)) return -1;
|
||||||
|
if (_places.Count == _maxCount) throw new StorageOverflowException(_maxCount);
|
||||||
|
_places.Insert(position, car);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if(position >= _maxCount || position >= _places.Count) throw new AircraftNotFoundException(position);
|
||||||
|
|
||||||
|
T res = _places[position];
|
||||||
|
_places.Remove(res);
|
||||||
|
|
||||||
|
if (res == null) throw new AircraftNotFoundException(position);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if(position < 0) return null;
|
||||||
|
if(position >= _places.Count) return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0) return;
|
||||||
|
if (position >= _places.Count) return;
|
||||||
|
// TODO вставка в список по позиции
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SortSet(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
if (comparer == null) return;
|
||||||
|
_places.Sort(comparer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T> GetCars()
|
||||||
|
{
|
||||||
|
foreach (var car in _places)
|
||||||
|
{
|
||||||
|
if (car != null)
|
||||||
|
{
|
||||||
|
yield return car;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
AirFighter/AirFighter/SimpleMap.cs
Normal file
54
AirFighter/AirFighter/SimpleMap.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class SimpleMap : AbstractMap
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка закрытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет участка открытого
|
||||||
|
/// </summary>
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||||
|
}
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
AirFighter/AirFighter/StorageOverflowException.cs
Normal file
13
AirFighter/AirFighter/StorageOverflowException.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
[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) { }
|
||||||
|
}
|
||||||
|
}
|
17
AirFighter/AirFighter/loggerConfig.json
Normal file
17
AirFighter/AirFighter/loggerConfig.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/log_.log",
|
||||||
|
"rollingInterval": "Day",
|
||||||
|
"outputTemplate": "{Level:u4}: {Message:lj} [{Timestamp:HH:mm:ss.fff}]{NewLine}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user