Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37aee9ad6a | |||
| b46a5f46b0 | |||
| ca9860ba86 | |||
| 262ac5cd8c | |||
| c9f8764af0 | |||
| 87c5a98333 | |||
| cd74aa1932 | |||
| 5a616231fd | |||
| 0b208db4dd | |||
| 51a27f8e12 | |||
| bdc1823059 | |||
| 2a452af6b5 | |||
| 89c04361e4 | |||
| 3194d59c46 | |||
| 45c7fb8ab3 | |||
| f652dfcd18 | |||
| 5287002a6f | |||
| 3c728ee2e1 | |||
| 7372ee4bd3 | |||
| 854b4ac296 | |||
| b1a2751514 | |||
| 0ab91a7bf3 | |||
| 988d1da071 |
@@ -18,11 +18,11 @@ namespace ProjectStormtrooper
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата начала прорисовки
|
||||
/// </summary>
|
||||
@@ -235,5 +235,9 @@ namespace ProjectStormtrooper
|
||||
g.FillRectangle(brushBodyColor, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
|
||||
g.DrawRectangle(penBlack, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawingPlane
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,5 +41,9 @@ namespace ProjectStormtrooper
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,5 +28,9 @@ namespace ProjectStormtrooper
|
||||
Rockets = rockets;
|
||||
Bombs = bombs;
|
||||
}
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
public static class ExtensionDrawingPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
public static DrawingPlane? CreateDrawingPlane(this string info, char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingPlane(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawingStormtrooper(
|
||||
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>
|
||||
public static string GetDataForSave(this DrawingPlane drawningPlane, char separatorForObject)
|
||||
{
|
||||
var plane = drawningPlane.EntityPlane;
|
||||
if (plane == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
|
||||
if (plane is not EntityStormtrooper stormtrooper)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForObject}{stormtrooper.AdditionalColor.Name}{separatorForObject}{stormtrooper.Rockets}{separatorForObject}{stormtrooper.Bombs}";
|
||||
}
|
||||
}
|
||||
}
|
||||
250
ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.Designer.cs
generated
Normal file
250
ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,250 @@
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
partial class FormPlaneCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
groupBoxStorages = new GroupBox();
|
||||
buttonRemoveStorage = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
buttonAddStorage = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemovePlane = new Button();
|
||||
buttonAddPlane = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
menuStrip = new MenuStrip();
|
||||
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||
сохранитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
загрузитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
groupBoxTools.SuspendLayout();
|
||||
groupBoxStorages.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(groupBoxStorages);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxTools.Controls.Add(buttonRemovePlane);
|
||||
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(787, 28);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(230, 510);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// groupBoxStorages
|
||||
//
|
||||
groupBoxStorages.Controls.Add(buttonRemoveStorage);
|
||||
groupBoxStorages.Controls.Add(listBoxStorages);
|
||||
groupBoxStorages.Controls.Add(buttonAddStorage);
|
||||
groupBoxStorages.Controls.Add(textBoxStorageName);
|
||||
groupBoxStorages.Location = new Point(6, 26);
|
||||
groupBoxStorages.Name = "groupBoxStorages";
|
||||
groupBoxStorages.Size = new Size(218, 241);
|
||||
groupBoxStorages.TabIndex = 5;
|
||||
groupBoxStorages.TabStop = false;
|
||||
groupBoxStorages.Text = "Наборы";
|
||||
//
|
||||
// buttonRemoveStorage
|
||||
//
|
||||
buttonRemoveStorage.Location = new Point(6, 204);
|
||||
buttonRemoveStorage.Name = "buttonRemoveStorage";
|
||||
buttonRemoveStorage.Size = new Size(206, 29);
|
||||
buttonRemoveStorage.TabIndex = 3;
|
||||
buttonRemoveStorage.Text = "Удалить набор";
|
||||
buttonRemoveStorage.UseVisualStyleBackColor = true;
|
||||
buttonRemoveStorage.Click += buttonDelStorage_Click;
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 20;
|
||||
listBoxStorages.Location = new Point(6, 94);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(206, 104);
|
||||
listBoxStorages.TabIndex = 2;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAddStorage
|
||||
//
|
||||
buttonAddStorage.Location = new Point(6, 59);
|
||||
buttonAddStorage.Name = "buttonAddStorage";
|
||||
buttonAddStorage.Size = new Size(206, 29);
|
||||
buttonAddStorage.TabIndex = 1;
|
||||
buttonAddStorage.Text = "Добавить набор";
|
||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||
buttonAddStorage.Click += buttonAddStorage_Click;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(6, 26);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(206, 27);
|
||||
textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(6, 404);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(218, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
maskedTextBoxNumber.TextAlign = HorizontalAlignment.Center;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(6, 497);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(218, 29);
|
||||
buttonRefreshCollection.TabIndex = 3;
|
||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||
//
|
||||
// buttonRemovePlane
|
||||
//
|
||||
buttonRemovePlane.Location = new Point(6, 437);
|
||||
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||
buttonRemovePlane.Size = new Size(218, 29);
|
||||
buttonRemovePlane.TabIndex = 2;
|
||||
buttonRemovePlane.Text = "Удалить самолет";
|
||||
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||
buttonRemovePlane.Click += buttonRemovePlane_Click;
|
||||
//
|
||||
// buttonAddPlane
|
||||
//
|
||||
buttonAddPlane.Location = new Point(6, 349);
|
||||
buttonAddPlane.Name = "buttonAddPlane";
|
||||
buttonAddPlane.Size = new Size(218, 29);
|
||||
buttonAddPlane.TabIndex = 0;
|
||||
buttonAddPlane.Text = "Добавить самолет";
|
||||
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||
buttonAddPlane.Click += buttonAddPlane_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||
pictureBoxCollection.Location = new Point(0, 28);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(787, 510);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1017, 28);
|
||||
menuStrip.TabIndex = 2;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сохранитьToolStripMenuItem, загрузитьToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(59, 24);
|
||||
файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// сохранитьToolStripMenuItem
|
||||
//
|
||||
сохранитьToolStripMenuItem.Name = "сохранитьToolStripMenuItem";
|
||||
сохранитьToolStripMenuItem.Size = new Size(166, 26);
|
||||
сохранитьToolStripMenuItem.Text = "Сохранить";
|
||||
сохранитьToolStripMenuItem.Click += saveToFileToolStripMenuItem_Click;
|
||||
//
|
||||
// загрузитьToolStripMenuItem
|
||||
//
|
||||
загрузитьToolStripMenuItem.Name = "загрузитьToolStripMenuItem";
|
||||
загрузитьToolStripMenuItem.Size = new Size(166, 26);
|
||||
загрузитьToolStripMenuItem.Text = "Загрузить";
|
||||
загрузитьToolStripMenuItem.Click += loadFromFileToolStripMenuItem_Click;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog1";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormPlaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1017, 538);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Name = "FormPlaneCollection";
|
||||
Text = "Набор самолетов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
groupBoxStorages.ResumeLayout(false);
|
||||
groupBoxStorages.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private Button buttonRefreshCollection;
|
||||
private Button buttonRemovePlane;
|
||||
private Button buttonAddPlane;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private GroupBox groupBoxStorages;
|
||||
private Button buttonRemoveStorage;
|
||||
private ListBox listBoxStorages;
|
||||
private Button buttonAddStorage;
|
||||
private TextBox textBoxStorageName;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem сохранитьToolStripMenuItem;
|
||||
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
||||
211
ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs
Normal file
211
ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
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;
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма для работы с набором объектов класса DrawningPlane
|
||||
/// </summary>
|
||||
public partial class FormPlaneCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly PlanesGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormPlaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new PlanesGenericStorage(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 buttonAddStorage_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 listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonDelStorage_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();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAddPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formPlaneConfig = new FormPlaneConfig();
|
||||
formPlaneConfig.AddEvent(AddPlaneListener);
|
||||
formPlaneConfig.Show();
|
||||
}
|
||||
public void AddPlaneListener(DrawingPlane plane)
|
||||
{
|
||||
plane._pictureWidth = pictureBoxCollection.Width;
|
||||
plane._pictureHeight = pictureBoxCollection.Height;
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (obj + plane > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonRemovePlane_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.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
RefreshCollection();
|
||||
}
|
||||
private void RefreshCollection()
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
|
||||
private void saveToFileToolStripMenuItem_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromFileToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
ReloadObjects();
|
||||
RefreshCollection();
|
||||
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
129
ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.resx
Normal file
129
ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.resx
Normal file
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd: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="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>152, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>319, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
358
ProjectStormtrooper/ProjectStormtrooper/FormPlaneConfig.Designer.cs
generated
Normal file
358
ProjectStormtrooper/ProjectStormtrooper/FormPlaneConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,358 @@
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
partial class FormPlaneConfig
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxParams = new GroupBox();
|
||||
groupBoxColors = new GroupBox();
|
||||
panelColorPink = new Panel();
|
||||
panelColorPurple = new Panel();
|
||||
panelColorBlue = new Panel();
|
||||
panelColorBrown = new Panel();
|
||||
panelColorGreen = new Panel();
|
||||
panelColorLightBlue = new Panel();
|
||||
panelColorYellow = new Panel();
|
||||
panelColorRed = new Panel();
|
||||
labelStormtrooper = new Label();
|
||||
labelPlane = new Label();
|
||||
checkBoxRockets = new CheckBox();
|
||||
checkBoxBombs = new CheckBox();
|
||||
numericUpDownWeight = new NumericUpDown();
|
||||
numericUpDownSpeed = new NumericUpDown();
|
||||
labelWeight = new Label();
|
||||
labelSpeed = new Label();
|
||||
buttonCancel = new Button();
|
||||
buttonApply = new Button();
|
||||
pictureBoxObject = new PictureBox();
|
||||
labelAddColor = new Label();
|
||||
labelColor = new Label();
|
||||
panelControl = new Panel();
|
||||
groupBoxParams.SuspendLayout();
|
||||
groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||
panelControl.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxParams
|
||||
//
|
||||
groupBoxParams.Controls.Add(groupBoxColors);
|
||||
groupBoxParams.Controls.Add(labelStormtrooper);
|
||||
groupBoxParams.Controls.Add(labelPlane);
|
||||
groupBoxParams.Controls.Add(checkBoxRockets);
|
||||
groupBoxParams.Controls.Add(checkBoxBombs);
|
||||
groupBoxParams.Controls.Add(numericUpDownWeight);
|
||||
groupBoxParams.Controls.Add(numericUpDownSpeed);
|
||||
groupBoxParams.Controls.Add(labelWeight);
|
||||
groupBoxParams.Controls.Add(labelSpeed);
|
||||
groupBoxParams.Location = new Point(2, 7);
|
||||
groupBoxParams.Name = "groupBoxParams";
|
||||
groupBoxParams.Size = new Size(497, 261);
|
||||
groupBoxParams.TabIndex = 0;
|
||||
groupBoxParams.TabStop = false;
|
||||
groupBoxParams.Text = "Параметры";
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
groupBoxColors.Controls.Add(panelColorPink);
|
||||
groupBoxColors.Controls.Add(panelColorPurple);
|
||||
groupBoxColors.Controls.Add(panelColorBlue);
|
||||
groupBoxColors.Controls.Add(panelColorBrown);
|
||||
groupBoxColors.Controls.Add(panelColorGreen);
|
||||
groupBoxColors.Controls.Add(panelColorLightBlue);
|
||||
groupBoxColors.Controls.Add(panelColorYellow);
|
||||
groupBoxColors.Controls.Add(panelColorRed);
|
||||
groupBoxColors.Location = new Point(176, 26);
|
||||
groupBoxColors.Name = "groupBoxColors";
|
||||
groupBoxColors.Size = new Size(308, 156);
|
||||
groupBoxColors.TabIndex = 8;
|
||||
groupBoxColors.TabStop = false;
|
||||
groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelColorPink
|
||||
//
|
||||
panelColorPink.BackColor = Color.PeachPuff;
|
||||
panelColorPink.Location = new Point(241, 89);
|
||||
panelColorPink.Name = "panelColorPink";
|
||||
panelColorPink.Size = new Size(50, 50);
|
||||
panelColorPink.TabIndex = 1;
|
||||
//
|
||||
// panelColorPurple
|
||||
//
|
||||
panelColorPurple.BackColor = Color.Fuchsia;
|
||||
panelColorPurple.Location = new Point(164, 89);
|
||||
panelColorPurple.Name = "panelColorPurple";
|
||||
panelColorPurple.Size = new Size(50, 50);
|
||||
panelColorPurple.TabIndex = 1;
|
||||
//
|
||||
// panelColorBlue
|
||||
//
|
||||
panelColorBlue.BackColor = Color.Blue;
|
||||
panelColorBlue.Location = new Point(87, 89);
|
||||
panelColorBlue.Name = "panelColorBlue";
|
||||
panelColorBlue.Size = new Size(50, 50);
|
||||
panelColorBlue.TabIndex = 1;
|
||||
//
|
||||
// panelColorBrown
|
||||
//
|
||||
panelColorBrown.BackColor = Color.DarkRed;
|
||||
panelColorBrown.Location = new Point(17, 89);
|
||||
panelColorBrown.Name = "panelColorBrown";
|
||||
panelColorBrown.Size = new Size(50, 50);
|
||||
panelColorBrown.TabIndex = 3;
|
||||
//
|
||||
// panelColorGreen
|
||||
//
|
||||
panelColorGreen.BackColor = Color.Lime;
|
||||
panelColorGreen.Location = new Point(241, 26);
|
||||
panelColorGreen.Name = "panelColorGreen";
|
||||
panelColorGreen.Size = new Size(50, 50);
|
||||
panelColorGreen.TabIndex = 1;
|
||||
//
|
||||
// panelColorLightBlue
|
||||
//
|
||||
panelColorLightBlue.BackColor = Color.Cyan;
|
||||
panelColorLightBlue.Location = new Point(164, 26);
|
||||
panelColorLightBlue.Name = "panelColorLightBlue";
|
||||
panelColorLightBlue.Size = new Size(50, 50);
|
||||
panelColorLightBlue.TabIndex = 2;
|
||||
//
|
||||
// panelColorYellow
|
||||
//
|
||||
panelColorYellow.BackColor = Color.Yellow;
|
||||
panelColorYellow.Location = new Point(87, 26);
|
||||
panelColorYellow.Name = "panelColorYellow";
|
||||
panelColorYellow.Size = new Size(50, 50);
|
||||
panelColorYellow.TabIndex = 1;
|
||||
//
|
||||
// panelColorRed
|
||||
//
|
||||
panelColorRed.BackColor = Color.Red;
|
||||
panelColorRed.Location = new Point(17, 26);
|
||||
panelColorRed.Name = "panelColorRed";
|
||||
panelColorRed.Size = new Size(50, 50);
|
||||
panelColorRed.TabIndex = 0;
|
||||
//
|
||||
// labelStormtrooper
|
||||
//
|
||||
labelStormtrooper.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelStormtrooper.Location = new Point(340, 203);
|
||||
labelStormtrooper.Name = "labelStormtrooper";
|
||||
labelStormtrooper.Padding = new Padding(10);
|
||||
labelStormtrooper.Size = new Size(127, 42);
|
||||
labelStormtrooper.TabIndex = 7;
|
||||
labelStormtrooper.Text = "Продвинутый";
|
||||
labelStormtrooper.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelStormtrooper.MouseDown += labelObject_MouseDown;
|
||||
//
|
||||
// labelPlane
|
||||
//
|
||||
labelPlane.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelPlane.Location = new Point(193, 203);
|
||||
labelPlane.Name = "labelPlane";
|
||||
labelPlane.Padding = new Padding(10);
|
||||
labelPlane.Size = new Size(120, 42);
|
||||
labelPlane.TabIndex = 6;
|
||||
labelPlane.Text = "Простой";
|
||||
labelPlane.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelPlane.MouseDown += labelObject_MouseDown;
|
||||
//
|
||||
// checkBoxRockets
|
||||
//
|
||||
checkBoxRockets.AutoSize = true;
|
||||
checkBoxRockets.Location = new Point(6, 145);
|
||||
checkBoxRockets.Name = "checkBoxRockets";
|
||||
checkBoxRockets.Size = new Size(79, 24);
|
||||
checkBoxRockets.TabIndex = 5;
|
||||
checkBoxRockets.Text = "Ракеты";
|
||||
checkBoxRockets.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxBombs
|
||||
//
|
||||
checkBoxBombs.AutoSize = true;
|
||||
checkBoxBombs.Location = new Point(6, 115);
|
||||
checkBoxBombs.Name = "checkBoxBombs";
|
||||
checkBoxBombs.Size = new Size(80, 24);
|
||||
checkBoxBombs.TabIndex = 4;
|
||||
checkBoxBombs.Text = "Бомбы";
|
||||
checkBoxBombs.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(88, 73);
|
||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(82, 27);
|
||||
numericUpDownWeight.TabIndex = 3;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(88, 29);
|
||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(82, 27);
|
||||
numericUpDownSpeed.TabIndex = 2;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
labelWeight.AutoSize = true;
|
||||
labelWeight.Location = new Point(6, 75);
|
||||
labelWeight.Name = "labelWeight";
|
||||
labelWeight.Size = new Size(36, 20);
|
||||
labelWeight.TabIndex = 1;
|
||||
labelWeight.Text = "Вес:";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
labelSpeed.AutoSize = true;
|
||||
labelSpeed.Location = new Point(6, 31);
|
||||
labelSpeed.Name = "labelSpeed";
|
||||
labelSpeed.Size = new Size(76, 20);
|
||||
labelSpeed.TabIndex = 0;
|
||||
labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(178, 220);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 4;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonApply
|
||||
//
|
||||
buttonApply.Location = new Point(21, 220);
|
||||
buttonApply.Name = "buttonApply";
|
||||
buttonApply.Size = new Size(94, 29);
|
||||
buttonApply.TabIndex = 3;
|
||||
buttonApply.Text = "Добавить";
|
||||
buttonApply.UseVisualStyleBackColor = true;
|
||||
buttonApply.Click += buttonApply_Click;
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(21, 68);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(251, 146);
|
||||
pictureBoxObject.TabIndex = 2;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// labelAddColor
|
||||
//
|
||||
labelAddColor.AllowDrop = true;
|
||||
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAddColor.Location = new Point(172, 16);
|
||||
labelAddColor.Name = "labelAddColor";
|
||||
labelAddColor.Size = new Size(100, 40);
|
||||
labelAddColor.TabIndex = 1;
|
||||
labelAddColor.Text = "Доп. цвет";
|
||||
labelAddColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAddColor.DragDrop += labelAddColor_DragDrop;
|
||||
labelAddColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
labelColor.AllowDrop = true;
|
||||
labelColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelColor.Location = new Point(21, 16);
|
||||
labelColor.Name = "labelColor";
|
||||
labelColor.Size = new Size(100, 40);
|
||||
labelColor.TabIndex = 0;
|
||||
labelColor.Text = "Цвет";
|
||||
labelColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelColor.DragDrop += labelColor_DragDrop;
|
||||
labelColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// panelControl
|
||||
//
|
||||
panelControl.AllowDrop = true;
|
||||
panelControl.Controls.Add(labelColor);
|
||||
panelControl.Controls.Add(buttonCancel);
|
||||
panelControl.Controls.Add(buttonApply);
|
||||
panelControl.Controls.Add(pictureBoxObject);
|
||||
panelControl.Controls.Add(labelAddColor);
|
||||
panelControl.Location = new Point(505, 12);
|
||||
panelControl.Name = "panelControl";
|
||||
panelControl.Size = new Size(298, 256);
|
||||
panelControl.TabIndex = 5;
|
||||
panelControl.DragDrop += panelControlObject_DragDrop;
|
||||
panelControl.DragEnter += panelControlObject_DragEnter;
|
||||
//
|
||||
// FormPlaneConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(809, 275);
|
||||
Controls.Add(panelControl);
|
||||
Controls.Add(groupBoxParams);
|
||||
Name = "FormPlaneConfig";
|
||||
Text = "Создание объекта";
|
||||
groupBoxParams.ResumeLayout(false);
|
||||
groupBoxParams.PerformLayout();
|
||||
groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||
panelControl.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxParams;
|
||||
private GroupBox groupBoxColors;
|
||||
private Label labelStormtrooper;
|
||||
private Label labelPlane;
|
||||
private CheckBox checkBoxRockets;
|
||||
private CheckBox checkBoxBombs;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private Panel panelColorRed;
|
||||
private Panel panelColorPink;
|
||||
private Panel panelColorPurple;
|
||||
private Panel panelColorBlue;
|
||||
private Panel panelColorBrown;
|
||||
private Panel panelColorGreen;
|
||||
private Panel panelColorLightBlue;
|
||||
private Panel panelColorYellow;
|
||||
private Button buttonCancel;
|
||||
private Button buttonApply;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Label labelAddColor;
|
||||
private Label labelColor;
|
||||
private Panel panelControl;
|
||||
}
|
||||
}
|
||||
127
ProjectStormtrooper/ProjectStormtrooper/FormPlaneConfig.cs
Normal file
127
ProjectStormtrooper/ProjectStormtrooper/FormPlaneConfig.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
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;
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
public partial class FormPlaneConfig : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная-выбранный самолет
|
||||
/// </summary>
|
||||
DrawingPlane? _plane = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event Action<DrawingPlane>? EventAddPlane;
|
||||
public FormPlaneConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
panelColorRed.MouseDown += panelColor_MouseDown;
|
||||
panelColorYellow.MouseDown += panelColor_MouseDown;
|
||||
panelColorLightBlue.MouseDown += panelColor_MouseDown;
|
||||
panelColorGreen.MouseDown += panelColor_MouseDown;
|
||||
panelColorBrown.MouseDown += panelColor_MouseDown;
|
||||
panelColorBlue.MouseDown += panelColor_MouseDown;
|
||||
panelColorPurple.MouseDown += panelColor_MouseDown;
|
||||
panelColorPink.MouseDown += panelColor_MouseDown;
|
||||
|
||||
buttonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
public void AddEvent(Action<DrawingPlane> ev)
|
||||
{
|
||||
if (EventAddPlane == null)
|
||||
{
|
||||
EventAddPlane = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddPlane += ev;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовать машину
|
||||
/// </summary>
|
||||
private void DrawPlane()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_plane?.SetPosition((int)((pictureBoxObject.Width - _plane?.GetWidth) / 2), (int)((pictureBoxObject.Height - _plane?.GetHeight) / 2));
|
||||
_plane?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
private void buttonApply_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddPlane?.Invoke(_plane);
|
||||
Close();
|
||||
}
|
||||
private void panelControlObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void panelControlObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelPlane":
|
||||
_plane = new DrawingPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelStormtrooper":
|
||||
_plane = new DrawingStormtrooper((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRockets.Checked, checkBoxBombs.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawPlane();
|
||||
}
|
||||
private void labelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void labelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_plane == null)
|
||||
return;
|
||||
_plane.EntityPlane.SetColor((Color)e.Data.GetData(typeof(Color).ToString()));
|
||||
DrawPlane();
|
||||
}
|
||||
private void labelAddColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_plane == null || _plane is not DrawingStormtrooper)
|
||||
return;
|
||||
(_plane.EntityPlane as EntityStormtrooper).SetAdditionalColor((Color)e.Data.GetData(typeof(Color).ToString()));
|
||||
DrawPlane();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
ProjectStormtrooper/ProjectStormtrooper/FormPlaneConfig.resx
Normal file
120
ProjectStormtrooper/ProjectStormtrooper/FormPlaneConfig.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd: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>
|
||||
@@ -37,6 +37,7 @@
|
||||
buttonCreatePlane = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonSelectPlane = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -45,7 +46,7 @@
|
||||
pictureBoxStormtrooper.Dock = DockStyle.Fill;
|
||||
pictureBoxStormtrooper.Location = new Point(0, 0);
|
||||
pictureBoxStormtrooper.Name = "pictureBoxStormtrooper";
|
||||
pictureBoxStormtrooper.Size = new Size(882, 453);
|
||||
pictureBoxStormtrooper.Size = new Size(948, 546);
|
||||
pictureBoxStormtrooper.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxStormtrooper.TabIndex = 0;
|
||||
pictureBoxStormtrooper.TabStop = false;
|
||||
@@ -53,7 +54,7 @@
|
||||
// buttonCreateStormtrooper
|
||||
//
|
||||
buttonCreateStormtrooper.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateStormtrooper.Location = new Point(12, 412);
|
||||
buttonCreateStormtrooper.Location = new Point(12, 505);
|
||||
buttonCreateStormtrooper.Name = "buttonCreateStormtrooper";
|
||||
buttonCreateStormtrooper.Size = new Size(201, 29);
|
||||
buttonCreateStormtrooper.TabIndex = 1;
|
||||
@@ -66,7 +67,7 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUP;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(804, 375);
|
||||
buttonUp.Location = new Point(870, 468);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 2;
|
||||
@@ -78,7 +79,7 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrowDOWN;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(804, 411);
|
||||
buttonDown.Location = new Point(870, 504);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 3;
|
||||
@@ -90,7 +91,7 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLEFT;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(768, 411);
|
||||
buttonLeft.Location = new Point(834, 504);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 4;
|
||||
@@ -102,7 +103,7 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRIGHT;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(840, 411);
|
||||
buttonRight.Location = new Point(906, 504);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 5;
|
||||
@@ -112,7 +113,7 @@
|
||||
// buttonCreatePlane
|
||||
//
|
||||
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreatePlane.Location = new Point(219, 412);
|
||||
buttonCreatePlane.Location = new Point(219, 505);
|
||||
buttonCreatePlane.Name = "buttonCreatePlane";
|
||||
buttonCreatePlane.Size = new Size(201, 29);
|
||||
buttonCreatePlane.TabIndex = 6;
|
||||
@@ -122,17 +123,19 @@
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightBottom" });
|
||||
comboBoxStrategy.Location = new Point(719, 12);
|
||||
comboBoxStrategy.Location = new Point(785, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(776, 46);
|
||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStep.Location = new Point(842, 46);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(94, 29);
|
||||
buttonStep.TabIndex = 8;
|
||||
@@ -140,11 +143,22 @@
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// buttonSelectPlane
|
||||
//
|
||||
buttonSelectPlane.Location = new Point(426, 505);
|
||||
buttonSelectPlane.Name = "buttonSelectPlane";
|
||||
buttonSelectPlane.Size = new Size(137, 29);
|
||||
buttonSelectPlane.TabIndex = 9;
|
||||
buttonSelectPlane.Text = "Выбрать";
|
||||
buttonSelectPlane.UseVisualStyleBackColor = true;
|
||||
buttonSelectPlane.Click += ButtonSelectPlane_Click;
|
||||
//
|
||||
// FormStormtrooper
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
ClientSize = new Size(948, 546);
|
||||
Controls.Add(buttonSelectPlane);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreatePlane);
|
||||
@@ -173,5 +187,6 @@
|
||||
private Button buttonCreatePlane;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonSelectPlane;
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,22 @@ namespace ProjectStormtrooper
|
||||
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
private DrawingPlane? _drawingPlane;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public DrawingPlane? SelectedPlane { get; private set; }
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public FormStormtrooper()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
SelectedPlane = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -39,11 +48,23 @@ namespace ProjectStormtrooper
|
||||
private void buttonCreateStormtrooper_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 dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog.Color;
|
||||
}
|
||||
_drawingPlane = new DrawingStormtrooper(
|
||||
random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
color,
|
||||
dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxStormtrooper.Width,
|
||||
@@ -60,10 +81,16 @@ namespace ProjectStormtrooper
|
||||
private void buttonCreatePlane_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 dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingPlane = new DrawingPlane(
|
||||
random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
color,
|
||||
pictureBoxStormtrooper.Width,
|
||||
pictureBoxStormtrooper.Height
|
||||
);
|
||||
@@ -112,30 +139,40 @@ namespace ProjectStormtrooper
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToRightBottom(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSelectPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedPlane = _drawingPlane;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный класс для набора объектов DrawningPlane
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class PlanesGenericCollection<T, U>
|
||||
where T : DrawingPlane
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 160;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int horizontalObjectsCount = picWidth / _placeSizeWidth;
|
||||
int verticalObjectsCount = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(horizontalObjectsCount * verticalObjectsCount);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(PlanesGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static T? operator -(PlanesGenericCollection<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 ShowPlanes()
|
||||
{
|
||||
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.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int placesColumnCount = _pictureHeight / _placeSizeHeight;
|
||||
int placesRowCount = _pictureWidth / _placeSizeWidth;
|
||||
int i = 0;
|
||||
foreach (var plane in _collection.GetPlanes())
|
||||
{
|
||||
if (plane != null)
|
||||
{
|
||||
// установка позиции
|
||||
plane.SetPosition(
|
||||
(int)((placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - plane.GetWidth) / 2),
|
||||
(int)(i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - plane.GetHeight) / 2)
|
||||
);
|
||||
// прорисовка объекта
|
||||
plane.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
|
||||
}
|
||||
}
|
||||
156
ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs
Normal file
156
ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
internal class PlanesGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _planeStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_planeStorages.Add(name, new PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_planeStorages.ContainsKey(name))
|
||||
_planeStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_planeStorages.ContainsKey(ind))
|
||||
return _planeStorages[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);
|
||||
}
|
||||
using (StreamWriter sw = File.CreateText(filename))
|
||||
{
|
||||
sw.WriteLine($"PlaneStorage");
|
||||
string storageString;
|
||||
foreach (var storage in _planeStorages)
|
||||
{
|
||||
storageString = "";
|
||||
foreach (var plane in storage.Value.GetPlanes)
|
||||
{
|
||||
storageString += $"{plane?.GetDataForSave(_separatorForObject)}{_separatorRecords}";
|
||||
}
|
||||
sw.WriteLine($"{storage.Key}{_separatorForKeyValue}{storageString}");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по автомобилям в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new StreamReader(filename))
|
||||
{
|
||||
string? currentLine = sr.ReadLine();
|
||||
if (currentLine == null || !currentLine.Contains("PlaneStorage"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_planeStorages.Clear();
|
||||
currentLine = sr.ReadLine();
|
||||
while (currentLine != null)
|
||||
{
|
||||
string[] record = currentLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawingPlane? plane = elem?.CreateDrawingPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (plane != null)
|
||||
{
|
||||
if (collection + plane == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_planeStorages.Add(record[0], collection);
|
||||
currentLine = sr.ReadLine();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace ProjectStormtrooper
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormStormtrooper());
|
||||
Application.Run(new FormPlaneCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
122
ProjectStormtrooper/ProjectStormtrooper/SetGeneric.cs
Normal file
122
ProjectStormtrooper/ProjectStormtrooper/SetGeneric.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
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="plane"></param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane)
|
||||
{
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="plane"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// Вставка по позиции
|
||||
_places.Insert(position, plane);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
T? plane = _places[position];
|
||||
_places[position] = null;
|
||||
return plane;
|
||||
}
|
||||
/// <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 >= _maxCount || Count == _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Вставка в список по позиции
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxPlanes.HasValue && i == maxPlanes.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user