Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
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>
|
85
AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs
Normal file
85
AirplaneWithRadar/AirplaneWithRadar/AbstractStrategy.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
23
AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs
Normal file
23
AirplaneWithRadar/AirplaneWithRadar/AirplaneEntity.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
17
AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj
Normal file
17
AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<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="AirplanesGenericCollection.cs" />
|
||||
<Compile Remove="Class1.cs" />
|
||||
<Compile Remove="SetGeneric.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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 = 210;
|
||||
private readonly int placeSizeHeight = 90;
|
||||
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 bool operator +(AirplanesGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?.collection.Insert(obj) ?? false;
|
||||
}
|
||||
public static T? operator -(AirplanesGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect.collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect.collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
}
|
16
AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs
Normal file
16
AirplaneWithRadar/AirplaneWithRadar/IMoveableObject.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
int GetStep { get; }
|
||||
bool CheckCanMove(Movement direction);
|
||||
void MoveObject(Movement direction);
|
||||
}
|
||||
}
|
59
AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs
Normal file
59
AirplaneWithRadar/AirplaneWithRadar/MoveToBorder.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
59
AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs
Normal file
59
AirplaneWithRadar/AirplaneWithRadar/MoveToCenter.cs
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
16
AirplaneWithRadar/AirplaneWithRadar/Movement.cs
Normal file
16
AirplaneWithRadar/AirplaneWithRadar/Movement.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
public enum Movement
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4,
|
||||
}
|
||||
}
|
35
AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs
Normal file
35
AirplaneWithRadar/AirplaneWithRadar/ObjectParameters.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
220
AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
Normal file
220
AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
Normal file
@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirplaneWithRadar.Entities;
|
||||
|
||||
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 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,48 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
37
AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs
Normal file
37
AirplaneWithRadar/AirplaneWithRadar/PaintObjectAirplane.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using AirplaneWithRadar.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
171
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs
generated
Normal file
171
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
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();
|
||||
((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;
|
||||
//
|
||||
// PlaneVisual
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
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;
|
||||
}
|
||||
}
|
107
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs
Normal file
107
AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using AirplaneWithRadar.MovementStrategy;
|
||||
using AirplaneWithRadar.PaintObjects;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
public partial class PlaneVisual : System.Windows.Forms.Form
|
||||
{
|
||||
private PaintAirplane? PaintPlanes;
|
||||
private AbstractStrategy? abstractStrategy;
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
PaintPlanes = new PaintAirplaneWithRadar(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), 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();
|
||||
PaintPlanes = new PaintAirplane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
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 PlaneVisual());
|
||||
}
|
||||
}
|
||||
}
|
65
AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
Normal file
65
AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar.Generics;
|
||||
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly T?[] places;
|
||||
public int Count => places.Length;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
places = new T?[count];
|
||||
}
|
||||
|
||||
public bool Insert(T airplane)
|
||||
{
|
||||
if (places[0] == null)
|
||||
{
|
||||
places[0] = airplane;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = Count - 1; i < 0; i--)
|
||||
{
|
||||
places[i] = places[i - 1];
|
||||
}
|
||||
places[0] = airplane;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Insert(T airplane, int position)
|
||||
{
|
||||
if (position > Count || position < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
places[position] = airplane;
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position > Count || position < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
places[position] = null;
|
||||
return true;
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position > Count || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return places[position];
|
||||
}
|
||||
}
|
15
AirplaneWithRadar/AirplaneWithRadar/Status.cs
Normal file
15
AirplaneWithRadar/AirplaneWithRadar/Status.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user