diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs
new file mode 100644
index 0000000..b8e9ce8
--- /dev/null
+++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs
@@ -0,0 +1,143 @@
+namespace ProjectTank
+{
+ partial class ArmoredTransportCollectionForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.ArmoredTransportCollectionFormToolsGroup = new System.Windows.Forms.GroupBox();
+ this.ButtonRefreshCollection = new System.Windows.Forms.Button();
+ this.ButtonRemoveArmoredTransport = new System.Windows.Forms.Button();
+ this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
+ this.ButtonAddArmoredTransport = new System.Windows.Forms.Button();
+ this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
+ this.ArmoredTransportCollectionFormToolsGroup.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
+ this.SuspendLayout();
+ //
+ // ArmoredTransportCollectionFormToolsGroup
+ //
+ this.ArmoredTransportCollectionFormToolsGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRefreshCollection);
+ this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRemoveArmoredTransport);
+ this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.maskedTextBoxNumber);
+ this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonAddArmoredTransport);
+ this.ArmoredTransportCollectionFormToolsGroup.Location = new System.Drawing.Point(1057, -4);
+ this.ArmoredTransportCollectionFormToolsGroup.Name = "ArmoredTransportCollectionFormToolsGroup";
+ this.ArmoredTransportCollectionFormToolsGroup.Size = new System.Drawing.Size(431, 865);
+ this.ArmoredTransportCollectionFormToolsGroup.TabIndex = 0;
+ this.ArmoredTransportCollectionFormToolsGroup.TabStop = false;
+ this.ArmoredTransportCollectionFormToolsGroup.Text = "Инструменты";
+ //
+ // ButtonRefreshCollection
+ //
+ this.ButtonRefreshCollection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.ButtonRefreshCollection.Location = new System.Drawing.Point(22, 394);
+ this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
+ this.ButtonRefreshCollection.Size = new System.Drawing.Size(391, 47);
+ this.ButtonRefreshCollection.TabIndex = 3;
+ this.ButtonRefreshCollection.Text = "Обновить коллекцию";
+ this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
+ this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
+ //
+ // ButtonRemoveArmoredTransport
+ //
+ this.ButtonRemoveArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.ButtonRemoveArmoredTransport.Location = new System.Drawing.Point(22, 251);
+ this.ButtonRemoveArmoredTransport.Name = "ButtonRemoveArmoredTransport";
+ this.ButtonRemoveArmoredTransport.Size = new System.Drawing.Size(391, 82);
+ this.ButtonRemoveArmoredTransport.TabIndex = 2;
+ this.ButtonRemoveArmoredTransport.Text = "Удалить бронированный транспорт";
+ this.ButtonRemoveArmoredTransport.UseVisualStyleBackColor = true;
+ this.ButtonRemoveArmoredTransport.Click += new System.EventHandler(this.ButtonRemoveArmoredTransport_Click);
+ //
+ // maskedTextBoxNumber
+ //
+ this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.maskedTextBoxNumber.Location = new System.Drawing.Point(71, 188);
+ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39);
+ this.maskedTextBoxNumber.TabIndex = 1;
+ this.maskedTextBoxNumber.TextChanged += new System.EventHandler(this.maskedTextBoxNumber_TextChanged);
+ //
+ // ButtonAddArmoredTransport
+ //
+ this.ButtonAddArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.ButtonAddArmoredTransport.Location = new System.Drawing.Point(22, 88);
+ this.ButtonAddArmoredTransport.Name = "ButtonAddArmoredTransport";
+ this.ButtonAddArmoredTransport.Size = new System.Drawing.Size(391, 82);
+ this.ButtonAddArmoredTransport.TabIndex = 0;
+ this.ButtonAddArmoredTransport.Text = "Добавить бронированный транспорт";
+ this.ButtonAddArmoredTransport.UseVisualStyleBackColor = true;
+ this.ButtonAddArmoredTransport.Click += new System.EventHandler(this.ButtonAddArmoredTransport_Click);
+ //
+ // contextMenuStrip1
+ //
+ this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(32, 32);
+ this.contextMenuStrip1.Name = "contextMenuStrip1";
+ this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
+ //
+ // pictureBoxCollection
+ //
+ this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxCollection.Name = "pictureBoxCollection";
+ this.pictureBoxCollection.Size = new System.Drawing.Size(1492, 873);
+ this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxCollection.TabIndex = 2;
+ this.pictureBoxCollection.TabStop = false;
+ //
+ // ArmoredTransportCollectionForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1492, 873);
+ this.Controls.Add(this.ArmoredTransportCollectionFormToolsGroup);
+ this.Controls.Add(this.pictureBoxCollection);
+ this.Name = "ArmoredTransportCollectionForm";
+ this.Text = "ArmoredTransportCollectionForm";
+ this.ArmoredTransportCollectionFormToolsGroup.ResumeLayout(false);
+ this.ArmoredTransportCollectionFormToolsGroup.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private GroupBox ArmoredTransportCollectionFormToolsGroup;
+ private Button ButtonRefreshCollection;
+ private Button ButtonRemoveArmoredTransport;
+ private TextBox maskedTextBoxNumber;
+ private Button ButtonAddArmoredTransport;
+ private ContextMenuStrip contextMenuStrip1;
+ private PictureBox pictureBoxCollection;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs
new file mode 100644
index 0000000..e3255e7
--- /dev/null
+++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using ProjectTank.DrawningObjects;
+using ProjectTank.Generics;
+using ProjectTank.MovementStrategy;
+
+namespace ProjectTank
+{
+ ///
+ /// Форма для работы с набором объектов класса DrawningCar
+ ///
+ public partial class ArmoredTransportCollectionForm : Form
+ {
+ ///
+ /// Набор объектов
+ ///
+ private readonly ArmoredTransportsGenericCollection _armoredTransports;
+ ///
+ /// Конструктор
+ ///
+ public ArmoredTransportCollectionForm()
+ {
+ InitializeComponent();
+ _armoredTransports = new ArmoredTransportsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ ///
+ ///
+ private void ButtonAddArmoredTransport_Click(object sender, EventArgs e)
+ {
+ TankForm form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_armoredTransports + form.SelectedArmoredTransport)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта из набора
+ ///
+ ///
+ ///
+ private void ButtonRemoveArmoredTransport_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_armoredTransports - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Обновление рисунка по набору
+ ///
+ ///
+ ///
+ private void ButtonRefreshCollection_Click(object sender, EventArgs
+ e)
+ {
+ pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
+ }
+
+ private void maskedTextBoxNumber_TextChanged(object sender, EventArgs e)
+ {
+
+ }
+ }
+}
diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx
new file mode 100644
index 0000000..2a349cc
--- /dev/null
+++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs
new file mode 100644
index 0000000..7e213ed
--- /dev/null
+++ b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs
@@ -0,0 +1,138 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectTank.DrawningObjects;
+using ProjectTank.MovementStrategy;
+
+namespace ProjectTank.Generics
+{
+ ///
+ /// Параметризованный класс для набора объектов DrawningArmoredTransport
+ ///
+ ///
+ ///
+ internal class ArmoredTransportsGenericCollection
+ where T : DrawningArmoredTransport
+ where U : IMoveableObject
+ {
+ ///
+ /// Ширина окна прорисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 200;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 80;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetGeneric _collection;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public ArmoredTransportsGenericCollection(int picWidth, int picHeight)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = new SetGeneric(width * height);
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static bool operator +(ArmoredTransportsGenericCollection collect, T? obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ return collect?._collection.Insert(obj) ?? false;
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T? operator -(ArmoredTransportsGenericCollection collect, int
+ pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ collect._collection.Remove(pos);
+ }
+ return obj;
+ }
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowArmoredTransports()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight +
+ 1; ++j)
+ {
+ //линия рамзетки места
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight,
+ i * _placeSizeWidth + _placeSizeWidth / 2, j *_placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
+ _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawObjects(Graphics g)
+ {
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ // TODO получение объекта
+ // TODO установка позиции
+ // TODO прорисовка объекта
+ }
+ }
+ }
+}
diff --git a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs
index ac81c1e..39fd477 100644
--- a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs
+++ b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectTank.Entities;
+using ProjectTank.MovementStrategy;
namespace ProjectTank.DrawningObjects
{
@@ -57,6 +58,10 @@ namespace ProjectTank.DrawningObjects
///
public int GetHeight => _transportHeight;
///
+ /// Получение объекта IMoveableObject из объекта DrawningArmoredTransport
+ ///
+ public IMoveableObject GetMoveableObject => new DrawningObjectArmoredTransport(this);
+ ///
/// Конструктор
///
/// Скорость
diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs
index 10b63f7..23b598f 100644
--- a/ProjectTank/ProjectTank/Program.cs
+++ b/ProjectTank/ProjectTank/Program.cs
@@ -10,8 +10,10 @@ namespace ProjectTank
[STAThread]
static void Main()
{
+ // To customize application configuration such as set high DPI settings or default font,
+ // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new TankForm());
+ Application.Run(new ArmoredTransportCollectionForm());
}
}
}
\ No newline at end of file
diff --git a/ProjectTank/ProjectTank/SetGeneric.cs b/ProjectTank/ProjectTank/SetGeneric.cs
new file mode 100644
index 0000000..2fcdd84
--- /dev/null
+++ b/ProjectTank/ProjectTank/SetGeneric.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectTank.Generics
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ internal class SetGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T?[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetGeneric(int count)
+ {
+ _places = new T?[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый автомобиль
+ ///
+ public bool Insert(T car)
+ {
+ // TODO вставка в начало набора
+ return true;
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый автомобиль
+ /// Позиция
+ ///
+ public bool Insert(T car, int position)
+ {
+ // TODO проверка позиции
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ // проверка, что после вставляемого элемента в массиве есть пустой элемент
+ // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
+ // TODO вставка по позиции
+ _places[position] = car;
+ return true;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ return true;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ return _places[position];
+ }
+ }
+}
diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs
index c4bfa90..4402c9e 100644
--- a/ProjectTank/ProjectTank/TankForm.cs
+++ b/ProjectTank/ProjectTank/TankForm.cs
@@ -18,11 +18,17 @@ namespace ProjectTank
///
private AbstractStrategy? _abstractStrategy;
///
+ ///
+ ///
+ public DrawningArmoredTransport? SelectedArmoredTransport { get; private set; }
+ ///
///
///
public TankForm()
{
InitializeComponent();
+ _abstractStrategy = null;
+ SelectedArmoredTransport = null;
}
///
///
@@ -46,10 +52,13 @@ namespace ProjectTank
private void ButtonCreateTank_Click(object sender, EventArgs e)
{
Random random = new();
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ //TODO
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ //TODO
_drawningArmoredTransport = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
+ color, dopColor,Convert.ToBoolean(random.Next(0, 2)),
+ Convert.ToBoolean(random.Next(0, 2)),
pictureBoxTanks.Width, pictureBoxTanks.Height);
_drawningArmoredTransport.SetPosition(random.Next(0, 100), random.Next(0, 100));
Draw();
@@ -62,9 +71,9 @@ namespace ProjectTank
private void ButtonCreateArmoredTransport_Click(object sender, EventArgs e)
{
Random random = new();
- _drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ //TODO
+ _drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), color,
pictureBoxTanks.Width, pictureBoxTanks.Height);
_drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100));
Draw();
@@ -122,14 +131,14 @@ namespace ProjectTank
{
return;
}
- _abstractStrategy.SetData(new DrawningObjectArmoredTransport(_drawningArmoredTransport),
+ _abstractStrategy.SetData(_drawningArmoredTransport.GetMoveableObject,
pictureBoxTanks.Width, pictureBoxTanks.Height);
- comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
+ comboBoxStrategy.Enabled = false;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
@@ -138,5 +147,15 @@ namespace ProjectTank
_abstractStrategy = null;
}
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ButtonSelectCar_Click(object sender, EventArgs e)
+ {
+ SelectedArmoredTransport = _drawningArmoredTransport;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file