Abazov A. A. LabWork04 #4
@ -88,13 +88,9 @@ namespace AirBomber
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
foreach (var airBomber in _setAirBombers.GetAirBombers())
|
||||
{
|
||||
var airBomber = _setAirBombers[i];
|
||||
if (airBomber != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
|
||||
}
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -163,10 +159,12 @@ namespace AirBomber
|
||||
private void DrawAirBombers(Graphics g)
|
||||
{
|
||||
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
int i = 0;
|
||||
foreach (var airBomber in _setAirBombers.GetAirBombers())
|
||||
{
|
||||
_setAirBombers[i]?.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
_setAirBombers[i]?.DrawingObject(g);
|
||||
airBomber.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
airBomber.DrawingObject(g);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
77
AirBomber/AirBomber/MapsCollection.cs
Normal file
77
AirBomber/AirBomber/MapsCollection.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public List<string> Keys => _mapStorages.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 MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
MessageBox.Show("Карта с таким названием уже существует!");
|
||||
|
||||
return;
|
||||
}
|
||||
_mapStorages.Add(name, new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -82,5 +82,24 @@ namespace AirBomber
|
||||
if (position < 0 || position >= _maxCount) Insert(value, position);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetAirBombers()
|
||||
{
|
||||
foreach (var airBomber in _places)
|
||||
{
|
||||
if (airBomber != null)
|
||||
{
|
||||
yield return airBomber;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
В классе с логикой не выводят сообщения