ну должна быть готова 7
This commit is contained in:
parent
9f41ebdfdf
commit
83035ffc77
@ -145,6 +145,7 @@ namespace Battleship
|
|||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
_logger.LogInformation($"Удален набор: {nameSet}");
|
_logger.LogInformation($"Удален набор: {nameSet}");
|
||||||
}
|
}
|
||||||
|
_logger.LogWarning("Отмена удаления набора");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -177,27 +178,32 @@ namespace Battleship
|
|||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Добавление пустого объекта");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (obj + drawningShip)
|
if (obj + drawningShip)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = obj.ShowShips();
|
pictureBoxCollection.Image = obj.ShowShips();
|
||||||
_logger.LogInformation($"Объект {obj.GetType()} добавлен");
|
_logger.LogInformation($"Объект {obj.GetType()} добавлен");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
|
||||||
_logger.LogInformation($"Не удалось добавить объект");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(StorageOverflowException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonRemoveShip_Click(object sender, EventArgs e)
|
private void buttonRemoveShip_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Удаление объекта из несуществующего набора");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
@ -207,6 +213,7 @@ namespace Battleship
|
|||||||
}
|
}
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Отмена удаления объекта");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,33 +17,31 @@ namespace Battleship.Generics
|
|||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_maxCount = count;
|
_maxCount = count;
|
||||||
_places = new List<T?>(count);
|
_places = new List<T?>(_maxCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Insert(T ship)
|
|
||||||
{
|
|
||||||
if(_places.Count == _maxCount)
|
|
||||||
{
|
|
||||||
throw new StorageOverflowException(_maxCount);
|
|
||||||
}
|
|
||||||
Insert(ship, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Insert(T ship, int position)
|
|
||||||
{
|
|
||||||
if(_places.Count == _maxCount)
|
|
||||||
throw new StorageOverflowException(_maxCount);
|
|
||||||
if (position < 0 || position >= _maxCount)
|
|
||||||
throw new ShipNotFoundException("Impossible to insert");
|
|
||||||
_places.Insert(position, ship);
|
|
||||||
|
|
||||||
|
public bool Insert(T ship)
|
||||||
|
{
|
||||||
|
return Insert(ship, 0);
|
||||||
}
|
}
|
||||||
public void Remove(int position)
|
|
||||||
|
public bool Insert(T ship, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
throw new ShipNotFoundException(position);
|
||||||
|
|
||||||
|
if (Count >= _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
_places.Insert(0, ship);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position > _maxCount || position >= Count)
|
if (position < 0 || position > _maxCount || position >= Count)
|
||||||
throw new ShipNotFoundException(position);
|
throw new ShipNotFoundException(position);
|
||||||
|
|
||||||
_places.RemoveAt(position);
|
_places.RemoveAt(position);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
public T? this[int position]
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Battleship.DrawningObjects;
|
using Battleship.DrawningObjects;
|
||||||
|
using Battleship.Exceptions;
|
||||||
using Battleship.MovementStrategy;
|
using Battleship.MovementStrategy;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -139,9 +140,18 @@ namespace Battleship.Generics
|
|||||||
DrawningShip? plane = elem?.CreateDrawningShip(_separatorForObject, _pictureWidth, _pictureHeight);
|
DrawningShip? plane = elem?.CreateDrawningShip(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
if (plane != null)
|
if (plane != null)
|
||||||
{
|
{
|
||||||
if (!(collection + plane))
|
try
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Ошибка добавления в коллекцию");
|
_ = collection + plane;
|
||||||
|
}
|
||||||
|
catch (ShipNotFoundException e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (StorageOverflowException e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user