Compare commits

..

No commits in common. "TankBasicLabSixth" and "main" have entirely different histories.

42 changed files with 621 additions and 3665 deletions

3
.gitignore vendored
View File

@ -4,9 +4,6 @@
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
#mac file
.DS_Store
# User-specific files
*.rsuser
*.suo

View File

@ -1,133 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectTank.DrawningObjects;
namespace ProjectTank.MovementStrategy
{
/// <summary>
/// Класс-стратегия перемещения объекта
/// </summary>
public abstract class AbstractStrategy
{
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject? _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private Status _state = Status.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth { get; private set; }
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight { get; private set; }
/// <summary>
/// Статус перемещения
/// </summary>
public Status GetStatus() { return _state; }
/// <summary>
/// Установка данных
/// </summary>
/// <param name="moveableObject">Перемещаемый объект</param>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
public void SetData(IMoveableObject moveableObject, int width,
int height){
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
protected bool MoveLeft() => MoveTo(DirectionType.Left);
/// <summary>
/// Перемещение вправо
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
protected bool MoveRight() => MoveTo(DirectionType.Right);
/// <summary>
/// Перемещение вверх
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
protected bool MoveUp() => MoveTo(DirectionType.Up);
/// <summary>
/// Перемещение вниз
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
protected bool MoveDown() => MoveTo(DirectionType.Down);
/// <summary>
/// Параметры объекта
/// </summary>
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
/// <summary>
/// Шаг объекта
/// </summary>
/// <returns></returns>
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract bool IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="directionType">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -1,273 +0,0 @@
namespace ProjectTank
{
partial class ArmoredTransportCollectionForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.ArmoredTransportCollectionFormToolsGroup = new System.Windows.Forms.GroupBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.buttonDelObject = new System.Windows.Forms.Button();
this.buttonAddObject = new System.Windows.Forms.Button();
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.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.ArmoredTransportCollectionFormToolsGroup.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.menuStrip.SuspendLayout();
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.groupBox1);
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 = "Инструменты";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.textBoxStorageName);
this.groupBox1.Controls.Add(this.listBoxStorages);
this.groupBox1.Controls.Add(this.buttonDelObject);
this.groupBox1.Controls.Add(this.buttonAddObject);
this.groupBox1.Location = new System.Drawing.Point(22, 38);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(391, 434);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Наборы";
//
// textBoxStorageName
//
this.textBoxStorageName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.textBoxStorageName.Location = new System.Drawing.Point(19, 38);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(353, 39);
this.textBoxStorageName.TabIndex = 3;
//
// listBoxStorages
//
this.listBoxStorages.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 32;
this.listBoxStorages.Location = new System.Drawing.Point(19, 165);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(353, 196);
this.listBoxStorages.TabIndex = 2;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
//
// buttonDelObject
//
this.buttonDelObject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDelObject.Location = new System.Drawing.Point(19, 374);
this.buttonDelObject.Name = "buttonDelObject";
this.buttonDelObject.Size = new System.Drawing.Size(353, 46);
this.buttonDelObject.TabIndex = 1;
this.buttonDelObject.Text = "Удалить набор";
this.buttonDelObject.UseVisualStyleBackColor = true;
this.buttonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// buttonAddObject
//
this.buttonAddObject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAddObject.Location = new System.Drawing.Point(19, 98);
this.buttonAddObject.Name = "buttonAddObject";
this.buttonAddObject.Size = new System.Drawing.Size(353, 46);
this.buttonAddObject.TabIndex = 0;
this.buttonAddObject.Text = "Добавить набор";
this.buttonAddObject.UseVisualStyleBackColor = true;
this.buttonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// 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, 773);
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, 641);
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, 589);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39);
this.maskedTextBoxNumber.TabIndex = 1;
this.maskedTextBoxNumber.Tag = "";
this.maskedTextBoxNumber.Text = "_";
//
// 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, 492);
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);
//
// contextMenuStrip
//
this.contextMenuStrip.ImageScalingSize = new System.Drawing.Size(32, 32);
this.contextMenuStrip.Name = "contextMenuStrip1";
this.contextMenuStrip.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;
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(32, 32);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1492, 40);
this.menuStrip.TabIndex = 3;
this.menuStrip.Text = "menuStrip1";
//
// ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(90, 36);
this.ToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(359, 44);
this.SaveToolStripMenuItem.Text = "Сохранить";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(359, 44);
this.LoadToolStripMenuItem.Text = "Загрузить";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// openFileDialog
//
this.openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
this.saveFileDialog.FileName = "Storage";
this.saveFileDialog.Filter = "txt file | *.txt";
//
// 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.menuStrip);
this.Controls.Add(this.ArmoredTransportCollectionFormToolsGroup);
this.Controls.Add(this.pictureBoxCollection);
this.MainMenuStrip = this.menuStrip;
this.Name = "ArmoredTransportCollectionForm";
this.Text = "ArmoredTransportCollectionForm";
this.ArmoredTransportCollectionFormToolsGroup.ResumeLayout(false);
this.ArmoredTransportCollectionFormToolsGroup.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private GroupBox ArmoredTransportCollectionFormToolsGroup;
private Button ButtonRefreshCollection;
private Button ButtonRemoveArmoredTransport;
private TextBox maskedTextBoxNumber;
private Button ButtonAddArmoredTransport;
private ContextMenuStrip contextMenuStrip;
private PictureBox pictureBoxCollection;
private GroupBox groupBox1;
private TextBox textBoxStorageName;
private ListBox listBoxStorages;
private Button buttonDelObject;
private Button buttonAddObject;
private MenuStrip menuStrip;
private ToolStripMenuItem ToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
}
}

View File

@ -1,224 +0,0 @@
using ProjectTank.DrawningObjects;
using ProjectTank.Generics;
using ProjectTank.MovementStrategy;
namespace ProjectTank
{
/// <summary>
/// Форма для работы с набором объектов класса DrawningArmoredTransport
/// </summary>
public partial class ArmoredTransportCollectionForm : Form
{
/// <summary>
/// Набор объектов
/// </summary>
private readonly ArmoredTransportsGenericStorage _storage;
/// <summary>
/// Конструктор
/// </summary>
public ArmoredTransportCollectionForm()
{
InitializeComponent();
_storage = new ArmoredTransportsGenericStorage(pictureBoxCollection.Width,
pictureBoxCollection.Height);
}
/// <summary>
/// Заполнение listBoxObjects
/// </summary>
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
/// <summary>
/// Добавление набора в коллекцию
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
/// <summary>
/// Выбор набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowArmoredTransports();
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowArmoredTransports();
}
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddArmoredTransport_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString()??string.Empty];
if (obj == null)
{
return;
}
ArmoredTransportConfigForm form = new(pictureBoxCollection.Width, pictureBoxCollection.Height);
form.Show();
Action<DrawningArmoredTransport>? armoredTransportDelegate = new((m) =>
{
bool q = (obj + m);
if (q)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowArmoredTransports();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
});
form.AddEvent(armoredTransportDelegate);
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveArmoredTransport_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowArmoredTransports();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefreshCollection_Click(object sender, EventArgs
e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowArmoredTransports();
}
/// <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);
foreach (var collection in _storage.Keys)
{
listBoxStorages.Items.Add(collection);
}
}
else
{
MessageBox.Show("Ошибка при загрузке", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

@ -1,72 +0,0 @@
<root>
<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:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>296, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>494, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>743, 17</value>
</metadata>
</root>

View File

@ -1,399 +0,0 @@
namespace ProjectTank
{
partial class ArmoredTransportConfigForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxMachineGun = new System.Windows.Forms.CheckBox();
this.checkBoxGun = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.panel9 = new System.Windows.Forms.Panel();
this.addColorLabel = new System.Windows.Forms.Label();
this.colorLabel = new System.Windows.Forms.Label();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.panel9.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.labelModifiedObject);
this.groupBox1.Controls.Add(this.labelSimpleObject);
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.checkBoxMachineGun);
this.groupBox1.Controls.Add(this.checkBoxGun);
this.groupBox1.Controls.Add(this.numericUpDownWeight);
this.groupBox1.Controls.Add(this.numericUpDownSpeed);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(23, 23);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(888, 523);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Параметры";
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(634, 428);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(230, 70);
this.labelModifiedObject.TabIndex = 8;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(348, 428);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(230, 70);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragDrop);
this.labelSimpleObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragEnter);
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.panelYellow);
this.groupBox2.Controls.Add(this.panelPurple);
this.groupBox2.Controls.Add(this.panelBlue);
this.groupBox2.Controls.Add(this.panelBlack);
this.groupBox2.Controls.Add(this.panelGreen);
this.groupBox2.Controls.Add(this.panelGray);
this.groupBox2.Controls.Add(this.panelWhite);
this.groupBox2.Controls.Add(this.panelRed);
this.groupBox2.Location = new System.Drawing.Point(348, 72);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(516, 298);
this.groupBox2.TabIndex = 6;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Цвета";
//
// panelYellow
//
this.panelYellow.AllowDrop = true;
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(381, 38);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(100, 100);
this.panelYellow.TabIndex = 4;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelPurple
//
this.panelPurple.AllowDrop = true;
this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(64)))));
this.panelPurple.Location = new System.Drawing.Point(381, 170);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(100, 100);
this.panelPurple.TabIndex = 4;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.AllowDrop = true;
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(259, 38);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(100, 100);
this.panelBlue.TabIndex = 4;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlack
//
this.panelBlack.AllowDrop = true;
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(259, 170);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(100, 100);
this.panelBlack.TabIndex = 4;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.AllowDrop = true;
this.panelGreen.BackColor = System.Drawing.Color.Lime;
this.panelGreen.Location = new System.Drawing.Point(138, 38);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(100, 100);
this.panelGreen.TabIndex = 2;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGray
//
this.panelGray.AllowDrop = true;
this.panelGray.BackColor = System.Drawing.Color.Silver;
this.panelGray.Location = new System.Drawing.Point(138, 170);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(100, 100);
this.panelGray.TabIndex = 3;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelWhite
//
this.panelWhite.AllowDrop = true;
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(20, 170);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(100, 100);
this.panelWhite.TabIndex = 1;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelRed
//
this.panelRed.AllowDrop = true;
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(20, 38);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(100, 100);
this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// checkBoxMachineGun
//
this.checkBoxMachineGun.AutoSize = true;
this.checkBoxMachineGun.Location = new System.Drawing.Point(20, 247);
this.checkBoxMachineGun.Name = "checkBoxMachineGun";
this.checkBoxMachineGun.Size = new System.Drawing.Size(141, 36);
this.checkBoxMachineGun.TabIndex = 5;
this.checkBoxMachineGun.Text = "Пулемет";
this.checkBoxMachineGun.UseVisualStyleBackColor = true;
//
// checkBoxGun
//
this.checkBoxGun.AutoSize = true;
this.checkBoxGun.Location = new System.Drawing.Point(20, 197);
this.checkBoxGun.Name = "checkBoxGun";
this.checkBoxGun.Size = new System.Drawing.Size(118, 36);
this.checkBoxGun.TabIndex = 4;
this.checkBoxGun.Text = "Пушка";
this.checkBoxGun.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(172, 118);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(143, 39);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(172, 65);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(143, 39);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(20, 125);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(57, 32);
this.label2.TabIndex = 1;
this.label2.Text = "Вес:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 72);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(121, 32);
this.label1.TabIndex = 0;
this.label1.Text = "Скорость:";
//
// pictureBox
//
this.pictureBox.Location = new System.Drawing.Point(16, 98);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(517, 289);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// panel9
//
this.panel9.AllowDrop = true;
this.panel9.Controls.Add(this.addColorLabel);
this.panel9.Controls.Add(this.colorLabel);
this.panel9.Controls.Add(this.pictureBox);
this.panel9.Location = new System.Drawing.Point(929, 42);
this.panel9.Name = "panel9";
this.panel9.Size = new System.Drawing.Size(549, 409);
this.panel9.TabIndex = 2;
this.panel9.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panel9.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// addColorLabel
//
this.addColorLabel.AllowDrop = true;
this.addColorLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.addColorLabel.Location = new System.Drawing.Point(303, 13);
this.addColorLabel.Name = "addColorLabel";
this.addColorLabel.Size = new System.Drawing.Size(230, 70);
this.addColorLabel.TabIndex = 10;
this.addColorLabel.Text = "Доп. цвет";
this.addColorLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.addColorLabel.DragDrop += new System.Windows.Forms.DragEventHandler(this.addColorLabel_DragDrop);
this.addColorLabel.DragEnter += new System.Windows.Forms.DragEventHandler(this.addColorLabel_DragEnter);
//
// colorLabel
//
this.colorLabel.AllowDrop = true;
this.colorLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.colorLabel.Location = new System.Drawing.Point(16, 13);
this.colorLabel.Name = "colorLabel";
this.colorLabel.Size = new System.Drawing.Size(230, 70);
this.colorLabel.TabIndex = 9;
this.colorLabel.Text = "Цвет";
this.colorLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.colorLabel.DragDrop += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragDrop);
this.colorLabel.DragEnter += new System.Windows.Forms.DragEventHandler(this.colorLabel_DragEnter);
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(945, 474);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(200, 60);
this.buttonOk.TabIndex = 3;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(1262, 474);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(200, 60);
this.buttonCancel.TabIndex = 4;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// ArmoredTransportConfigForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1497, 577);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panel9);
this.Controls.Add(this.groupBox1);
this.Name = "ArmoredTransportConfigForm";
this.Text = "Создание объекта";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.panel9.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private CheckBox checkBoxMachineGun;
private CheckBox checkBoxGun;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label label2;
private Label label1;
private Label labelModifiedObject;
private Label labelSimpleObject;
private GroupBox groupBox2;
private Panel panelYellow;
private Panel panelPurple;
private Panel panelBlue;
private Panel panelBlack;
private Panel panelGreen;
private Panel panelGray;
private Panel panelWhite;
private Panel panelRed;
private PictureBox pictureBox;
private Panel panel9;
private Label addColorLabel;
private Label colorLabel;
private Button buttonOk;
private Button buttonCancel;
}
}

View File

@ -1,171 +0,0 @@
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 System;
using System.Collections.Generic;
using ProjectTank.DrawningObjects;
using ProjectTank.Entities;
namespace ProjectTank
{
/// <summary>
/// Форма создания объекта
/// </summary>
public partial class ArmoredTransportConfigForm : Form
{
private readonly int PictureWidth;
private readonly int PictureHeight;
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawningArmoredTransport? _armoredTransport = null;
/// <summary>
/// Событие
/// </summary>
Action<DrawningArmoredTransport>? EventAddArmoredTransport;
/// <summary>
/// Конструктор
/// </summary>
public ArmoredTransportConfigForm(int width, int height)
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
PictureWidth = width;
PictureHeight = height;
}
/// <summary>
/// Отрисовать машину
/// </summary>
private void DrawArmoredTransport()
{
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
Graphics gr = Graphics.FromImage(bmp);
_armoredTransport?.SetPosition(5, 5);
_armoredTransport?.DrawTransport(gr);
pictureBox.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(Action<DrawningArmoredTransport>? ev)
{
if (EventAddArmoredTransport == null)
{
EventAddArmoredTransport = ev;
}
else
{
EventAddArmoredTransport += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_armoredTransport = new DrawningArmoredTransport((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, PictureWidth, PictureHeight);
break;
case "labelModifiedObject":
_armoredTransport = new DrawningTank((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxGun.Checked, checkBoxMachineGun.Checked, PictureWidth, PictureHeight);
break;
}
DrawArmoredTransport();
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Добавление машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddArmoredTransport?.Invoke(_armoredTransport);
Close();
}
private void colorLabel_DragDrop(object sender, DragEventArgs e)
{
if (_armoredTransport == null)
return;
_armoredTransport.ChangeColor((Color)e.Data.GetData(typeof(Color)));
DrawArmoredTransport();
}
private void colorLabel_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void addColorLabel_DragDrop(object sender, DragEventArgs e)
{
if ((_armoredTransport == null) || (_armoredTransport is DrawningTank == false))
return;
((DrawningTank)_armoredTransport).ChangeAddColor((Color)e.Data.GetData(typeof(Color)));
DrawArmoredTransport();
}
private void addColorLabel_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<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:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,151 +0,0 @@
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
{
/// <summary>
/// Параметризованный класс для набора объектов DrawningArmoredTransport
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class ArmoredTransportsGenericCollection<T, U>
where T : DrawningArmoredTransport
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 200;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public ArmoredTransportsGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Получение объектов коллекции
/// </summary>
public IEnumerable<T?> GetArmoredTransports => _collection.GetArmoredTransports();
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(ArmoredTransportsGenericCollection<T, U> collect, T? obj)
{
if (obj == null || collect == null)
{
return false;
}
return collect?._collection.Insert(obj)??false;
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(ArmoredTransportsGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowArmoredTransports()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
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.DrawString("P", new Font("Courier New", 30.0F), new SolidBrush(Color.Blue),
new Point(i * _placeSizeWidth, (j-1) * _placeSizeHeight));
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
_pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int width = (_pictureWidth / _placeSizeWidth);
int height = _pictureHeight / _placeSizeHeight;
int i = 0;
foreach (var armoredTransport in _collection.GetArmoredTransports())
{
if (armoredTransport != null)
{
int row = height - 1 - (i / width);
int col = width - 1 - (i % width);
armoredTransport.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
armoredTransport.DrawTransport(g);
}
i++;
}
}
}
}

View File

@ -1,174 +0,0 @@
using System;
using System.Text;
using ProjectTank.DrawningObjects;
using ProjectTank.Drawnings;
using ProjectTank.MovementStrategy;
namespace ProjectTank.Generics
{
/// <summary>
/// Класс для хранения коллекции
/// </summary>
internal class ArmoredTransportsGenericStorage
{
/// <summary>
/// Словарь (хранилище)
/// </summary>
readonly Dictionary<string, ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>> _armoredTransportStorages;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<string> Keys => _armoredTransportStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Разделитель для записи ключа и значения элемента словаря
/// </summary>
private static readonly char _separatorForKeyValue = '|';
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly char _separatorRecords = ';';
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public ArmoredTransportsGenericStorage(int pictureWidth, int pictureHeight)
{
_armoredTransportStorages = new Dictionary<string, ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление набора
/// </summary>
/// <param name="name">Название набора</param>
public void AddSet(string name)
{
_armoredTransportStorages.Add(name, new ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>(_pictureWidth, _pictureHeight));
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="name">Название набора</param>
public void DelSet(string name)
{
if (!_armoredTransportStorages.ContainsKey(name))
{
return;
}
_armoredTransportStorages.Remove(name);
}
/// <summary>
/// Доступ к набору
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>? this[string ind]
{
get
{
if (_armoredTransportStorages.ContainsKey(ind))
{
return _armoredTransportStorages[ind];
}
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,ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>> record in _armoredTransportStorages)
{ //создается тип пара ключ значение, который представляет строку и на каждой итерации берется элемент record коллекции _armoredTransportStorages
StringBuilder records = new();
foreach (DrawningArmoredTransport? elem in record.Value.GetArmoredTransports) // проход по списку коллекции с получением значения объекта
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); //добавление в стрингбилдер свойств объекта с разделителем : и в конце ;
}
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); // добавление значения словаря ключа в начало и разделение разделитем
}
if (data.Length == 0)
{
return false;
}
string toWrite = $"ArmoredTransportsStorage{Environment.NewLine}{data}";
var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); // разделение по символам новой строки
using (StreamWriter sw = new(filename))
{
foreach (var str in strs)
{
sw.WriteLine(str);
}
}
return true;
}
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader sr = new(filename))
{
string str = sr.ReadLine();
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].StartsWith("ArmoredTransportsStorage"))
{
//если нет такой записи, то это не те данные
return false;
}
_armoredTransportStorages.Clear();
do
{
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
str = sr.ReadLine();
continue;
}
ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>
collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawningArmoredTransport? armoredTransport = elem?.CreateDrawningArmoredTransport(_separatorForObject, _pictureWidth, _pictureHeight);
if (armoredTransport != null)
{
if (!(collection + armoredTransport))
{
return false;
}
}
}
_armoredTransportStorages.Add(record[0], collection);
str = sr.ReadLine();
} while (str != null);
}
return true;
}
}
}

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank
{
public enum DirectionType
{
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}
}

View File

@ -1,236 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectTank.Entities;
using ProjectTank.MovementStrategy;
namespace ProjectTank.DrawningObjects
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningArmoredTransport
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityArmoredTransport? EntityArmoredTransport { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
private int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки транспорта
/// </summary>
protected int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки транспорта
/// </summary>
protected int _startPosY;
/// <summary>
/// Ширина прорисовки транспорта
/// </summary>
protected readonly int _transportWidth = 200;
/// <summary>
/// Высота прорисовки транспорта
/// </summary>
protected readonly int _transportHeight = 80;
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _transportWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _transportHeight;
/// <summary>
/// Получение объекта IMoveableObject из объекта DrawningArmoredTransport
/// </summary>
public IMoveableObject GetMoveableObject => new DrawningObjectArmoredTransport(this);
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningArmoredTransport(int speed, double weight, Color bodyColor, int
width, int height)
{
if ((height > _transportHeight) && (width > _transportWidth))
{
EntityArmoredTransport = new EntityArmoredTransport(speed, weight, bodyColor);
}
_pictureWidth = width;
_pictureHeight = height;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <param name="transportWidth">Ширина прорисовки транспорта</param>
/// <param name="transportHeight">Высота прорисовки транспорта</param>
protected DrawningArmoredTransport(int speed, double weight, Color bodyColor, int
width, int height, int transportWidth, int transportHeight)
{
if ((height > transportHeight) && (width > transportWidth))
{
EntityArmoredTransport = new EntityArmoredTransport(speed, weight, bodyColor);
}
_pictureWidth = width;
_pictureHeight = height;
_transportWidth = transportWidth;
_transportHeight = transportHeight;
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if ((x < 0 || y < 0) || (x + _transportWidth > _pictureWidth || y + _transportHeight > _pictureHeight))
{
_startPosX = 0;
_startPosY = 0;
}
else
{
_startPosX = x;
_startPosY = y;
}
}
public void ChangeColor(Color color)
{
if (EntityArmoredTransport == null)
{
return;
}
EntityArmoredTransport.BodyColor = color;
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (EntityArmoredTransport == null)
{
return;
}
Pen pen = new(Color.Black, 3);
Pen penGray = new(Color.Gray, 4);
Brush grayColorBrush = new SolidBrush(Color.Gray);
Brush blackColorBrush = new SolidBrush(Color.Black);
Brush bodyBrush = new SolidBrush(EntityArmoredTransport.BodyColor);
// Границы транспорта
// гусеницы
g.DrawEllipse(pen, _startPosX + 14, _startPosY + 44, 151, 31);
g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30);
g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10);
g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10);
g.DrawEllipse(penGray, _startPosX + 44, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 124, _startPosY + 59, 10, 10);
g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 61, 10, 10);
g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 61, 10, 10);
g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 62, 10, 10);
// Кузов
g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21);
g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 35, 140, 20);
// Башня
g.FillRectangle(blackColorBrush, _startPosX + 75, _startPosY + 10, 25, 5);
g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21);
g.FillRectangle(bodyBrush, _startPosX + 65, _startPosY + 15, 65, 20);
//Точки для отрисовки передней и задней части
Point pointFirstBackSide = new Point(_startPosX + 18, _startPosY + 35);
Point pointSecondBackSide = new Point(_startPosX + 18, _startPosY + 55);
Point pointThirdBackSide = new Point(_startPosX + 0, _startPosY + 55);
Point pointFirstFrontSide = new Point(_startPosX + 162, _startPosY + 35);
Point pointSecondFrontSide = new Point(_startPosX + 185, _startPosY + 55);
Point pointThirdFrontSide = new Point(_startPosX + 162, _startPosY + 55);
// Задняя часть
Point[] backSide = { pointFirstBackSide, pointSecondBackSide, pointThirdBackSide };
g.DrawPolygon(pen, backSide);
g.FillPolygon(bodyBrush, backSide);
// Передняя часть
Point[] frontSide = { pointFirstFrontSide, pointSecondFrontSide, pointThirdFrontSide };
g.DrawPolygon(pen, frontSide);
g.FillPolygon(bodyBrush, frontSide);
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанномунаправлению</returns>
public bool CanMove(DirectionType direction)
{
if (EntityArmoredTransport == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityArmoredTransport.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityArmoredTransport.Step > 0,
// вправо
DirectionType.Right => _startPosX + _transportWidth + EntityArmoredTransport.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + _transportHeight + EntityArmoredTransport.Step < _pictureHeight,
_ => false,
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityArmoredTransport == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
_startPosX -= (int)EntityArmoredTransport.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityArmoredTransport.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityArmoredTransport.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityArmoredTransport.Step;
break;
}
}
}
}

View File

@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectTank.DrawningObjects;
namespace ProjectTank.MovementStrategy
{
/// <summary>
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningArmoredTransport(паттерн Adapter)
/// </summary>
public class DrawningObjectArmoredTransport : IMoveableObject
{
private readonly DrawningArmoredTransport? _drawningArmoredTransport = null;
public DrawningObjectArmoredTransport(DrawningArmoredTransport drawningArmoredTransport)
{
_drawningArmoredTransport = drawningArmoredTransport;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningArmoredTransport == null || _drawningArmoredTransport.EntityArmoredTransport == null)
{
return null;
}
return new ObjectParameters(_drawningArmoredTransport.GetPosX, _drawningArmoredTransport.GetPosY,
_drawningArmoredTransport.GetWidth, _drawningArmoredTransport.GetHeight);
}
}
public int GetStep => (int)(_drawningArmoredTransport?.EntityArmoredTransport?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>_drawningArmoredTransport?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>_drawningArmoredTransport?.MoveTransport(direction);
}
}

View File

@ -1,73 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectTank.Entities;
namespace ProjectTank.DrawningObjects
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningTank : DrawningArmoredTransport
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="gun">Пушка</param>
/// <param name="machineGun">Пулемет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningTank(int speed, double weight, Color bodyColor, Color
additionalColor, bool gun, bool machineGun, int width, int height) : base(speed,weight, bodyColor, width, height, 200, 80)
{
if (EntityArmoredTransport != null)
{
EntityArmoredTransport = new EntityTank(speed, weight, bodyColor,
additionalColor, gun, machineGun);
}
}
public void ChangeAddColor(Color color)
{
((EntityTank)EntityArmoredTransport).AdditionalColor = color;
}
public override void DrawTransport(Graphics g)
{
if (EntityArmoredTransport is not EntityTank tank)
{
return;
}
Pen pen = new(Color.Black, 3);
Brush blackColorBrush = new SolidBrush(Color.Black);
Brush additionalBrush = new SolidBrush(tank.AdditionalColor);
// пушка
if (tank.Gun)
{
g.DrawRectangle(pen, _startPosX + 129, _startPosY + 19, 56, 6);
g.FillRectangle(additionalBrush, _startPosX + 130, _startPosY + 20, 55, 5);
g.DrawRectangle(pen, _startPosX + 184, _startPosY + 17, 16, 11);
g.FillRectangle(blackColorBrush, _startPosX + 185, _startPosY + 18, 15, 10);
}
// пулемет
if (tank.MachineGun)
{
g.DrawRectangle(pen, _startPosX + 104, _startPosY + 9, 16, 6);
g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 10, 15, 5);
g.DrawRectangle(pen, _startPosX + 111, _startPosY, 4, 6);
g.FillRectangle(additionalBrush, _startPosX + 112, _startPosY + 1, 4, 7);
g.FillRectangle(blackColorBrush, _startPosX + 98, _startPosY, 7, 7);
g.DrawRectangle(pen, _startPosX + 104, _startPosY + 2, 30, 3);
g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 3, 29, 3);
g.FillRectangle(blackColorBrush, _startPosX + 135, _startPosY, 15, 8);
}
base.DrawTransport(g);
}
}
}

View File

@ -1,43 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank.Entities
{
/// <summary>
/// Класс-сущность "Бронирванный транспорт"
/// </summary>
public class EntityArmoredTransport
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Конструктор с параметрами
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityArmoredTransport(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -1,44 +0,0 @@
using ProjectTank.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank.Entities
{
/// <summary>
/// Класс-сущность "Танк"
/// </summary>
public class EntityTank : EntityArmoredTransport
{
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; set; }
/// <summary>
/// Пушка
/// </summary>
public bool Gun { get; private set; }
/// <summary>
/// Пулемет
/// </summary>
public bool MachineGun { get; private set; }
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="gun">Признак наличия пушки</param>
/// <param name="machineGun">Признак наличия пулемета</param>
public EntityTank(int speed, double weight, Color bodyColor, Color additionalColor, bool gun,
bool machineGun) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Gun = gun;
MachineGun = machineGun;
}
}
}

View File

@ -1,64 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectTank.Entities;
using ProjectTank.DrawningObjects;
namespace ProjectTank.Drawnings
{
public static class ExtentionDrawningArmoredTransport
{
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
/// <returns>Объект</returns>
public static DrawningArmoredTransport? CreateDrawningArmoredTransport(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawningArmoredTransport(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 6)
{
return new DrawningTank(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="drawningArmoredTransport">Сохраняемый объект</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawningArmoredTransport drawningArmoredTransport, char separatorForObject)
{
var armoredTransport = drawningArmoredTransport.EntityArmoredTransport;
if (armoredTransport == null)
{
return string.Empty;
}
var str =
$"{armoredTransport.Speed}{separatorForObject}{armoredTransport.Weight}{separatorForObject}{armoredTransport.BodyColor.Name}";
if (armoredTransport is not EntityTank tank)
{
return str;
}
return
$"{str}{separatorForObject}{tank.AdditionalColor.Name}" +
$"{separatorForObject}{tank.Gun}" +
$"{separatorForObject}{tank.MachineGun}";
}
}
}

View File

@ -0,0 +1,39 @@
namespace ProjectTank
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -0,0 +1,10 @@
namespace ProjectTank
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -117,17 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="btnDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\btnDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="btnLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\btnLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="btnRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\btnRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="btnUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\btnUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectTank.DrawningObjects;
namespace ProjectTank.MovementStrategy
{
/// <summary>
/// Интерфейс для работы с перемещаемым объектом
/// </summary>
public interface IMoveableObject
{
/// <summary>
/// Получение координаты X объекта
/// </summary>
ObjectParameters? GetObjectPosition { get; }
/// <summary>
/// Шаг объекта
/// </summary>
int GetStep { get; }
/// <summary>
/// Проверка, можно ли переместиться по нужному направлению
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
bool CheckCanMove(DirectionType direction);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
void MoveObject(DirectionType direction);
}
}

View File

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank.MovementStrategy
{
/// <summary>
/// Стратегия перемещения объекта в центр экрана
/// </summary>
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
}
}
}
}

View File

@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank.MovementStrategy
{
/// <summary>
/// Стратегия перемещения объекта в центр экранa
/// </summary>
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank.MovementStrategy
{
/// <summary>
/// Параметры-координаты объекта
/// </summary>
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
/// <summary>
/// Левая граница
/// </summary>
public int LeftBorder => _x;
/// <summary>
/// Верхняя граница
/// </summary>
public int TopBorder => _y;
/// <summary>
/// Правая граница
/// </summary>
public int RightBorder => _x + _width;
/// <summary>
/// Нижняя граница
/// </summary>
public int DownBorder => _y + _height;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleHorizontal => _x + _width / 2;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleVertical => _y + _height / 2;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -1,5 +1,3 @@
using System.Drawing;
namespace ProjectTank
{
internal static class Program
@ -13,7 +11,7 @@ namespace ProjectTank
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new ArmoredTransportCollectionForm());
Application.Run(new Form1());
}
}
}

View File

@ -8,19 +8,4 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -1,103 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectTank.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectTank.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap btnDown {
get {
object obj = ResourceManager.GetObject("btnDown", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap btnLeft {
get {
object obj = ResourceManager.GetObject("btnLeft", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap btnRight {
get {
object obj = ResourceManager.GetObject("btnRight", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap btnUp {
get {
object obj = ResourceManager.GetObject("btnUp", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 B

View File

@ -1,112 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank.Generics
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetGeneric<T>
where T : class
{
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Count;
/// <summary>
/// Максимальное количество объектов в списке
/// </summary>
private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(count);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="armoredTransport">Добавляемый броне-транспорт</param>
/// <returns></returns>
public bool Insert(T armoredTransport)
{
if (_places.Count == _maxCount)
return false;
Insert(armoredTransport, 0);
return true;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="car">Добавляемый броне-транспорт</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T armoredTransport, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
return false;
_places.Insert(position, armoredTransport);
return true;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (!(position >= 0 && position < Count))
return false;
_places.RemoveAt(position);
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? this[int position]
{
get
{
if (!(position >= 0 && position < Count))
return null;
return _places[position];
}
set
{
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
return;
_places.Insert(position, value);
return;
}
}
/// <summary>
/// Проход по списку
/// </summary>
/// <returns></returns>
public IEnumerable<T?> GetArmoredTransports(int? maxArmoredTransport = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxArmoredTransport.HasValue && i == maxArmoredTransport.Value)
{
yield break;
}
}
}
}
}

View File

@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTank.MovementStrategy
{
/// <summary>
/// Статус выполнения операции перемещения
/// </summary>
public enum Status
{
NotInit,
InProgress,
Finish
}
}

View File

@ -1,216 +0,0 @@
namespace ProjectTank
{
partial class TankForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxTanks = new System.Windows.Forms.PictureBox();
this.ButtonCreateTank = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.ButtonCreateArmoredTransport = new System.Windows.Forms.Button();
this.ButtonStep = new System.Windows.Forms.Button();
this.ButtonSelectArmoredTransport = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit();
this.SuspendLayout();
//
// pictureBoxTanks
//
this.pictureBoxTanks.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxTanks.Location = new System.Drawing.Point(0, 0);
this.pictureBoxTanks.Margin = new System.Windows.Forms.Padding(6);
this.pictureBoxTanks.Name = "pictureBoxTanks";
this.pictureBoxTanks.Size = new System.Drawing.Size(1445, 881);
this.pictureBoxTanks.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxTanks.TabIndex = 0;
this.pictureBoxTanks.TabStop = false;
//
// ButtonCreateTank
//
this.ButtonCreateTank.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ButtonCreateTank.Location = new System.Drawing.Point(22, 806);
this.ButtonCreateTank.Margin = new System.Windows.Forms.Padding(6);
this.ButtonCreateTank.Name = "ButtonCreateTank";
this.ButtonCreateTank.Size = new System.Drawing.Size(192, 49);
this.ButtonCreateTank.TabIndex = 1;
this.ButtonCreateTank.Text = "Создать Танк";
this.ButtonCreateTank.UseVisualStyleBackColor = true;
this.ButtonCreateTank.Click += new System.EventHandler(this.ButtonCreateTank_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectTank.Properties.Resources.btnUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(1300, 730);
this.buttonUp.Margin = new System.Windows.Forms.Padding(6);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(56, 64);
this.buttonUp.TabIndex = 2;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectTank.Properties.Resources.btnRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(1367, 806);
this.buttonRight.Margin = new System.Windows.Forms.Padding(6);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(56, 64);
this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectTank.Properties.Resources.btnLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(1233, 806);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(6);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(56, 64);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectTank.Properties.Resources.btnDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(1300, 806);
this.buttonDown.Margin = new System.Windows.Forms.Padding(6);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(56, 64);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(1172, 0);
this.label1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(0, 32);
this.label1.TabIndex = 6;
//
// comboBoxStrategy
//
this.comboBoxStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"0",
"1"});
this.comboBoxStrategy.Location = new System.Drawing.Point(1181, 12);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(242, 40);
this.comboBoxStrategy.TabIndex = 7;
//
// ButtonCreateArmoredTransport
//
this.ButtonCreateArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ButtonCreateArmoredTransport.Location = new System.Drawing.Point(241, 806);
this.ButtonCreateArmoredTransport.Margin = new System.Windows.Forms.Padding(6);
this.ButtonCreateArmoredTransport.Name = "ButtonCreateArmoredTransport";
this.ButtonCreateArmoredTransport.Size = new System.Drawing.Size(401, 49);
this.ButtonCreateArmoredTransport.TabIndex = 8;
this.ButtonCreateArmoredTransport.Text = "Создать Бронированную машину";
this.ButtonCreateArmoredTransport.UseVisualStyleBackColor = true;
this.ButtonCreateArmoredTransport.Click += new System.EventHandler(this.ButtonCreateArmoredTransport_Click);
//
// ButtonStep
//
this.ButtonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonStep.Location = new System.Drawing.Point(1263, 61);
this.ButtonStep.Margin = new System.Windows.Forms.Padding(6);
this.ButtonStep.Name = "ButtonStep";
this.ButtonStep.Size = new System.Drawing.Size(160, 49);
this.ButtonStep.TabIndex = 9;
this.ButtonStep.Text = "Шаг";
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// ButtonSelectArmoredTransport
//
this.ButtonSelectArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ButtonSelectArmoredTransport.Location = new System.Drawing.Point(664, 806);
this.ButtonSelectArmoredTransport.Margin = new System.Windows.Forms.Padding(6);
this.ButtonSelectArmoredTransport.Name = "ButtonSelectArmoredTransport";
this.ButtonSelectArmoredTransport.Size = new System.Drawing.Size(227, 49);
this.ButtonSelectArmoredTransport.TabIndex = 10;
this.ButtonSelectArmoredTransport.Text = "Выбор";
this.ButtonSelectArmoredTransport.UseVisualStyleBackColor = true;
this.ButtonSelectArmoredTransport.Click += new System.EventHandler(this.ButtonSelectArmoredTransport_Click);
//
// TankForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1445, 881);
this.Controls.Add(this.ButtonSelectArmoredTransport);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.ButtonCreateArmoredTransport);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.ButtonCreateTank);
this.Controls.Add(this.pictureBoxTanks);
this.Margin = new System.Windows.Forms.Padding(6);
this.Name = "TankForm";
this.Text = "Tank";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button ButtonCreateTank;
private Button buttonUp;
private Button buttonRight;
private Button buttonLeft;
private Button buttonDown;
public PictureBox pictureBoxTanks;
private Label label1;
private ComboBox comboBoxStrategy;
private Button ButtonCreateArmoredTransport;
private Button ButtonStep;
private Button ButtonSelectArmoredTransport;
}
}

View File

@ -1,174 +0,0 @@
using System.Reflection.Emit;
using ProjectTank.DrawningObjects;
using ProjectTank.MovementStrategy;
namespace ProjectTank
{
/// <summary>
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Òàíê"
/// </summary>
public partial class TankForm : Form
{
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawningArmoredTransport? _drawningArmoredTransport;
/// <summary>
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
/// </summary>
private AbstractStrategy? _abstractStrategy;
/// <summary>
/// Âûáðàííûé àâòîìîáèëü
/// </summary>
public DrawningArmoredTransport? SelectedArmoredTransport { get; private set; }
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
public TankForm()
{
InitializeComponent();
_abstractStrategy = null;
SelectedArmoredTransport = null;
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû
/// </summary>
private void Draw()
{
if (_drawningArmoredTransport == null)
{
return;
}
Bitmap bmp = new(pictureBoxTanks.Width, pictureBoxTanks.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningArmoredTransport.DrawTransport(gr);
pictureBoxTanks.Image = bmp;
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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));
ColorDialog dialogMain = new();
if (dialogMain.ShowDialog() == DialogResult.OK)
{
color = dialogMain.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_drawningArmoredTransport = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000),
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();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü àâòîìîáèëü"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateArmoredTransport_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 âûáîð îñíîâíîãî öâåòà
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_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();
}
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningArmoredTransport == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningArmoredTransport.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningArmoredTransport.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningArmoredTransport.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningArmoredTransport.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningArmoredTransport == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(_drawningArmoredTransport.GetMoveableObject,
pictureBoxTanks.Width, pictureBoxTanks.Height);
}
if (_abstractStrategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
/// <summary>
/// Âûáîð àâòîìîáèëÿ
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectArmoredTransport_Click(object sender, EventArgs e)
{
SelectedArmoredTransport = _drawningArmoredTransport;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<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:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 B