This commit is contained in:
Мельников Игорь 2022-10-13 14:45:43 +04:00
parent 9e6f53cfcc
commit 55e54327c6
13 changed files with 633 additions and 28 deletions

View File

@ -186,7 +186,6 @@
int x = _random.Next(10, 100); int x = _random.Next(10, 100);
int y = _random.Next(10, 100); int y = _random.Next(10, 100);
_drawningObject.SetObject(x, y, _width, _height); _drawningObject.SetObject(x, y, _width, _height);
// TODO првоерка, что объект не "накладывается" на закрытые участки
if (!AbleToSetObject()) if (!AbleToSetObject())
{ {
return false; return false;

View File

@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Перечисление направлений перемещения /// Перечисление направлений перемещения
/// </summary> /// </summary>
internal enum Direction public enum Direction
{ {
/// <summary> /// <summary>
/// никуда /// никуда

View File

@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Класс, отвечающий за отрисовку объекта-сущности /// Класс, отвечающий за отрисовку объекта-сущности
/// </summary> /// </summary>
internal class DrawningLocomotive public class DrawningLocomotive
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность

View File

@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Класс-сущность локомотив /// Класс-сущность локомотив
/// </summary> /// </summary>
internal class EntityLocomotive public class EntityLocomotive
{ {
/// <summary> /// <summary>
/// Скорость /// Скорость

View File

@ -33,11 +33,16 @@
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button(); this.buttonCreate = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectLocomotive = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -59,7 +64,10 @@
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed, this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight, this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor}); this.toolStripStatusLabelBodyColor,
this.toolStripStatusLabelAdditionalColor,
this.toolStripStatusLabelHasPipe,
this.toolStripStatusLabelHasFuelTank});
this.statusStrip.Location = new System.Drawing.Point(0, 428); this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip"; this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22); this.statusStrip.Size = new System.Drawing.Size(800, 22);
@ -84,6 +92,24 @@
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет: "; this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
// //
// toolStripStatusLabelAdditionalColor
//
this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor";
this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17);
this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: ";
//
// toolStripStatusLabelHasPipe
//
this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe";
this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17);
this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: ";
//
// toolStripStatusLabelHasFuelTank
//
this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank";
this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17);
this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: ";
//
// buttonCreate // buttonCreate
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
@ -143,11 +169,35 @@
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.Location = new System.Drawing.Point(108, 395);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(109, 30);
this.buttonCreateModif.TabIndex = 8;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// buttonSelectLocomotive
//
this.buttonSelectLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSelectLocomotive.Location = new System.Drawing.Point(602, 395);
this.buttonSelectLocomotive.Name = "buttonSelectLocomotive";
this.buttonSelectLocomotive.Size = new System.Drawing.Size(78, 30);
this.buttonSelectLocomotive.TabIndex = 9;
this.buttonSelectLocomotive.Text = "Выбрать";
this.buttonSelectLocomotive.UseVisualStyleBackColor = true;
this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
//
// FormLocomotive // FormLocomotive
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSelectLocomotive);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
@ -177,5 +227,10 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonDown; private Button buttonDown;
private Button buttonUp; private Button buttonUp;
private ToolStripStatusLabel toolStripStatusLabelAdditionalColor;
private ToolStripStatusLabel toolStripStatusLabelHasPipe;
private ToolStripStatusLabel toolStripStatusLabelHasFuelTank;
private Button buttonCreateModif;
private Button buttonSelectLocomotive;
} }
} }

View File

@ -6,6 +6,10 @@
/// Объект от класса отрисовки локомотива /// Объект от класса отрисовки локомотива
/// </summary> /// </summary>
private DrawningLocomotive _locomotive; private DrawningLocomotive _locomotive;
/// <summary>
/// Выбранный объект
/// </summary>
public DrawningLocomotive SelectedLocomotive { get; private set; }
public FormLocomotive() public FormLocomotive()
{ {
@ -22,6 +26,34 @@
pictureBoxLocomotive.Image = bmp; pictureBoxLocomotive.Image = bmp;
} }
/// <summary> /// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="locomotive">Объект от класса отрисовки или его наследника</param>
private void SetData(DrawningLocomotive locomotive)
{
Random rnd = new();
toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д";
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д";
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д";
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
}
/// <summary>
/// Заполнение дополнительной информации по объекту (только для усложнённого объекта)
/// </summary>
/// <param name="warmlylocomotive">Объект от наследника класса отрисовки</param>
private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive)
{
if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
{
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}";
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}";
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}";
}
}
/// <summary>
/// Метод обработки нажатия на кнопку "Создать" /// Метод обработки нажатия на кнопку "Создать"
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
@ -29,11 +61,14 @@
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); ColorDialog dialog = new();
toolStripStatusLabelSpeed.Text = $"Скорость: {_locomotive.Locomotive.Speed}"; if (dialog.ShowDialog() == DialogResult.OK)
toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}"; {
toolStripStatusLabelBodyColor.Text = $"Цвет: {_locomotive.Locomotive.BodyColor.Name}"; color = dialog.Color;
}
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData(_locomotive);
Draw(); Draw();
} }
/// <summary> /// <summary>
@ -72,5 +107,41 @@
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); _locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
Draw(); Draw();
} }
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color additionalColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
additionalColor = dialogDop.Color;
}
_locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
color,
160, 85,
additionalColor,
Convert.ToBoolean(rnd.Next(0, 2)),
Convert.ToBoolean(rnd.Next(0, 2)));
SetData(_locomotive);
SetAdditionalData((DrawningWarmlyLocomotive)_locomotive);
Draw();
}
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
{
SelectedLocomotive = _locomotive;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -0,0 +1,217 @@
namespace Locomotives
{
partial class FormMapWithSetLocomotives
{
/// <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.groupBoxTools = new System.Windows.Forms.GroupBox();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveLocomotive = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddCar = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBoxLocomotives = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).BeginInit();
this.SuspendLayout();
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddCar);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(577, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(223, 450);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Locomotives.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(107, 378);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 10;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.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::Locomotives.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(107, 414);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.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::Locomotives.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(71, 414);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.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::Locomotives.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(143, 414);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 7;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(31, 314);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(164, 26);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(31, 217);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(164, 26);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveLocomotive
//
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(31, 156);
this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
this.buttonRemoveLocomotive.Size = new System.Drawing.Size(164, 26);
this.buttonRemoveLocomotive.TabIndex = 3;
this.buttonRemoveLocomotive.Text = "Удалить локомотив";
this.buttonRemoveLocomotive.UseVisualStyleBackColor = true;
this.buttonRemoveLocomotive.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(31, 127);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(164, 23);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddCar
//
this.buttonAddCar.Location = new System.Drawing.Point(31, 72);
this.buttonAddCar.Name = "buttonAddCar";
this.buttonAddCar.Size = new System.Drawing.Size(164, 26);
this.buttonAddCar.TabIndex = 1;
this.buttonAddCar.Text = "Добавить локомотив";
this.buttonAddCar.UseVisualStyleBackColor = true;
this.buttonAddCar.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Карта с крестом",
"Карта с дорожками"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(31, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(164, 23);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBoxLocomotives
//
this.pictureBoxLocomotives.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxLocomotives.Location = new System.Drawing.Point(0, 0);
this.pictureBoxLocomotives.Name = "pictureBoxLocomotives";
this.pictureBoxLocomotives.Size = new System.Drawing.Size(577, 450);
this.pictureBoxLocomotives.TabIndex = 1;
this.pictureBoxLocomotives.TabStop = false;
//
// FormMapWithSetLocomotives
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pictureBoxLocomotives);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetLocomotives";
this.Text = "Карта с набором объектов";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotives)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private PictureBox pictureBoxLocomotives;
private ComboBox comboBoxSelectorMap;
private Button buttonAddCar;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRemoveLocomotive;
private Button buttonShowStorage;
private Button buttonShowOnMap;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
}
}

View File

@ -0,0 +1,161 @@
namespace Locomotives
{
/// <summary>
/// Форма для работы с набором объектов
/// </summary>
public partial class FormMapWithSetLocomotives : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> _mapCarsCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetLocomotives()
{
InitializeComponent();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Карта с крестом":
map = new CrossMap();
break;
case "Карта с дорожками":
map = new RoadsMap();
break;
default:
break;
}
if (map != null)
{
_mapCarsCollectionGeneric = new
MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(pictureBoxLocomotives.Width, pictureBoxLocomotives.Height, map);
}
else
{
_mapCarsCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
{
return;
}
FormLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive);
if (_mapCarsCollectionGeneric + locomotive)
{
MessageBox.Show("Объект добавлен");
pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapCarsCollectionGeneric - pos)
{
MessageBox.Show("Объект удален");
pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
{
return;
}
pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
{
return;
}
pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
{
return;
}
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBoxLocomotives.Image = _mapCarsCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -0,0 +1,60 @@
<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

@ -19,7 +19,7 @@
/// <summary> /// <summary>
/// Размер занимаемого объектом места (высота) /// Размер занимаемого объектом места (высота)
/// </summary> /// </summary>
private readonly int _placeSizeHeight = 90; private readonly int _placeSizeHeight = 110;
/// <summary> /// <summary>
/// Набор объектов /// Набор объектов
/// </summary> /// </summary>
@ -59,8 +59,7 @@
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator -(MapWithSetLocomotivesGeneric<T, U> map, int public static bool operator -(MapWithSetLocomotivesGeneric<T, U> map, int position)
position)
{ {
return map._setLocomotives.Remove(position); return map._setLocomotives.Remove(position);
} }
@ -157,12 +156,23 @@
/// <param name="g"></param> /// <param name="g"></param>
private void DrawLocomotives(Graphics g) private void DrawLocomotives(Graphics g)
{ {
int LocomotivesInLine = _pictureWidth / _placeSizeWidth;
int CurrentVertPos = 20;
int CurrentHorPos = 0;
for (int i = 0; i < _setLocomotives.Count; i++) for (int i = 0; i < _setLocomotives.Count; i++)
{ {
// TODO установка позиции _setLocomotives.Get(i)?.SetObject(CurrentHorPos, CurrentVertPos, _pictureWidth, _pictureHeight);
_setLocomotives.Get(i)?.DrawningObject(g); _setLocomotives.Get(i)?.DrawningObject(g);
if (CurrentHorPos < LocomotivesInLine)
{
CurrentHorPos += _placeSizeWidth;
}
else
{
CurrentHorPos = 0;
CurrentVertPos += _placeSizeHeight;
}
} }
} }
} }
} }

View File

@ -9,7 +9,7 @@ namespace Locomotives
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormMap()); Application.Run(new FormMapWithSetLocomotives());
} }
} }
} }

View File

@ -26,7 +26,12 @@
/// <returns></returns> /// <returns></returns>
public bool Insert(T locomotive) public bool Insert(T locomotive)
{ {
// TODO вставка в начало набора // TODO проверка на наличие свободных мест
for (int i = Count - 2; i >= 0; i--)
{
_places[i + 1] = _places[i];
}
_places[0] = locomotive;
return true; return true;
} }
/// <summary> /// <summary>
@ -42,6 +47,24 @@
// проверка, что после вставляемого элемента в массиве есть пустой элемент // проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции // TODO вставка по позиции
if (position < 0 || position >= Count)
{
return false;
}
int ClosestNullElementIndex = position;
while (_places[ClosestNullElementIndex] != null)
{
if (ClosestNullElementIndex == Count)
{
return false;
}
ClosestNullElementIndex++;
}
while (ClosestNullElementIndex != position)
{
_places[ClosestNullElementIndex] = _places[ClosestNullElementIndex - 1];
ClosestNullElementIndex--;
}
_places[position] = locomotive; _places[position] = locomotive;
return true; return true;
} }
@ -54,6 +77,11 @@
{ {
// TODO проверка позиции // TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива значение null // TODO удаление объекта из массива, присовив элементу массива значение null
if (_places[position] == null)
{
return false;
}
_places[position] = null;
return true; return true;
} }
/// <summary> /// <summary>
@ -64,7 +92,11 @@
public T Get(int position) public T Get(int position)
{ {
// TODO проверка позиции // TODO проверка позиции
return _places[position]; if (_places[position] != null)
{
return _places[position];
}
return null;
} }
} }
} }

View File

@ -34,16 +34,16 @@
_map[i, j] = _freeRoad; _map[i, j] = _freeRoad;
} }
} }
while (counter < 50) //while (counter < 50)
{ //{
int x = _random.Next(0, 100); // int x = _random.Next(0, 100);
int y = _random.Next(0, 100); // int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad) // if (_map[x, y] == _freeRoad)
{ // {
_map[x, y] = _barrier; // _map[x, y] = _barrier;
counter++; // counter++;
} // }
} //}
} }
} }
} }