лабик6
This commit is contained in:
parent
ca794a942e
commit
7c9431a20e
@ -63,7 +63,7 @@ namespace Cruiser.Drawing
|
|||||||
/// <param name="secColor">Элементов цвет</param>
|
/// <param name="secColor">Элементов цвет</param>
|
||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
public DrawingCruiser(int speed, double weight, Color bodyColor, Color secColor, int width, int height)
|
public DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height)
|
||||||
{
|
{
|
||||||
if (width < _cruiserWidth || height < _cruiserHeight)
|
if (width < _cruiserWidth || height < _cruiserHeight)
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ namespace Cruiser.Drawing
|
|||||||
}
|
}
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor, secColor);
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);//переделал конструктор, т.к. secColor не использовался в конечном результате для отрисовки
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -80,18 +80,17 @@ namespace Cruiser.Drawing
|
|||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// <param name="secColor">Элементов цвет</param>
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
/// <param name="cruiserWidth">Ширина прорисовки крейсера</param>
|
/// <param name="cruiserWidth">Ширина прорисовки крейсера</param>
|
||||||
/// <param name="cruiserHeight">Высота прорисовки крейсера</param>
|
/// <param name="cruiserHeight">Высота прорисовки крейсера</param>
|
||||||
public DrawingCruiser(int speed, double weight, Color bodyColor, Color secColor, int width, int height, int cruiserWidth, int cruiserHeight)
|
public DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height, int cruiserWidth, int cruiserHeight)
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
_cruiserHeight = cruiserHeight;
|
_cruiserHeight = cruiserHeight;
|
||||||
_cruiserWidth = cruiserWidth;
|
_cruiserWidth = cruiserWidth;
|
||||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor, secColor);
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor); //переделал конструктор, т.к. secColor не использовался в конечном результате для отрисовки
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
@ -199,6 +198,7 @@ namespace Cruiser.Drawing
|
|||||||
Brush brush = new SolidBrush(EntityCruiser.BodyColor);
|
Brush brush = new SolidBrush(EntityCruiser.BodyColor);
|
||||||
g.FillPolygon(brush, Paluba);
|
g.FillPolygon(brush, Paluba);
|
||||||
// элементы
|
// элементы
|
||||||
|
Brush colForElem = new SolidBrush(Color.Black); //поменял цвет для элементов(ОСНОВНЫХ) на чёрный, т.к. secColor не использовался
|
||||||
Point[] Elements = new Point[8]
|
Point[] Elements = new Point[8]
|
||||||
{
|
{
|
||||||
new Point(_startPosX + 50,_startPosY + 20),
|
new Point(_startPosX + 50,_startPosY + 20),
|
||||||
@ -210,13 +210,12 @@ namespace Cruiser.Drawing
|
|||||||
new Point(_startPosX + 70,_startPosY + 40),
|
new Point(_startPosX + 70,_startPosY + 40),
|
||||||
new Point(_startPosX + 50,_startPosY + 40),
|
new Point(_startPosX + 50,_startPosY + 40),
|
||||||
};
|
};
|
||||||
Brush brushElem = new SolidBrush(EntityCruiser.SecondColor);
|
// шар на корабле
|
||||||
g.FillPolygon(brushElem, Elements);
|
g.FillPolygon(colForElem, Elements);
|
||||||
g.FillEllipse(brushElem, _startPosX + 100, _startPosY + 20, 20, 20);
|
g.FillEllipse(colForElem, _startPosX + 100, _startPosY + 20, 20, 20);
|
||||||
// турбины
|
// турбины
|
||||||
Brush Turbins = new SolidBrush(Color.Black);
|
g.FillRectangle(colForElem, _startPosX, _startPosY + 10, 10, 20);
|
||||||
g.FillRectangle(Turbins, _startPosX, _startPosY + 10, 10, 20);
|
g.FillRectangle(colForElem, _startPosX, _startPosY + 35, 10, 20);
|
||||||
g.FillRectangle(Turbins, _startPosX, _startPosY + 35, 10, 20);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,13 @@ namespace Cruiser.Drawing
|
|||||||
{
|
{
|
||||||
(EntityCruiser as EntityProCruiser).ElementsColor = color;
|
(EntityCruiser as EntityProCruiser).ElementsColor = color;
|
||||||
}
|
}
|
||||||
public DrawingProCruiser(int speed, double weight, Color bodyColor, Color secColor, Color elemColor, bool rocketMines, bool helipad, int width, int height) :
|
public DrawingProCruiser(int speed, double weight, Color bodyColor, Color elemColor, bool rocketMines, bool helipad, int width, int height) :
|
||||||
base (speed, weight, bodyColor, secColor, width, height, 150, 60)
|
base (speed, weight, bodyColor, width, height, 150, 60)
|
||||||
{
|
{
|
||||||
if (EntityCruiser != null)
|
if (EntityCruiser != null)
|
||||||
{
|
{
|
||||||
EntityCruiser = new EntityProCruiser(speed, weight, bodyColor, secColor, elemColor, rocketMines, helipad);
|
EntityCruiser = new EntityProCruiser(speed, weight, bodyColor, elemColor, rocketMines, helipad);
|
||||||
|
// по тем же причинам, что и для обычного, фиксим конструктор класса отрисовки для улучшенного
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
|
64
Cruiser/Drawing/ExtentionDrawingCruiser.cs
Normal file
64
Cruiser/Drawing/ExtentionDrawingCruiser.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Cruiser.Drawing;
|
||||||
|
using Cruiser.Entities;
|
||||||
|
namespace Cruiser.Drawing
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Расширение для класса EntityCruiser
|
||||||
|
/// </summary>
|
||||||
|
public static class ExtentionDrawningCruiser
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
public static DrawingCruiser? CreateDrawingCruiser(this string info, char separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingCruiser(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingProCruiser(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]), width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawingCruiser">Сохраняемый объект</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawingCruiser drawingCruiser, char separatorForObject)
|
||||||
|
{
|
||||||
|
var cruiser = drawingCruiser.EntityCruiser;
|
||||||
|
if (cruiser == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{cruiser.Speed}{separatorForObject}{cruiser.Weight}{separatorForObject}{cruiser.BodyColor.Name}";
|
||||||
|
if (cruiser is not EntityProCruiser proCruiser)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{separatorForObject}{proCruiser.ElementsColor.Name}{separatorForObject}{proCruiser.RocketMines}{separatorForObject}{proCruiser.Helipad}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -24,23 +24,19 @@ namespace Cruiser.Entities
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; set; }
|
public Color BodyColor { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Второстепенный цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color SecondColor { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения Крейсера
|
/// Шаг перемещения Крейсера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
// убрал secColor т.к. у обычного крейсера должен быть один цвет + не использовался для отрисовки
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес Крейсера</param>
|
/// <param name="weight">Вес Крейсера</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// <param name="secColor">Второстепенный цвет</param>
|
/// <param name="secColor">Второстепенный цвет</param>
|
||||||
public EntityCruiser(int speed, double weight, Color bodyColor, Color secColor)
|
public EntityCruiser(int speed, double weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor; // переделал конструктор и убрал secondColor, т.к. у обычного крейсера должен быть один цвет + не использовался для отрисовки
|
||||||
SecondColor = secColor;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,16 +26,15 @@ namespace Cruiser.Entities
|
|||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес Крейсера</param>
|
/// <param name="weight">Вес Крейсера</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// <param name="secColor">Второстепенный цвет</param>
|
|
||||||
/// <param name="elemColor">Элементов цвет</param>
|
/// <param name="elemColor">Элементов цвет</param>
|
||||||
/// <param name="rocketMines">Признак наличия ракетных шахт</param>
|
/// <param name="rocketMines">Признак наличия ракетных шахт</param>
|
||||||
/// <param name="helipad">Признак наличия вертолётной площадки</param>
|
/// <param name="helipad">Признак наличия вертолётной площадки</param>
|
||||||
public EntityProCruiser(int speed, double weight, Color bodyColor, Color secColor, Color elemColor, bool rocketMines, bool helipad) :
|
public EntityProCruiser(int speed, double weight, Color bodyColor, Color elemColor, bool rocketMines, bool helipad) :
|
||||||
base(speed, weight, bodyColor, secColor)
|
base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
RocketMines = rocketMines;
|
RocketMines = rocketMines;
|
||||||
Helipad = helipad;
|
Helipad = helipad;
|
||||||
ElementsColor = elemColor;
|
ElementsColor = elemColor; // по тем же причинам, что и для обычного, фиксим конструктор класса для улучшенного
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,8 +132,7 @@ namespace Cruiser
|
|||||||
|
|
||||||
_drawningCruiser = new DrawingCruiser(random.Next(100, 300),
|
_drawningCruiser = new DrawingCruiser(random.Next(100, 300),
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000),
|
||||||
colorFirst,
|
colorFirst, // всё ещё фикс конструкторов
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
pictureBoxCruiser.Width,
|
pictureBoxCruiser.Width,
|
||||||
pictureBoxCruiser.Height);
|
pictureBoxCruiser.Height);
|
||||||
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
@ -157,8 +156,7 @@ namespace Cruiser
|
|||||||
_drawningCruiser = new DrawingProCruiser(random.Next(100, 300),
|
_drawningCruiser = new DrawingProCruiser(random.Next(100, 300),
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000),
|
||||||
colorFirst,
|
colorFirst,
|
||||||
colorSecond,
|
colorSecond, // всё ещё фикс конструкторов
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(1, 2)),
|
Convert.ToBoolean(random.Next(1, 2)),
|
||||||
Convert.ToBoolean(random.Next(1, 2)),
|
Convert.ToBoolean(random.Next(1, 2)),
|
||||||
pictureBoxCruiser.Width,
|
pictureBoxCruiser.Width,
|
||||||
|
64
Cruiser/FormCruiserCollection.Designer.cs
generated
64
Cruiser/FormCruiserCollection.Designer.cs
generated
@ -39,9 +39,16 @@
|
|||||||
buttonDelObject = new Button();
|
buttonDelObject = new Button();
|
||||||
textBoxStorageName = new TextBox();
|
textBoxStorageName = new TextBox();
|
||||||
buttonAddObject = new Button();
|
buttonAddObject = new Button();
|
||||||
|
menuStripCruiser = new MenuStrip();
|
||||||
|
FileToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
UploadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
groupBoxStorage.SuspendLayout();
|
groupBoxStorage.SuspendLayout();
|
||||||
|
menuStripCruiser.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
@ -75,7 +82,7 @@
|
|||||||
//
|
//
|
||||||
// buttonAddCruiser
|
// buttonAddCruiser
|
||||||
//
|
//
|
||||||
buttonAddCruiser.Location = new Point(15, 22);
|
buttonAddCruiser.Location = new Point(15, 26);
|
||||||
buttonAddCruiser.Name = "buttonAddCruiser";
|
buttonAddCruiser.Name = "buttonAddCruiser";
|
||||||
buttonAddCruiser.Size = new Size(122, 38);
|
buttonAddCruiser.Size = new Size(122, 38);
|
||||||
buttonAddCruiser.TabIndex = 0;
|
buttonAddCruiser.TabIndex = 0;
|
||||||
@ -95,9 +102,9 @@
|
|||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(14, 1);
|
pictureBoxCollection.Location = new Point(14, 27);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(642, 448);
|
pictureBoxCollection.Size = new Size(642, 422);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -151,15 +158,57 @@
|
|||||||
buttonAddObject.UseVisualStyleBackColor = true;
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
buttonAddObject.Click += ButtonAddObject_Click;
|
buttonAddObject.Click += ButtonAddObject_Click;
|
||||||
//
|
//
|
||||||
|
// menuStripCruiser
|
||||||
|
//
|
||||||
|
menuStripCruiser.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem });
|
||||||
|
menuStripCruiser.Location = new Point(0, 0);
|
||||||
|
menuStripCruiser.Name = "menuStripCruiser";
|
||||||
|
menuStripCruiser.Size = new Size(800, 24);
|
||||||
|
menuStripCruiser.TabIndex = 4;
|
||||||
|
menuStripCruiser.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// FileToolStripMenuItem
|
||||||
|
//
|
||||||
|
FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, UploadToolStripMenuItem });
|
||||||
|
FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||||
|
FileToolStripMenuItem.Size = new Size(48, 20);
|
||||||
|
FileToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
SaveToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
SaveToolStripMenuItem.Text = "Сохранить";
|
||||||
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// UploadToolStripMenuItem
|
||||||
|
//
|
||||||
|
UploadToolStripMenuItem.Name = "UploadToolStripMenuItem";
|
||||||
|
UploadToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
UploadToolStripMenuItem.Text = "Загрузить";
|
||||||
|
UploadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.FileName = "openFileDialog";
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.FileName = "saveFileDialog";
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
// FormCruiserCollection
|
// FormCruiserCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(menuStripCruiser);
|
||||||
Controls.Add(buttonRefreshCollection);
|
Controls.Add(buttonRefreshCollection);
|
||||||
Controls.Add(groupBoxStorage);
|
Controls.Add(groupBoxStorage);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
|
MainMenuStrip = menuStripCruiser;
|
||||||
Name = "FormCruiserCollection";
|
Name = "FormCruiserCollection";
|
||||||
Text = "Набор Крейсеров";
|
Text = "Набор Крейсеров";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
@ -167,7 +216,10 @@
|
|||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
groupBoxStorage.ResumeLayout(false);
|
groupBoxStorage.ResumeLayout(false);
|
||||||
groupBoxStorage.PerformLayout();
|
groupBoxStorage.PerformLayout();
|
||||||
|
menuStripCruiser.ResumeLayout(false);
|
||||||
|
menuStripCruiser.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -183,5 +235,11 @@
|
|||||||
private TextBox textBoxStorageName;
|
private TextBox textBoxStorageName;
|
||||||
private Button buttonAddObject;
|
private Button buttonAddObject;
|
||||||
private ListBox listBoxStorages;
|
private ListBox listBoxStorages;
|
||||||
|
private MenuStrip menuStripCruiser;
|
||||||
|
private ToolStripMenuItem FileToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem UploadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -184,5 +184,44 @@ namespace Cruiser
|
|||||||
formCruiserConfig.Show();
|
formCruiserConfig.Show();
|
||||||
formCruiserConfig.AddEvent(AddCruiser);
|
formCruiserConfig.AddEvent(AddCruiser);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Сохранение"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.SaveData(saveFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Загрузка"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.LoadData(openFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,4 +117,13 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="menuStripCruiser.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>163, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>296, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -106,15 +106,15 @@ namespace Cruiser
|
|||||||
{
|
{
|
||||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
{
|
{
|
||||||
case "labelCruiser":
|
case "labelCruiser": //переделал из за изменения конструкторов (см. комментарии там)
|
||||||
_cruiser = new DrawingCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
_cruiser = new DrawingCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
||||||
Color.Orchid, Color.Black,
|
Color.Orchid,
|
||||||
pictureBoxToCruiser.Width,
|
pictureBoxToCruiser.Width,
|
||||||
pictureBoxToCruiser.Height);
|
pictureBoxToCruiser.Height);
|
||||||
break;
|
break;
|
||||||
case "labelProCruiser":
|
case "labelProCruiser": //переделал из за изменения конструкторов (см. комментарии там)
|
||||||
_cruiser = new DrawingProCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
_cruiser = new DrawingProCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value,
|
||||||
Color.Orchid, Color.Black, Color.Aquamarine,
|
Color.Orchid, Color.Aquamarine,
|
||||||
checkBoxRockMines.Checked, checkBoxHelipad.Checked,
|
checkBoxRockMines.Checked, checkBoxHelipad.Checked,
|
||||||
pictureBoxToCruiser.Width,
|
pictureBoxToCruiser.Width,
|
||||||
pictureBoxToCruiser.Height);
|
pictureBoxToCruiser.Height);
|
||||||
|
@ -17,6 +17,10 @@ namespace Cruiser.Generics
|
|||||||
where T : DrawingCruiser
|
where T : DrawingCruiser
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объектов коллекции
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<T?> GetCruisers => _collection.GetCruisers();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна прорисовки
|
/// Ширина окна прорисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -6,15 +6,27 @@ using System.Threading.Tasks;
|
|||||||
using Cruiser.Drawing;
|
using Cruiser.Drawing;
|
||||||
using Cruiser.MovementStrategy;
|
using Cruiser.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
namespace Cruiser.Generics
|
namespace Cruiser.Generics
|
||||||
{
|
{
|
||||||
internal class CruisersGenericStorage
|
internal class CruisersGenericStorage
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище)
|
/// Словарь (хранилище)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly Dictionary<string, CarsGenericCollection<DrawingCruiser,DrawningObjectCar>> _cruiserStorages;
|
readonly Dictionary<string, CarsGenericCollection<DrawingCruiser, DrawningObjectCar>> _cruiserStorages;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий наборов
|
/// Возвращение списка названий наборов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,7 +46,7 @@ namespace Cruiser.Generics
|
|||||||
/// <param name="pictureHeight"></param>
|
/// <param name="pictureHeight"></param>
|
||||||
public CruisersGenericStorage(int pictureWidth, int pictureHeight)
|
public CruisersGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_cruiserStorages = new Dictionary<string,CarsGenericCollection<DrawingCruiser, DrawningObjectCar>>();
|
_cruiserStorages = new Dictionary<string, CarsGenericCollection<DrawingCruiser, DrawningObjectCar>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@ -70,6 +82,92 @@ namespace Cruiser.Generics
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<string, CarsGenericCollection<DrawingCruiser, DrawningObjectCar>> record in _cruiserStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawingCruiser? elem in record.Value.GetCruisers)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string dataStr = data.ToString();
|
||||||
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
|
{
|
||||||
|
writer.WriteLine("CruiserStorage");
|
||||||
|
writer.WriteLine(dataStr);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка информации по крейсеру в хранилище из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (StreamReader reader = new StreamReader(filename))
|
||||||
|
{
|
||||||
|
string checker = reader.ReadLine();
|
||||||
|
if (checker == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!checker.StartsWith("CruiserStorage"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_cruiserStorages.Clear();
|
||||||
|
string strs;
|
||||||
|
bool firstinit = true;
|
||||||
|
while ((strs = reader.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
if (strs == null && firstinit)
|
||||||
|
return false;
|
||||||
|
if (strs == null)
|
||||||
|
break;
|
||||||
|
if (strs == string.Empty)
|
||||||
|
break;
|
||||||
|
firstinit = false;
|
||||||
|
string name = strs.Split('|')[0];
|
||||||
|
CarsGenericCollection<DrawingCruiser, DrawningObjectCar> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
foreach (string data in strs.Split('|')[1].Split(';').Reverse())
|
||||||
|
{
|
||||||
|
DrawingCruiser? cruiser = data?.CreateDrawingCruiser(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (cruiser != null)
|
||||||
|
{
|
||||||
|
if (collection + cruiser == false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
_cruiserStorages.Add(name, collection);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
Cruiser/resources/saveFileDialog.txt
Normal file
4
Cruiser/resources/saveFileDialog.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
CruiserStorage
|
||||||
|
1|100:104:Sienna:Crimson:True:True;100:100:Gold:ForestGreen:True:False;100:100:Gold;
|
||||||
|
2|100:100:Aquamarine:Red:False:False;100:100:Gold:ForestGreen:True:False;100:100:Plum;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user