PIbd22_NikiforovaMV_Contain.../ContainerShip/ShipsGenericStorage.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2023-12-16 11:14:14 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ContainerShip.MovementStrategy;
using ContainerShip.DrawningObjects;
namespace ContainerShip.Generic
{
internal class ShipsGenericStorage
{
readonly Dictionary<string, ShipsGenericCollection<DrawningShip, 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<DrawningShip, DrawingObjectShip>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
foreach (string nameStorage in Keys)
{
if (nameStorage == name)
{
MessageBox.Show("Набор с заданным именем уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
_shipStorages.Add(name, new ShipsGenericCollection<DrawningShip, DrawingObjectShip>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (_shipStorages.ContainsKey(name))
{
_shipStorages.Remove(name);
}
}
public ShipsGenericCollection<DrawningShip, DrawingObjectShip>? this[string ind]
{
get
{
if (_shipStorages.ContainsKey(ind))
{
return _shipStorages[ind];
}
return null;
}
}
}
}