Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b23314bce | |||
| e3831212b6 | |||
| 57fd0ad585 | |||
| a913fca4df | |||
| 1dbafea6ea | |||
| 879c1e15ec | |||
| d622a4d68c | |||
| 42ba1341e8 | |||
| b919800295 | |||
| d8bb364702 | |||
| ab5748661d | |||
| e98de68fc0 | |||
| 87c4397967 | |||
| aa26d4ed74 | |||
| 635f2c9535 | |||
| f4460c4f86 | |||
| c5ab74952a | |||
| 89ec1ca650 | |||
| df1763d033 | |||
| 513c83543b | |||
| f114eaf924 | |||
| 7a0e613b8f | |||
| 046d6fa073 | |||
| dbfce5a591 | |||
| 23a70fbf75 | |||
| 7a6735b1a2 | |||
| e769920644 | |||
| e362903c4d | |||
| cd1bc62668 | |||
| 3b037b5de0 | |||
| 21d89cec7b | |||
| 49c93d0ada | |||
| bc45f4ef20 | |||
| cc0c33e907 | |||
| 7ad72d90a7 | |||
| 70102bcf7d | |||
| f8dfa86e69 | |||
| 4dab796efa | |||
| 8efe9be84a | |||
| cda44e6ec9 | |||
| 3cc8122f19 |
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[,] _map = null;
|
||||
@@ -37,16 +37,12 @@ namespace AirFighter
|
||||
{
|
||||
int CollisionFlag = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
Size objSize1 = new Size(100,100);
|
||||
|
||||
//COLLISION CHECK
|
||||
if (direction == Direction.Up)
|
||||
{
|
||||
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
@@ -123,12 +119,7 @@ namespace AirFighter
|
||||
{
|
||||
Point LeftTop = new Point((int)(_drawingObject.GetCurrentPosition().Left + _drawingObject.Step), (int)_drawingObject.GetCurrentPosition().Top);
|
||||
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||
|
||||
|
||||
|
||||
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||
|
||||
|
||||
if (objectRect.IntersectsWith(rectBarrier))
|
||||
{
|
||||
CollisionFlag = 1;
|
||||
@@ -175,11 +166,8 @@ namespace AirFighter
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private Bitmap DrawMapWithObject()
|
||||
@@ -208,14 +196,51 @@ namespace AirFighter
|
||||
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 (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var diffMap = other;
|
||||
if (diffMap == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (diffMap._height != _height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (diffMap._width != _width)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (diffMap._size_x != _size_x)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (diffMap._size_y != _size_y )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (diffMap._map[i, j] != _map[j, i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,27 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" 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.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>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
13
AirFighter/AirFighterForm.Designer.cs
generated
13
AirFighter/AirFighterForm.Designer.cs
generated
@@ -39,6 +39,7 @@
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModification = new System.Windows.Forms.Button();
|
||||
this.SelectButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||
this.statusStripAircraft.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@@ -152,11 +153,22 @@
|
||||
this.buttonCreateModification.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModification.Click += new System.EventHandler(this.buttonCreateModification_Click);
|
||||
//
|
||||
// SelectButton
|
||||
//
|
||||
this.SelectButton.Location = new System.Drawing.Point(551, 390);
|
||||
this.SelectButton.Name = "SelectButton";
|
||||
this.SelectButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.SelectButton.TabIndex = 8;
|
||||
this.SelectButton.Text = "Select";
|
||||
this.SelectButton.UseVisualStyleBackColor = true;
|
||||
this.SelectButton.Click += new System.EventHandler(this.SelectButton_Click);
|
||||
//
|
||||
// AirFighterForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.SelectButton);
|
||||
this.Controls.Add(this.buttonCreateModification);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@@ -188,5 +200,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateModification;
|
||||
private Button SelectButton;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ namespace AirFighter
|
||||
{
|
||||
private DrawingAircraft _aircraft;
|
||||
|
||||
public DrawingAircraft SelectedAircraft { get; private set; }
|
||||
|
||||
public AirFighterForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -17,7 +19,6 @@ namespace AirFighter
|
||||
pictureBoxAirFighter.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
@@ -28,14 +29,21 @@ namespace AirFighter
|
||||
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
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;
|
||||
}
|
||||
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
color);
|
||||
SetData();
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
@@ -75,14 +83,34 @@ namespace AirFighter
|
||||
|
||||
private void buttonCreateModification_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_aircraft = new DrawingMilitaryAircraft(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)));
|
||||
|
||||
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;
|
||||
}
|
||||
_aircraft = new DrawingMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
|
||||
2)));
|
||||
SetData();
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void SelectButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAircraft = _aircraft;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
77
AirFighter/AircraftCompareByColor.cs
Normal file
77
AirFighter/AircraftCompareByColor.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
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)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xAircraft = x as DrawingObjectAircraft;
|
||||
var yAircraft = y as DrawingObjectAircraft;
|
||||
if (xAircraft == null && yAircraft == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xAircraft == null && yAircraft != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xAircraft != null && yAircraft == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (xAircraft.GetAircraft.Plane.BodyColor.R.CompareTo(yAircraft.GetAircraft.Plane.BodyColor.R) != 0)
|
||||
{
|
||||
return xAircraft.GetAircraft.Plane.BodyColor.R.CompareTo(yAircraft.GetAircraft.Plane.BodyColor.R);
|
||||
}
|
||||
if (xAircraft.GetAircraft.Plane.BodyColor.G.CompareTo(yAircraft.GetAircraft.Plane.BodyColor.G) != 0)
|
||||
{
|
||||
return xAircraft.GetAircraft.Plane.BodyColor.G.CompareTo(yAircraft.GetAircraft.Plane.BodyColor.G);
|
||||
}
|
||||
if (xAircraft.GetAircraft.Plane.BodyColor.B.CompareTo(yAircraft.GetAircraft.Plane.BodyColor.B) != 0)
|
||||
{
|
||||
return xAircraft.GetAircraft.Plane.BodyColor.B.CompareTo(yAircraft.GetAircraft.Plane.BodyColor.B);
|
||||
}
|
||||
|
||||
if (xAircraft.GetAircraft.Plane is EntityMilitaryAircraft xMilitaryAircraft && yAircraft.GetAircraft.Plane is EntityMilitaryAircraft yMilitaryAircraft)
|
||||
{
|
||||
if (xMilitaryAircraft.ExtraColor.R.CompareTo(yMilitaryAircraft.ExtraColor.R) != 0)
|
||||
{
|
||||
return xMilitaryAircraft.ExtraColor.R.CompareTo(yMilitaryAircraft.ExtraColor.R);
|
||||
}
|
||||
if (xMilitaryAircraft.ExtraColor.G.CompareTo(yMilitaryAircraft.ExtraColor.G) != 0)
|
||||
{
|
||||
return xMilitaryAircraft.ExtraColor.G.CompareTo(yMilitaryAircraft.ExtraColor.G);
|
||||
}
|
||||
if (xMilitaryAircraft.ExtraColor.B.CompareTo(yMilitaryAircraft.ExtraColor.B) != 0)
|
||||
{
|
||||
return xMilitaryAircraft.ExtraColor.B.CompareTo(yMilitaryAircraft.ExtraColor.B);
|
||||
}
|
||||
}
|
||||
|
||||
var speedCompare = xAircraft.GetAircraft.Plane.Speed.CompareTo(yAircraft.GetAircraft.Plane.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xAircraft.GetAircraft.Plane.Weight.CompareTo(yAircraft.GetAircraft.Plane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
AirFighter/AircraftCompareByType.cs
Normal file
55
AirFighter/AircraftCompareByType.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xAircraft = x as DrawingObjectAircraft;
|
||||
var yAircraft = y as DrawingObjectAircraft;
|
||||
if (xAircraft == null && yAircraft == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xAircraft == null && yAircraft != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xAircraft != null && yAircraft == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xAircraft.GetAircraft.GetType().Name != yAircraft.GetAircraft.GetType().Name)
|
||||
{
|
||||
if (xAircraft.GetAircraft.GetType().Name == "DrawingAircraft")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xAircraft.GetAircraft.Plane.Speed.CompareTo(yAircraft.GetAircraft.Plane.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xAircraft.GetAircraft.Plane.Weight.CompareTo(yAircraft.GetAircraft.Plane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
AirFighter/AircraftDelegate.cs
Normal file
10
AirFighter/AircraftDelegate.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
public delegate void AircraftDelegate(DrawingAircraft aircraft);
|
||||
}
|
||||
19
AirFighter/AircraftNotFoundException.cs
Normal file
19
AirFighter/AircraftNotFoundException.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class AircraftNotFoundException : ApplicationException
|
||||
{
|
||||
public AircraftNotFoundException() : base() { }
|
||||
public AircraftNotFoundException(string message) : base(message) { }
|
||||
public AircraftNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
public AircraftNotFoundException(SerializationInfo info, StreamingContext contex) : base(info,contex) { }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up =1,
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawingAircraft
|
||||
public class DrawingAircraft
|
||||
{
|
||||
public EntityAircraft Plane { get; protected set; }
|
||||
|
||||
@@ -140,8 +140,6 @@ namespace AirFighter
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Aircraft Body
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brWhite = new SolidBrush(Plane.BodyColor);
|
||||
@@ -150,7 +148,6 @@ namespace AirFighter
|
||||
g.DrawRectangle(pen,_startPosX + 20, _startPosY + 45, 80, 14);
|
||||
|
||||
//Wings
|
||||
|
||||
GraphicsPath pathWing1 = new GraphicsPath();
|
||||
|
||||
Point point1B = new Point((int)(_startPosX + 50), (int)(_startPosY + 45));
|
||||
@@ -163,7 +160,6 @@ namespace AirFighter
|
||||
g.DrawPath(pen, pathWing1);
|
||||
g.FillPath(brWhite, pathWing1);
|
||||
|
||||
|
||||
GraphicsPath pathWing2 = new GraphicsPath();
|
||||
|
||||
Point point1B2 = new Point((int)(_startPosX + 50), (int)(_startPosY + 60));
|
||||
@@ -242,6 +238,11 @@ namespace AirFighter
|
||||
|
||||
}
|
||||
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
(Plane as EntityAircraft).setColor(color);
|
||||
}
|
||||
|
||||
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _aircraftWidth - 1, _startPosY + _aircraftHeight - 1);
|
||||
|
||||
@@ -26,9 +26,6 @@ namespace AirFighter
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
|
||||
|
||||
|
||||
if (militaryAircraft.ExtraWings)
|
||||
{
|
||||
GraphicsPath pathExtraWing1 = new GraphicsPath();
|
||||
@@ -57,8 +54,6 @@ namespace AirFighter
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (militaryAircraft.Rockets)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 30,17,4);
|
||||
@@ -87,12 +82,13 @@ namespace AirFighter
|
||||
pathRocketHead2.AddLines(pointsExtraRocketHead2);
|
||||
g.DrawPath(pen, pathRocketHead2);
|
||||
g.FillPath(extraBrush, pathRocketHead2);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void SetExtraColor(Color color)
|
||||
{
|
||||
(Plane as EntityMilitaryAircraft).setColor(color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace AirFighter
|
||||
|
||||
public float Step => _aircraft.Plane?.Step ?? 0;
|
||||
|
||||
public DrawingAircraft GetAircraft => _aircraft;
|
||||
|
||||
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _aircraft?.GetCurrentPosition() ?? default;
|
||||
@@ -43,6 +45,59 @@ namespace AirFighter
|
||||
Random rnd = new Random();
|
||||
int x = rnd.Next(0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
public string ReceiveInfo() => _aircraft?.ReceiveDataForSaving();
|
||||
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectAircraft(data.CreateDrawingAircraft());
|
||||
|
||||
public bool Equals(IDrawingObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var diffAircraft = other as DrawingObjectAircraft;
|
||||
if (diffAircraft == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var aircraft = _aircraft.Plane;
|
||||
var diffAircraftCast = diffAircraft._aircraft.Plane;
|
||||
if (aircraft.Speed != diffAircraftCast.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (aircraft.Weight != diffAircraftCast.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (aircraft.BodyColor != diffAircraftCast.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aircraft is EntityMilitaryAircraft || diffAircraftCast is EntityMilitaryAircraft)
|
||||
{
|
||||
if (aircraft is EntityMilitaryAircraft && diffAircraftCast is EntityMilitaryAircraft)
|
||||
{
|
||||
if ((aircraft as EntityMilitaryAircraft).ExtraColor != (diffAircraftCast as EntityMilitaryAircraft).ExtraColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((aircraft as EntityMilitaryAircraft).Rockets != (diffAircraftCast as EntityMilitaryAircraft).Rockets)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((aircraft as EntityMilitaryAircraft).ExtraWings != (diffAircraftCast as EntityMilitaryAircraft).ExtraWings)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class EntityAircraft
|
||||
public class EntityAircraft
|
||||
{
|
||||
public int Speed
|
||||
{
|
||||
@@ -28,14 +28,18 @@ namespace AirFighter
|
||||
|
||||
//=> оператор подобный return
|
||||
public float Step => Speed * 100 / Weight;
|
||||
|
||||
|
||||
|
||||
public EntityAircraft(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public void setColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,17 +10,20 @@ namespace AirFighter
|
||||
{
|
||||
public Color ExtraColor { get; private set; }
|
||||
|
||||
|
||||
public bool Rockets { get; private set; }
|
||||
|
||||
public bool ExtraWings { get; private set; }
|
||||
|
||||
|
||||
public EntityMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, bool rockets, bool extraWings) : base(speed, weight, bodyColor)
|
||||
{
|
||||
ExtraColor = extraColor;
|
||||
Rockets = rockets;
|
||||
ExtraWings = extraWings;
|
||||
}
|
||||
|
||||
public new void setColor(Color color)
|
||||
{
|
||||
ExtraColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
AirFighter/ExtensionAircraft.cs
Normal file
40
AirFighter/ExtensionAircraft.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal static class ExtensionAircraft
|
||||
{
|
||||
private static readonly char _separatorForObjects = ':';
|
||||
|
||||
public static DrawingAircraft CreateDrawingAircraft(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObjects);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingAircraft(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawingMilitaryAircraft(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 ReceiveDataForSaving(this DrawingAircraft drawingAircraft)
|
||||
{
|
||||
var aircraft = drawingAircraft.Plane;
|
||||
var str = $"{aircraft.Speed}{_separatorForObjects}{aircraft.Weight}{_separatorForObjects}{aircraft.BodyColor.Name}";
|
||||
if (aircraft is not EntityMilitaryAircraft militaryAircraft)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{_separatorForObjects}{militaryAircraft.ExtraColor.Name}{_separatorForObjects}{militaryAircraft.ExtraWings}{_separatorForObjects}{militaryAircraft.Rockets}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
375
AirFighter/FormAircraftConfig.Designer.cs
generated
Normal file
375
AirFighter/FormAircraftConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,375 @@
|
||||
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.labelMilitary = new System.Windows.Forms.Label();
|
||||
this.labelSimple = new System.Windows.Forms.Label();
|
||||
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
this.panelOrange = new System.Windows.Forms.Panel();
|
||||
this.panelAqua = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.panelGold = new System.Windows.Forms.Panel();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.checkBoxExtraWings = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxRockets = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.panelObject = new System.Windows.Forms.Panel();
|
||||
this.labelExtraColor = new System.Windows.Forms.Label();
|
||||
this.labelColor = new System.Windows.Forms.Label();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.groupBoxConfig.SuspendLayout();
|
||||
this.groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.panelObject.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxConfig
|
||||
//
|
||||
this.groupBoxConfig.Controls.Add(this.labelMilitary);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSimple);
|
||||
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxExtraWings);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxRockets);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||
this.groupBoxConfig.Size = new System.Drawing.Size(447, 245);
|
||||
this.groupBoxConfig.TabIndex = 0;
|
||||
this.groupBoxConfig.TabStop = false;
|
||||
this.groupBoxConfig.Text = "Config";
|
||||
//
|
||||
// labelMilitary
|
||||
//
|
||||
this.labelMilitary.AllowDrop = true;
|
||||
this.labelMilitary.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelMilitary.Location = new System.Drawing.Point(319, 177);
|
||||
this.labelMilitary.Name = "labelMilitary";
|
||||
this.labelMilitary.Size = new System.Drawing.Size(106, 33);
|
||||
this.labelMilitary.TabIndex = 8;
|
||||
this.labelMilitary.Text = "Military";
|
||||
this.labelMilitary.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelMilitary.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
|
||||
this.labelMilitary.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
|
||||
this.labelMilitary.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label_MouseDown);
|
||||
//
|
||||
// labelSimple
|
||||
//
|
||||
this.labelSimple.AllowDrop = true;
|
||||
this.labelSimple.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimple.Location = new System.Drawing.Point(191, 177);
|
||||
this.labelSimple.Name = "labelSimple";
|
||||
this.labelSimple.Size = new System.Drawing.Size(106, 33);
|
||||
this.labelSimple.TabIndex = 7;
|
||||
this.labelSimple.Text = "Simple";
|
||||
this.labelSimple.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimple.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
|
||||
this.labelSimple.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
|
||||
this.labelSimple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label_MouseDown);
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
this.groupBoxColors.Controls.Add(this.panelOrange);
|
||||
this.groupBoxColors.Controls.Add(this.panelAqua);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||
this.groupBoxColors.Controls.Add(this.panelGold);
|
||||
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||
this.groupBoxColors.Location = new System.Drawing.Point(197, 22);
|
||||
this.groupBoxColors.Name = "groupBoxColors";
|
||||
this.groupBoxColors.Size = new System.Drawing.Size(244, 142);
|
||||
this.groupBoxColors.TabIndex = 6;
|
||||
this.groupBoxColors.TabStop = false;
|
||||
this.groupBoxColors.Text = "Colors";
|
||||
//
|
||||
// panelOrange
|
||||
//
|
||||
this.panelOrange.BackColor = System.Drawing.Color.Orange;
|
||||
this.panelOrange.Location = new System.Drawing.Point(184, 78);
|
||||
this.panelOrange.Name = "panelOrange";
|
||||
this.panelOrange.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelOrange.TabIndex = 7;
|
||||
this.panelOrange.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelAqua
|
||||
//
|
||||
this.panelAqua.BackColor = System.Drawing.Color.Aqua;
|
||||
this.panelAqua.Location = new System.Drawing.Point(184, 22);
|
||||
this.panelAqua.Name = "panelAqua";
|
||||
this.panelAqua.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelAqua.TabIndex = 3;
|
||||
this.panelAqua.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(128, 78);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelBlue.TabIndex = 6;
|
||||
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.YellowGreen;
|
||||
this.panelGreen.Location = new System.Drawing.Point(128, 22);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelGreen.TabIndex = 2;
|
||||
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(72, 78);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelRed.TabIndex = 5;
|
||||
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelGold
|
||||
//
|
||||
this.panelGold.BackColor = System.Drawing.Color.Gold;
|
||||
this.panelGold.Location = new System.Drawing.Point(72, 22);
|
||||
this.panelGold.Name = "panelGold";
|
||||
this.panelGold.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelGold.TabIndex = 1;
|
||||
this.panelGold.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(16, 78);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelPurple.TabIndex = 4;
|
||||
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(16, 22);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelBlack.TabIndex = 0;
|
||||
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// checkBoxExtraWings
|
||||
//
|
||||
this.checkBoxExtraWings.AutoSize = true;
|
||||
this.checkBoxExtraWings.Location = new System.Drawing.Point(16, 145);
|
||||
this.checkBoxExtraWings.Name = "checkBoxExtraWings";
|
||||
this.checkBoxExtraWings.Size = new System.Drawing.Size(145, 19);
|
||||
this.checkBoxExtraWings.TabIndex = 5;
|
||||
this.checkBoxExtraWings.Text = "Extra wings availability";
|
||||
this.checkBoxExtraWings.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxRockets
|
||||
//
|
||||
this.checkBoxRockets.AutoSize = true;
|
||||
this.checkBoxRockets.Location = new System.Drawing.Point(16, 120);
|
||||
this.checkBoxRockets.Name = "checkBoxRockets";
|
||||
this.checkBoxRockets.Size = new System.Drawing.Size(121, 19);
|
||||
this.checkBoxRockets.TabIndex = 4;
|
||||
this.checkBoxRockets.Text = "Missile availability";
|
||||
this.checkBoxRockets.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(64, 73);
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(73, 23);
|
||||
this.numericUpDownWeight.TabIndex = 3;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(16, 75);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(48, 15);
|
||||
this.labelWeight.TabIndex = 2;
|
||||
this.labelWeight.Text = "Weight:";
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(64, 36);
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(73, 23);
|
||||
this.numericUpDownSpeed.TabIndex = 1;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(16, 38);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(42, 15);
|
||||
this.labelSpeed.TabIndex = 0;
|
||||
this.labelSpeed.Text = "Speed:";
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(14, 44);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(188, 153);
|
||||
this.pictureBoxObject.TabIndex = 1;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
this.panelObject.AllowDrop = true;
|
||||
this.panelObject.Controls.Add(this.labelExtraColor);
|
||||
this.panelObject.Controls.Add(this.labelColor);
|
||||
this.panelObject.Controls.Add(this.pictureBoxObject);
|
||||
this.panelObject.Location = new System.Drawing.Point(474, 12);
|
||||
this.panelObject.Name = "panelObject";
|
||||
this.panelObject.Size = new System.Drawing.Size(217, 210);
|
||||
this.panelObject.TabIndex = 2;
|
||||
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
|
||||
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
|
||||
//
|
||||
// labelExtraColor
|
||||
//
|
||||
this.labelExtraColor.AllowDrop = true;
|
||||
this.labelExtraColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelExtraColor.Location = new System.Drawing.Point(114, 10);
|
||||
this.labelExtraColor.Name = "labelExtraColor";
|
||||
this.labelExtraColor.Size = new System.Drawing.Size(88, 31);
|
||||
this.labelExtraColor.TabIndex = 3;
|
||||
this.labelExtraColor.Text = "Extra color";
|
||||
this.labelExtraColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelExtraColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelExtraColor_DragDrop);
|
||||
this.labelExtraColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelExtraColor_DragEnter);
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
this.labelColor.AllowDrop = true;
|
||||
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelColor.Location = new System.Drawing.Point(14, 10);
|
||||
this.labelColor.Name = "labelColor";
|
||||
this.labelColor.Size = new System.Drawing.Size(89, 31);
|
||||
this.labelColor.TabIndex = 2;
|
||||
this.labelColor.Text = "Main color";
|
||||
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
|
||||
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(474, 228);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(103, 29);
|
||||
this.buttonAdd.TabIndex = 3;
|
||||
this.buttonAdd.Text = "Add";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(588, 228);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(103, 29);
|
||||
this.buttonCancel.TabIndex = 4;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormAircraftConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(708, 269);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.panelObject);
|
||||
this.Controls.Add(this.groupBoxConfig);
|
||||
this.Name = "FormAircraftConfig";
|
||||
this.Text = "Aircraft creation";
|
||||
this.groupBoxConfig.ResumeLayout(false);
|
||||
this.groupBoxConfig.PerformLayout();
|
||||
this.groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.panelObject.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxConfig;
|
||||
private CheckBox checkBoxExtraWings;
|
||||
private CheckBox checkBoxRockets;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private Label labelWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelSpeed;
|
||||
private Label labelMilitary;
|
||||
private Label labelSimple;
|
||||
private GroupBox groupBoxColors;
|
||||
private Panel panelOrange;
|
||||
private Panel panelAqua;
|
||||
private Panel panelBlue;
|
||||
private Panel panelGreen;
|
||||
private Panel panelRed;
|
||||
private Panel panelGold;
|
||||
private Panel panelPurple;
|
||||
private Panel panelBlack;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Panel panelObject;
|
||||
private Label labelExtraColor;
|
||||
private Label labelColor;
|
||||
private Button buttonAdd;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
||||
140
AirFighter/FormAircraftConfig.cs
Normal file
140
AirFighter/FormAircraftConfig.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
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 FormAircraftConfig : Form
|
||||
{
|
||||
DrawingAircraft _aircraft = null;
|
||||
|
||||
private event AircraftDelegate EventAddAircraft;
|
||||
|
||||
public FormAircraftConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelAqua.MouseDown += PanelColor_MouseDown;
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
panelGold.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelOrange.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (object sender, EventArgs e) => Close();
|
||||
}
|
||||
|
||||
private void DrawAircraft()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_aircraft?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
_aircraft?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
|
||||
public void AddEvent(AircraftDelegate ev)
|
||||
{
|
||||
if (EventAddAircraft == null)
|
||||
{
|
||||
EventAddAircraft = new AircraftDelegate(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddAircraft += ev;
|
||||
}
|
||||
}
|
||||
|
||||
private void panelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimple":
|
||||
{
|
||||
_aircraft = new DrawingAircraft((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||||
}
|
||||
break;
|
||||
case "labelMilitary":
|
||||
{
|
||||
_aircraft = new DrawingMilitaryAircraft((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White,Color.Black,checkBoxRockets.Checked,checkBoxExtraWings.Checked);
|
||||
}
|
||||
break;
|
||||
}
|
||||
DrawAircraft();
|
||||
}
|
||||
|
||||
private void panelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor,DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void labelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
_aircraft.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||
DrawAircraft();
|
||||
}
|
||||
|
||||
private void labelExtraColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void labelExtraColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_aircraft is DrawingMilitaryAircraft)
|
||||
{
|
||||
(_aircraft as DrawingMilitaryAircraft).SetExtraColor((Color)e.Data.GetData(typeof(Color)));
|
||||
|
||||
}
|
||||
DrawAircraft();
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddAircraft?.Invoke(_aircraft);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void label_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label).DoDragDrop((sender as Label).Name,DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStripAircraft.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
207
AirFighter/FormMap.Designer.cs
generated
207
AirFighter/FormMap.Designer.cs
generated
@@ -1,207 +0,0 @@
|
||||
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.pictureBoxAirFighter = new System.Windows.Forms.PictureBox();
|
||||
this.statusStripAircraft = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModification = new System.Windows.Forms.Button();
|
||||
this.comboBoxMapSelection = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||
this.statusStripAircraft.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxAirFighter
|
||||
//
|
||||
this.pictureBoxAirFighter.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxAirFighter.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxAirFighter.Name = "pictureBoxAirFighter";
|
||||
this.pictureBoxAirFighter.Size = new System.Drawing.Size(800, 428);
|
||||
this.pictureBoxAirFighter.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxAirFighter.TabIndex = 0;
|
||||
this.pictureBoxAirFighter.TabStop = false;
|
||||
//
|
||||
// statusStripAircraft
|
||||
//
|
||||
this.statusStripAircraft.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusSpeed,
|
||||
this.toolStripStatusWeight,
|
||||
this.toolStripStatusBodyColor});
|
||||
this.statusStripAircraft.Location = new System.Drawing.Point(0, 428);
|
||||
this.statusStripAircraft.Name = "statusStripAircraft";
|
||||
this.statusStripAircraft.Size = new System.Drawing.Size(800, 22);
|
||||
this.statusStripAircraft.TabIndex = 1;
|
||||
//
|
||||
// toolStripStatusSpeed
|
||||
//
|
||||
this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
|
||||
this.toolStripStatusSpeed.Size = new System.Drawing.Size(42, 17);
|
||||
this.toolStripStatusSpeed.Text = "Speed:";
|
||||
//
|
||||
// toolStripStatusWeight
|
||||
//
|
||||
this.toolStripStatusWeight.Name = "toolStripStatusWeight";
|
||||
this.toolStripStatusWeight.Size = new System.Drawing.Size(48, 17);
|
||||
this.toolStripStatusWeight.Text = "Weight:";
|
||||
//
|
||||
// toolStripStatusBodyColor
|
||||
//
|
||||
this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor";
|
||||
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(66, 17);
|
||||
this.toolStripStatusBodyColor.Text = "BodyColor:";
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 389);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Create";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.ArrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(702, 346);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 3;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.ArrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(666, 382);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 4;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.ArrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(738, 382);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.ArrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(702, 382);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 6;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonCreateModification
|
||||
//
|
||||
this.buttonCreateModification.Location = new System.Drawing.Point(103, 389);
|
||||
this.buttonCreateModification.Name = "buttonCreateModification";
|
||||
this.buttonCreateModification.Size = new System.Drawing.Size(110, 23);
|
||||
this.buttonCreateModification.TabIndex = 7;
|
||||
this.buttonCreateModification.Text = "Modification";
|
||||
this.buttonCreateModification.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModification.Click += new System.EventHandler(this.buttonCreateModification_Click);
|
||||
//
|
||||
// comboBoxMapSelection
|
||||
//
|
||||
this.comboBoxMapSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxMapSelection.FormattingEnabled = true;
|
||||
this.comboBoxMapSelection.Items.AddRange(new object[] {
|
||||
"1. Simple map",
|
||||
"2. NightSky map"});
|
||||
this.comboBoxMapSelection.Location = new System.Drawing.Point(12, 12);
|
||||
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
|
||||
this.comboBoxMapSelection.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboBoxMapSelection.TabIndex = 8;
|
||||
this.comboBoxMapSelection.SelectedIndexChanged += new System.EventHandler(this.comboBoxMapSelection_SelectedIndexChanged);
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.comboBoxMapSelection);
|
||||
this.Controls.Add(this.buttonCreateModification);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxAirFighter);
|
||||
this.Controls.Add(this.statusStripAircraft);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "Map";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).EndInit();
|
||||
this.statusStripAircraft.ResumeLayout(false);
|
||||
this.statusStripAircraft.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAirFighter;
|
||||
private StatusStrip statusStripAircraft;
|
||||
private ToolStripStatusLabel toolStripStatusSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusWeight;
|
||||
private ToolStripStatusLabel toolStripStatusBodyColor;
|
||||
private Button buttonCreate;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateModification;
|
||||
private ComboBox comboBoxMapSelection;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
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 AbstractMap _abstractMap;
|
||||
public FormMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
private void SetData(DrawingAircraft plane)
|
||||
{
|
||||
toolStripStatusSpeed.Text = $"Speed: {plane.Plane.Speed}";
|
||||
toolStripStatusWeight.Text = $"Weight: {plane.Plane.Weight}";
|
||||
toolStripStatusBodyColor.Text = $"BodyColor: {plane.Plane.BodyColor.Name}";
|
||||
pictureBoxAirFighter.Image = _abstractMap.CreateMap(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height, new DrawingObjectAircraft(plane) );
|
||||
}
|
||||
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
var plane = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
SetData(plane);
|
||||
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
{
|
||||
dir = Direction.Up;
|
||||
}
|
||||
break;
|
||||
case "buttonDown":
|
||||
{
|
||||
dir = Direction.Down;
|
||||
}
|
||||
break;
|
||||
case "buttonLeft":
|
||||
{
|
||||
dir = Direction.Left;
|
||||
}
|
||||
break;
|
||||
case "buttonRight":
|
||||
{
|
||||
dir = Direction.Right;
|
||||
}
|
||||
break;
|
||||
}
|
||||
pictureBoxAirFighter.Image = _abstractMap?.MoveObject(dir);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void buttonCreateModification_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
var plane = new DrawingMilitaryAircraft(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(plane);
|
||||
|
||||
}
|
||||
|
||||
private void comboBoxMapSelection_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxMapSelection.Text)
|
||||
{
|
||||
case "1. Simple map":
|
||||
{
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
break;
|
||||
case "2. NightSky map":
|
||||
{
|
||||
_abstractMap = new NightSkyMap();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
364
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
Normal file
364
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
Normal file
@@ -0,0 +1,364 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
partial class FormMapWithSetAircrafts
|
||||
{
|
||||
/// <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.PanelGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.SortByColorButton = new System.Windows.Forms.Button();
|
||||
this.SortByTypeButton = new System.Windows.Forms.Button();
|
||||
this.MapsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.DeleteMapButton = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.AddMapButton = new System.Windows.Forms.Button();
|
||||
this.newMapTextBox = new System.Windows.Forms.TextBox();
|
||||
this.comboBoxMapSelection = new System.Windows.Forms.ComboBox();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.ShowMapButton = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.ShowHangarButton = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.DeleteAircraftButton = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPostion = new System.Windows.Forms.MaskedTextBox();
|
||||
this.AddAircraftButton = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.fileToolStripMenuItem = 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.PanelGroupBox.SuspendLayout();
|
||||
this.MapsGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// PanelGroupBox
|
||||
//
|
||||
this.PanelGroupBox.Controls.Add(this.SortByColorButton);
|
||||
this.PanelGroupBox.Controls.Add(this.SortByTypeButton);
|
||||
this.PanelGroupBox.Controls.Add(this.MapsGroupBox);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonDown);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonRight);
|
||||
this.PanelGroupBox.Controls.Add(this.ShowMapButton);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonLeft);
|
||||
this.PanelGroupBox.Controls.Add(this.ShowHangarButton);
|
||||
this.PanelGroupBox.Controls.Add(this.buttonUp);
|
||||
this.PanelGroupBox.Controls.Add(this.DeleteAircraftButton);
|
||||
this.PanelGroupBox.Controls.Add(this.maskedTextBoxPostion);
|
||||
this.PanelGroupBox.Controls.Add(this.AddAircraftButton);
|
||||
this.PanelGroupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.PanelGroupBox.Location = new System.Drawing.Point(672, 24);
|
||||
this.PanelGroupBox.Name = "PanelGroupBox";
|
||||
this.PanelGroupBox.Size = new System.Drawing.Size(218, 702);
|
||||
this.PanelGroupBox.TabIndex = 0;
|
||||
this.PanelGroupBox.TabStop = false;
|
||||
this.PanelGroupBox.Text = "Function panel";
|
||||
//
|
||||
// SortByColorButton
|
||||
//
|
||||
this.SortByColorButton.Location = new System.Drawing.Point(12, 339);
|
||||
this.SortByColorButton.Name = "SortByColorButton";
|
||||
this.SortByColorButton.Size = new System.Drawing.Size(176, 36);
|
||||
this.SortByColorButton.TabIndex = 17;
|
||||
this.SortByColorButton.Text = "Sort by color";
|
||||
this.SortByColorButton.UseVisualStyleBackColor = true;
|
||||
this.SortByColorButton.Click += new System.EventHandler(this.SortByColorButton_Click);
|
||||
//
|
||||
// SortByTypeButton
|
||||
//
|
||||
this.SortByTypeButton.Location = new System.Drawing.Point(12, 297);
|
||||
this.SortByTypeButton.Name = "SortByTypeButton";
|
||||
this.SortByTypeButton.Size = new System.Drawing.Size(176, 36);
|
||||
this.SortByTypeButton.TabIndex = 16;
|
||||
this.SortByTypeButton.Text = "Sort by type";
|
||||
this.SortByTypeButton.UseVisualStyleBackColor = true;
|
||||
this.SortByTypeButton.Click += new System.EventHandler(this.SortByTypeButton_Click);
|
||||
//
|
||||
// MapsGroupBox
|
||||
//
|
||||
this.MapsGroupBox.Controls.Add(this.DeleteMapButton);
|
||||
this.MapsGroupBox.Controls.Add(this.listBoxMaps);
|
||||
this.MapsGroupBox.Controls.Add(this.AddMapButton);
|
||||
this.MapsGroupBox.Controls.Add(this.newMapTextBox);
|
||||
this.MapsGroupBox.Controls.Add(this.comboBoxMapSelection);
|
||||
this.MapsGroupBox.Location = new System.Drawing.Point(6, 22);
|
||||
this.MapsGroupBox.Name = "MapsGroupBox";
|
||||
this.MapsGroupBox.Size = new System.Drawing.Size(188, 260);
|
||||
this.MapsGroupBox.TabIndex = 15;
|
||||
this.MapsGroupBox.TabStop = false;
|
||||
this.MapsGroupBox.Text = "Maps";
|
||||
//
|
||||
// DeleteMapButton
|
||||
//
|
||||
this.DeleteMapButton.Location = new System.Drawing.Point(6, 222);
|
||||
this.DeleteMapButton.Name = "DeleteMapButton";
|
||||
this.DeleteMapButton.Size = new System.Drawing.Size(176, 32);
|
||||
this.DeleteMapButton.TabIndex = 13;
|
||||
this.DeleteMapButton.Text = "Delete map";
|
||||
this.DeleteMapButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteMapButton.Click += new System.EventHandler(this.DeleteMapButton_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 15;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(8, 122);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(174, 94);
|
||||
this.listBoxMaps.TabIndex = 12;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// AddMapButton
|
||||
//
|
||||
this.AddMapButton.Location = new System.Drawing.Point(6, 81);
|
||||
this.AddMapButton.Name = "AddMapButton";
|
||||
this.AddMapButton.Size = new System.Drawing.Size(176, 35);
|
||||
this.AddMapButton.TabIndex = 11;
|
||||
this.AddMapButton.Text = "Add map";
|
||||
this.AddMapButton.UseVisualStyleBackColor = true;
|
||||
this.AddMapButton.Click += new System.EventHandler(this.AddMapButton_Click);
|
||||
//
|
||||
// newMapTextBox
|
||||
//
|
||||
this.newMapTextBox.Location = new System.Drawing.Point(6, 22);
|
||||
this.newMapTextBox.Name = "newMapTextBox";
|
||||
this.newMapTextBox.Size = new System.Drawing.Size(176, 23);
|
||||
this.newMapTextBox.TabIndex = 10;
|
||||
//
|
||||
// comboBoxMapSelection
|
||||
//
|
||||
this.comboBoxMapSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxMapSelection.FormattingEnabled = true;
|
||||
this.comboBoxMapSelection.Items.AddRange(new object[] {
|
||||
"1. Simple map",
|
||||
"2. NightSky map"});
|
||||
this.comboBoxMapSelection.Location = new System.Drawing.Point(6, 51);
|
||||
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
|
||||
this.comboBoxMapSelection.Size = new System.Drawing.Size(176, 23);
|
||||
this.comboBoxMapSelection.TabIndex = 9;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.ArrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(99, 660);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 11;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.ArrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(135, 660);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 10;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ShowMapButton
|
||||
//
|
||||
this.ShowMapButton.Location = new System.Drawing.Point(12, 578);
|
||||
this.ShowMapButton.Name = "ShowMapButton";
|
||||
this.ShowMapButton.Size = new System.Drawing.Size(182, 36);
|
||||
this.ShowMapButton.TabIndex = 14;
|
||||
this.ShowMapButton.Text = "Show map";
|
||||
this.ShowMapButton.UseVisualStyleBackColor = true;
|
||||
this.ShowMapButton.Click += new System.EventHandler(this.ShowMapButton_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.ArrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(63, 660);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 9;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ShowHangarButton
|
||||
//
|
||||
this.ShowHangarButton.Location = new System.Drawing.Point(12, 542);
|
||||
this.ShowHangarButton.Name = "ShowHangarButton";
|
||||
this.ShowHangarButton.Size = new System.Drawing.Size(182, 30);
|
||||
this.ShowHangarButton.TabIndex = 13;
|
||||
this.ShowHangarButton.Text = "Show hangar";
|
||||
this.ShowHangarButton.UseVisualStyleBackColor = true;
|
||||
this.ShowHangarButton.Click += new System.EventHandler(this.ShowHangarButton_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.ArrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(99, 624);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 8;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// DeleteAircraftButton
|
||||
//
|
||||
this.DeleteAircraftButton.Location = new System.Drawing.Point(12, 500);
|
||||
this.DeleteAircraftButton.Name = "DeleteAircraftButton";
|
||||
this.DeleteAircraftButton.Size = new System.Drawing.Size(182, 36);
|
||||
this.DeleteAircraftButton.TabIndex = 12;
|
||||
this.DeleteAircraftButton.Text = "Delete aircraft";
|
||||
this.DeleteAircraftButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteAircraftButton.Click += new System.EventHandler(this.DeleteAircraftButton_Click);
|
||||
//
|
||||
// maskedTextBoxPostion
|
||||
//
|
||||
this.maskedTextBoxPostion.Location = new System.Drawing.Point(12, 453);
|
||||
this.maskedTextBoxPostion.Mask = "00";
|
||||
this.maskedTextBoxPostion.Name = "maskedTextBoxPostion";
|
||||
this.maskedTextBoxPostion.Size = new System.Drawing.Size(182, 23);
|
||||
this.maskedTextBoxPostion.TabIndex = 11;
|
||||
//
|
||||
// AddAircraftButton
|
||||
//
|
||||
this.AddAircraftButton.Location = new System.Drawing.Point(12, 412);
|
||||
this.AddAircraftButton.Name = "AddAircraftButton";
|
||||
this.AddAircraftButton.Size = new System.Drawing.Size(182, 35);
|
||||
this.AddAircraftButton.TabIndex = 10;
|
||||
this.AddAircraftButton.Text = "Add aircraft";
|
||||
this.AddAircraftButton.UseVisualStyleBackColor = true;
|
||||
this.AddAircraftButton.Click += new System.EventHandler(this.AddAircraftButton_Click);
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 24);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(672, 702);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.fileToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(890, 24);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
//
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
||||
this.fileToolStripMenuItem.Text = "File";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
|
||||
this.SaveToolStripMenuItem.Text = "Save";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
|
||||
this.LoadToolStripMenuItem.Text = "Load";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.FileName = "openFileDialog1";
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormMapWithSetAircrafts
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(890, 726);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.PanelGroupBox);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMapWithSetAircrafts";
|
||||
this.Text = "MapWithSelectedAircrafts";
|
||||
this.PanelGroupBox.ResumeLayout(false);
|
||||
this.PanelGroupBox.PerformLayout();
|
||||
this.MapsGroupBox.ResumeLayout(false);
|
||||
this.MapsGroupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox PanelGroupBox;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxMapSelection;
|
||||
private Button ShowMapButton;
|
||||
private Button ShowHangarButton;
|
||||
private Button DeleteAircraftButton;
|
||||
private MaskedTextBox maskedTextBoxPostion;
|
||||
private Button AddAircraftButton;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private GroupBox MapsGroupBox;
|
||||
private Button DeleteMapButton;
|
||||
private ListBox listBoxMaps;
|
||||
private Button AddMapButton;
|
||||
private TextBox newMapTextBox;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem fileToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button SortByColorButton;
|
||||
private Button SortByTypeButton;
|
||||
}
|
||||
}
|
||||
299
AirFighter/FormMapWithSetAircrafts.cs
Normal file
299
AirFighter/FormMapWithSetAircrafts.cs
Normal file
@@ -0,0 +1,299 @@
|
||||
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 FormMapWithSetAircrafts : Form
|
||||
{
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Simple map", new SimpleMap() },
|
||||
|
||||
{"Nightsky map", new NightSkyMap()}
|
||||
};
|
||||
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public FormMapWithSetAircrafts(ILogger<FormMapWithSetAircrafts> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxMapSelection.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxMapSelection.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshMaps()
|
||||
{
|
||||
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 ShowMapButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
|
||||
private void AddAircraftButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formAircraftConfig = new FormAircraftConfig();
|
||||
formAircraftConfig.AddEvent(new(AddAircraft));
|
||||
formAircraftConfig.Show();
|
||||
}
|
||||
|
||||
public void AddAircraft(DrawingAircraft aircraft)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectAircraft(aircraft) != -1)
|
||||
{
|
||||
MessageBox.Show("Object is added");
|
||||
_logger.LogInformation($"{aircraft.Plane.GetType()} was added.");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Unable to add object");
|
||||
_logger.LogInformation($"Unable to add object.");
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
catch (VaultOverflowException ex)
|
||||
{
|
||||
|
||||
_logger.LogWarning($"Vault overflow exception: {ex.Message}");
|
||||
MessageBox.Show($"Vault overflow exception: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Unknown error: {ex.Message}");
|
||||
MessageBox.Show($"Unknown error: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DeleteAircraftButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPostion.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Delete object?", "Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPostion.Text);
|
||||
try
|
||||
{
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Object is deleted");
|
||||
_logger.LogInformation($"Aircraft was removed from {pos} position.");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Unable to delete object");
|
||||
_logger.LogInformation($"Unable to remove aircraft from {pos} position.");
|
||||
}
|
||||
}
|
||||
catch(AircraftNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show($"Deletion error: {ex.Message}");
|
||||
_logger.LogWarning($"Aircraft is not found exception: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Unknown error: {ex.Message}");
|
||||
_logger.LogWarning($"Unknow error: {ex.Message}.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ShowHangarButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
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 "buttonUp":
|
||||
{
|
||||
dir = Direction.Up;
|
||||
}
|
||||
break;
|
||||
case "buttonDown":
|
||||
{
|
||||
dir = Direction.Down;
|
||||
}
|
||||
break;
|
||||
case "buttonLeft":
|
||||
{
|
||||
dir = Direction.Left;
|
||||
}
|
||||
break;
|
||||
case "buttonRight":
|
||||
{
|
||||
dir = Direction.Right;
|
||||
}
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
private void AddMapButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxMapSelection.SelectedIndex == -1 || string.IsNullOrEmpty(newMapTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Not all data is filled", " Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Failed to add map since {0}", comboBoxMapSelection.SelectedIndex == -1? "example of map wasn't choosen." : "name of map is missing");
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxMapSelection.Text))
|
||||
{
|
||||
MessageBox.Show("There is no such map","Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"There is no map with {comboBoxMapSelection.Text} name.");
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(newMapTextBox.Text, _mapsDict[comboBoxMapSelection.Text]);
|
||||
RefreshMaps();
|
||||
_logger.LogInformation("Map was added.");
|
||||
}
|
||||
|
||||
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation($"Map was changed to {listBoxMaps.SelectedItem}.");
|
||||
}
|
||||
|
||||
private void DeleteMapButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DeleteMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
RefreshMaps();
|
||||
_logger.LogInformation($"Map was removed {listBoxMaps.SelectedItem}.");
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Data is saved successfully!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"{saveFileDialog.FileName} is saved.");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Something went wrong: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Unable to save: {saveFileDialog.FileName} | {ex.Message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
RefreshMaps();
|
||||
MessageBox.Show("Data is loaded successfully!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"{openFileDialog.FileName} is loaded.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Something went wrong: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Unable to load: {openFileDialog.FileName} | {ex.Message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SortByTypeButton_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();
|
||||
}
|
||||
|
||||
private void SortByColorButton_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
69
AirFighter/FormMapWithSetAircrafts.resx
Normal file
69
AirFighter/FormMapWithSetAircrafts.resx
Normal file
@@ -0,0 +1,69 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.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>125, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>265, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
@@ -19,5 +19,6 @@ namespace AirFighter
|
||||
|
||||
(float Left, float Top, float Right, float Bottom) GetCurrentPosition();
|
||||
|
||||
string ReceiveInfo();
|
||||
}
|
||||
}
|
||||
|
||||
168
AirFighter/MapWithSetAircraftsGeneric.cs
Normal file
168
AirFighter/MapWithSetAircraftsGeneric.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class MapWithSetAircraftsGeneric<T, U>
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 145;
|
||||
|
||||
private readonly int _placeSizeHeight = 145;
|
||||
|
||||
private readonly SetAircraftsGeneric<T> _setAircrafts;
|
||||
|
||||
private readonly U _map;
|
||||
|
||||
public MapWithSetAircraftsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setAircrafts = new SetAircraftsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static int operator +(MapWithSetAircraftsGeneric<T, U> map, T aircraft)
|
||||
{
|
||||
return map._setAircrafts.Insert(aircraft);
|
||||
}
|
||||
|
||||
public static T operator -(MapWithSetAircraftsGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setAircrafts.Remove(position);
|
||||
}
|
||||
|
||||
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawAircrafts(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
|
||||
foreach (var aircraft in _setAircrafts.GetAircrafts())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, aircraft);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
|
||||
}
|
||||
|
||||
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 aircraft in _setAircrafts.GetAircrafts())
|
||||
{
|
||||
data += $"{aircraft.ReceiveInfo()}{separatorData}";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var record in records)
|
||||
{
|
||||
_setAircrafts.Insert(DrawingObjectAircraft.Create(record) as T);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setAircrafts.SortSet(comparer);
|
||||
}
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setAircrafts.Count - 1;
|
||||
for (int i = 0; i < _setAircrafts.Count; i++)
|
||||
{
|
||||
if (_setAircrafts[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var aircraft = _setAircrafts[j];
|
||||
if (aircraft != null)
|
||||
{
|
||||
_setAircrafts.Insert(aircraft, i);
|
||||
_setAircrafts.Remove(j);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 2);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth + 1; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 135, _placeSizeWidth - 80, j * _placeSizeHeight + 135);
|
||||
if(i * _placeSizeWidth + _placeSizeWidth + 20 < _pictureWidth - 10)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 60, i * _placeSizeWidth + _placeSizeWidth / 2 + 20, j * _placeSizeHeight + 45);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth / 2 + 20, j * _placeSizeHeight + 45, i * _placeSizeWidth + _placeSizeWidth + 20 , j * _placeSizeHeight + 60);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 135, i * _placeSizeWidth + 20, j * _placeSizeHeight + 60);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DrawAircrafts(Graphics g)
|
||||
{
|
||||
int curX = _pictureWidth / _placeSizeWidth - 1;
|
||||
int curY = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
foreach (var aircraft in _setAircrafts.GetAircrafts())
|
||||
{
|
||||
aircraft.SetObject(curX * _placeSizeWidth + 30, curY * _placeSizeHeight + 40, _pictureWidth, _pictureHeight);
|
||||
aircraft.DrawingObject(g);
|
||||
|
||||
if (curX <= 0)
|
||||
{
|
||||
curX = _pictureWidth / _placeSizeWidth - 1;
|
||||
curY--;
|
||||
}
|
||||
else
|
||||
{
|
||||
curX--;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
121
AirFighter/MapsCollection.cs
Normal file
121
AirFighter/MapsCollection.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
readonly Dictionary<string, MapWithSetAircraftsGeneric<IDrawingObject, AbstractMap>> _mapsVault;
|
||||
|
||||
public List<string> Keys => _mapsVault.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly char separatorDict = '|';
|
||||
private readonly char separatorData = ';';
|
||||
|
||||
private bool flag = false;
|
||||
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
_mapsVault = new Dictionary<string, MapWithSetAircraftsGeneric<IDrawingObject, AbstractMap>>();
|
||||
}
|
||||
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (!Keys.Contains(name))
|
||||
{
|
||||
_mapsVault.Add(name, new MapWithSetAircraftsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DeleteMap(string name)
|
||||
{
|
||||
if (Keys.Contains(name))
|
||||
{
|
||||
_mapsVault.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public MapWithSetAircraftsGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mapsVault.ContainsKey(ind) ? _mapsVault[ind] : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (StreamWriter sw = new StreamWriter(filename))
|
||||
{
|
||||
sw.WriteLine($"MapsCollection");
|
||||
foreach (var vault in _mapsVault)
|
||||
{
|
||||
sw.WriteLine($"{vault.Key}{separatorDict}{vault.Value.GetData(separatorDict, separatorData)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("File was not found.");
|
||||
}
|
||||
|
||||
string str;
|
||||
int count = 0;
|
||||
_mapsVault.Clear();
|
||||
using (StreamReader sr = new StreamReader(filename))
|
||||
{
|
||||
while ((str = sr.ReadLine()) != null)
|
||||
{
|
||||
if (count == 0)
|
||||
{
|
||||
if (!str.Contains("MapsCollection"))
|
||||
{
|
||||
throw new FileFormatException("Wrong data format in file.");
|
||||
}
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
var elem = str.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "NightSkyMap":
|
||||
map = new NightSkyMap();
|
||||
break;
|
||||
}
|
||||
|
||||
_mapsVault.Add(elem[0], new MapWithSetAircraftsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapsVault[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
using Serilog;
|
||||
using System.ServiceProcess;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal static class Program
|
||||
@@ -11,7 +19,32 @@ namespace AirFighter
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMap());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetAircrafts>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormMapWithSetAircrafts>().AddLogging(option =>
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile(path: "appsettings.json", false, true)
|
||||
.Build();
|
||||
|
||||
var serilogLogger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(serilogLogger);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
118
AirFighter/SetAircraftsGeneric.cs
Normal file
118
AirFighter/SetAircraftsGeneric.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class SetAircraftsGeneric<T>
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
|
||||
public int Count => _places.Count;
|
||||
|
||||
private readonly int _maxCount;
|
||||
|
||||
public SetAircraftsGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
|
||||
public int Insert(T aircraft)
|
||||
{
|
||||
return Insert(aircraft, 0);
|
||||
}
|
||||
|
||||
public int Insert(T aircraft, int position)
|
||||
{
|
||||
foreach (var instAircraft in _places)
|
||||
{
|
||||
if (aircraft.Equals(instAircraft))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (position > Count || position < 0 || Count == _maxCount)
|
||||
{
|
||||
throw new VaultOverflowException("Overflow of storage.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
_places.Insert(position, aircraft);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < Count && position >= 0)
|
||||
{
|
||||
if (_places.ElementAt(position) != null)
|
||||
{
|
||||
T result = _places.ElementAt(position);
|
||||
|
||||
_places.RemoveAt(position);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
throw new AircraftNotFoundException($"There is no aircraft in {position} position.");
|
||||
return null;
|
||||
}
|
||||
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < _maxCount && position >= 0)
|
||||
{
|
||||
return _places.ElementAt(position);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < _maxCount && position >= 0)
|
||||
{
|
||||
Insert(value,position);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAircrafts()
|
||||
{
|
||||
|
||||
foreach (var aircraft in _places)
|
||||
{
|
||||
if (aircraft != null)
|
||||
{
|
||||
yield return aircraft;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
17
AirFighter/VaultOverflowException.cs
Normal file
17
AirFighter/VaultOverflowException.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class VaultOverflowException : ApplicationException
|
||||
{
|
||||
public VaultOverflowException() : base() { }
|
||||
public VaultOverflowException(string message) : base(message) { }
|
||||
public VaultOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
protected VaultOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
17
AirFighter/appsettings.json
Normal file
17
AirFighter/appsettings.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": ["Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/logs.log",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user