л4
This commit is contained in:
parent
bb1b96f3ff
commit
61099f558b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
129
MotorShip/MotorShip/FormShipCollection.Designer.cs
generated
129
MotorShip/MotorShip/FormShipCollection.Designer.cs
generated
@ -30,35 +30,76 @@
|
|||||||
{
|
{
|
||||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
this.panelCollection = new System.Windows.Forms.Panel();
|
this.panelCollection = new System.Windows.Forms.Panel();
|
||||||
this.labelCollection = new System.Windows.Forms.Label();
|
|
||||||
this.buttonAddShip = new System.Windows.Forms.Button();
|
|
||||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
|
||||||
this.buttonRemoveShip = new System.Windows.Forms.Button();
|
|
||||||
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRemoveShip = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.buttonAddShip = new System.Windows.Forms.Button();
|
||||||
|
this.labelCollection = new System.Windows.Forms.Label();
|
||||||
|
this.groupBoxSets = new System.Windows.Forms.GroupBox();
|
||||||
|
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonnAddObject = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||||
|
this.buttonDelObject = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
this.panelCollection.SuspendLayout();
|
this.panelCollection.SuspendLayout();
|
||||||
|
this.groupBoxSets.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
this.pictureBoxCollection.Size = new System.Drawing.Size(700, 453);
|
this.pictureBoxCollection.Size = new System.Drawing.Size(864, 536);
|
||||||
this.pictureBoxCollection.TabIndex = 0;
|
this.pictureBoxCollection.TabIndex = 0;
|
||||||
this.pictureBoxCollection.TabStop = false;
|
this.pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// panelCollection
|
// panelCollection
|
||||||
//
|
//
|
||||||
|
this.panelCollection.Controls.Add(this.groupBoxSets);
|
||||||
this.panelCollection.Controls.Add(this.buttonRefreshCollection);
|
this.panelCollection.Controls.Add(this.buttonRefreshCollection);
|
||||||
this.panelCollection.Controls.Add(this.buttonRemoveShip);
|
this.panelCollection.Controls.Add(this.buttonRemoveShip);
|
||||||
this.panelCollection.Controls.Add(this.maskedTextBoxNumber);
|
this.panelCollection.Controls.Add(this.maskedTextBoxNumber);
|
||||||
this.panelCollection.Controls.Add(this.buttonAddShip);
|
this.panelCollection.Controls.Add(this.buttonAddShip);
|
||||||
this.panelCollection.Controls.Add(this.labelCollection);
|
this.panelCollection.Controls.Add(this.labelCollection);
|
||||||
this.panelCollection.Location = new System.Drawing.Point(699, 0);
|
this.panelCollection.Location = new System.Drawing.Point(870, 0);
|
||||||
this.panelCollection.Name = "panelCollection";
|
this.panelCollection.Name = "panelCollection";
|
||||||
this.panelCollection.Size = new System.Drawing.Size(218, 453);
|
this.panelCollection.Size = new System.Drawing.Size(218, 536);
|
||||||
this.panelCollection.TabIndex = 1;
|
this.panelCollection.TabIndex = 1;
|
||||||
//
|
//
|
||||||
|
// buttonRefreshCollection
|
||||||
|
//
|
||||||
|
this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 482);
|
||||||
|
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
|
this.buttonRefreshCollection.Size = new System.Drawing.Size(171, 40);
|
||||||
|
this.buttonRefreshCollection.TabIndex = 4;
|
||||||
|
this.buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// buttonRemoveShip
|
||||||
|
//
|
||||||
|
this.buttonRemoveShip.Location = new System.Drawing.Point(16, 424);
|
||||||
|
this.buttonRemoveShip.Name = "buttonRemoveShip";
|
||||||
|
this.buttonRemoveShip.Size = new System.Drawing.Size(171, 40);
|
||||||
|
this.buttonRemoveShip.TabIndex = 3;
|
||||||
|
this.buttonRemoveShip.Text = "Удалить теплоход";
|
||||||
|
this.buttonRemoveShip.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 375);
|
||||||
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(171, 27);
|
||||||
|
this.maskedTextBoxNumber.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonAddShip
|
||||||
|
//
|
||||||
|
this.buttonAddShip.Location = new System.Drawing.Point(16, 309);
|
||||||
|
this.buttonAddShip.Name = "buttonAddShip";
|
||||||
|
this.buttonAddShip.Size = new System.Drawing.Size(171, 40);
|
||||||
|
this.buttonAddShip.TabIndex = 1;
|
||||||
|
this.buttonAddShip.Text = "Добавить теплоход";
|
||||||
|
this.buttonAddShip.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// labelCollection
|
// labelCollection
|
||||||
//
|
//
|
||||||
this.labelCollection.AutoSize = true;
|
this.labelCollection.AutoSize = true;
|
||||||
@ -68,45 +109,58 @@
|
|||||||
this.labelCollection.TabIndex = 0;
|
this.labelCollection.TabIndex = 0;
|
||||||
this.labelCollection.Text = "Инструменты";
|
this.labelCollection.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// buttonAddShip
|
// groupBoxSets
|
||||||
//
|
//
|
||||||
this.buttonAddShip.Location = new System.Drawing.Point(16, 38);
|
this.groupBoxSets.Controls.Add(this.buttonDelObject);
|
||||||
this.buttonAddShip.Name = "buttonAddShip";
|
this.groupBoxSets.Controls.Add(this.listBoxStorages);
|
||||||
this.buttonAddShip.Size = new System.Drawing.Size(171, 40);
|
this.groupBoxSets.Controls.Add(this.buttonnAddObject);
|
||||||
this.buttonAddShip.TabIndex = 1;
|
this.groupBoxSets.Controls.Add(this.textBoxStorageName);
|
||||||
this.buttonAddShip.Text = "Добавить теплоход";
|
this.groupBoxSets.Location = new System.Drawing.Point(12, 42);
|
||||||
this.buttonAddShip.UseVisualStyleBackColor = true;
|
this.groupBoxSets.Name = "groupBoxSets";
|
||||||
|
this.groupBoxSets.Size = new System.Drawing.Size(199, 242);
|
||||||
|
this.groupBoxSets.TabIndex = 5;
|
||||||
|
this.groupBoxSets.TabStop = false;
|
||||||
|
this.groupBoxSets.Text = "Наборы";
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// textBoxStorageName
|
||||||
//
|
//
|
||||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 117);
|
this.textBoxStorageName.Location = new System.Drawing.Point(0, 26);
|
||||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(171, 27);
|
this.textBoxStorageName.Size = new System.Drawing.Size(193, 27);
|
||||||
this.maskedTextBoxNumber.TabIndex = 2;
|
this.textBoxStorageName.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// buttonRemoveShip
|
// buttonnAddObject
|
||||||
//
|
//
|
||||||
this.buttonRemoveShip.Location = new System.Drawing.Point(16, 166);
|
this.buttonnAddObject.Location = new System.Drawing.Point(4, 71);
|
||||||
this.buttonRemoveShip.Name = "buttonRemoveShip";
|
this.buttonnAddObject.Name = "buttonnAddObject";
|
||||||
this.buttonRemoveShip.Size = new System.Drawing.Size(171, 40);
|
this.buttonnAddObject.Size = new System.Drawing.Size(189, 29);
|
||||||
this.buttonRemoveShip.TabIndex = 3;
|
this.buttonnAddObject.TabIndex = 1;
|
||||||
this.buttonRemoveShip.Text = "Удалить теплоход";
|
this.buttonnAddObject.Text = "Добавить набор";
|
||||||
this.buttonRemoveShip.UseVisualStyleBackColor = true;
|
this.buttonnAddObject.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// buttonRefreshCollection
|
// listBoxStorages
|
||||||
//
|
//
|
||||||
this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 239);
|
this.listBoxStorages.FormattingEnabled = true;
|
||||||
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
|
this.listBoxStorages.ItemHeight = 20;
|
||||||
this.buttonRefreshCollection.Size = new System.Drawing.Size(171, 40);
|
this.listBoxStorages.Location = new System.Drawing.Point(6, 117);
|
||||||
this.buttonRefreshCollection.TabIndex = 4;
|
this.listBoxStorages.Name = "listBoxStorages";
|
||||||
this.buttonRefreshCollection.Text = "Обновить коллекцию";
|
this.listBoxStorages.Size = new System.Drawing.Size(187, 84);
|
||||||
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
|
this.listBoxStorages.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonDelObject
|
||||||
|
//
|
||||||
|
this.buttonDelObject.Location = new System.Drawing.Point(6, 207);
|
||||||
|
this.buttonDelObject.Name = "buttonDelObject";
|
||||||
|
this.buttonDelObject.Size = new System.Drawing.Size(187, 29);
|
||||||
|
this.buttonDelObject.TabIndex = 3;
|
||||||
|
this.buttonDelObject.Text = "Удалить набор";
|
||||||
|
this.buttonDelObject.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// FormShipCollection
|
// FormShipCollection
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(918, 453);
|
this.ClientSize = new System.Drawing.Size(1093, 534);
|
||||||
this.Controls.Add(this.panelCollection);
|
this.Controls.Add(this.panelCollection);
|
||||||
this.Controls.Add(this.pictureBoxCollection);
|
this.Controls.Add(this.pictureBoxCollection);
|
||||||
this.Name = "FormShipCollection";
|
this.Name = "FormShipCollection";
|
||||||
@ -114,6 +168,8 @@
|
|||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||||
this.panelCollection.ResumeLayout(false);
|
this.panelCollection.ResumeLayout(false);
|
||||||
this.panelCollection.PerformLayout();
|
this.panelCollection.PerformLayout();
|
||||||
|
this.groupBoxSets.ResumeLayout(false);
|
||||||
|
this.groupBoxSets.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -127,5 +183,10 @@
|
|||||||
private MaskedTextBox maskedTextBoxNumber;
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
private Button buttonAddShip;
|
private Button buttonAddShip;
|
||||||
private Label labelCollection;
|
private Label labelCollection;
|
||||||
|
private GroupBox groupBoxSets;
|
||||||
|
private Button buttonDelObject;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonnAddObject;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,83 +9,47 @@ namespace WarmlyShip.Generics
|
|||||||
internal class SetGeneric<T>
|
internal class SetGeneric<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
private readonly List<T?> _places;
|
||||||
/// Массив объектов, которые храним
|
public int Count => _places.Count;
|
||||||
/// </summary>
|
private readonly int _maxCount;
|
||||||
private readonly T?[] _places;
|
|
||||||
/// <summary>
|
|
||||||
/// Количество объектов в массиве
|
|
||||||
/// </summary>
|
|
||||||
public int Count => _places.Length;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="count"></param>
|
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
/// <summary>
|
public bool Insert(T warmlyship)
|
||||||
/// Добавление объекта в набор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="warmlyship">Добавляемый теплоход</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int Insert(T warmlyship)
|
|
||||||
{
|
{
|
||||||
return Insert(warmlyship, 0);
|
if (_places.Count == _maxCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Insert(warmlyship, 0);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="warmlyship">Добавляемый теплоход</param>
|
|
||||||
/// <param name="position">Позиция</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int Insert(T warmlyship, int position)
|
|
||||||
{
|
|
||||||
int nullIndex = -1;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (position < 0 || position >= Count)
|
public bool Insert(T warmlyship, int position)
|
||||||
return -1;
|
{
|
||||||
|
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_places.Insert(position, warmlyship);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = position; i < Count; i++)
|
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
nullIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nullIndex < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (i = nullIndex; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[position] = warmlyship;
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
/// <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)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Получение объекта из набора по позиции
|
public T? this[int position]
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="position"></param>
|
get
|
||||||
/// <returns></returns>
|
|
||||||
public T? Get(int position)
|
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
@ -93,5 +57,27 @@ namespace WarmlyShip.Generics
|
|||||||
}
|
}
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_places.Insert(position, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<T> GetShips(int? maxShips = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxShips.HasValue && i == maxShips.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
using WarmlyShip.DrawingObjects;
|
using WarmlyShip.DrawingObjects;
|
||||||
using WarmlyShip.MovementStrategy;
|
using WarmlyShip.MovementStrategy;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
||||||
|
|
||||||
namespace WarmlyShip.Generics
|
namespace WarmlyShip.Generics
|
||||||
{
|
{
|
||||||
@ -14,31 +13,11 @@ namespace WarmlyShip.Generics
|
|||||||
where T : DrawingWarmlyShip
|
where T : DrawingWarmlyShip
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Ширина окна прорисовки
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
/// <summary>
|
|
||||||
/// Высота окна прорисовки
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
/// <summary>
|
|
||||||
/// Размер занимаемого объектом места (ширина)
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _placeSizeWidth = 185;
|
private readonly int _placeSizeWidth = 185;
|
||||||
/// <summary>
|
|
||||||
/// Размер занимаемого объектом места (высота)
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _placeSizeHeight = 185;
|
private readonly int _placeSizeHeight = 185;
|
||||||
/// <summary>
|
|
||||||
/// Набор объектов
|
|
||||||
/// </summary>
|
|
||||||
private readonly SetGeneric<T> _collection;
|
private readonly SetGeneric<T> _collection;
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="picWidth"></param>
|
|
||||||
/// <param name="picHeight"></param>
|
|
||||||
public ShipsGenericCollection(int picWidth, int picHeight)
|
public ShipsGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
@ -47,50 +26,29 @@ namespace WarmlyShip.Generics
|
|||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
/// <summary>
|
public static bool operator +(ShipsGenericCollection<T, U> collect, T?
|
||||||
/// Перегрузка оператора сложения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="collect"></param>
|
|
||||||
/// <param name="obj"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static int operator +(ShipsGenericCollection<T, U> collect, T?
|
|
||||||
obj)
|
obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
return collect._collection.Insert(obj);
|
return (bool)collect?._collection.Insert(obj);
|
||||||
}
|
}
|
||||||
/// <summary>
|
public static T? operator -(ShipsGenericCollection<T, U> collect, int
|
||||||
/// Перегрузка оператора вычитания
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="collect"></param>
|
|
||||||
/// <param name="pos"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool operator -(ShipsGenericCollection<T, U> collect, int
|
|
||||||
pos)
|
pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
collect._collection.Remove(pos);
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return false;
|
return obj;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Получение объекта IMoveableObject
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pos"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Вывод всего набора объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public Bitmap ShowShips()
|
public Bitmap ShowShips()
|
||||||
{
|
{
|
||||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
@ -99,10 +57,6 @@ namespace WarmlyShip.Generics
|
|||||||
DrawObjects(gr);
|
DrawObjects(gr);
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Метод отрисовки фона
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
private void DrawBackground(Graphics g)
|
private void DrawBackground(Graphics g)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.Black, 3);
|
Pen pen = new(Color.Black, 3);
|
||||||
@ -110,7 +64,7 @@ namespace WarmlyShip.Generics
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||||
1; ++j)
|
1; ++j)
|
||||||
{//линия рамзетки места
|
{
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||||
_placeSizeHeight);
|
_placeSizeHeight);
|
||||||
@ -119,32 +73,19 @@ namespace WarmlyShip.Generics
|
|||||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// /// Метод прорисовки объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
T? ship;
|
int i = 0;
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
foreach (var ship in _collection.GetShips())
|
||||||
int diff = 1;
|
|
||||||
int currWidth = 0;
|
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
|
||||||
{
|
{
|
||||||
currWidth++;
|
|
||||||
if (currWidth > width)
|
|
||||||
{
|
|
||||||
diff++;
|
|
||||||
currWidth = 1;
|
|
||||||
}
|
|
||||||
ship = _collection.Get(i);
|
|
||||||
if (ship != null)
|
if (ship != null)
|
||||||
{
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
ship.SetPosition((width - 1 - (i % width)) * _placeSizeWidth, i / width * _placeSizeHeight);
|
ship.SetPosition((width - 1 - (i % width)) * _placeSizeWidth, i / width * _placeSizeHeight);
|
||||||
ship.DrawTransport(g);
|
ship.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
50
MotorShip/MotorShip/ShipsGenericStorage.cs
Normal file
50
MotorShip/MotorShip/ShipsGenericStorage.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WarmlyShip.DrawingObjects;
|
||||||
|
using WarmlyShip.MovementStrategy;
|
||||||
|
|
||||||
|
namespace WarmlyShip.Generics
|
||||||
|
{
|
||||||
|
internal class ShipsGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>> _shipStorages;
|
||||||
|
public List<string> Keys => _shipStorages.Keys.ToList();
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
public ShipsGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_shipStorages = new Dictionary<string,
|
||||||
|
ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (_shipStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_shipStorages[name] = new ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_shipStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_shipStorages.Remove(name);
|
||||||
|
}
|
||||||
|
public ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shipStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _shipStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
|||||||
06cd6889c77069e0f55068eddb8f6c6d07ea4abf
|
621cbda5ca6541382078a80e2a7b1378f7a5c582
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user