lab4
This commit is contained in:
parent
9b908da61c
commit
9c7884da80
@ -28,35 +28,92 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxCollection = new GroupBox();
|
||||
groupBoxCollectionTools = new GroupBox();
|
||||
groupBoxCollectionSets = new GroupBox();
|
||||
textBoxStorageName = new TextBox();
|
||||
buttonDelObject = new Button();
|
||||
buttonAddObject = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemoveWarship = new Button();
|
||||
buttonAddWarship = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
groupBoxCollection.SuspendLayout();
|
||||
groupBoxCollectionTools.SuspendLayout();
|
||||
groupBoxCollectionSets.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxCollection
|
||||
// groupBoxCollectionTools
|
||||
//
|
||||
groupBoxCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
groupBoxCollection.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxCollection.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxCollection.Controls.Add(buttonRemoveWarship);
|
||||
groupBoxCollection.Controls.Add(buttonAddWarship);
|
||||
groupBoxCollection.Location = new Point(893, 3);
|
||||
groupBoxCollection.Margin = new Padding(4, 5, 4, 5);
|
||||
groupBoxCollection.Name = "groupBoxCollection";
|
||||
groupBoxCollection.Padding = new Padding(4, 5, 4, 5);
|
||||
groupBoxCollection.Size = new Size(247, 743);
|
||||
groupBoxCollection.TabIndex = 0;
|
||||
groupBoxCollection.TabStop = false;
|
||||
groupBoxCollection.Text = "Tools";
|
||||
groupBoxCollectionTools.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
groupBoxCollectionTools.Controls.Add(groupBoxCollectionSets);
|
||||
groupBoxCollectionTools.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxCollectionTools.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxCollectionTools.Controls.Add(buttonRemoveWarship);
|
||||
groupBoxCollectionTools.Controls.Add(buttonAddWarship);
|
||||
groupBoxCollectionTools.Location = new Point(893, 3);
|
||||
groupBoxCollectionTools.Margin = new Padding(4, 5, 4, 5);
|
||||
groupBoxCollectionTools.Name = "groupBoxCollectionTools";
|
||||
groupBoxCollectionTools.Padding = new Padding(4, 5, 4, 5);
|
||||
groupBoxCollectionTools.Size = new Size(247, 743);
|
||||
groupBoxCollectionTools.TabIndex = 0;
|
||||
groupBoxCollectionTools.TabStop = false;
|
||||
groupBoxCollectionTools.Text = "Tools";
|
||||
//
|
||||
// groupBoxCollectionSets
|
||||
//
|
||||
groupBoxCollectionSets.Controls.Add(textBoxStorageName);
|
||||
groupBoxCollectionSets.Controls.Add(buttonDelObject);
|
||||
groupBoxCollectionSets.Controls.Add(buttonAddObject);
|
||||
groupBoxCollectionSets.Controls.Add(listBoxStorages);
|
||||
groupBoxCollectionSets.Location = new Point(9, 32);
|
||||
groupBoxCollectionSets.Name = "groupBoxCollectionSets";
|
||||
groupBoxCollectionSets.Size = new Size(230, 323);
|
||||
groupBoxCollectionSets.TabIndex = 5;
|
||||
groupBoxCollectionSets.TabStop = false;
|
||||
groupBoxCollectionSets.Text = "Sets";
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(6, 30);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(218, 31);
|
||||
textBoxStorageName.TabIndex = 4;
|
||||
//
|
||||
// buttonDelObject
|
||||
//
|
||||
buttonDelObject.Location = new Point(6, 276);
|
||||
buttonDelObject.Name = "buttonDelObject";
|
||||
buttonDelObject.Size = new Size(218, 41);
|
||||
buttonDelObject.TabIndex = 3;
|
||||
buttonDelObject.Text = "Delete Set";
|
||||
buttonDelObject.UseVisualStyleBackColor = true;
|
||||
buttonDelObject.Click += ButtonDelObject_Click;
|
||||
//
|
||||
// buttonAddObject
|
||||
//
|
||||
buttonAddObject.Location = new Point(6, 67);
|
||||
buttonAddObject.Name = "buttonAddObject";
|
||||
buttonAddObject.Size = new Size(218, 43);
|
||||
buttonAddObject.TabIndex = 2;
|
||||
buttonAddObject.Text = "Add set";
|
||||
buttonAddObject.UseVisualStyleBackColor = true;
|
||||
buttonAddObject.Click += ButtonAddObject_Click;
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 25;
|
||||
listBoxStorages.Location = new Point(6, 116);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(218, 154);
|
||||
listBoxStorages.TabIndex = 1;
|
||||
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(56, 115);
|
||||
maskedTextBoxNumber.Location = new Point(56, 468);
|
||||
maskedTextBoxNumber.Margin = new Padding(4, 5, 4, 5);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(141, 31);
|
||||
@ -65,10 +122,10 @@
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(9, 300);
|
||||
buttonRefreshCollection.Location = new Point(9, 688);
|
||||
buttonRefreshCollection.Margin = new Padding(4, 5, 4, 5);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(224, 45);
|
||||
buttonRefreshCollection.Size = new Size(230, 45);
|
||||
buttonRefreshCollection.TabIndex = 3;
|
||||
buttonRefreshCollection.Text = "Refresh collection";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
@ -76,10 +133,10 @@
|
||||
//
|
||||
// buttonRemoveWarship
|
||||
//
|
||||
buttonRemoveWarship.Location = new Point(9, 187);
|
||||
buttonRemoveWarship.Location = new Point(9, 509);
|
||||
buttonRemoveWarship.Margin = new Padding(4, 5, 4, 5);
|
||||
buttonRemoveWarship.Name = "buttonRemoveWarship";
|
||||
buttonRemoveWarship.Size = new Size(224, 45);
|
||||
buttonRemoveWarship.Size = new Size(230, 45);
|
||||
buttonRemoveWarship.TabIndex = 2;
|
||||
buttonRemoveWarship.Text = "Remove warship";
|
||||
buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||
@ -87,7 +144,7 @@
|
||||
//
|
||||
// buttonAddWarship
|
||||
//
|
||||
buttonAddWarship.Location = new Point(9, 37);
|
||||
buttonAddWarship.Location = new Point(9, 413);
|
||||
buttonAddWarship.Margin = new Padding(4, 5, 4, 5);
|
||||
buttonAddWarship.Name = "buttonAddWarship";
|
||||
buttonAddWarship.Size = new Size(230, 45);
|
||||
@ -111,23 +168,30 @@
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1143, 750);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBoxCollection);
|
||||
Controls.Add(groupBoxCollectionTools);
|
||||
Margin = new Padding(4, 5, 4, 5);
|
||||
Name = "FormWarshipCollection";
|
||||
Text = "Warship Collection";
|
||||
groupBoxCollection.ResumeLayout(false);
|
||||
groupBoxCollection.PerformLayout();
|
||||
groupBoxCollectionTools.ResumeLayout(false);
|
||||
groupBoxCollectionTools.PerformLayout();
|
||||
groupBoxCollectionSets.ResumeLayout(false);
|
||||
groupBoxCollectionSets.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxCollection;
|
||||
private GroupBox groupBoxCollectionTools;
|
||||
private Button buttonRefreshCollection;
|
||||
private Button buttonRemoveWarship;
|
||||
private Button buttonAddWarship;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBoxCollectionSets;
|
||||
private ListBox listBoxStorages;
|
||||
private Button buttonDelObject;
|
||||
private Button buttonAddObject;
|
||||
private TextBox textBoxStorageName;
|
||||
}
|
||||
}
|
@ -11,36 +11,115 @@ namespace ProjectAircraftCarrier
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly WarshipsGenericCollection<DrawingWarship,
|
||||
DrawingObjectWarship> _warships;
|
||||
private readonly WarshipsGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormWarshipCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_warships = new WarshipsGenericCollection<DrawingWarship,
|
||||
DrawingObjectWarship>(pictureBoxCollection.Width,
|
||||
_storage = new WarshipsGenericStorage(pictureBoxCollection.Width,
|
||||
pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Not all data is filled in", "Error",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ??
|
||||
string.Empty]?.ShowWarships();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Delete an object" +
|
||||
$"{ listBoxStorages.SelectedItem}?",
|
||||
"Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
||||
== DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||||
?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddWarship_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAircraftCarrier form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_warships + form.SelectedWarship != -1)
|
||||
if (obj + form.SelectedWarship)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _warships.ShowWarships();
|
||||
MessageBox.Show("Object added");
|
||||
pictureBoxCollection.Image = obj.ShowWarships();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
MessageBox.Show("Failed to add an object");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,20 +130,31 @@ namespace ProjectAircraftCarrier
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Delete an object?", "Deletion",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
|
||||
DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_warships - pos)
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _warships.ShowWarships();
|
||||
MessageBox.Show("Object deleted");
|
||||
pictureBoxCollection.Image = obj.ShowWarships();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show("Failed to delete an object");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -74,7 +164,17 @@ namespace ProjectAircraftCarrier
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _warships.ShowWarships();
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowWarships();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectAircraftCarrier.Generics
|
||||
using System.Numerics;
|
||||
|
||||
namespace ProjectAircraftCarrier.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
@ -10,29 +12,35 @@
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T?[] _places;
|
||||
private readonly List<T?> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="warship">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T warship)
|
||||
public bool Insert(T warship)
|
||||
{
|
||||
if (_places[Count - 1] != null)
|
||||
return -1;
|
||||
return Insert(warship, 0);
|
||||
if (_places.Count == _maxCount)
|
||||
return false;
|
||||
Insert(warship, 0);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -40,27 +48,13 @@
|
||||
/// <param name="warship">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T warship, int position)
|
||||
public bool Insert(T warship, int position)
|
||||
{
|
||||
int nullIndex = -1, i;
|
||||
if (position < 0 || position >= Count)
|
||||
return -1;
|
||||
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] = warship;
|
||||
return position;
|
||||
if (!(position >= 0 && position <= Count && _places.Count <
|
||||
_maxCount))
|
||||
return false;
|
||||
_places.Insert(position, warship);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@ -69,8 +63,9 @@
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return false;
|
||||
_places[position] = null;
|
||||
if (!(position >= 0 && position < Count))
|
||||
return false;
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -78,11 +73,33 @@
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
public T? this[int position]
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
get
|
||||
{
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return;
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetWarships(int? maxWarships = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxWarships.HasValue && i == maxWarships.Value)
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -51,12 +51,11 @@ namespace ProjectAircraftCarrier.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(WarshipsGenericCollection<T, U> collect, T? obj)
|
||||
public static bool operator +(WarshipsGenericCollection<T, U>?
|
||||
collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (obj == null || collect == null)
|
||||
return false;
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
/// <summary>
|
||||
@ -65,14 +64,15 @@ namespace ProjectAircraftCarrier.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(WarshipsGenericCollection<T, U> collect, int pos)
|
||||
public static T? operator -(WarshipsGenericCollection<T, U>
|
||||
collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
@ -81,7 +81,7 @@ namespace ProjectAircraftCarrier.Generics
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
@ -104,15 +104,14 @@ namespace ProjectAircraftCarrier.Generics
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth
|
||||
/ 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
_pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -121,15 +120,18 @@ namespace ProjectAircraftCarrier.Generics
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
int i = 0;
|
||||
foreach (var warship in _collection.GetWarships())
|
||||
{
|
||||
DrawingWarship warship = _collection.Get(i);
|
||||
if (warship != null)
|
||||
{
|
||||
warship.SetPosition(i % inRow * _placeSizeWidth + 3, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + 5);
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
warship.SetPosition(i % inRow * _placeSizeWidth,
|
||||
_pictureHeight - _pictureHeight % _placeSizeHeight
|
||||
- (i / inRow + 1) * _placeSizeHeight);
|
||||
warship.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
84
AircraftCarrier/AircraftCarrier/WarshipsGenericStorage.cs
Normal file
84
AircraftCarrier/AircraftCarrier/WarshipsGenericStorage.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using ProjectAircraftCarrier.DrawingObjects;
|
||||
using ProjectAircraftCarrier.MovementStrategy;
|
||||
namespace ProjectAircraftCarrier.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции
|
||||
/// </summary>
|
||||
internal class WarshipsGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, WarshipsGenericCollection<DrawingWarship,
|
||||
DrawingObjectWarship>> _warshipStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _warshipStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public WarshipsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_warshipStorages = new Dictionary<string,
|
||||
WarshipsGenericCollection<DrawingWarship,
|
||||
DrawingObjectWarship>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (!_warshipStorages.ContainsKey(name))
|
||||
{
|
||||
_warshipStorages.Add(name, new WarshipsGenericCollection
|
||||
<DrawingWarship, DrawingObjectWarship>(_pictureWidth,
|
||||
_pictureHeight));
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("This set already exists");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_warshipStorages.ContainsKey(name))
|
||||
return;
|
||||
_warshipStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public WarshipsGenericCollection<DrawingWarship, DrawingObjectWarship>
|
||||
?this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_warshipStorages.ContainsKey(ind))
|
||||
return _warshipStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user