lab4
This commit is contained in:
parent
160e1ae53b
commit
8d8e031953
@ -8,7 +8,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectCruiser
|
namespace ProjectCruiser
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class CruiserGenericCollection<T, U>
|
internal class CruiserGenericCollection<T, U>
|
||||||
where T : DrawningCruiser
|
where T : DrawningCruiser
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
@ -43,17 +42,17 @@ namespace ProjectCruiser
|
|||||||
|
|
||||||
public static bool operator -(CruiserGenericCollection<T, U> collect, int pos)
|
public static bool operator -(CruiserGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return collect._collection.Remove(pos);
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap ShowCruiser()
|
public Bitmap ShowCruiser()
|
||||||
@ -86,16 +85,18 @@ namespace ProjectCruiser
|
|||||||
{
|
{
|
||||||
int Ix = 3;
|
int Ix = 3;
|
||||||
int Iy = 15;
|
int Iy = 15;
|
||||||
for (int i = 0; i < _collection.Count - 1; i++)
|
int i = 0;
|
||||||
|
foreach (var cruiser in _collection.GetCruiser())
|
||||||
{
|
{
|
||||||
_collection.Get(i)?.SetPosition(Ix, Iy);
|
_collection[i]?.SetPosition(Ix, Iy);
|
||||||
_collection.Get(i)?.DrawTransport(g);
|
_collection[i]?.DrawTransport(g);
|
||||||
Ix += _placeSizeWidth;
|
Ix += _placeSizeWidth;
|
||||||
if (Ix + _placeSizeHeight > _pictureWidth)
|
if (Ix + _placeSizeHeight > _pictureWidth)
|
||||||
{
|
{
|
||||||
Ix = 0;
|
Ix = 0;
|
||||||
Iy = _placeSizeHeight;
|
Iy = _placeSizeHeight;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
59
Cruiser/Cruiser/CruiserGenericStorage.cs
Normal file
59
Cruiser/Cruiser/CruiserGenericStorage.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using ProjectCruiser.DrawningObjects;
|
||||||
|
using ProjectCruiser.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectCruiser
|
||||||
|
{
|
||||||
|
internal class CruiserGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, CruiserGenericCollection<DrawningCruiser,
|
||||||
|
DrawningObjectCruiser>> _CruiserStorages;
|
||||||
|
|
||||||
|
public List<string> Keys => _CruiserStorages.Keys.ToList();
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
public CruiserGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_CruiserStorages = new Dictionary<string,
|
||||||
|
CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (!_CruiserStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
var ustaCollection = new CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>(_pictureWidth, _pictureHeight);
|
||||||
|
_CruiserStorages.Add(name, ustaCollection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (_CruiserStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_CruiserStorages.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_CruiserStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _CruiserStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -131,7 +131,6 @@ namespace ProjectCruiser.DrawningObjects
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
|
|
||||||
Brush BodyColor = new SolidBrush(EntityCruiser.BodyColor);
|
Brush BodyColor = new SolidBrush(EntityCruiser.BodyColor);
|
||||||
|
|
||||||
GraphicsPath path1 = new GraphicsPath();
|
GraphicsPath path1 = new GraphicsPath();
|
||||||
|
@ -29,7 +29,6 @@ namespace ProjectCruiser.DrawningObjects
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
|
|
||||||
Brush additionalBrush = new SolidBrush(cruiserDou.AdditionalColor);
|
Brush additionalBrush = new SolidBrush(cruiserDou.AdditionalColor);
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
|
||||||
@ -50,7 +49,9 @@ namespace ProjectCruiser.DrawningObjects
|
|||||||
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 18, 15, 12);
|
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 18, 15, 12);
|
||||||
g.DrawEllipse(pen, _startPosX + 8, _startPosY + 33, 15, 12);
|
g.DrawEllipse(pen, _startPosX + 8, _startPosY + 33, 15, 12);
|
||||||
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 33, 15, 12);
|
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 33, 15, 12);
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace ProjectCruiser
|
|||||||
{
|
{
|
||||||
public partial class FormCruiser : Form
|
public partial class FormCruiser : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
private DrawningCruiser? _drawningCruiser;
|
private DrawningCruiser? _drawningCruiser;
|
||||||
|
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
192
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
192
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
@ -28,90 +28,151 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBox1 = new GroupBox();
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
maskedTextBoxNumber = new MaskedTextBox();
|
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||||
ButtonRefreshCollection = new Button();
|
this.listBoxStorage = new System.Windows.Forms.ListBox();
|
||||||
ButtonRemoveCruiser = new Button();
|
this.textBoxStorageName = new System.Windows.Forms.MaskedTextBox();
|
||||||
buttonAddCruiser = new Button();
|
this.ButtonAddObject = new System.Windows.Forms.Button();
|
||||||
pictureBoxCollection = new PictureBox();
|
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||||
groupBox1.SuspendLayout();
|
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||||
SuspendLayout();
|
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAddCruiser = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
this.groupBox2.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
this.groupBox1.Controls.Add(this.groupBox2);
|
||||||
groupBox1.Controls.Add(ButtonRefreshCollection);
|
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
|
||||||
groupBox1.Controls.Add(ButtonRemoveCruiser);
|
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
|
||||||
groupBox1.Controls.Add(buttonAddCruiser);
|
this.groupBox1.Controls.Add(this.ButtonRemoveCruiser);
|
||||||
groupBox1.Location = new Point(844, 12);
|
this.groupBox1.Controls.Add(this.buttonAddCruiser);
|
||||||
groupBox1.Name = "groupBox1";
|
this.groupBox1.Location = new System.Drawing.Point(643, 12);
|
||||||
groupBox1.Size = new Size(196, 319);
|
this.groupBox1.Name = "groupBox1";
|
||||||
groupBox1.TabIndex = 0;
|
this.groupBox1.Size = new System.Drawing.Size(196, 436);
|
||||||
groupBox1.TabStop = false;
|
this.groupBox1.TabIndex = 0;
|
||||||
groupBox1.Text = "Инструменты";
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// groupBox2
|
||||||
|
//
|
||||||
|
this.groupBox2.Controls.Add(this.listBoxStorage);
|
||||||
|
this.groupBox2.Controls.Add(this.textBoxStorageName);
|
||||||
|
this.groupBox2.Controls.Add(this.ButtonAddObject);
|
||||||
|
this.groupBox2.Controls.Add(this.ButtonDelObject);
|
||||||
|
this.groupBox2.Location = new System.Drawing.Point(9, 24);
|
||||||
|
this.groupBox2.Name = "groupBox2";
|
||||||
|
this.groupBox2.Size = new System.Drawing.Size(179, 256);
|
||||||
|
this.groupBox2.TabIndex = 4;
|
||||||
|
this.groupBox2.TabStop = false;
|
||||||
|
this.groupBox2.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// listBoxStorage
|
||||||
|
//
|
||||||
|
this.listBoxStorage.FormattingEnabled = true;
|
||||||
|
this.listBoxStorage.ItemHeight = 15;
|
||||||
|
this.listBoxStorage.Location = new System.Drawing.Point(6, 93);
|
||||||
|
this.listBoxStorage.Name = "listBoxStorage";
|
||||||
|
this.listBoxStorage.Size = new System.Drawing.Size(167, 109);
|
||||||
|
this.listBoxStorage.TabIndex = 5;
|
||||||
|
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
this.textBoxStorageName.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
|
this.textBoxStorageName.Location = new System.Drawing.Point(6, 22);
|
||||||
|
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
this.textBoxStorageName.Size = new System.Drawing.Size(167, 26);
|
||||||
|
this.textBoxStorageName.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
this.ButtonAddObject.Location = new System.Drawing.Point(6, 54);
|
||||||
|
this.ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
this.ButtonAddObject.Size = new System.Drawing.Size(167, 33);
|
||||||
|
this.ButtonAddObject.TabIndex = 3;
|
||||||
|
this.ButtonAddObject.Text = "Добавить набор";
|
||||||
|
this.ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||||
|
//
|
||||||
|
// ButtonDelObject
|
||||||
|
//
|
||||||
|
this.ButtonDelObject.Location = new System.Drawing.Point(6, 217);
|
||||||
|
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||||
|
this.ButtonDelObject.Size = new System.Drawing.Size(167, 33);
|
||||||
|
this.ButtonDelObject.TabIndex = 2;
|
||||||
|
this.ButtonDelObject.Text = "Удалить набор";
|
||||||
|
this.ButtonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Font = new Font("Lucida Sans Unicode", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
this.maskedTextBoxNumber.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
maskedTextBoxNumber.Location = new Point(29, 78);
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(34, 325);
|
||||||
maskedTextBoxNumber.Mask = "00";
|
this.maskedTextBoxNumber.Mask = "00";
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(130, 26);
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(130, 26);
|
||||||
maskedTextBoxNumber.TabIndex = 3;
|
this.maskedTextBoxNumber.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// ButtonRefreshCollection
|
// ButtonRefreshCollection
|
||||||
//
|
//
|
||||||
ButtonRefreshCollection.Location = new Point(6, 195);
|
this.ButtonRefreshCollection.Location = new System.Drawing.Point(6, 396);
|
||||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
ButtonRefreshCollection.Size = new Size(184, 33);
|
this.ButtonRefreshCollection.Size = new System.Drawing.Size(184, 33);
|
||||||
ButtonRefreshCollection.TabIndex = 2;
|
this.ButtonRefreshCollection.TabIndex = 2;
|
||||||
ButtonRefreshCollection.Text = "Обовить коллекцию";
|
this.ButtonRefreshCollection.Text = "Обовить коллекцию";
|
||||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||||
//
|
//
|
||||||
// ButtonRemoveCruiser
|
// ButtonRemoveCruiser
|
||||||
//
|
//
|
||||||
ButtonRemoveCruiser.Location = new Point(6, 136);
|
this.ButtonRemoveCruiser.Location = new System.Drawing.Point(6, 357);
|
||||||
ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
|
this.ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
|
||||||
ButtonRemoveCruiser.Size = new Size(184, 33);
|
this.ButtonRemoveCruiser.Size = new System.Drawing.Size(184, 33);
|
||||||
ButtonRemoveCruiser.TabIndex = 1;
|
this.ButtonRemoveCruiser.TabIndex = 1;
|
||||||
ButtonRemoveCruiser.Text = "Удалить Крейсер";
|
this.ButtonRemoveCruiser.Text = "Удалить крейсер";
|
||||||
ButtonRemoveCruiser.UseVisualStyleBackColor = true;
|
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
|
||||||
ButtonRemoveCruiser.Click += ButtonRemoveCruiser_Click;
|
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
|
||||||
//
|
//
|
||||||
// buttonAddCruiser
|
// buttonAddCruiser
|
||||||
//
|
//
|
||||||
buttonAddCruiser.Location = new Point(6, 22);
|
this.buttonAddCruiser.Location = new System.Drawing.Point(6, 286);
|
||||||
buttonAddCruiser.Name = "buttonAddCruiser";
|
this.buttonAddCruiser.Name = "buttonAddCruiser";
|
||||||
buttonAddCruiser.Size = new Size(184, 33);
|
this.buttonAddCruiser.Size = new System.Drawing.Size(184, 33);
|
||||||
buttonAddCruiser.TabIndex = 0;
|
this.buttonAddCruiser.TabIndex = 0;
|
||||||
buttonAddCruiser.Text = "Добавить Крейсер";
|
this.buttonAddCruiser.Text = "Добавить крейсер";
|
||||||
buttonAddCruiser.UseVisualStyleBackColor = true;
|
this.buttonAddCruiser.UseVisualStyleBackColor = true;
|
||||||
buttonAddCruiser.Click += buttonAddCruiser_Click;
|
this.buttonAddCruiser.Click += new System.EventHandler(this.buttonAddCruiser_Click);
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(0, -1);
|
this.pictureBoxCollection.Location = new System.Drawing.Point(0, -1);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(838, 432);
|
this.pictureBoxCollection.Size = new System.Drawing.Size(637, 449);
|
||||||
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
|
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||||
pictureBoxCollection.TabIndex = 1;
|
this.pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
this.pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// FormCruiserCollection
|
// FormCruiserCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1062, 489);
|
this.ClientSize = new System.Drawing.Size(851, 458);
|
||||||
Controls.Add(pictureBoxCollection);
|
this.Controls.Add(this.pictureBoxCollection);
|
||||||
Controls.Add(groupBox1);
|
this.Controls.Add(this.groupBox1);
|
||||||
Name = "FormCruiserCollection";
|
this.Name = "FormCruiserCollection";
|
||||||
Text = "FormCruiserCollection";
|
this.Text = "FormCruiserCollection";
|
||||||
groupBox1.ResumeLayout(false);
|
this.groupBox1.ResumeLayout(false);
|
||||||
groupBox1.PerformLayout();
|
this.groupBox1.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
this.groupBox2.ResumeLayout(false);
|
||||||
ResumeLayout(false);
|
this.groupBox2.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -122,5 +183,10 @@
|
|||||||
private Button ButtonRemoveCruiser;
|
private Button ButtonRemoveCruiser;
|
||||||
private Button buttonAddCruiser;
|
private Button buttonAddCruiser;
|
||||||
private PictureBox pictureBoxCollection;
|
private PictureBox pictureBoxCollection;
|
||||||
|
private GroupBox groupBox2;
|
||||||
|
private ListBox listBoxStorage;
|
||||||
|
private MaskedTextBox textBoxStorageName;
|
||||||
|
private Button ButtonAddObject;
|
||||||
|
private Button ButtonDelObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,23 +14,87 @@ namespace ProjectCruiser
|
|||||||
{
|
{
|
||||||
public partial class FormCruiserCollection : Form
|
public partial class FormCruiserCollection : Form
|
||||||
{
|
{
|
||||||
private readonly CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser> _cruiser;
|
private readonly CruiserGenericStorage _storage;
|
||||||
|
|
||||||
public FormCruiserCollection()
|
public FormCruiserCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_cruiser = new CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new CruiserGenericStorage(pictureBoxCollection.Width,
|
||||||
|
pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorage.SelectedIndex;
|
||||||
|
listBoxStorage.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
|
||||||
|
>= listBoxStorage.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorage.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorage.Items.Count > 0 && index > -1 &&
|
||||||
|
index < listBoxStorage.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorage.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listBoxStorage_SelectedIndexChanged(object sender,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowCruiser();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonAddCruiser_Click(object sender, EventArgs e)
|
private void buttonAddCruiser_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FormCruiser form = new();
|
FormCruiser form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_cruiser + form.SelectedCruiser > -1)
|
if (obj + form.SelectedCruiser > -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _cruiser.ShowCruiser();
|
pictureBoxCollection.Image = obj.ShowCruiser();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -41,15 +105,26 @@ namespace ProjectCruiser
|
|||||||
|
|
||||||
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
|
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (_cruiser - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _cruiser.ShowCruiser();
|
pictureBoxCollection.Image = obj.ShowCruiser();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -59,7 +134,17 @@ namespace ProjectCruiser
|
|||||||
|
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _cruiser.ShowCruiser();
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowCruiser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,64 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<root>
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
@ -9,7 +9,6 @@ namespace ProjectCruiser.MovementStrategy
|
|||||||
{
|
{
|
||||||
public interface IMoveableObject
|
public interface IMoveableObject
|
||||||
{
|
{
|
||||||
|
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
int GetStep { get; }
|
int GetStep { get; }
|
||||||
|
@ -9,7 +9,6 @@ using ProjectCruiser.Drawnings;
|
|||||||
|
|
||||||
namespace ProjectCruiser.MovementStrategy
|
namespace ProjectCruiser.MovementStrategy
|
||||||
{
|
{
|
||||||
|
|
||||||
public class DrawningObjectCruiser : IMoveableObject
|
public class DrawningObjectCruiser : IMoveableObject
|
||||||
{
|
{
|
||||||
private readonly DrawningCruiser? _drawningCruiser = null;
|
private readonly DrawningCruiser? _drawningCruiser = null;
|
||||||
|
@ -6,13 +6,15 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectCruiser.MovementStrategy
|
namespace ProjectCruiser.MovementStrategy
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры-координаты объекта
|
||||||
|
/// </summary>
|
||||||
public class ObjectParameters
|
public class ObjectParameters
|
||||||
{
|
{
|
||||||
private readonly int _x;
|
private readonly int _x;
|
||||||
private readonly int _y;
|
private readonly int _y;
|
||||||
private readonly int _width;
|
private readonly int _width;
|
||||||
private readonly int _height;
|
private readonly int _height;
|
||||||
|
|
||||||
public int LeftBorder => _x;
|
public int LeftBorder => _x;
|
||||||
|
|
||||||
public int TopBorder => _y;
|
public int TopBorder => _y;
|
||||||
|
@ -9,14 +9,16 @@ namespace ProjectCruiser
|
|||||||
internal class SetGeneric<T>
|
internal class SetGeneric<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
|
private readonly List<T?> _places;
|
||||||
|
|
||||||
private readonly T?[] _places;
|
public int Count => _places.Count;
|
||||||
|
|
||||||
public int Count => _places.Length;
|
private readonly int _maxCount;
|
||||||
|
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T cruiser)
|
public int Insert(T cruiser)
|
||||||
@ -26,51 +28,49 @@ namespace ProjectCruiser
|
|||||||
|
|
||||||
public int Insert(T cruiser, int position)
|
public int Insert(T cruiser, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 && position > Count)
|
|
||||||
{
|
if (position < 0 || position >= _maxCount)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
if (Count >= _maxCount)
|
||||||
if (_places[position] != null)
|
|
||||||
{
|
|
||||||
int d = 0;
|
|
||||||
for (int j = 1; j < Count - position; j++)
|
|
||||||
{
|
|
||||||
if (_places[position + j] == null)
|
|
||||||
{
|
|
||||||
d = position + j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (d == 0)
|
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
_places.Insert(position, cruiser);
|
||||||
for (int j = d; j > position; j--)
|
|
||||||
{
|
|
||||||
_places[j] = _places[j - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_places[position] = cruiser;
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _places.Length)
|
|
||||||
{
|
if ((position < 0) || (position > _maxCount)) return false;
|
||||||
return false;
|
_places.RemoveAt(position);
|
||||||
}
|
|
||||||
_places[position] = null;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Get(int position)
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _places.Length)
|
get
|
||||||
{
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return;
|
||||||
|
_places[position] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T?> GetCruiser(int? maxCruiser = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxCruiser.HasValue && i == maxCruiser.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user