This commit is contained in:
DavidMakarov 2023-10-31 21:17:10 +04:00
parent c21d23e3e6
commit 79f59d7743
19 changed files with 298 additions and 160 deletions

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.MovementStrategy
{ {
public abstract class AbstractStrategy public abstract class AbstractStrategy
{ {

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar.Entities
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.Entities
{ {
public class AirplaneEntity public class AirplaneEntity
{ {

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar.Entities
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.Entities
{ {
public class AirplaneWithRadarEntity : AirplaneEntity public class AirplaneWithRadarEntity : AirplaneEntity
{ {

View File

@ -1,9 +1,4 @@
using System.Collections.Generic; using AirplaneWithRadar.PaintObjects;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.MovementStrategy; using AirplaneWithRadar.MovementStrategy;
namespace AirplaneWithRadar.Generics namespace AirplaneWithRadar.Generics
@ -38,7 +33,7 @@ namespace AirplaneWithRadar.Generics
} }
public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos) public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
{ {
T? obj = collect.collection.Get(pos); T? obj = collect.collection[pos];
if (obj == null) if (obj == null)
{ {
return false; return false;
@ -48,7 +43,7 @@ namespace AirplaneWithRadar.Generics
public U? GetU(int pos) public U? GetU(int pos)
{ {
return (U?)collection.Get(pos)?.GetMoveableObject; return (U?)collection[pos]?.GetMoveableObject;
} }
public Bitmap ShowAirplanes() public Bitmap ShowAirplanes()
@ -80,9 +75,7 @@ namespace AirplaneWithRadar.Generics
int j = 3; int j = 3;
int k = 0; int k = 0;
for (int i = 0; i < collection.Count; i++) foreach (var airplane in collection.GetAirplanes()) {
{
PaintAirplane? airplane = collection.Get(i);
if (j < 0) if (j < 0)
{ {
j += 4; j += 4;

View File

@ -0,0 +1,37 @@
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.MovementStrategy;
namespace AirplaneWithRadar.Generics
{
internal class AirplanesGenericStorage
{
readonly Dictionary<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>> airplaneStorages;
public List<string> Keys => airplaneStorages.Keys.ToList();
private readonly int pictWidth;
private readonly int pictHeight;
public AirplanesGenericStorage(int pictureWidth, int pictureHeight)
{
airplaneStorages = new Dictionary<string, AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>>();
pictWidth = pictureWidth;
pictHeight = pictureHeight;
}
public void AddSet(string name)
{
airplaneStorages.Add(name, new AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>(pictWidth, pictHeight));
}
public void DelSet(string name)
{
airplaneStorages.Remove(name);
}
public AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>? this[string ind]
{
get
{
if (airplaneStorages.ContainsKey(ind)) return airplaneStorages[ind];
return null;
}
}
}
}

View File

@ -29,17 +29,24 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBox1 = new GroupBox(); groupBox1 = new GroupBox();
groupBox2 = new GroupBox();
buttonDelObject = new Button();
buttonAddObject = new Button();
textBoxStorageName = new TextBox();
listBoxStorages = new ListBox();
maskedTextBoxNumber = new TextBox(); maskedTextBoxNumber = new TextBox();
ButtonRefreshCollection = new Button(); ButtonRefreshCollection = new Button();
ButtonDeleteAirplane = new Button(); ButtonDeleteAirplane = new Button();
ButtonAddAirplane = new Button(); ButtonAddAirplane = new Button();
pictureBoxCollection = new PictureBox(); pictureBoxCollection = new PictureBox();
groupBox1.SuspendLayout(); groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// groupBox1 // groupBox1
// //
groupBox1.Controls.Add(groupBox2);
groupBox1.Controls.Add(maskedTextBoxNumber); groupBox1.Controls.Add(maskedTextBoxNumber);
groupBox1.Controls.Add(ButtonRefreshCollection); groupBox1.Controls.Add(ButtonRefreshCollection);
groupBox1.Controls.Add(ButtonDeleteAirplane); groupBox1.Controls.Add(ButtonDeleteAirplane);
@ -51,16 +58,66 @@
groupBox1.TabStop = false; groupBox1.TabStop = false;
groupBox1.Text = "Инструменты"; 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
// //
maskedTextBoxNumber.Location = new Point(39, 148); maskedTextBoxNumber.Location = new Point(39, 289);
maskedTextBoxNumber.Name = "maskedTextBoxNumber"; maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(161, 23); maskedTextBoxNumber.Size = new Size(161, 23);
maskedTextBoxNumber.TabIndex = 3; maskedTextBoxNumber.TabIndex = 3;
// //
// ButtonRefreshCollection // ButtonRefreshCollection
// //
ButtonRefreshCollection.Location = new Point(20, 229); ButtonRefreshCollection.Location = new Point(20, 370);
ButtonRefreshCollection.Name = "ButtonRefreshCollection"; ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(194, 46); ButtonRefreshCollection.Size = new Size(194, 46);
ButtonRefreshCollection.TabIndex = 2; ButtonRefreshCollection.TabIndex = 2;
@ -70,7 +127,7 @@
// //
// ButtonDeleteAirplane // ButtonDeleteAirplane
// //
ButtonDeleteAirplane.Location = new Point(20, 177); ButtonDeleteAirplane.Location = new Point(20, 318);
ButtonDeleteAirplane.Name = "ButtonDeleteAirplane"; ButtonDeleteAirplane.Name = "ButtonDeleteAirplane";
ButtonDeleteAirplane.Size = new Size(194, 46); ButtonDeleteAirplane.Size = new Size(194, 46);
ButtonDeleteAirplane.TabIndex = 1; ButtonDeleteAirplane.TabIndex = 1;
@ -80,7 +137,7 @@
// //
// ButtonAddAirplane // ButtonAddAirplane
// //
ButtonAddAirplane.Location = new Point(20, 22); ButtonAddAirplane.Location = new Point(23, 237);
ButtonAddAirplane.Name = "ButtonAddAirplane"; ButtonAddAirplane.Name = "ButtonAddAirplane";
ButtonAddAirplane.Size = new Size(194, 46); ButtonAddAirplane.Size = new Size(194, 46);
ButtonAddAirplane.TabIndex = 0; ButtonAddAirplane.TabIndex = 0;
@ -108,6 +165,8 @@
Text = "FormAirplaneCollection"; Text = "FormAirplaneCollection";
groupBox1.ResumeLayout(false); groupBox1.ResumeLayout(false);
groupBox1.PerformLayout(); groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
@ -120,5 +179,10 @@
private Button ButtonAddAirplane; private Button ButtonAddAirplane;
private PictureBox pictureBoxCollection; private PictureBox pictureBoxCollection;
private TextBox maskedTextBoxNumber; private TextBox maskedTextBoxNumber;
private ListBox listBoxStorages;
private GroupBox groupBox2;
private Button buttonDelObject;
private Button buttonAddObject;
private TextBox textBoxStorageName;
} }
} }

View File

@ -1,69 +1,119 @@
using AirplaneWithRadar.Generics; using AirplaneWithRadar.Generics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.MovementStrategy;
namespace AirplaneWithRadar namespace AirplaneWithRadar
{ {
public partial class FormAirplaneCollection : Form public partial class FormAirplaneCollection : Form
{ {
private readonly AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane> airplanes; private readonly AirplanesGenericStorage storage;
public FormAirplaneCollection() public FormAirplaneCollection()
{ {
InitializeComponent(); InitializeComponent();
airplanes = new AirplanesGenericCollection<PaintAirplane, PaintObjectAirplane>(pictureBoxCollection.Width, pictureBoxCollection.Height); 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 buttonDelObject_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
}
private void ButtonAddAirplane_Click(object sender, EventArgs e) private void ButtonAddAirplane_Click(object sender, EventArgs e)
{ {
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
PlaneVisual form = new(); PlaneVisual form = new();
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (airplanes + form.SelectedAirplane != -1) if (!(obj + form.SelectedAirplane == -1))
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = airplanes.ShowAirplanes(); pictureBoxCollection.Image = obj.ShowAirplanes();
} }
else else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} }
} }
private void ButtonDeleteAirplane_Click(object sender, EventArgs e) 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) if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{ {
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxNumber.Text); int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (airplanes - pos != false) if (obj - pos != false)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBoxCollection.Image = airplanes.ShowAirplanes(); pictureBoxCollection.Image = obj.ShowAirplanes();
} }
else else
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show("Не удалось удалить объект");
} }
} }
private void ButtonRefreshCollection_Click(object sender, EventArgs e) private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{ {
pictureBoxCollection.Image = airplanes.ShowAirplanes(); if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowAirplanes();
}
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image = storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes();
} }
} }
} }

View File

@ -1,4 +1,64 @@
<root> <?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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class GenericClass<T>
where T : AirplaneWithRadar.PaintObjects.PaintAirplaneWithRadar
{
}
}

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.MovementStrategy
{ {
public interface IMoveableObject public interface IMoveableObject
{ {

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.MovementStrategy
{ {
public class MoveToBorder : AbstractStrategy public class MoveToBorder : AbstractStrategy
{ {

View File

@ -1,11 +1,4 @@
 namespace AirplaneWithRadar.MovementStrategy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.MovementStrategy
{ {
public class MoveToCenter : AbstractStrategy public class MoveToCenter : AbstractStrategy
{ {

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{ {
public enum Movement public enum Movement
{ {

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.MovementStrategy
{ {
public class ObjectParameters public class ObjectParameters
{ {

View File

@ -1,9 +1,4 @@
using System; using System.Drawing.Drawing2D;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirplaneWithRadar.Entities; using AirplaneWithRadar.Entities;
using AirplaneWithRadar.MovementStrategy; using AirplaneWithRadar.MovementStrategy;

View File

@ -1,12 +1,4 @@
 using AirplaneWithRadar.Entities;
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 namespace AirplaneWithRadar.PaintObjects
{ {

View File

@ -1,10 +1,4 @@
using AirplaneWithRadar.MovementStrategy; using AirplaneWithRadar.PaintObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirplaneWithRadar.PaintObjects;
namespace AirplaneWithRadar.MovementStrategy namespace AirplaneWithRadar.MovementStrategy

View File

@ -1,22 +1,24 @@
using System.Collections.Generic; namespace AirplaneWithRadar.Generics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.Generics;
internal class SetGeneric<T> internal class SetGeneric<T>
where T : class where T : class
{ {
private readonly T?[] places; private readonly List<T?> places;
public int Count => places.Length; public int Count => places.Count;
public readonly int maxCount;
public SetGeneric(int count) public SetGeneric(int count)
{ {
places = new T?[count]; maxCount = count;
places = new List<T?>(count);
} }
public int Insert(T airplane) public int Insert(T airplane)
{ {
if (Count == 0)
{
places.Add(airplane);
return 0;
}
int emptyPosition = -1; int emptyPosition = -1;
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
@ -28,15 +30,10 @@ internal class SetGeneric<T>
} }
if (emptyPosition < 0) if (emptyPosition < 0)
{ {
return -1; places.Add(airplane);
return 0;
} }
Insert(airplane, emptyPosition);
for (int i = emptyPosition; i > 0; i--)
{
places[i] = places[i - 1];
}
places[0] = airplane;
return 0; return 0;
} }
public int Insert(T airplane, int position) public int Insert(T airplane, int position)
@ -79,15 +76,41 @@ internal class SetGeneric<T>
{ {
return false; return false;
} }
places[position] = null; places[position]=null;
return true; return true;
} }
public T? Get(int position)
public T? this[int position]
{ {
if (position >= Count && position < 0) get
{ {
return null; 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;
}
} }
return places[position];
} }
} }

View File

@ -1,10 +1,4 @@
using System; namespace AirplaneWithRadar.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar.MovementStrategy
{ {
public enum Status public enum Status
{ {