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)
{
int i = 0;
foreach (var cruiser in _collection.GetTheBuses())
foreach (var cruiser in _collection.GetCruiser())
{
if (cruiser != null)
{

View File

@ -18,14 +18,14 @@
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.panelCruiser = 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.ButtonRefresh = new System.Windows.Forms.Button();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.ButtonAddObject = 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.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();
this.panelCruiser.SuspendLayout();
this.panelSet.SuspendLayout();
@ -40,108 +40,103 @@
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCruiser.TabIndex = 0;
this.pictureBoxCruiser.TabStop = false;
this.pictureBoxCruiser.Click += new System.EventHandler(this.pictureBoxCruiser_Click);
//
// panelCruiser
//
this.panelCruiser.Controls.Add(this.panelSet);
this.panelCruiser.Controls.Add(this.ButtonRefresh);
this.panelCruiser.Controls.Add(this.ButtonRefreshCollection);
this.panelCruiser.Controls.Add(this.ButtonRemoveCruiser);
this.panelCruiser.Controls.Add(this.ButtonAddCruiser);
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.Size = new System.Drawing.Size(303, 486);
this.panelCruiser.Size = new System.Drawing.Size(221, 486);
this.panelCruiser.TabIndex = 1;
this.panelCruiser.Paint += new System.Windows.Forms.PaintEventHandler(this.panelCruiser_Paint);
//
// panelSet
//
this.panelSet.AccessibleDescription = "";
this.panelSet.AccessibleName = "";
this.panelSet.Controls.Add(this.ButtonDelObject);
this.panelSet.Controls.Add(this.listBoxStorages);
this.panelSet.Controls.Add(this.ButtonAddObject);
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.Size = new System.Drawing.Size(258, 242);
this.panelSet.TabIndex = 4;
this.panelSet.Tag = "";
this.panelSet.Size = new System.Drawing.Size(185, 241);
this.panelSet.TabIndex = 0;
//
// ButtonDelObject
// textBoxSet
//
this.ButtonDelObject.Location = new System.Drawing.Point(40, 188);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(161, 39);
this.ButtonDelObject.TabIndex = 3;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
this.textBoxSet.Location = new System.Drawing.Point(38, 21);
this.textBoxSet.Name = "textBoxSet";
this.textBoxSet.Size = new System.Drawing.Size(118, 31);
this.textBoxSet.TabIndex = 0;
//
// ButtonAddObject
//
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
//
this.listBoxStorages.FormattingEnabled = true;
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.Size = new System.Drawing.Size(103, 79);
this.listBoxStorages.TabIndex = 2;
this.listBoxStorages.Size = new System.Drawing.Size(97, 54);
this.listBoxStorages.TabIndex = 3;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
//
// ButtonAddObject
// ButtonDelObject
//
this.ButtonAddObject.Location = new System.Drawing.Point(40, 53);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(161, 44);
this.ButtonAddObject.TabIndex = 1;
this.ButtonAddObject.Text = "Создать набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_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);
this.ButtonDelObject.Location = new System.Drawing.Point(18, 175);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(153, 47);
this.ButtonDelObject.TabIndex = 2;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// 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.Size = new System.Drawing.Size(168, 54);
this.ButtonAddCruiser.TabIndex = 3;
this.ButtonAddCruiser.Text = "Добавить объект";
this.ButtonAddCruiser.Size = new System.Drawing.Size(133, 38);
this.ButtonAddCruiser.TabIndex = 2;
this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
//
// 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.Size = new System.Drawing.Size(168, 31);
this.textBoxCruiser.TabIndex = 2;
this.textBoxCruiser.Size = new System.Drawing.Size(133, 31);
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
//
@ -165,14 +160,14 @@
private PictureBox pictureBoxCruiser;
private Panel panelCruiser;
private Button ButtonRemoveCruiser;
private Button ButtonAddCruiser;
private TextBox textBoxCruiser;
private Button ButtonRefresh;
private Panel panelSet;
private Button ButtonDelObject;
private TextBox textBoxSet;
private ListBox listBoxStorages;
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.Threading.Tasks;
using System.Windows.Forms;
using Cruiser.DrawningObjects;
using Cruiser.MovementStrategy;
namespace Cruiser
{
@ -137,15 +135,5 @@ namespace Cruiser
}
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>
where T : class
{
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _places;
/// <summary>
/// Количество объектов в cписке
/// </summary>
public int Count => _places.Count;
/// <summary>
/// Максимальное количество объектов в cписке
/// </summary>
private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(count);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="bus">Добавляемый автобус</param>
/// <returns></returns>
public bool Insert(T bus)
public bool Insert(T cruiser)
{
if (_places.Count == _maxCount)
{
return false;
}
Insert(bus, 0);
Insert(cruiser, 0);
return true;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="bus">Добавляемый автобус</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T bus, int position)
public bool Insert(T cruiser, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
{
return false;
}
_places.Insert(position, bus);
_places.Insert(position, cruiser);
return true;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (position < 0 || position >= Count)
@ -82,12 +46,6 @@ namespace Cruiser.Generics
_places.RemoveAt(position);
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? this[int position]
{
get
@ -96,7 +54,6 @@ namespace Cruiser.Generics
{
return null;
}
return _places[position];
}
set
@ -105,26 +62,20 @@ namespace Cruiser.Generics
{
return;
}
_places.Insert(position, value);
return;
}
}
/// <summary>
/// Проход по списку
/// </summary>
/// <returns></returns>
public IEnumerable<T?> GetTheBuses(int? maxTheBuses = null)
public IEnumerable<T?> GetCruiser(int? maxCruisers = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxTheBuses.HasValue && i == maxTheBuses.Value)
if (maxCruisers.HasValue && i == maxCruisers.Value)
{
yield break;
}
}
}
}
}
}