Возвращение злых кнопок(Laba4)
This commit is contained in:
parent
22f93d7571
commit
6be2956699
@ -31,7 +31,8 @@ namespace AircraftCarrier.Generics
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// Перегрузка оператора сложения
|
||||
/// Перегрузка оператора сложения
|
||||
|
||||
public static int operator +(AircraftsGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
@ -42,20 +43,22 @@ namespace AircraftCarrier.Generics
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
/// Перегрузка оператора вычитания
|
||||
public static bool operator -(AircraftsGenericCollection<T, U> collect, int pos)
|
||||
public static T? operator -(AircraftsGenericCollection<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;
|
||||
}
|
||||
|
||||
/// Получение объекта IMoveableObject
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
|
||||
/// Вывод всего набора объектов
|
||||
public Bitmap ShowAircraft()
|
||||
{
|
||||
@ -86,15 +89,14 @@ namespace AircraftCarrier.Generics
|
||||
/// Метод прорисовки объектов
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
foreach (var car in _collection.GetAircrafts())
|
||||
{
|
||||
DrawningAircraft aircraft = _collection.Get(i);
|
||||
if (aircraft != null)
|
||||
if (car != null)
|
||||
{
|
||||
|
||||
aircraft.SetPosition(i % inRow * _placeSizeWidth+3, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + 5);
|
||||
aircraft.DrawTransport(g);
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
car.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
51
AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs
Normal file
51
AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AircraftCarrier.DrawningObjects;
|
||||
using AircraftCarrier.MovementStrategy;
|
||||
namespace AircraftCarrier.Generics
|
||||
{
|
||||
/// Класс для хранения коллекции
|
||||
internal class AircraftsGenericStorage
|
||||
{
|
||||
/// Словарь (хранилище)
|
||||
readonly Dictionary<string, AircraftsGenericCollection<DrawningAircraft,
|
||||
DrawningObjectAircraft>> _AircraftStorages;
|
||||
/// Возвращение списка названий наборов
|
||||
public List<string> Keys => _AircraftStorages.Keys.ToList();
|
||||
/// Ширина окна отрисовки
|
||||
private readonly int _pictureWidth;
|
||||
/// Высота окна отрисовки
|
||||
private readonly int _pictureHeight;
|
||||
/// Конструктор
|
||||
public AircraftsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_AircraftStorages = new Dictionary<string,
|
||||
AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// Добавление набора
|
||||
public void AddSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
}
|
||||
/// Удаление набора
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
}
|
||||
/// Доступ к набору
|
||||
public AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>?
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -30,38 +30,59 @@
|
||||
{
|
||||
PictureBoxCollection = new PictureBox();
|
||||
PanelTools = new Panel();
|
||||
PanelSets = new Panel();
|
||||
ButtonRefreshCollection = new Button();
|
||||
ButtonRemoveAircraft = new Button();
|
||||
MaskedTextBoxNumber = new MaskedTextBox();
|
||||
ButtonAddAircraft = new Button();
|
||||
LabelTools = new Label();
|
||||
labelTools = new Label();
|
||||
labelSets = new Label();
|
||||
textBoxStorageName = new TextBox();
|
||||
ButtonAddObject = new Button();
|
||||
listBoxStorage = new ListBox();
|
||||
ButtonRemoveObject = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)PictureBoxCollection).BeginInit();
|
||||
PanelTools.SuspendLayout();
|
||||
PanelSets.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// PictureBoxCollection
|
||||
//
|
||||
PictureBoxCollection.Location = new Point(0, 0);
|
||||
PictureBoxCollection.Name = "PictureBoxCollection";
|
||||
PictureBoxCollection.Size = new Size(599, 450);
|
||||
PictureBoxCollection.Size = new Size(768, 651);
|
||||
PictureBoxCollection.TabIndex = 0;
|
||||
PictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// PanelTools
|
||||
//
|
||||
PanelTools.BorderStyle = BorderStyle.FixedSingle;
|
||||
PanelTools.Controls.Add(labelTools);
|
||||
PanelTools.Controls.Add(PanelSets);
|
||||
PanelTools.Controls.Add(ButtonRefreshCollection);
|
||||
PanelTools.Controls.Add(ButtonRemoveAircraft);
|
||||
PanelTools.Controls.Add(MaskedTextBoxNumber);
|
||||
PanelTools.Controls.Add(ButtonAddAircraft);
|
||||
PanelTools.Location = new Point(599, 12);
|
||||
PanelTools.Location = new Point(774, 12);
|
||||
PanelTools.Name = "PanelTools";
|
||||
PanelTools.Size = new Size(202, 438);
|
||||
PanelTools.Size = new Size(232, 639);
|
||||
PanelTools.TabIndex = 1;
|
||||
//
|
||||
// PanelSets
|
||||
//
|
||||
PanelSets.Controls.Add(ButtonRemoveObject);
|
||||
PanelSets.Controls.Add(listBoxStorage);
|
||||
PanelSets.Controls.Add(ButtonAddObject);
|
||||
PanelSets.Controls.Add(textBoxStorageName);
|
||||
PanelSets.Controls.Add(labelSets);
|
||||
PanelSets.Location = new Point(16, 37);
|
||||
PanelSets.Name = "PanelSets";
|
||||
PanelSets.Size = new Size(204, 339);
|
||||
PanelSets.TabIndex = 4;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(15, 206);
|
||||
ButtonRefreshCollection.Location = new Point(36, 572);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(168, 41);
|
||||
ButtonRefreshCollection.TabIndex = 3;
|
||||
@ -71,7 +92,7 @@
|
||||
//
|
||||
// ButtonRemoveAircraft
|
||||
//
|
||||
ButtonRemoveAircraft.Location = new Point(15, 137);
|
||||
ButtonRemoveAircraft.Location = new Point(36, 497);
|
||||
ButtonRemoveAircraft.Name = "ButtonRemoveAircraft";
|
||||
ButtonRemoveAircraft.Size = new Size(168, 41);
|
||||
ButtonRemoveAircraft.TabIndex = 2;
|
||||
@ -81,7 +102,7 @@
|
||||
//
|
||||
// MaskedTextBoxNumber
|
||||
//
|
||||
MaskedTextBoxNumber.Location = new Point(36, 95);
|
||||
MaskedTextBoxNumber.Location = new Point(57, 438);
|
||||
MaskedTextBoxNumber.Name = "MaskedTextBoxNumber";
|
||||
MaskedTextBoxNumber.Size = new Size(125, 27);
|
||||
MaskedTextBoxNumber.TabIndex = 1;
|
||||
@ -89,7 +110,7 @@
|
||||
//
|
||||
// ButtonAddAircraft
|
||||
//
|
||||
ButtonAddAircraft.Location = new Point(15, 19);
|
||||
ButtonAddAircraft.Location = new Point(36, 391);
|
||||
ButtonAddAircraft.Name = "ButtonAddAircraft";
|
||||
ButtonAddAircraft.Size = new Size(168, 41);
|
||||
ButtonAddAircraft.TabIndex = 0;
|
||||
@ -97,21 +118,63 @@
|
||||
ButtonAddAircraft.UseVisualStyleBackColor = true;
|
||||
ButtonAddAircraft.Click += ButtonAddAircraft_Click;
|
||||
//
|
||||
// LabelTools
|
||||
// labelTools
|
||||
//
|
||||
LabelTools.AutoSize = true;
|
||||
LabelTools.Location = new Point(615, 0);
|
||||
LabelTools.Name = "LabelTools";
|
||||
LabelTools.Size = new Size(103, 20);
|
||||
LabelTools.TabIndex = 0;
|
||||
LabelTools.Text = "Инструменты";
|
||||
labelTools.AutoSize = true;
|
||||
labelTools.Location = new Point(16, -4);
|
||||
labelTools.Name = "labelTools";
|
||||
labelTools.Size = new Size(103, 20);
|
||||
labelTools.TabIndex = 5;
|
||||
labelTools.Text = "Инструменты";
|
||||
//
|
||||
// labelSets
|
||||
//
|
||||
labelSets.AutoSize = true;
|
||||
labelSets.Location = new Point(11, 9);
|
||||
labelSets.Name = "labelSets";
|
||||
labelSets.Size = new Size(55, 20);
|
||||
labelSets.TabIndex = 0;
|
||||
labelSets.Text = "Набор";
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(41, 41);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(125, 27);
|
||||
textBoxStorageName.TabIndex = 1;
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
ButtonAddObject.Location = new Point(20, 83);
|
||||
ButtonAddObject.Name = "ButtonAddObject";
|
||||
ButtonAddObject.Size = new Size(168, 41);
|
||||
ButtonAddObject.TabIndex = 2;
|
||||
ButtonAddObject.Text = "Добавить набор";
|
||||
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// listBoxStorage
|
||||
//
|
||||
listBoxStorage.FormattingEnabled = true;
|
||||
listBoxStorage.ItemHeight = 20;
|
||||
listBoxStorage.Location = new Point(29, 147);
|
||||
listBoxStorage.Name = "listBoxStorage";
|
||||
listBoxStorage.Size = new Size(150, 124);
|
||||
listBoxStorage.TabIndex = 3;
|
||||
//
|
||||
// ButtonRemoveObject
|
||||
//
|
||||
ButtonRemoveObject.Location = new Point(20, 286);
|
||||
ButtonRemoveObject.Name = "ButtonRemoveObject";
|
||||
ButtonRemoveObject.Size = new Size(168, 41);
|
||||
ButtonRemoveObject.TabIndex = 4;
|
||||
ButtonRemoveObject.Text = "Удалить набор";
|
||||
ButtonRemoveObject.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormAircraftCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(LabelTools);
|
||||
ClientSize = new Size(1007, 651);
|
||||
Controls.Add(PanelTools);
|
||||
Controls.Add(PictureBoxCollection);
|
||||
Name = "FormAircraftCollection";
|
||||
@ -119,8 +182,9 @@
|
||||
((System.ComponentModel.ISupportInitialize)PictureBoxCollection).EndInit();
|
||||
PanelTools.ResumeLayout(false);
|
||||
PanelTools.PerformLayout();
|
||||
PanelSets.ResumeLayout(false);
|
||||
PanelSets.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -129,8 +193,14 @@
|
||||
private Panel PanelTools;
|
||||
private MaskedTextBox MaskedTextBoxNumber;
|
||||
private Button ButtonAddAircraft;
|
||||
private Label LabelTools;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveAircraft;
|
||||
private Panel PanelSets;
|
||||
private Label labelTools;
|
||||
private Label labelSets;
|
||||
private Button ButtonAddObject;
|
||||
private TextBox textBoxStorageName;
|
||||
private Button ButtonRemoveObject;
|
||||
private ListBox listBoxStorage;
|
||||
}
|
||||
}
|
@ -58,5 +58,7 @@ namespace AircraftCarrier
|
||||
{
|
||||
PictureBoxCollection.Image = _Aircrafts.ShowAircraft();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -8,60 +8,67 @@ namespace AircraftCarrier.Generics
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// Массив объектов, которые храним
|
||||
private readonly T?[] _places;
|
||||
/// Список объектов, которые храним
|
||||
private readonly List<T?> _places;
|
||||
/// Количество объектов в массиве
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
/// Максимальное количество объектов в списке
|
||||
private readonly int _maxCount;
|
||||
/// Конструктор
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// Добавление объекта в набор
|
||||
public int Insert(T Aircraft)
|
||||
public bool Insert(T Aircraft)
|
||||
{
|
||||
return Insert(Aircraft, 0);
|
||||
// TODO вставка в начало набора
|
||||
return true;
|
||||
}
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T Aircraft, int position)
|
||||
public bool Insert(T Aircraft, 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];
|
||||
}
|
||||
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что есть место для вставки
|
||||
// TODO вставка по позиции
|
||||
_places[position] = Aircraft;
|
||||
return position;
|
||||
return true;
|
||||
}
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return false;
|
||||
_places[position] = null;
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
return true;
|
||||
}
|
||||
/// Получение объекта из набора по позиции
|
||||
public T? Get(int position)
|
||||
public T? this[int position]
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
return _places[position];
|
||||
get
|
||||
{
|
||||
// TODO проверка позиции
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка свободных мест в списке
|
||||
// TODO вставка в список по позиции
|
||||
}
|
||||
}
|
||||
/// Проход по списку
|
||||
public IEnumerable<T?> GetAircrafts(int? maxAircrafts = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxAircrafts.HasValue && i == maxAircrafts.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user