Compare commits

..

No commits in common. "lab6" and "main" have entirely different histories.
lab6 ... main

29 changed files with 0 additions and 2752 deletions

View File

@ -1,25 +0,0 @@

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

View File

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

View File

@ -1,79 +0,0 @@
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;
}
}
}

View File

@ -1,17 +0,0 @@
namespace AirplaneWithRadar.Entities
{
public class AirplaneEntity
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; set; }
public double Step => (double)Speed * 100 / Weight;
public AirplaneEntity(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -1,16 +0,0 @@
<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>

View File

@ -1,17 +0,0 @@
namespace AirplaneWithRadar.Entities
{
public class AirplaneWithRadarEntity : AirplaneEntity
{
public Color AdditColor { get; 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;
}
}
}

View File

@ -1,95 +0,0 @@
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.MovementStrategy;
using System.Text;
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--;
}
}
public IEnumerable<T?> GetAirplanes => collection.GetAirplanes();
}
}

View File

@ -1,121 +0,0 @@
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.MovementStrategy;
using System.Text;
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;
private static readonly char separatorForKeyValue = '|';
private readonly char separatorRecords = ';';
private static readonly char separatorForObject = ':';
public AirplanesGenericStorage(int pictureWidth, int pictureHeight)
{
airplaneStorages = new Dictionary<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>>();
pictWidth = pictureWidth;
pictHeight = pictureHeight;
}
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>> record in airplaneStorages)
{
StringBuilder records = new();
foreach (PaintAirplane? elem in record.Value.GetAirplanes)
{
records.Append($"{elem?.GetDataForSave(separatorForObject)}{separatorRecords}");
}
data.AppendLine($"{record.Key}{separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
return false;
}
string strs = data.ToString();
using (StreamWriter sr = new StreamWriter(filename)) {
sr.WriteLine("AirplaneStorage");
sr.WriteLine(strs);
}
return true;
}
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader reader = new StreamReader(filename))
{
string checker = reader.ReadLine();
if (checker == null)
{
return false;
}
if (!checker.StartsWith("AirplaneStorage"))
{
return false;
}
airplaneStorages.Clear();
string strs;
bool firstinit = true;
while ((strs = reader.ReadLine()) != null)
{
if (strs == null && firstinit)
return false;
if (strs == null)
break;
if (strs == String.Empty)
break;
firstinit = false;
string name = strs.Split('|')[0];
AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane> collection = new(pictWidth, pictHeight);
foreach (string data in strs.Split('|')[1].Split(';'))
{
PaintAirplane? airplane =
data?.CreatePaintAirplane(separatorForObject, pictWidth, pictHeight);
if (airplane != null)
{
if (collection + airplane == -1)
{
return false;
}
}
}
airplaneStorages.Add(name, collection);
}
return true;
}
}
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;
}
}
}
}

View File

@ -1,45 +0,0 @@
using AirplaneWithRadar.Entities;
namespace AirplaneWithRadar.PaintObjects
{
public static class ExtentionPaintAirplane
{
public static PaintAirplane? CreatePaintAirplane(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new PaintAirplane(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 6)
{
return new PaintAirplaneWithRadar(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]),
Color.FromName(strs[2]),
Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]), width, height);
}
return null;
}
public static string GetDataForSave(this PaintAirplane paintAirplane, char separatorForObject)
{
var airplane = paintAirplane.AirplaneEntity;
if (airplane == null)
{
return string.Empty;
}
var str = $"{airplane.Speed}{separatorForObject}{airplane.Weight}{separatorForObject}{airplane.BodyColor.Name}";
if (airplane is not AirplaneWithRadarEntity airplaneWithRadar)
{
return str;
}
return $"{str}{separatorForObject}{airplaneWithRadar.AdditColor.Name}{separatorForObject}{airplaneWithRadar.RadarOnBoard}" +
$"{separatorForObject}{airplaneWithRadar.AdditFuelPod}";
}
}
}

View File

@ -1,271 +0,0 @@
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();
openFileDialog = new OpenFileDialog();
saveFileDialog = new SaveFileDialog();
menuStrip1 = new MenuStrip();
файлToolStripMenuItem1 = new ToolStripMenuItem();
сохранитьToolStripMenuItem1 = new ToolStripMenuItem();
загрузитьToolStripMenuItem1 = new ToolStripMenuItem();
сохранитьToolStripMenuItem = new ToolStripMenuItem();
загрузитьToolStripMenuItem = new ToolStripMenuItem();
файлToolStripMenuItem = new ToolStripMenuItem();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
menuStrip1.SuspendLayout();
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, 452);
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, 24);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(984, 437);
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog1";
openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
saveFileDialog.Filter = "txt file | *.txt";
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem1 });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(984, 24);
menuStrip1.TabIndex = 2;
menuStrip1.Text = "menuStrip1";
//
// файлToolStripMenuItem1
//
файлToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { сохранитьToolStripMenuItem1, загрузитьToolStripMenuItem1 });
файлToolStripMenuItem1.Name = айлToolStripMenuItem1";
файлToolStripMenuItem1.Size = new Size(48, 20);
файлToolStripMenuItem1.Text = "Файл";
//
// сохранитьToolStripMenuItem1
//
сохранитьToolStripMenuItem1.Name = "сохранитьToolStripMenuItem1";
сохранитьToolStripMenuItem1.Size = new Size(180, 22);
сохранитьToolStripMenuItem1.Text = "Сохранить";
сохранитьToolStripMenuItem1.Click += SaveToolStripMenuItem_Click;
//
// загрузитьToolStripMenuItem1
//
загрузитьToolStripMenuItem1.Name = агрузитьToolStripMenuItem1";
загрузитьToolStripMenuItem1.Size = new Size(180, 22);
загрузитьToolStripMenuItem1.Text = "Загрузить";
загрузитьToolStripMenuItem1.Click += LoadToolStripMenuItem_Click;
//
// сохранитьToolStripMenuItem
//
сохранитьToolStripMenuItem.Name = "сохранитьToolStripMenuItem";
сохранитьToolStripMenuItem.Size = new Size(133, 22);
сохранитьToolStripMenuItem.Text = "Сохранить";
//
// загрузитьToolStripMenuItem
//
загрузитьToolStripMenuItem.Name = агрузитьToolStripMenuItem";
загрузитьToolStripMenuItem.Size = new Size(133, 22);
загрузитьToolStripMenuItem.Text = "Загрузить";
//
// файлToolStripMenuItem
//
файлToolStripMenuItem.Checked = true;
файлToolStripMenuItem.CheckState = CheckState.Checked;
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранитьToolStripMenuItem, загрузитьToolStripMenuItem });
файлToolStripMenuItem.Name = айлToolStripMenuItem";
файлToolStripMenuItem.Size = new Size(48, 20);
файлToolStripMenuItem.Text = "Файл";
//
// FormAirplaneCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(984, 461);
Controls.Add(groupBox1);
Controls.Add(pictureBoxCollection);
Controls.Add(menuStrip1);
Name = "FormAirplaneCollection";
Text = "FormAirplaneCollection";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private GroupBox groupBox1;
private 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;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private MenuStrip menuStrip1;
private ToolStripMenuItem файлToolStripMenuItem1;
private ToolStripMenuItem сохранитьToolStripMenuItem;
private ToolStripMenuItem загрузитьToolStripMenuItem;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem сохранитьToolStripMenuItem1;
private ToolStripMenuItem загрузитьToolStripMenuItem1;
}
}

View File

@ -1,169 +0,0 @@
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;
}
var formAirplaneConfig = new FormAirplaneConfig();
formAirplaneConfig.AddEvent(airplane =>
{
if (listBoxStorages.SelectedIndex != -1)
{
var obj = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty];
if (obj != null)
{
if (obj + airplane != 1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowAirplanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
});
formAirplaneConfig.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();
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (storage.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (storage.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка произошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не загузилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
ReloadObjects();
}
}
}
}

View File

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

View File

@ -1,367 +0,0 @@
namespace AirplaneWithRadar
{
partial class FormAirplaneConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBox1 = new GroupBox();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
groupBox2 = new GroupBox();
panelPurple = new Panel();
panelBlack = new Panel();
panelGray = new Panel();
panelWhite = new Panel();
panelYellow = new Panel();
panelBlue = new Panel();
panelGreen = new Panel();
panelRed = new Panel();
checkBoxAdditFuelPod = new CheckBox();
checkBoxRadar = new CheckBox();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
label2 = new Label();
label1 = new Label();
panelColor = new Panel();
labelAdditColor = new Label();
labelMainColor = new Label();
pictureBoxObject = new PictureBox();
buttonOk = new Button();
buttonCancel = new Button();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
panelColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(labelModifiedObject);
groupBox1.Controls.Add(labelSimpleObject);
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(checkBoxAdditFuelPod);
groupBox1.Controls.Add(checkBoxRadar);
groupBox1.Controls.Add(numericUpDownWeight);
groupBox1.Controls.Add(numericUpDownSpeed);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Location = new Point(10, 11);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(428, 427);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Параметры";
//
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(282, 197);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(91, 41);
labelModifiedObject.TabIndex = 8;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += labelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(174, 197);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(91, 41);
labelSimpleObject.TabIndex = 7;
labelSimpleObject.Text = "Простой";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += labelObject_MouseDown;
//
// groupBox2
//
groupBox2.Controls.Add(panelPurple);
groupBox2.Controls.Add(panelBlack);
groupBox2.Controls.Add(panelGray);
groupBox2.Controls.Add(panelWhite);
groupBox2.Controls.Add(panelYellow);
groupBox2.Controls.Add(panelBlue);
groupBox2.Controls.Add(panelGreen);
groupBox2.Controls.Add(panelRed);
groupBox2.Location = new Point(140, 27);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(274, 150);
groupBox2.TabIndex = 6;
groupBox2.TabStop = false;
groupBox2.Text = "Цвет";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(209, 86);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(47, 48);
panelPurple.TabIndex = 4;
panelPurple.MouseClick += PanelColor_MouseDown;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(142, 86);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(47, 48);
panelBlack.TabIndex = 3;
panelBlack.MouseClick += PanelColor_MouseDown;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(78, 86);
panelGray.Name = "panelGray";
panelGray.Size = new Size(47, 48);
panelGray.TabIndex = 2;
panelGray.MouseClick += PanelColor_MouseDown;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(13, 86);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(47, 48);
panelWhite.TabIndex = 1;
panelWhite.MouseClick += PanelColor_MouseDown;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(209, 24);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(47, 48);
panelYellow.TabIndex = 3;
panelYellow.MouseClick += PanelColor_MouseDown;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(142, 24);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(47, 48);
panelBlue.TabIndex = 2;
panelBlue.MouseClick += PanelColor_MouseDown;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(78, 24);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(47, 48);
panelGreen.TabIndex = 1;
panelGreen.MouseClick += PanelColor_MouseDown;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(13, 24);
panelRed.Name = "panelRed";
panelRed.Size = new Size(47, 48);
panelRed.TabIndex = 0;
panelRed.MouseClick += PanelColor_MouseDown;
//
// checkBoxAdditFuelPod
//
checkBoxAdditFuelPod.AutoSize = true;
checkBoxAdditFuelPod.Location = new Point(19, 167);
checkBoxAdditFuelPod.Name = "checkBoxAdditFuelPod";
checkBoxAdditFuelPod.Size = new Size(97, 19);
checkBoxAdditFuelPod.TabIndex = 5;
checkBoxAdditFuelPod.Text = "Есть доп. бак";
checkBoxAdditFuelPod.UseVisualStyleBackColor = true;
//
// checkBoxRadar
//
checkBoxRadar.AutoSize = true;
checkBoxRadar.Location = new Point(19, 142);
checkBoxRadar.Name = "checkBoxRadar";
checkBoxRadar.Size = new Size(84, 19);
checkBoxRadar.TabIndex = 4;
checkBoxRadar.Text = "Есть радар";
checkBoxRadar.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(19, 89);
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(65, 23);
numericUpDownWeight.TabIndex = 3;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(19, 45);
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(65, 23);
numericUpDownSpeed.TabIndex = 2;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(15, 71);
label2.Name = "label2";
label2.Size = new Size(26, 15);
label2.TabIndex = 1;
label2.Text = "Вес";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(15, 27);
label1.Name = "label1";
label1.Size = new Size(59, 15);
label1.TabIndex = 0;
label1.Text = "Скорость";
//
// panelColor
//
panelColor.AllowDrop = true;
panelColor.Controls.Add(labelAdditColor);
panelColor.Controls.Add(labelMainColor);
panelColor.Controls.Add(pictureBoxObject);
panelColor.Location = new Point(444, 11);
panelColor.Name = "panelColor";
panelColor.Size = new Size(344, 344);
panelColor.TabIndex = 1;
panelColor.DragDrop += PanelObject_DragDrop;
panelColor.DragEnter += PanelObject_DragEnter;
panelColor.MouseDown += PanelColor_MouseDown;
//
// labelAdditColor
//
labelAdditColor.AllowDrop = true;
labelAdditColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditColor.Location = new Point(193, 21);
labelAdditColor.Name = "labelAdditColor";
labelAdditColor.Size = new Size(131, 33);
labelAdditColor.TabIndex = 10;
labelAdditColor.Text = "Доп. цвет";
labelAdditColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditColor.DragDrop += labelAdditColor_DragDrop;
labelAdditColor.DragEnter += labelColor_DragEnter;
labelAdditColor.MouseDown += labelObject_MouseDown;
//
// labelMainColor
//
labelMainColor.AllowDrop = true;
labelMainColor.BorderStyle = BorderStyle.FixedSingle;
labelMainColor.Location = new Point(26, 21);
labelMainColor.Name = "labelMainColor";
labelMainColor.Size = new Size(128, 33);
labelMainColor.TabIndex = 9;
labelMainColor.Text = "Цвет";
labelMainColor.TextAlign = ContentAlignment.MiddleCenter;
labelMainColor.DragDrop += labelMainColor_DragDrop;
labelMainColor.DragEnter += labelColor_DragEnter;
labelMainColor.MouseDown += labelObject_MouseDown;
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(26, 65);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(298, 264);
pictureBoxObject.TabIndex = 11;
pictureBoxObject.TabStop = false;
//
// buttonOk
//
buttonOk.Location = new Point(470, 379);
buttonOk.Name = "buttonOk";
buttonOk.Size = new Size(128, 44);
buttonOk.TabIndex = 2;
buttonOk.Text = "Добавить";
buttonOk.UseVisualStyleBackColor = true;
buttonOk.Click += buttonOk_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(623, 379);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(128, 44);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// FormAirplaneConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonCancel);
Controls.Add(buttonOk);
Controls.Add(panelColor);
Controls.Add(groupBox1);
Name = "FormAirplaneConfig";
Text = "FormAirplaneConfig";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
panelColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Label label1;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label label2;
private GroupBox groupBox2;
private CheckBox checkBoxAdditFuelPod;
private CheckBox checkBoxRadar;
private Label labelModifiedObject;
private Label labelSimpleObject;
private Panel panelColor;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelGray;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private PictureBox pictureBoxObject;
private Label labelAdditColor;
private Label labelMainColor;
private Button buttonOk;
private Button buttonCancel;
}
}

View File

@ -1,135 +0,0 @@
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.Entities;
namespace AirplaneWithRadar
{
public partial class FormAirplaneConfig : Form
{
PaintAirplane? airplane = null;
private event Action<PaintAirplane> EventAddAirplane;
public FormAirplaneConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
public void DrawAirplane()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
airplane?.SetPosition(5, 5);
airplane?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(Action<PaintAirplane> ev)
{
if (EventAddAirplane == null)
{
EventAddAirplane = new Action<PaintAirplane>(ev);
}
else
{
EventAddAirplane += ev;
}
}
private void labelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
airplane = new PaintAirplane((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelModifiedObject":
airplane = new PaintAirplaneWithRadar((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRadar.Checked,
checkBoxAdditFuelPod.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
break;
}
DrawAirplane();
}
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (airplane != null && airplane.AirplaneEntity is AirplaneWithRadarEntity entityAirplane)
{
labelAdditColor.AllowDrop = true;
}
else
{
labelAdditColor.AllowDrop = false;
}
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelMainColor_DragDrop(object sender, DragEventArgs e)
{
if (airplane != null)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
airplane.AirplaneEntity.BodyColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAirplane();
}
}
private void labelAdditColor_DragDrop(object sender, DragEventArgs e)
{
if (airplane != null && airplane.AirplaneEntity is AirplaneWithRadarEntity airplaneWithRadarEntity)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
airplaneWithRadarEntity.AdditColor = (Color)e.Data.GetData(typeof(Color));
}
DrawAirplane();
}
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void buttonOk_Click(object sender, EventArgs e)
{
EventAddAirplane?.Invoke(airplane);
Close();
}
}
}

View File

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

View File

@ -1,10 +0,0 @@
namespace AirplaneWithRadar.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(Movement direction);
void MoveObject(Movement direction);
}
}

View File

@ -1,53 +0,0 @@
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();
}
}
}
}
}

View File

@ -1,52 +0,0 @@
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();
}
}
}
}
}

View File

@ -1,10 +0,0 @@
namespace AirplaneWithRadar
{
public enum Movement
{
Up = 1,
Down = 2,
Left = 3,
Right = 4,
}
}

View File

@ -1,29 +0,0 @@
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;
}
}
}

View File

@ -1,218 +0,0 @@
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);
}
}
}
}

View File

@ -1,40 +0,0 @@
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);
}
}
}
}

View File

@ -1,31 +0,0 @@
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);
}
}

View File

@ -1,184 +0,0 @@
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;
}
}

View File

@ -1,137 +0,0 @@
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;
}
}
}

View File

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

View File

@ -1,17 +0,0 @@
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());
}
}
}

View File

@ -1,116 +0,0 @@
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;
}
}
}
}

View File

@ -1,9 +0,0 @@
namespace AirplaneWithRadar.MovementStrategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}