Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
4f80893e3e | |||
fc9c663a4e | |||
79f59d7743 | |||
c21d23e3e6 | |||
06b1fe82e7 | |||
18d5f5f466 | |||
ff6f059599 | |||
f52bed00f4 |
25
AirplaneWithRadar/AirplaneWithRadar.sln
Normal file
25
AirplaneWithRadar/AirplaneWithRadar.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.6.33815.320
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AirplaneWithRadar", "AirplaneWithRadar\AirplaneWithRadar.csproj", "{AF704CA3-06A3-4E16-BD8E-E38D724F52C4}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{AF704CA3-06A3-4E16-BD8E-E38D724F52C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AF704CA3-06A3-4E16-BD8E-E38D724F52C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AF704CA3-06A3-4E16-BD8E-E38D724F52C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AF704CA3-06A3-4E16-BD8E-E38D724F52C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {C29B6A34-9081-42AD-A30A-C976A7E636B5}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
120
AirplaneWithRadar/AirplaneWithRadar/.resx
Normal file
120
AirplaneWithRadar/AirplaneWithRadar/.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
79
AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs
Normal file
79
AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
namespace AirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
private IMoveableObject? moveableObject;
|
||||||
|
|
||||||
|
private Status state = Status.NotInit;
|
||||||
|
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
|
||||||
|
public Status GetStatus() { return state; }
|
||||||
|
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int
|
||||||
|
height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state = Status.InProgress;
|
||||||
|
this.moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool MoveLeft() => MoveTo(Movement.Left);
|
||||||
|
|
||||||
|
protected bool MoveRight() => MoveTo(Movement.Right);
|
||||||
|
|
||||||
|
protected bool MoveUp() => MoveTo(Movement.Up);
|
||||||
|
|
||||||
|
protected bool MoveDown() => MoveTo(Movement.Down);
|
||||||
|
|
||||||
|
protected ObjectParameters? GetObjectParameters => moveableObject?.GetObjectPosition;
|
||||||
|
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
|
||||||
|
private bool MoveTo(Movement directionType)
|
||||||
|
{
|
||||||
|
if (state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs
Normal file
17
AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace AirplaneWithRadar.Entities
|
||||||
|
{
|
||||||
|
public class AirplaneEntity
|
||||||
|
{
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
|
||||||
|
public AirplaneEntity(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj
Normal file
16
AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="Class1.cs" />
|
||||||
|
<Compile Remove="GenericClass.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,17 @@
|
|||||||
|
namespace AirplaneWithRadar.Entities
|
||||||
|
{
|
||||||
|
public class AirplaneWithRadarEntity : AirplaneEntity
|
||||||
|
{
|
||||||
|
public Color AdditColor { get; private set; }
|
||||||
|
public bool RadarOnBoard { get; private set; }
|
||||||
|
public bool AdditFuelPod { get; private set; }
|
||||||
|
|
||||||
|
public AirplaneWithRadarEntity(int speed, double weight, Color mainColor, Color additColor, bool radarOnBoard, bool additFuelPod)
|
||||||
|
: base (speed, weight, mainColor)
|
||||||
|
{
|
||||||
|
AdditColor = additColor;
|
||||||
|
RadarOnBoard = radarOnBoard;
|
||||||
|
AdditFuelPod = additFuelPod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
using AirplaneWithRadar.PaintObjects;
|
||||||
|
using AirplaneWithRadar.MovementStrategy;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class AirplanesGenericCollection<T, U>
|
||||||
|
where T : PaintAirplane
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly int pictWidth;
|
||||||
|
private readonly int pictHeight;
|
||||||
|
private readonly int placeSizeWidth = 200;
|
||||||
|
private readonly int placeSizeHeight = 70;
|
||||||
|
private readonly SetGeneric<T> collection;
|
||||||
|
|
||||||
|
public AirplanesGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / placeSizeWidth;
|
||||||
|
int height = picHeight / placeSizeHeight;
|
||||||
|
pictWidth = picWidth;
|
||||||
|
pictHeight = picHeight;
|
||||||
|
collection = new SetGeneric<T>(width * height);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int? operator +(AirplanesGenericCollection<T, U> collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect?.collection.Insert(obj);
|
||||||
|
}
|
||||||
|
public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect.collection[pos];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return collect.collection.Remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowAirplanes()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictWidth, pictHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < pictWidth / placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < pictHeight / placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * placeSizeWidth, j * placeSizeHeight, i * placeSizeWidth + placeSizeWidth / 2, j * placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * placeSizeWidth, 0, i * placeSizeWidth, pictHeight / placeSizeHeight * placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int width = pictWidth / placeSizeWidth;
|
||||||
|
int height = pictHeight / placeSizeHeight;
|
||||||
|
|
||||||
|
int j = 3;
|
||||||
|
int k = 0;
|
||||||
|
|
||||||
|
foreach (var airplane in collection.GetAirplanes()) {
|
||||||
|
if (j < 0)
|
||||||
|
{
|
||||||
|
j += 4;
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
if (airplane != null)
|
||||||
|
{
|
||||||
|
airplane.SetPosition(placeSizeWidth * j, placeSizeHeight * k);
|
||||||
|
airplane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
using AirplaneWithRadar.PaintObjects;
|
||||||
|
using AirplaneWithRadar.MovementStrategy;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar.Generics
|
||||||
|
{
|
||||||
|
internal class AirplanesGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>> airplaneStorages;
|
||||||
|
public List<string> Keys => airplaneStorages.Keys.ToList();
|
||||||
|
private readonly int pictWidth;
|
||||||
|
private readonly int pictHeight;
|
||||||
|
public AirplanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
airplaneStorages = new Dictionary<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>>();
|
||||||
|
pictWidth = pictureWidth;
|
||||||
|
pictHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (airplaneStorages.ContainsKey(name)) { return; }
|
||||||
|
airplaneStorages.Add(name, new AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>(pictWidth, pictHeight));
|
||||||
|
}
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (airplaneStorages.ContainsKey(name))
|
||||||
|
airplaneStorages.Remove(name);
|
||||||
|
}
|
||||||
|
public AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (airplaneStorages.ContainsKey(ind)) return airplaneStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
188
AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs
generated
Normal file
188
AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
partial class FormAirplaneCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
groupBox2 = new GroupBox();
|
||||||
|
buttonDelObject = new Button();
|
||||||
|
buttonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
maskedTextBoxNumber = new TextBox();
|
||||||
|
ButtonRefreshCollection = new Button();
|
||||||
|
ButtonDeleteAirplane = new Button();
|
||||||
|
ButtonAddAirplane = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
groupBox2.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Controls.Add(groupBox2);
|
||||||
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBox1.Controls.Add(ButtonRefreshCollection);
|
||||||
|
groupBox1.Controls.Add(ButtonDeleteAirplane);
|
||||||
|
groupBox1.Controls.Add(ButtonAddAirplane);
|
||||||
|
groupBox1.Location = new Point(749, 9);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(223, 440);
|
||||||
|
groupBox1.TabIndex = 0;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// groupBox2
|
||||||
|
//
|
||||||
|
groupBox2.Controls.Add(buttonDelObject);
|
||||||
|
groupBox2.Controls.Add(buttonAddObject);
|
||||||
|
groupBox2.Controls.Add(textBoxStorageName);
|
||||||
|
groupBox2.Controls.Add(listBoxStorages);
|
||||||
|
groupBox2.Location = new Point(13, 22);
|
||||||
|
groupBox2.Name = "groupBox2";
|
||||||
|
groupBox2.Size = new Size(204, 209);
|
||||||
|
groupBox2.TabIndex = 5;
|
||||||
|
groupBox2.TabStop = false;
|
||||||
|
groupBox2.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// buttonDelObject
|
||||||
|
//
|
||||||
|
buttonDelObject.Location = new Point(17, 178);
|
||||||
|
buttonDelObject.Name = "buttonDelObject";
|
||||||
|
buttonDelObject.Size = new Size(170, 25);
|
||||||
|
buttonDelObject.TabIndex = 7;
|
||||||
|
buttonDelObject.Text = "Удалить набор";
|
||||||
|
buttonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelObject.Click += buttonDelObject_Click;
|
||||||
|
//
|
||||||
|
// buttonAddObject
|
||||||
|
//
|
||||||
|
buttonAddObject.Location = new Point(17, 51);
|
||||||
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
|
buttonAddObject.Size = new Size(170, 23);
|
||||||
|
buttonAddObject.TabIndex = 6;
|
||||||
|
buttonAddObject.Text = "Добавить набор";
|
||||||
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddObject.Click += buttonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(10, 22);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(188, 23);
|
||||||
|
textBoxStorageName.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 15;
|
||||||
|
listBoxStorages.Location = new Point(10, 93);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(188, 79);
|
||||||
|
listBoxStorages.TabIndex = 4;
|
||||||
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(39, 289);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(161, 23);
|
||||||
|
maskedTextBoxNumber.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(20, 370);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(194, 46);
|
||||||
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// ButtonDeleteAirplane
|
||||||
|
//
|
||||||
|
ButtonDeleteAirplane.Location = new Point(20, 318);
|
||||||
|
ButtonDeleteAirplane.Name = "ButtonDeleteAirplane";
|
||||||
|
ButtonDeleteAirplane.Size = new Size(194, 46);
|
||||||
|
ButtonDeleteAirplane.TabIndex = 1;
|
||||||
|
ButtonDeleteAirplane.Text = "Удалить самолёт";
|
||||||
|
ButtonDeleteAirplane.UseVisualStyleBackColor = true;
|
||||||
|
ButtonDeleteAirplane.Click += ButtonDeleteAirplane_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddAirplane
|
||||||
|
//
|
||||||
|
ButtonAddAirplane.Location = new Point(23, 237);
|
||||||
|
ButtonAddAirplane.Name = "ButtonAddAirplane";
|
||||||
|
ButtonAddAirplane.Size = new Size(194, 46);
|
||||||
|
ButtonAddAirplane.TabIndex = 0;
|
||||||
|
ButtonAddAirplane.Text = "Добавить самолёт";
|
||||||
|
ButtonAddAirplane.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddAirplane.Click += ButtonAddAirplane_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(984, 461);
|
||||||
|
pictureBoxCollection.TabIndex = 1;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormAirplaneCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(984, 461);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormAirplaneCollection";
|
||||||
|
Text = "FormAirplaneCollection";
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
groupBox1.PerformLayout();
|
||||||
|
groupBox2.ResumeLayout(false);
|
||||||
|
groupBox2.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private Button ButtonDeleteAirplane;
|
||||||
|
private Button ButtonAddAirplane;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private TextBox maskedTextBoxNumber;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private GroupBox groupBox2;
|
||||||
|
private Button buttonDelObject;
|
||||||
|
private Button buttonAddObject;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
}
|
||||||
|
}
|
126
AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
Normal file
126
AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
using AirplaneWithRadar.Generics;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
public partial class FormAirplaneCollection : Form
|
||||||
|
{
|
||||||
|
private readonly AirplanesGenericStorage storage;
|
||||||
|
public FormAirplaneCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
storage = new AirplanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorages.SelectedIndex;
|
||||||
|
listBoxStorages.Items.Clear();
|
||||||
|
for (int i = 0; i < storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
|
||||||
|
}
|
||||||
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAddAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlaneVisual form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (!(obj + form.SelectedAirplane == -1))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowAirplanes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDeleteAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (obj - pos != false)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = obj.ShowAirplanes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowAirplanes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx
Normal file
120
AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
10
AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs
Normal file
10
AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace AirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
int GetStep { get; }
|
||||||
|
bool CheckCanMove(Movement direction);
|
||||||
|
void MoveObject(Movement direction);
|
||||||
|
}
|
||||||
|
}
|
53
AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs
Normal file
53
AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
namespace AirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs
Normal file
52
AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
namespace AirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
AirplaneWithRadar/AirplaneWithRadar/Movement.cs
Normal file
10
AirplaneWithRadar/AirplaneWithRadar/Movement.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
public enum Movement
|
||||||
|
{
|
||||||
|
Up = 1,
|
||||||
|
Down = 2,
|
||||||
|
Left = 3,
|
||||||
|
Right = 4,
|
||||||
|
}
|
||||||
|
}
|
29
AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs
Normal file
29
AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
namespace AirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int x;
|
||||||
|
private readonly int y;
|
||||||
|
private readonly int width;
|
||||||
|
private readonly int height;
|
||||||
|
public int LeftBorder => x;
|
||||||
|
|
||||||
|
public int TopBorder => y;
|
||||||
|
|
||||||
|
public int RightBorder => x + width;
|
||||||
|
|
||||||
|
public int DownBorder => y + height;
|
||||||
|
|
||||||
|
public int ObjectMiddleHorizontal => x + width / 2;
|
||||||
|
|
||||||
|
public int ObjectMiddleVertical => y + height / 2;
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
218
AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
Normal file
218
AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using AirplaneWithRadar.Entities;
|
||||||
|
using AirplaneWithRadar.MovementStrategy;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar.PaintObjects
|
||||||
|
{
|
||||||
|
public class PaintAirplane
|
||||||
|
{
|
||||||
|
public AirplaneEntity? AirplaneEntity { get; protected set; }
|
||||||
|
private int pictWidth;
|
||||||
|
private int pictHeight;
|
||||||
|
protected int startPosX;
|
||||||
|
protected int startPosY;
|
||||||
|
protected readonly int planeWidth = 140;
|
||||||
|
protected readonly int planeHeight = 60;
|
||||||
|
|
||||||
|
public int GetPosX => startPosX;
|
||||||
|
public int GetPosY => startPosY;
|
||||||
|
public int GetWidth => planeWidth;
|
||||||
|
public int GetHeight => planeHeight;
|
||||||
|
|
||||||
|
public IMoveableObject GetMoveableObject => new PaintObjectAirplane(this);
|
||||||
|
|
||||||
|
public bool CanMove(Movement dir)
|
||||||
|
{
|
||||||
|
if (AirplaneEntity == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return dir switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
Movement.Left => startPosX - AirplaneEntity.Step > 0,
|
||||||
|
//вверх
|
||||||
|
Movement.Up => startPosY - AirplaneEntity.Step > 0,
|
||||||
|
// вправо
|
||||||
|
Movement.Right => startPosX + planeWidth + AirplaneEntity.Step < pictWidth,
|
||||||
|
//вниз
|
||||||
|
Movement.Down => startPosY + planeHeight + AirplaneEntity.Step < pictHeight,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public PaintAirplane(int speed, double weight, Color bodyColor, int width, int height)
|
||||||
|
{
|
||||||
|
if (planeWidth > width || planeHeight > height) { return; }
|
||||||
|
|
||||||
|
pictHeight = height;
|
||||||
|
pictWidth = width;
|
||||||
|
AirplaneEntity = new AirplaneEntity(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PaintAirplane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
|
||||||
|
{
|
||||||
|
if (this.planeWidth > width || this.planeHeight > height) { return; }
|
||||||
|
|
||||||
|
pictHeight = height;
|
||||||
|
pictWidth = width;
|
||||||
|
this.planeWidth = planeWidth;
|
||||||
|
this.planeHeight = planeHeight;
|
||||||
|
AirplaneEntity = new AirplaneEntity(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if ((x >= 0 && y >= 0)&&(x + planeHeight <= pictHeight || y + planeWidth <= pictWidth)) {
|
||||||
|
startPosX = x;
|
||||||
|
startPosY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Move(Movement dir)
|
||||||
|
{
|
||||||
|
if (!CanMove(dir) || AirplaneEntity == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (dir)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case Movement.Left:
|
||||||
|
startPosX -= (int)AirplaneEntity.Step;
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case Movement.Up:
|
||||||
|
startPosY -= (int)AirplaneEntity.Step;
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case Movement.Right:
|
||||||
|
startPosX += (int)AirplaneEntity.Step;
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case Movement.Down:
|
||||||
|
startPosY += (int)AirplaneEntity.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (AirplaneEntity == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush brush = new SolidBrush(AirplaneEntity.BodyColor);
|
||||||
|
|
||||||
|
//основа
|
||||||
|
g.FillRectangle(brush, startPosX + planeWidth / 44, startPosY + planeHeight / 2, planeWidth - 2* planeWidth/11, planeHeight / 2 - planeHeight / 8);
|
||||||
|
g.FillEllipse(brush, new Rectangle(startPosX, startPosY + planeHeight / 2, planeWidth / 24, planeHeight / 2 - planeHeight / 8));
|
||||||
|
g.DrawLine(pen, new Point(startPosX + planeWidth / 44, startPosY + planeHeight / 2), new Point(startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight / 2));
|
||||||
|
g.DrawLine(pen, new Point(startPosX + planeWidth / 44, startPosY + planeHeight - planeHeight / 8), new Point(startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight - planeHeight / 8));
|
||||||
|
|
||||||
|
|
||||||
|
g.DrawArc(pen, new Rectangle(startPosX, startPosY + planeHeight / 2, planeWidth / 24, planeHeight / 2 - planeHeight / 8), 90.0f, 180.0f);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DrawTriangle(g, pen,
|
||||||
|
startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight / 2, // 1
|
||||||
|
startPosX + planeWidth, startPosY + 5 * planeHeight / 7, // 2
|
||||||
|
startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight - planeHeight / 8); // 3
|
||||||
|
|
||||||
|
DrawTriangle(g, pen,
|
||||||
|
startPosX, startPosY, // 1
|
||||||
|
startPosX + planeWidth / 4, startPosY + planeHeight / 2, // 2
|
||||||
|
startPosX, startPosY + planeHeight / 2); // 3
|
||||||
|
g.DrawLine(pen, new Point(startPosX + planeWidth - planeWidth / 6, startPosY + 5 * planeHeight / 7),
|
||||||
|
new Point(startPosX + planeWidth, startPosY + 5 * planeHeight / 7));
|
||||||
|
// колеса
|
||||||
|
g.DrawLine(pen, new Point(startPosX + planeWidth / 4, startPosY + planeHeight - planeHeight / 8),
|
||||||
|
new Point(startPosX + planeWidth / 4, startPosY + planeHeight - planeHeight / 11));
|
||||||
|
g.DrawLine(pen, new Point(startPosX + planeWidth - 2 * planeWidth / 9, startPosY + planeHeight - planeHeight / 8),
|
||||||
|
new Point(startPosX + planeWidth - 2 * planeWidth / 9, startPosY + planeHeight - planeHeight / 11));
|
||||||
|
g.DrawEllipse(pen, new Rectangle(startPosX + planeWidth / 4 - planeWidth / 23, startPosY + 11 * planeHeight / 12,
|
||||||
|
planeHeight / 12, planeHeight / 12));
|
||||||
|
g.DrawEllipse(pen, new Rectangle(startPosX + planeWidth / 4 + planeWidth / 72, startPosY + 11 * planeHeight / 12,
|
||||||
|
planeHeight / 12, planeHeight / 12));
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, new Rectangle(startPosX + planeWidth - 5 * planeWidth / 21, startPosY + 11 * planeHeight / 12,
|
||||||
|
planeHeight / 12, planeHeight / 12));
|
||||||
|
|
||||||
|
FillRoundedRectangle(g, new SolidBrush(Color.Black), new Rectangle(startPosX + 2 * planeWidth / 9, startPosY + planeHeight / 2 + planeHeight / 7, planeWidth / 2, planeHeight / 7), 5);
|
||||||
|
FillRoundedRectangle(g, new SolidBrush(Color.Black), new Rectangle(startPosX, startPosY + planeHeight / 2 - planeHeight / 9, planeWidth / 5, planeHeight / 6), 5);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void DrawTriangle(Graphics g, Pen pen, int x1, int y1, int x2, int y2, int x3, int y3)
|
||||||
|
{
|
||||||
|
Point p1 = new Point(x1, y1);
|
||||||
|
Point p2 = new Point(x2, y2);
|
||||||
|
Point p3 = new Point(x3, y3);
|
||||||
|
g.DrawLine(pen, p1, p2);
|
||||||
|
g.DrawLine(pen, p2, p3);
|
||||||
|
g.DrawLine(pen, p3, p1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static GraphicsPath RoundedRect(Rectangle bounds, int radius)
|
||||||
|
{
|
||||||
|
int diameter = radius * 2;
|
||||||
|
Size size = new Size(diameter, diameter);
|
||||||
|
Rectangle arc = new Rectangle(bounds.Location, size);
|
||||||
|
GraphicsPath path = new GraphicsPath();
|
||||||
|
|
||||||
|
if (radius == 0)
|
||||||
|
{
|
||||||
|
path.AddRectangle(bounds);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// top left arc
|
||||||
|
path.AddArc(arc, 180, 90);
|
||||||
|
|
||||||
|
// top right arc
|
||||||
|
arc.X = bounds.Right - diameter;
|
||||||
|
path.AddArc(arc, 270, 90);
|
||||||
|
|
||||||
|
// bottom right arc
|
||||||
|
arc.Y = bounds.Bottom - diameter;
|
||||||
|
path.AddArc(arc, 0, 90);
|
||||||
|
|
||||||
|
// bottom left arc
|
||||||
|
arc.X = bounds.Left;
|
||||||
|
path.AddArc(arc, 90, 90);
|
||||||
|
|
||||||
|
path.CloseFigure();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void DrawRoundedRectangle(Graphics graphics, Pen pen, Rectangle bounds, int cornerRadius)
|
||||||
|
{
|
||||||
|
if (graphics == null)
|
||||||
|
throw new ArgumentNullException(nameof(graphics));
|
||||||
|
if (pen == null)
|
||||||
|
throw new ArgumentNullException(nameof(pen));
|
||||||
|
|
||||||
|
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
|
||||||
|
{
|
||||||
|
graphics.DrawPath(pen, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void FillRoundedRectangle(Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
|
||||||
|
{
|
||||||
|
if (graphics == null)
|
||||||
|
throw new ArgumentNullException(nameof(graphics));
|
||||||
|
if (brush == null)
|
||||||
|
throw new ArgumentNullException(nameof(brush));
|
||||||
|
|
||||||
|
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
|
||||||
|
{
|
||||||
|
graphics.FillPath(brush, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using AirplaneWithRadar.Entities;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar.PaintObjects
|
||||||
|
{
|
||||||
|
public class PaintAirplaneWithRadar : PaintAirplane
|
||||||
|
{
|
||||||
|
public AirplaneWithRadarEntity? PlaneEntity { get; private set; }
|
||||||
|
|
||||||
|
public PaintAirplaneWithRadar(int speed, double weight, Color mainColor, Color additColor, bool radarOnBoard, bool additFuelPod, int width, int height)
|
||||||
|
: base(speed, weight, mainColor, width, height, 140, 60)
|
||||||
|
{
|
||||||
|
if (AirplaneEntity != null)
|
||||||
|
{
|
||||||
|
AirplaneEntity = new AirplaneWithRadarEntity(speed, weight, mainColor, additColor, radarOnBoard, additFuelPod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (AirplaneEntity is not AirplaneWithRadarEntity AirplaneWithRadar)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additBrush = new SolidBrush(AirplaneWithRadar.AdditColor);
|
||||||
|
base.DrawTransport(g);
|
||||||
|
if (AirplaneWithRadar.RadarOnBoard) {
|
||||||
|
g.DrawLine(pen, new Point(startPosX + planeWidth / 3, startPosY + planeHeight / 2), new Point(startPosX + planeWidth / 3, startPosY + planeHeight / 3));
|
||||||
|
g.FillPie(additBrush, new Rectangle(startPosX + planeWidth / 4, startPosY + planeHeight / 10, planeWidth / 6, planeHeight / 4), 30.0f, 180.0f);
|
||||||
|
}
|
||||||
|
if (AirplaneWithRadar.AdditFuelPod)
|
||||||
|
{
|
||||||
|
FillRoundedRectangle(g, additBrush, new Rectangle(startPosX, startPosY + planeHeight - 2*planeHeight / 5, planeWidth / 5, planeHeight / 6), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
31
AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs
Normal file
31
AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using AirplaneWithRadar.PaintObjects;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public class PaintObjectAirplane : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly PaintAirplane? paintAirplane = null;
|
||||||
|
|
||||||
|
public PaintObjectAirplane(PaintAirplane paintAirplane)
|
||||||
|
{
|
||||||
|
this.paintAirplane = paintAirplane;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (paintAirplane == null || paintAirplane.AirplaneEntity == null) { return null; }
|
||||||
|
return new ObjectParameters(paintAirplane.GetPosX, paintAirplane.GetPosY, paintAirplane.GetWidth, paintAirplane.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStep => (int)(paintAirplane?.AirplaneEntity?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(Movement dir) =>
|
||||||
|
paintAirplane?.CanMove(dir) ?? false;
|
||||||
|
public void MoveObject(Movement dir) =>
|
||||||
|
paintAirplane?.Move(dir);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
184
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs
generated
Normal file
184
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs
generated
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
partial class PlaneVisual
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
CreateButton = new Button();
|
||||||
|
UpButton = new Button();
|
||||||
|
LeftButton = new Button();
|
||||||
|
DownButton = new Button();
|
||||||
|
RightButton = new Button();
|
||||||
|
PlanesPictureBox = new PictureBox();
|
||||||
|
StrategyComboBox = new ComboBox();
|
||||||
|
StepButton = new Button();
|
||||||
|
CreateAirplaneButton = new Button();
|
||||||
|
buttonSelectAirplane = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)PlanesPictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// CreateButton
|
||||||
|
//
|
||||||
|
CreateButton.Location = new Point(30, 391);
|
||||||
|
CreateButton.Name = "CreateButton";
|
||||||
|
CreateButton.Size = new Size(120, 40);
|
||||||
|
CreateButton.TabIndex = 0;
|
||||||
|
CreateButton.Text = "Создать самолёт с радаром";
|
||||||
|
CreateButton.UseVisualStyleBackColor = true;
|
||||||
|
CreateButton.Click += CreateButton_Click;
|
||||||
|
//
|
||||||
|
// UpButton
|
||||||
|
//
|
||||||
|
UpButton.Font = new Font("Segoe UI", 20F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
UpButton.Location = new Point(692, 345);
|
||||||
|
UpButton.Name = "UpButton";
|
||||||
|
UpButton.Size = new Size(40, 40);
|
||||||
|
UpButton.TabIndex = 1;
|
||||||
|
UpButton.Text = "↑";
|
||||||
|
UpButton.TextAlign = ContentAlignment.TopCenter;
|
||||||
|
UpButton.UseVisualStyleBackColor = true;
|
||||||
|
UpButton.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// LeftButton
|
||||||
|
//
|
||||||
|
LeftButton.Font = new Font("Segoe UI", 22F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
LeftButton.Location = new Point(646, 391);
|
||||||
|
LeftButton.Name = "LeftButton";
|
||||||
|
LeftButton.Size = new Size(40, 40);
|
||||||
|
LeftButton.TabIndex = 2;
|
||||||
|
LeftButton.Text = "←";
|
||||||
|
LeftButton.TextAlign = ContentAlignment.TopCenter;
|
||||||
|
LeftButton.UseVisualStyleBackColor = true;
|
||||||
|
LeftButton.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// DownButton
|
||||||
|
//
|
||||||
|
DownButton.Font = new Font("Segoe UI", 22F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
DownButton.Location = new Point(692, 391);
|
||||||
|
DownButton.Name = "DownButton";
|
||||||
|
DownButton.Size = new Size(40, 40);
|
||||||
|
DownButton.TabIndex = 3;
|
||||||
|
DownButton.Text = "↓";
|
||||||
|
DownButton.TextAlign = ContentAlignment.TopCenter;
|
||||||
|
DownButton.UseVisualStyleBackColor = true;
|
||||||
|
DownButton.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// RightButton
|
||||||
|
//
|
||||||
|
RightButton.Font = new Font("Segoe UI", 22F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
RightButton.Location = new Point(735, 391);
|
||||||
|
RightButton.Name = "RightButton";
|
||||||
|
RightButton.Size = new Size(40, 40);
|
||||||
|
RightButton.TabIndex = 4;
|
||||||
|
RightButton.Text = "→";
|
||||||
|
RightButton.UseVisualStyleBackColor = true;
|
||||||
|
RightButton.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// PlanesPictureBox
|
||||||
|
//
|
||||||
|
PlanesPictureBox.Dock = DockStyle.Fill;
|
||||||
|
PlanesPictureBox.Location = new Point(0, 0);
|
||||||
|
PlanesPictureBox.Name = "PlanesPictureBox";
|
||||||
|
PlanesPictureBox.Size = new Size(800, 450);
|
||||||
|
PlanesPictureBox.TabIndex = 5;
|
||||||
|
PlanesPictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// StrategyComboBox
|
||||||
|
//
|
||||||
|
StrategyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
StrategyComboBox.FormattingEnabled = true;
|
||||||
|
StrategyComboBox.Items.AddRange(new object[] { "Центр", "Граница" });
|
||||||
|
StrategyComboBox.Location = new Point(667, 12);
|
||||||
|
StrategyComboBox.Name = "StrategyComboBox";
|
||||||
|
StrategyComboBox.Size = new Size(121, 23);
|
||||||
|
StrategyComboBox.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// StepButton
|
||||||
|
//
|
||||||
|
StepButton.Location = new Point(713, 41);
|
||||||
|
StepButton.Name = "StepButton";
|
||||||
|
StepButton.Size = new Size(75, 23);
|
||||||
|
StepButton.TabIndex = 7;
|
||||||
|
StepButton.Text = "Шаг";
|
||||||
|
StepButton.UseVisualStyleBackColor = true;
|
||||||
|
StepButton.Click += StepButton_Click;
|
||||||
|
//
|
||||||
|
// CreateAirplaneButton
|
||||||
|
//
|
||||||
|
CreateAirplaneButton.Location = new Point(156, 391);
|
||||||
|
CreateAirplaneButton.Name = "CreateAirplaneButton";
|
||||||
|
CreateAirplaneButton.Size = new Size(120, 40);
|
||||||
|
CreateAirplaneButton.TabIndex = 8;
|
||||||
|
CreateAirplaneButton.Text = "Создать самолёт";
|
||||||
|
CreateAirplaneButton.UseVisualStyleBackColor = true;
|
||||||
|
CreateAirplaneButton.Click += CreateAirplaneButton_Click;
|
||||||
|
//
|
||||||
|
// buttonSelectAirplane
|
||||||
|
//
|
||||||
|
buttonSelectAirplane.Location = new Point(282, 391);
|
||||||
|
buttonSelectAirplane.Name = "buttonSelectAirplane";
|
||||||
|
buttonSelectAirplane.Size = new Size(120, 40);
|
||||||
|
buttonSelectAirplane.TabIndex = 9;
|
||||||
|
buttonSelectAirplane.Text = "Выбрать самолёт";
|
||||||
|
buttonSelectAirplane.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectAirplane.Click += buttonSelectAirplane_Click;
|
||||||
|
//
|
||||||
|
// PlaneVisual
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonSelectAirplane);
|
||||||
|
Controls.Add(CreateAirplaneButton);
|
||||||
|
Controls.Add(StepButton);
|
||||||
|
Controls.Add(StrategyComboBox);
|
||||||
|
Controls.Add(RightButton);
|
||||||
|
Controls.Add(DownButton);
|
||||||
|
Controls.Add(LeftButton);
|
||||||
|
Controls.Add(UpButton);
|
||||||
|
Controls.Add(CreateButton);
|
||||||
|
Controls.Add(PlanesPictureBox);
|
||||||
|
Name = "PlaneVisual";
|
||||||
|
Text = "Самолёт";
|
||||||
|
((System.ComponentModel.ISupportInitialize)PlanesPictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button CreateButton;
|
||||||
|
private Button UpButton;
|
||||||
|
private Button LeftButton;
|
||||||
|
private Button DownButton;
|
||||||
|
private Button RightButton;
|
||||||
|
private PictureBox PlanesPictureBox;
|
||||||
|
private ComboBox StrategyComboBox;
|
||||||
|
private Button StepButton;
|
||||||
|
private Button CreateAirplaneButton;
|
||||||
|
private Button buttonSelectAirplane;
|
||||||
|
}
|
||||||
|
}
|
137
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs
Normal file
137
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using AirplaneWithRadar.MovementStrategy;
|
||||||
|
using AirplaneWithRadar.PaintObjects;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
public partial class PlaneVisual : System.Windows.Forms.Form
|
||||||
|
{
|
||||||
|
private PaintAirplane? PaintPlanes;
|
||||||
|
private AbstractStrategy? abstractStrategy;
|
||||||
|
public PaintAirplane? SelectedAirplane { get; private set; }
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (PaintPlanes == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bitmap = new Bitmap(PlanesPictureBox.Width, PlanesPictureBox.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bitmap);
|
||||||
|
PaintPlanes.DrawTransport(gr);
|
||||||
|
PlanesPictureBox.Image = bitmap;
|
||||||
|
}
|
||||||
|
public PlaneVisual()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
abstractStrategy = null;
|
||||||
|
SelectedAirplane = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (PaintPlanes == null) { return; }
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "UpButton":
|
||||||
|
PaintPlanes.Move(Movement.Up);
|
||||||
|
break;
|
||||||
|
case "DownButton":
|
||||||
|
PaintPlanes.Move(Movement.Down);
|
||||||
|
break;
|
||||||
|
case "LeftButton":
|
||||||
|
PaintPlanes.Move(Movement.Left);
|
||||||
|
break;
|
||||||
|
case "RightButton":
|
||||||
|
PaintPlanes.Move(Movement.Right);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
PaintPlanes = new PaintAirplaneWithRadar(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, true,
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), PlanesPictureBox.Width, PlanesPictureBox.Height);
|
||||||
|
PaintPlanes.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateAirplaneButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
PaintPlanes = new PaintAirplane(random.Next(100, 300), random.Next(1000, 3000), color,
|
||||||
|
PlanesPictureBox.Width, PlanesPictureBox.Height);
|
||||||
|
PaintPlanes.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StepButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (PaintPlanes == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StrategyComboBox.Enabled)
|
||||||
|
{
|
||||||
|
abstractStrategy = StrategyComboBox.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
if (abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
abstractStrategy.SetData(new PaintObjectAirplane(PaintPlanes), PlanesPictureBox.Width, PlanesPictureBox.Height);
|
||||||
|
StrategyComboBox.Enabled = false;
|
||||||
|
}
|
||||||
|
if (abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
StrategyComboBox.Enabled = true;
|
||||||
|
abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSelectAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedAirplane = PaintPlanes;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.resx
Normal file
120
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
17
AirplaneWithRadar/AirplaneWithRadar/Program.cs
Normal file
17
AirplaneWithRadar/AirplaneWithRadar/Program.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.Run(new FormAirplaneCollection());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
116
AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
Normal file
116
AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
namespace AirplaneWithRadar.Generics;
|
||||||
|
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly List<T?> places;
|
||||||
|
public int Count => places.Count;
|
||||||
|
public readonly int maxCount;
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
maxCount = count;
|
||||||
|
places = new List<T?>(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T airplane)
|
||||||
|
{
|
||||||
|
if (Count == 0)
|
||||||
|
{
|
||||||
|
places.Add(airplane);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int emptyPosition = -1;
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (places[i] == null)
|
||||||
|
{
|
||||||
|
emptyPosition = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (emptyPosition < 0)
|
||||||
|
{
|
||||||
|
places.Add(airplane);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Insert(airplane, emptyPosition);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
public int Insert(T airplane, int position)
|
||||||
|
{
|
||||||
|
if (position > Count || position < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (places[position] == null)
|
||||||
|
{
|
||||||
|
places[position] = airplane;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
int emptyPosition = -1;
|
||||||
|
for (int i = position + 1; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (places[i]==null)
|
||||||
|
{
|
||||||
|
emptyPosition = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (emptyPosition < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = emptyPosition; i > position; i--)
|
||||||
|
{
|
||||||
|
places[i] = places[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
places[position] = airplane;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if ((position >= Count && position < 0) || places[position] == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
places[position]=null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Count <= maxCount)
|
||||||
|
{
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<T?> GetAirplanes(int? maxAirplanes = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return places[i];
|
||||||
|
if (maxAirplanes.HasValue && i == maxAirplanes.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
AirplaneWithRadar/AirplaneWithRadar/Status.cs
Normal file
9
AirplaneWithRadar/AirplaneWithRadar/Status.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace AirplaneWithRadar.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user