Шестая лабораторная работа
This commit is contained in:
parent
c69dd461c0
commit
0b264223c2
@ -30,5 +30,7 @@ namespace HoistingCrane
|
||||
{
|
||||
_hoistingCrane?.DrawTransport(g);
|
||||
}
|
||||
public string GetInfo() => _hoistingCrane?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectHoistingCrane(data.CreateDrawingHoistingCrane());
|
||||
}
|
||||
}
|
||||
|
53
HoistingCrane/HoistingCrane/ExtentionHoistingCrane.cs
Normal file
53
HoistingCrane/HoistingCrane/ExtentionHoistingCrane.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HoistingCrane
|
||||
{
|
||||
internal static class ExtentionHoistingCrane
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
public static DrawingHoistingCrane CreateDrawingHoistingCrane(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingHoistingCrane(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawingAdvancedHoistingCrane(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="DrawingHoistingCrane"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDataForSave(this DrawingHoistingCrane DrawingHoistingCrane)
|
||||
{
|
||||
var hoistingCrane = DrawingHoistingCrane.HoistingCrane;
|
||||
var str = $"{hoistingCrane.Speed}{_separatorForObject}{hoistingCrane.Weight}{_separatorForObject}{hoistingCrane.BodyColor.Name}";
|
||||
if (!(hoistingCrane is EntityAdvancedHoistingCrane HoistingCrane))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{_separatorForObject}{HoistingCrane.DopColor.Name}{_separatorForObject}{HoistingCrane.Crane}{_separatorForObject}{HoistingCrane.Сounterweight}";
|
||||
}
|
||||
}
|
||||
}
|
@ -13,5 +13,6 @@ namespace HoistingCrane
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
string GetInfo();
|
||||
}
|
||||
}
|
||||
|
@ -14,27 +14,27 @@ namespace HoistingCrane
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 200;
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
private readonly SetHoistingCraneGeneric<T> _setHoistingCrane;
|
||||
private readonly SetHoistingCraneGeneric<T> _setHoistingCranes;
|
||||
private readonly U _map;
|
||||
|
||||
public MapWithSetHoistingCraneGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setHoistingCrane = new SetHoistingCraneGeneric<T>(width * height);
|
||||
_setHoistingCranes = new SetHoistingCraneGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static int operator +(MapWithSetHoistingCraneGeneric<T, U> map, T bulldozer)
|
||||
public static int operator +(MapWithSetHoistingCraneGeneric<T, U> map, T hoistingcrane)
|
||||
{
|
||||
return map._setHoistingCrane.Insert(bulldozer);
|
||||
return map._setHoistingCranes.Insert(hoistingcrane);
|
||||
}
|
||||
|
||||
public static T operator -(MapWithSetHoistingCraneGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setHoistingCrane.Remove(position);
|
||||
return map._setHoistingCranes.Remove(position);
|
||||
}
|
||||
|
||||
public Bitmap ShowSet()
|
||||
@ -42,14 +42,14 @@ namespace HoistingCrane
|
||||
Bitmap bmp = new(_pictureWidth, _pictureWidth);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawBulldozers(gr);
|
||||
DrawHoistingCranes(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
foreach (var hoistingCrane in _setHoistingCrane.GetHoistingCrane())
|
||||
foreach (var hoistingCrane in _setHoistingCranes.GetHoistingCranes())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, hoistingCrane);
|
||||
}
|
||||
@ -67,18 +67,18 @@ namespace HoistingCrane
|
||||
|
||||
public void Shaking()
|
||||
{
|
||||
int j = _setHoistingCrane.Count - 1;
|
||||
for (int i = 0; i < _setHoistingCrane.Count; i++)
|
||||
int j = _setHoistingCranes.Count - 1;
|
||||
for (int i = 0; i < _setHoistingCranes.Count; i++)
|
||||
{
|
||||
if (_setHoistingCrane[i] == null)
|
||||
if (_setHoistingCranes[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var warship = _setHoistingCrane[j];
|
||||
var warship = _setHoistingCranes[j];
|
||||
if (warship != null)
|
||||
{
|
||||
_setHoistingCrane.Insert(warship, i);
|
||||
_setHoistingCrane.Remove(j);
|
||||
_setHoistingCranes.Insert(warship, i);
|
||||
_setHoistingCranes.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -103,22 +103,22 @@ namespace HoistingCrane
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBulldozers(Graphics gr)
|
||||
private void DrawHoistingCranes(Graphics gr)
|
||||
{
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int curWidth = 3;
|
||||
int curHeight = 3;
|
||||
|
||||
for (int i = 0; i < _setHoistingCrane.Count; i++)
|
||||
for (int i = 0; i < _setHoistingCranes.Count; i++)
|
||||
{
|
||||
if (curHeight < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_setHoistingCrane[i]?.SetObject(curWidth * _placeSizeWidth + 10,
|
||||
_setHoistingCranes[i]?.SetObject(curWidth * _placeSizeWidth + 10,
|
||||
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setHoistingCrane[i]?.DrawingObject(gr);
|
||||
_setHoistingCranes[i]?.DrawingObject(gr);
|
||||
|
||||
if (curWidth == 0)
|
||||
{
|
||||
@ -129,5 +129,25 @@ namespace HoistingCrane
|
||||
curWidth--;
|
||||
}
|
||||
}
|
||||
public string GetData(char separatorType, char separatorData)
|
||||
{
|
||||
string data = $"{_map.GetType().Name}{separatorType}";
|
||||
foreach (var Boat in _setHoistingCranes.GetHoistingCranes())
|
||||
{
|
||||
data += $"{Boat.GetInfo()}{separatorData}";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка списка из массива строк
|
||||
/// </summary>
|
||||
/// <param name="records"></param>
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records)
|
||||
{
|
||||
_setHoistingCranes.Insert(DrawingObjectHoistingCrane.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace HoistingCrane
|
||||
Insert(value, position);
|
||||
}
|
||||
}
|
||||
public IEnumerable<T> GetHoistingCrane()
|
||||
public IEnumerable<T> GetHoistingCranes()
|
||||
{
|
||||
foreach (var hoistingcrane in _places)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user