ISEbd-12 Khaliullov LabWork07 Simple #8
@ -1,4 +1,5 @@
|
||||
using Stormtrooper.Drawnings;
|
||||
using Stormtrooper.Exceptions;
|
||||
|
||||
namespace Stormtrooper.CollectionGenericObjects;
|
||||
|
||||
@ -92,12 +93,17 @@ public abstract class AbstractCompany
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackgound(graphics);
|
||||
DrawBackground(graphics);
|
||||
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningAircraft? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
try
|
||||
{
|
||||
DrawningAircraft? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
catch (ObjectNotFoundException) { };
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
@ -105,7 +111,7 @@ public abstract class AbstractCompany
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
protected abstract void DrawBackgound(Graphics g);
|
||||
protected abstract void DrawBackground(Graphics g);
|
||||
|
||||
/// <summary>
|
||||
/// Расстановка объектов
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Stormtrooper.Drawnings;
|
||||
using Stormtrooper.Exceptions;
|
||||
|
||||
namespace Stormtrooper.CollectionGenericObjects
|
||||
{
|
||||
@ -17,7 +18,7 @@ namespace Stormtrooper.CollectionGenericObjects
|
||||
ICollectionGenericObjects<DrawningAircraft> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
@ -41,18 +42,17 @@ namespace Stormtrooper.CollectionGenericObjects
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection.Get(i) != null)
|
||||
{
|
||||
try {
|
||||
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10);
|
||||
}
|
||||
|
||||
catch (ObjectNotFoundException) { }
|
||||
if (curWidth > 0)
|
||||
curWidth--;
|
||||
else
|
||||
{
|
||||
curWidth = width - 1;
|
||||
curHeight ++;
|
||||
curWidth = width - 1;
|
||||
curHeight++;
|
||||
}
|
||||
|
||||
if (curHeight >= height)
|
||||
@ -63,3 +63,4 @@ namespace Stormtrooper.CollectionGenericObjects
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,21 @@ where T : class
|
||||
private int _maxCount;
|
||||
public int Count => _collection.Count;
|
||||
|
||||
public int MaxCount { set { if (value > 0) { _maxCount = value; } } get { return Count; } }
|
||||
public int MaxCount
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
_maxCount = value;
|
||||
}
|
||||
}
|
||||
get
|
||||
{
|
||||
|
||||
return Count;
|
||||
}
|
||||
}
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.List;
|
||||
|
||||
@ -41,6 +55,7 @@ where T : class
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
if (_collection.Count + 1 <= _maxCount)
|
||||
@ -50,6 +65,7 @@ where T : class
|
||||
}
|
||||
throw new CollectionOverflowException(MaxCount);
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (_collection.Count + 1 > MaxCount)
|
||||
@ -59,6 +75,7 @@ where T : class
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _collection.Count)
|
||||
|
@ -59,7 +59,11 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
// проверка позиции
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
throw new ObjectNotFoundException(position);
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
@ -76,18 +80,18 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
throw new CollectionOverflowException(_collection.Length);
|
||||
}
|
||||
public int Insert(T obj, int position)
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{ return -1; }
|
||||
{ throw new PositionOutOfCollectionException(position); }
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
return true;
|
||||
}
|
||||
int index;
|
||||
|
||||
@ -96,7 +100,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,18 +109,20 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
throw new CollectionOverflowException(_collection.Length);
|
||||
}
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{ return null; }
|
||||
T DrawningAircraft = _collection[position];
|
||||
{ throw new PositionOutOfCollectionException(position); }
|
||||
if (_collection[position] == null)
|
||||
throw new ObjectNotFoundException(position);
|
||||
T temp = _collection[position];
|
||||
_collection[position] = null;
|
||||
return DrawningAircraft;
|
||||
return temp;
|
||||
}
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
|
@ -154,32 +154,28 @@ where T : DrawningAircraft
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new Exception("Файл не существует");
|
||||
throw new FileNotFoundException("Файл не существует");
|
||||
}
|
||||
using (StreamReader sr = new StreamReader(filename))// открываем файла на чтение
|
||||
|
||||
using (StreamReader sr = new StreamReader(filename))
|
||||
{
|
||||
string? str;
|
||||
str = sr.ReadLine();
|
||||
if (str != _collectionKey.ToString())
|
||||
throw new Exception("Неверные данные");
|
||||
|
||||
throw new FormatException("В файле неверные данные");
|
||||
_storages.Clear();
|
||||
|
||||
while ((str = sr.ReadLine()) != null)
|
||||
{
|
||||
string[] record = str.Split(_separatorForKeyValue);
|
||||
|
||||
|
||||
if (record.Length != 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
if (collection == null)
|
||||
{
|
||||
throw new Exception("Не удалось определить тип коллекции");
|
||||
throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]);
|
||||
}
|
||||
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
@ -191,7 +187,7 @@ where T : DrawningAircraft
|
||||
{
|
||||
try
|
||||
{
|
||||
if (collection.Insert(aircraft) == -1)
|
||||
if (collection.Insert(ship) == -1)
|
||||
{
|
||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
@ -202,7 +198,6 @@ where T : DrawningAircraft
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_storages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user