fix
This commit is contained in:
parent
3f93e90ef3
commit
9b56a06fb4
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
void IDrawningObject.DrawningObject(Graphics g)
|
void IDrawningObject.DrawningObject(Graphics g)
|
||||||
{
|
{
|
||||||
_warplane.DrawTransport(g);
|
_warplane?.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetInfo() => _warplane?.GetDataForSave();
|
public string GetInfo() => _warplane?.GetDataForSave();
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
return new DrawningWarPlane(Convert.ToInt32(strs[0]),
|
return new DrawningWarPlane(Convert.ToInt32(strs[0]),
|
||||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||||
}
|
}
|
||||||
if (strs.Length == 7)
|
if (strs.Length == 6)
|
||||||
{
|
{
|
||||||
return new DrawningFighter(Convert.ToInt32(strs[0]),
|
return new DrawningFighter(Convert.ToInt32(strs[0]),
|
||||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||||
@ -44,7 +44,7 @@
|
|||||||
{
|
{
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
return $"{str}{_separatorForObject}{Fighter.DopColor.Name}{_separatorForObject}{_separatorForObject}{Fighter.Wing}{_separatorForObject}";
|
return $"{str}{_separatorForObject}{Fighter.DopColor.Name}{_separatorForObject}{Fighter.Rocket}{_separatorForObject}{Fighter.Wing}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -232,17 +232,16 @@
|
|||||||
|
|
||||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if(openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
try
|
if (_mapsCollection.LoadData(openFileDialog.FileName))
|
||||||
{
|
{
|
||||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
MessageBox.Show("Открытие прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Не удалось открыть: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace AirFighter
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище) с картами
|
/// Словарь (хранилище) с картами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly Dictionary<string, MapWithSetWarPlanesGeneric<DrawningObjectWarPlane, AbstractMap>> _mapStorages;
|
readonly Dictionary<string, MapWithSetWarPlanesGeneric<IDrawningObject, AbstractMap>> _mapStorages;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий карт
|
/// Возвращение списка названий карт
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -38,7 +38,7 @@ namespace AirFighter
|
|||||||
/// <param name="pictureHeight"></param>
|
/// <param name="pictureHeight"></param>
|
||||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_mapStorages = new Dictionary<string, MapWithSetWarPlanesGeneric<DrawningObjectWarPlane, AbstractMap>>();
|
_mapStorages = new Dictionary<string, MapWithSetWarPlanesGeneric<IDrawningObject, AbstractMap>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@ -63,9 +63,6 @@ namespace AirFighter
|
|||||||
{
|
{
|
||||||
_mapStorages.Remove(name);
|
_mapStorages.Remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод записи информации в файл
|
/// Метод записи информации в файл
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -87,17 +84,16 @@ namespace AirFighter
|
|||||||
{
|
{
|
||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
using (FileStream fs = new(filename, FileMode.Create))
|
using (StreamWriter fs = new(filename))
|
||||||
{
|
{
|
||||||
WriteToFile($"MapsCollection{Environment.NewLine}", fs);
|
fs.Write($"MapsCollection{Environment.NewLine}");
|
||||||
foreach (var storage in _mapStorages)
|
foreach (var storage in _mapStorages)
|
||||||
{
|
{
|
||||||
WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs);
|
fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Загрузка нформации по самолётам на парковках из файла
|
/// Загрузка нформации по самолётам на парковках из файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -109,46 +105,40 @@ namespace AirFighter
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
string bufferTextFromFile = "";
|
using (StreamReader fs = new(filename))
|
||||||
using (FileStream fs = new(filename, FileMode.Open))
|
|
||||||
{
|
{
|
||||||
byte[] b = new byte[fs.Length];
|
if (!fs.ReadLine().Contains("MapsCollection"))
|
||||||
UTF8Encoding temp = new(true);
|
|
||||||
while (fs.Read(b, 0, b.Length) > 0)
|
|
||||||
{
|
|
||||||
bufferTextFromFile += temp.GetString(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (!strs[0].Contains("MapsCollection"))
|
|
||||||
{
|
{
|
||||||
//если нет такой записи, то это не те данные
|
//если нет такой записи, то это не те данные
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//очищаем записи
|
//очищаем записи
|
||||||
_mapStorages.Clear();
|
_mapStorages.Clear();
|
||||||
for (int i = 1; i < strs.Length; ++i)
|
while (!fs.EndOfStream)
|
||||||
{
|
{
|
||||||
var elem = strs[i].Split(separatorDict);
|
var elem = fs.ReadLine().Split(separatorDict);
|
||||||
AbstractMap map = null;
|
AbstractMap map = null;
|
||||||
switch (elem[1])
|
switch (elem[1])
|
||||||
{
|
{
|
||||||
case "SimpleMap":
|
case "SimpleMap":
|
||||||
map = new SimpleMap();
|
map = new SimpleMap();
|
||||||
break;
|
break;
|
||||||
|
case "CloseMap":
|
||||||
|
map = new CloseMap();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
//_mapStorages.Add(elem[0], new MapWithSetWarPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
_mapStorages.Add(elem[0], new MapWithSetWarPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Доступ к парковке
|
/// Доступ к парковке
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ind"></param>
|
/// <param name="ind"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public MapWithSetWarPlanesGeneric<DrawningObjectWarPlane, AbstractMap> this[string ind]
|
public MapWithSetWarPlanesGeneric<IDrawningObject, AbstractMap> this[string ind]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user