This commit is contained in:
Alenka 2023-11-24 22:21:54 +04:00
parent f0cb0ab565
commit ce753bc8db
4 changed files with 80 additions and 146 deletions

View File

@ -78,7 +78,7 @@ namespace Cruiser.Generics
private void DrawObjects(Graphics g) private void DrawObjects(Graphics g)
{ {
int i = 0; int i = 0;
foreach (var cruiser in _collection.GetTheBuses()) foreach (var cruiser in _collection.GetCruiser())
{ {
if (cruiser != null) if (cruiser != null)
{ {

View File

@ -18,14 +18,14 @@
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox(); this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.panelCruiser = new System.Windows.Forms.Panel(); this.panelCruiser = new System.Windows.Forms.Panel();
this.panelSet = new System.Windows.Forms.Panel(); this.panelSet = new System.Windows.Forms.Panel();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.textBoxSet = new System.Windows.Forms.TextBox(); this.textBoxSet = new System.Windows.Forms.TextBox();
this.ButtonRefresh = new System.Windows.Forms.Button(); this.ButtonAddObject = new System.Windows.Forms.Button();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button(); this.listBoxStorages = new System.Windows.Forms.ListBox();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.ButtonAddCruiser = new System.Windows.Forms.Button(); this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.textBoxCruiser = new System.Windows.Forms.TextBox(); this.textBoxCruiser = new System.Windows.Forms.TextBox();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.panelCruiser.SuspendLayout(); this.panelCruiser.SuspendLayout();
this.panelSet.SuspendLayout(); this.panelSet.SuspendLayout();
@ -40,108 +40,103 @@
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCruiser.TabIndex = 0; this.pictureBoxCruiser.TabIndex = 0;
this.pictureBoxCruiser.TabStop = false; this.pictureBoxCruiser.TabStop = false;
this.pictureBoxCruiser.Click += new System.EventHandler(this.pictureBoxCruiser_Click);
// //
// panelCruiser // panelCruiser
// //
this.panelCruiser.Controls.Add(this.panelSet); this.panelCruiser.Controls.Add(this.ButtonRefreshCollection);
this.panelCruiser.Controls.Add(this.ButtonRefresh);
this.panelCruiser.Controls.Add(this.ButtonRemoveCruiser); this.panelCruiser.Controls.Add(this.ButtonRemoveCruiser);
this.panelCruiser.Controls.Add(this.ButtonAddCruiser);
this.panelCruiser.Controls.Add(this.textBoxCruiser); this.panelCruiser.Controls.Add(this.textBoxCruiser);
this.panelCruiser.Location = new System.Drawing.Point(589, 12); this.panelCruiser.Controls.Add(this.ButtonAddCruiser);
this.panelCruiser.Controls.Add(this.panelSet);
this.panelCruiser.Location = new System.Drawing.Point(655, 12);
this.panelCruiser.Name = "panelCruiser"; this.panelCruiser.Name = "panelCruiser";
this.panelCruiser.Size = new System.Drawing.Size(303, 486); this.panelCruiser.Size = new System.Drawing.Size(221, 486);
this.panelCruiser.TabIndex = 1; this.panelCruiser.TabIndex = 1;
this.panelCruiser.Paint += new System.Windows.Forms.PaintEventHandler(this.panelCruiser_Paint);
// //
// panelSet // panelSet
// //
this.panelSet.AccessibleDescription = "";
this.panelSet.AccessibleName = "";
this.panelSet.Controls.Add(this.ButtonDelObject); this.panelSet.Controls.Add(this.ButtonDelObject);
this.panelSet.Controls.Add(this.listBoxStorages); this.panelSet.Controls.Add(this.listBoxStorages);
this.panelSet.Controls.Add(this.ButtonAddObject); this.panelSet.Controls.Add(this.ButtonAddObject);
this.panelSet.Controls.Add(this.textBoxSet); this.panelSet.Controls.Add(this.textBoxSet);
this.panelSet.Location = new System.Drawing.Point(26, 3); this.panelSet.Location = new System.Drawing.Point(22, 19);
this.panelSet.Name = "panelSet"; this.panelSet.Name = "panelSet";
this.panelSet.Size = new System.Drawing.Size(258, 242); this.panelSet.Size = new System.Drawing.Size(185, 241);
this.panelSet.TabIndex = 4; this.panelSet.TabIndex = 0;
this.panelSet.Tag = "";
// //
// ButtonDelObject // textBoxSet
// //
this.ButtonDelObject.Location = new System.Drawing.Point(40, 188); this.textBoxSet.Location = new System.Drawing.Point(38, 21);
this.ButtonDelObject.Name = "ButtonDelObject"; this.textBoxSet.Name = "textBoxSet";
this.ButtonDelObject.Size = new System.Drawing.Size(161, 39); this.textBoxSet.Size = new System.Drawing.Size(118, 31);
this.ButtonDelObject.TabIndex = 3; this.textBoxSet.TabIndex = 0;
this.ButtonDelObject.Text = "Удалить набор"; //
this.ButtonDelObject.UseVisualStyleBackColor = true; // ButtonAddObject
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click); //
this.ButtonAddObject.Location = new System.Drawing.Point(18, 58);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(153, 51);
this.ButtonAddObject.TabIndex = 2;
this.ButtonAddObject.Text = "Создать набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
// //
// listBoxStorages // listBoxStorages
// //
this.listBoxStorages.FormattingEnabled = true; this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 25; this.listBoxStorages.ItemHeight = 25;
this.listBoxStorages.Location = new System.Drawing.Point(77, 103); this.listBoxStorages.Location = new System.Drawing.Point(49, 115);
this.listBoxStorages.Name = "listBoxStorages"; this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(103, 79); this.listBoxStorages.Size = new System.Drawing.Size(97, 54);
this.listBoxStorages.TabIndex = 2; this.listBoxStorages.TabIndex = 3;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged); this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
// //
// ButtonAddObject // ButtonDelObject
// //
this.ButtonAddObject.Location = new System.Drawing.Point(40, 53); this.ButtonDelObject.Location = new System.Drawing.Point(18, 175);
this.ButtonAddObject.Name = "ButtonAddObject"; this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonAddObject.Size = new System.Drawing.Size(161, 44); this.ButtonDelObject.Size = new System.Drawing.Size(153, 47);
this.ButtonAddObject.TabIndex = 1; this.ButtonDelObject.TabIndex = 2;
this.ButtonAddObject.Text = "Создать набор"; this.ButtonDelObject.Text = "Удалить набор";
this.ButtonAddObject.UseVisualStyleBackColor = true; this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click); this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// textBoxSet
//
this.textBoxSet.Location = new System.Drawing.Point(61, 16);
this.textBoxSet.Name = "textBoxSet";
this.textBoxSet.Size = new System.Drawing.Size(119, 31);
this.textBoxSet.TabIndex = 0;
//
// ButtonRefresh
//
this.ButtonRefresh.Location = new System.Drawing.Point(57, 452);
this.ButtonRefresh.Name = "ButtonRefresh";
this.ButtonRefresh.Size = new System.Drawing.Size(168, 31);
this.ButtonRefresh.TabIndex = 2;
this.ButtonRefresh.Text = "Обновить";
this.ButtonRefresh.UseVisualStyleBackColor = true;
this.ButtonRefresh.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveCruiser
//
this.ButtonRemoveCruiser.Location = new System.Drawing.Point(57, 394);
this.ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
this.ButtonRemoveCruiser.Size = new System.Drawing.Size(168, 34);
this.ButtonRemoveCruiser.TabIndex = 2;
this.ButtonRemoveCruiser.Text = "Удалить";
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
// //
// ButtonAddCruiser // ButtonAddCruiser
// //
this.ButtonAddCruiser.Location = new System.Drawing.Point(57, 262); this.ButtonAddCruiser.Location = new System.Drawing.Point(45, 266);
this.ButtonAddCruiser.Name = "ButtonAddCruiser"; this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(168, 54); this.ButtonAddCruiser.Size = new System.Drawing.Size(133, 38);
this.ButtonAddCruiser.TabIndex = 3; this.ButtonAddCruiser.TabIndex = 2;
this.ButtonAddCruiser.Text = "Добавить объект"; this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true; this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click); this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
// //
// textBoxCruiser // textBoxCruiser
// //
this.textBoxCruiser.Location = new System.Drawing.Point(57, 336); this.textBoxCruiser.Location = new System.Drawing.Point(45, 330);
this.textBoxCruiser.Name = "textBoxCruiser"; this.textBoxCruiser.Name = "textBoxCruiser";
this.textBoxCruiser.Size = new System.Drawing.Size(168, 31); this.textBoxCruiser.Size = new System.Drawing.Size(133, 31);
this.textBoxCruiser.TabIndex = 2; this.textBoxCruiser.TabIndex = 3;
//
// ButtonRemoveCruiser
//
this.ButtonRemoveCruiser.Location = new System.Drawing.Point(45, 391);
this.ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
this.ButtonRemoveCruiser.Size = new System.Drawing.Size(138, 38);
this.ButtonRemoveCruiser.TabIndex = 2;
this.ButtonRemoveCruiser.Text = "Удалить";
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
//
// ButtonRefreshCollection
//
this.ButtonRefreshCollection.Location = new System.Drawing.Point(45, 435);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(138, 41);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
// //
// FormCruiserCollection // FormCruiserCollection
// //
@ -165,14 +160,14 @@
private PictureBox pictureBoxCruiser; private PictureBox pictureBoxCruiser;
private Panel panelCruiser; private Panel panelCruiser;
private Button ButtonRemoveCruiser;
private Button ButtonAddCruiser;
private TextBox textBoxCruiser;
private Button ButtonRefresh;
private Panel panelSet; private Panel panelSet;
private Button ButtonDelObject; private TextBox textBoxSet;
private ListBox listBoxStorages; private ListBox listBoxStorages;
private Button ButtonAddObject; private Button ButtonAddObject;
private TextBox textBoxSet; private Button ButtonDelObject;
private Button ButtonAddCruiser;
private Button ButtonRemoveCruiser;
private TextBox textBoxCruiser;
private Button ButtonRefreshCollection;
} }
} }

View File

@ -8,8 +8,6 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Cruiser.DrawningObjects;
using Cruiser.MovementStrategy;
namespace Cruiser namespace Cruiser
{ {
@ -137,15 +135,5 @@ namespace Cruiser
} }
pictureBoxCruiser.Image = obj.ShowCruisers(); pictureBoxCruiser.Image = obj.ShowCruisers();
} }
private void panelCruiser_Paint(object sender, PaintEventArgs e)
{
}
private void pictureBoxCruiser_Click(object sender, EventArgs e)
{
}
} }
} }

View File

@ -9,69 +9,33 @@ namespace Cruiser.Generics
internal class SetGeneric<T> internal class SetGeneric<T>
where T : class where T : class
{ {
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _places; private readonly List<T?> _places;
/// <summary>
/// Количество объектов в cписке
/// </summary>
public int Count => _places.Count; public int Count => _places.Count;
/// <summary>
/// Максимальное количество объектов в cписке
/// </summary>
private readonly int _maxCount; private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetGeneric(int count) public SetGeneric(int count)
{ {
_maxCount = count; _maxCount = count;
_places = new List<T?>(count); _places = new List<T?>(count);
} }
public bool Insert(T cruiser)
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="bus">Добавляемый автобус</param>
/// <returns></returns>
public bool Insert(T bus)
{ {
if (_places.Count == _maxCount) if (_places.Count == _maxCount)
{ {
return false; return false;
} }
Insert(bus, 0); Insert(cruiser, 0);
return true; return true;
} }
public bool Insert(T cruiser, int position)
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="bus">Добавляемый автобус</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T bus, int position)
{ {
if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
{ {
return false; return false;
} }
_places.Insert(position, cruiser);
_places.Insert(position, bus);
return true; return true;
} }
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position) public bool Remove(int position)
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
@ -82,12 +46,6 @@ namespace Cruiser.Generics
_places.RemoveAt(position); _places.RemoveAt(position);
return true; return true;
} }
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? this[int position] public T? this[int position]
{ {
get get
@ -96,7 +54,6 @@ namespace Cruiser.Generics
{ {
return null; return null;
} }
return _places[position]; return _places[position];
} }
set set
@ -105,26 +62,20 @@ namespace Cruiser.Generics
{ {
return; return;
} }
_places.Insert(position, value); _places.Insert(position, value);
return; return;
} }
} }
public IEnumerable<T?> GetCruiser(int? maxCruisers = null)
/// <summary>
/// Проход по списку
/// </summary>
/// <returns></returns>
public IEnumerable<T?> GetTheBuses(int? maxTheBuses = null)
{ {
for (int i = 0; i < _places.Count; ++i) for (int i = 0; i < _places.Count; ++i)
{ {
yield return _places[i]; yield return _places[i];
if (maxTheBuses.HasValue && i == maxTheBuses.Value) if (maxCruisers.HasValue && i == maxCruisers.Value)
{ {
yield break; yield break;
} }
} }
} }
} }
} }