5я лаба

This commit is contained in:
Vladislav_396ntk 2024-05-06 10:16:15 +04:00
parent 87c20a4587
commit 3ee857a83c
13 changed files with 737 additions and 60 deletions

View File

@ -7,7 +7,7 @@ namespace LocomativeProject.Drawnings
/// <summary>
/// Класс-сущность
/// </summary>
public EntityBaseLocomotive? _EntityLocomotive { get; protected set; }
public EntityBaseLocomotive? _EntityBaseLocomotive { get; protected set; }
/// <summary>
/// Ширина окна
@ -79,7 +79,7 @@ namespace LocomativeProject.Drawnings
/// <param name="bodyColor">Основной цвет</param>
public DrawningBaseLocomotive(int speed, double weight, Color bodyColor) : this()
{
_EntityLocomotive = new EntityBaseLocomotive(speed, weight, bodyColor);
_EntityBaseLocomotive = new EntityBaseLocomotive(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
@ -156,7 +156,7 @@ namespace LocomativeProject.Drawnings
/// невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (_EntityLocomotive == null || !_startPosX.HasValue ||
if (_EntityBaseLocomotive == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return false;
@ -165,30 +165,30 @@ namespace LocomativeProject.Drawnings
{
//влево
case DirectionType.Left:
if (_startPosX.Value - _EntityLocomotive.Step > 0)
if (_startPosX.Value - _EntityBaseLocomotive.Step > 0)
{
_startPosX -= (int)_EntityLocomotive.Step;
_startPosX -= (int)_EntityBaseLocomotive.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - _EntityLocomotive.Step > 0)
if (_startPosY.Value - _EntityBaseLocomotive.Step > 0)
{
_startPosY -= (int)_EntityLocomotive.Step;
_startPosY -= (int)_EntityBaseLocomotive.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + _drawningBaseLocomotiveWidth + _EntityLocomotive.Step < _pictureWidth)
if (_startPosX.Value + _drawningBaseLocomotiveWidth + _EntityBaseLocomotive.Step < _pictureWidth)
{
_startPosX += (int)_EntityLocomotive.Step;
_startPosX += (int)_EntityBaseLocomotive.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + _drawningBaseLocomotiveHeight + _EntityLocomotive.Step < _pictureHeight)
if (_startPosY.Value + _drawningBaseLocomotiveHeight + _EntityBaseLocomotive.Step < _pictureHeight)
{
_startPosY += (int)_EntityLocomotive.Step;
_startPosY += (int)_EntityBaseLocomotive.Step;
}
return true;
default:
@ -224,12 +224,12 @@ namespace LocomativeProject.Drawnings
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (_EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (_EntityBaseLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(_EntityLocomotive.BodyColor);
Brush bodyBrush = new SolidBrush(_EntityBaseLocomotive.BodyColor);
Brush blackBrush = new SolidBrush(Color.Black);
Brush whiteBrush = new SolidBrush(Color.White);
//границы тепловоза

View File

@ -16,12 +16,12 @@ namespace LocomotiveProject.Drawnings
/// <param name="fuelCompartment">Признак наличия топливного отсека</param>
public DrawningLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool exehaustPipe, bool fuelCompartment) : base(120, 60)
{
_EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor, additionalColor, exehaustPipe, fuelCompartment);
_EntityBaseLocomotive = new EntityLocomotive(speed, weight, bodyColor, additionalColor, exehaustPipe, fuelCompartment);
}
public override void DrawTransport(Graphics g)
{
if (_EntityLocomotive == null || _EntityLocomotive is not EntityLocomotive entityLocomotive || !_startPosX.HasValue || !_startPosY.HasValue)
if (_EntityBaseLocomotive == null || _EntityBaseLocomotive is not EntityLocomotive entityLocomotive || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}

View File

@ -17,6 +17,12 @@
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Установка основого цвета
/// </summary>
/// <param name="bodyColor"></param>
public void setBodyColor(Color bodyColor) { BodyColor = bodyColor; }
/// <summary>
/// Шаг перемещения тепловоза
/// </summary>

View File

@ -4,8 +4,16 @@ namespace LocomotiveProject.Entities
{
public class EntityLocomotive : EntityBaseLocomotive
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Задать доп цвет
/// </summary>
/// <param name="color"></param>
public void setAdditionalColor(Color color) { AdditionalColor = color; }
/// <summary>
/// Признак (опция) наличие трубы
/// </summary>
public bool ExehaustPipe { get; private set; }

View File

@ -0,0 +1,353 @@
namespace LocomotiveProject
{
partial class FormLocomotiveConfig
{
/// <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()
{
groupBoxConfig = new GroupBox();
groupBoxColors = new GroupBox();
panelPurple = new Panel();
panelYellow = new Panel();
panelBlack = new Panel();
panelBlue = new Panel();
panelGray = new Panel();
panelRed = new Panel();
panelGreen = new Panel();
panelWhite = new Panel();
checkBoxHelipad = new CheckBox();
checkBoxRocketMine = new CheckBox();
numericUpDownWeight = new NumericUpDown();
labelWeight = new Label();
numericUpDownSpeed = new NumericUpDown();
labelSpeed = new Label();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
pictureBoxObject = new PictureBox();
buttonAdd = new Button();
buttonCancel = new Button();
panelObject = new Panel();
labelAdditionalColor = new Label();
labelBodyColor = new Label();
groupBoxConfig.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
panelObject.SuspendLayout();
SuspendLayout();
//
// groupBoxConfig
//
groupBoxConfig.Controls.Add(groupBoxColors);
groupBoxConfig.Controls.Add(checkBoxHelipad);
groupBoxConfig.Controls.Add(checkBoxRocketMine);
groupBoxConfig.Controls.Add(numericUpDownWeight);
groupBoxConfig.Controls.Add(labelWeight);
groupBoxConfig.Controls.Add(numericUpDownSpeed);
groupBoxConfig.Controls.Add(labelSpeed);
groupBoxConfig.Controls.Add(labelModifiedObject);
groupBoxConfig.Controls.Add(labelSimpleObject);
groupBoxConfig.Dock = DockStyle.Left;
groupBoxConfig.Location = new Point(0, 0);
groupBoxConfig.Name = "groupBoxConfig";
groupBoxConfig.Size = new Size(581, 213);
groupBoxConfig.TabIndex = 0;
groupBoxConfig.TabStop = false;
groupBoxConfig.Text = "Параметры";
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelPurple);
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelBlack);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelGray);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Controls.Add(panelWhite);
groupBoxColors.Location = new Point(402, 44);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(142, 109);
groupBoxColors.TabIndex = 8;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Цвета";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(102, 67);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(26, 27);
panelPurple.TabIndex = 1;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(102, 22);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(26, 27);
panelYellow.TabIndex = 1;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(70, 67);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(26, 27);
panelBlack.TabIndex = 1;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(70, 22);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(26, 27);
panelBlue.TabIndex = 1;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(38, 67);
panelGray.Name = "panelGray";
panelGray.Size = new Size(26, 27);
panelGray.TabIndex = 1;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(6, 22);
panelRed.Name = "panelRed";
panelRed.Size = new Size(26, 27);
panelRed.TabIndex = 1;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(38, 22);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(26, 27);
panelGreen.TabIndex = 1;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(6, 67);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(26, 27);
panelWhite.TabIndex = 0;
//
// checkBoxHelipad
//
checkBoxHelipad.AutoSize = true;
checkBoxHelipad.Location = new Point(6, 119);
checkBoxHelipad.Name = "checkBoxHelipad";
checkBoxHelipad.Size = new Size(256, 19);
checkBoxHelipad.TabIndex = 7;
checkBoxHelipad.Text = "Признак наличие вертолетной площадки";
checkBoxHelipad.UseVisualStyleBackColor = true;
//
// checkBoxRocketMine
//
checkBoxRocketMine.AutoSize = true;
checkBoxRocketMine.Location = new Point(6, 94);
checkBoxRocketMine.Name = "checkBoxRocketMine";
checkBoxRocketMine.Size = new Size(217, 19);
checkBoxRocketMine.TabIndex = 6;
checkBoxRocketMine.Text = "Признак наличие ракетной шахты";
checkBoxRocketMine.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(76, 55);
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(97, 23);
numericUpDownWeight.TabIndex = 5;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(27, 57);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(26, 15);
labelWeight.TabIndex = 4;
labelWeight.Text = "Вес";
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(76, 22);
numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(97, 23);
numericUpDownSpeed.TabIndex = 3;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelSpeed
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(11, 24);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(59, 15);
labelSpeed.TabIndex = 2;
labelSpeed.Text = "Скорость";
//
// labelModifiedObject
//
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(475, 181);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(100, 23);
labelModifiedObject.TabIndex = 1;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(369, 181);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(100, 23);
labelSimpleObject.TabIndex = 0;
labelSimpleObject.Text = "Обычный";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(3, 33);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(198, 125);
pictureBoxObject.TabIndex = 1;
pictureBoxObject.TabStop = false;
//
// buttonAdd
//
buttonAdd.Location = new Point(604, 178);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(75, 23);
buttonAdd.TabIndex = 2;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(713, 178);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отменить";
buttonCancel.UseVisualStyleBackColor = true;
//
// panelObject
//
panelObject.AllowDrop = true;
panelObject.Controls.Add(labelAdditionalColor);
panelObject.Controls.Add(labelBodyColor);
panelObject.Controls.Add(pictureBoxObject);
panelObject.Location = new Point(587, 11);
panelObject.Name = "panelObject";
panelObject.Size = new Size(205, 161);
panelObject.TabIndex = 4;
panelObject.DragDrop += PanelObject_DragDrop;
panelObject.DragEnter += PanelObject_DragEnter;
//
// labelAdditionalColor
//
labelAdditionalColor.AllowDrop = true;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(133, 5);
labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(69, 23);
labelAdditionalColor.TabIndex = 3;
labelAdditionalColor.Text = "Доп.Цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += LabelAdditionalColor_DragDrop;
labelAdditionalColor.DragEnter += LabelAdditionalColor_DragEnter;
//
// labelBodyColor
//
labelBodyColor.AllowDrop = true;
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
labelBodyColor.Location = new Point(3, 5);
labelBodyColor.Name = "labelBodyColor";
labelBodyColor.Size = new Size(69, 23);
labelBodyColor.TabIndex = 2;
labelBodyColor.Text = "Цвет";
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
labelBodyColor.DragDrop += LabelBodyColor_DragDrop;
labelBodyColor.DragEnter += LabelBodyColor_DragEnter;
//
// FormLocomotiveConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 213);
Controls.Add(panelObject);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Controls.Add(groupBoxConfig);
Name = "FormLocomotiveConfig";
Text = "Создание объекта";
groupBoxConfig.ResumeLayout(false);
groupBoxConfig.PerformLayout();
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
panelObject.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private Label labelModifiedObject;
private Label labelSimpleObject;
private CheckBox checkBoxRocketMine;
private NumericUpDown numericUpDownWeight;
private Label labelWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelSpeed;
private CheckBox checkBoxHelipad;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelYellow;
private Panel panelBlack;
private Panel panelBlue;
private Panel panelGray;
private Panel panelRed;
private Panel panelGreen;
private Panel panelWhite;
private PictureBox pictureBoxObject;
private Button buttonAdd;
private Button buttonCancel;
private Panel panelObject;
private Label labelAdditionalColor;
private Label labelBodyColor;
}
}

View File

@ -0,0 +1,167 @@
using LocomativeProject.Drawnings;
using LocomotiveProject.Drawnings;
using LocomotiveProject.Entities;
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 LocomotiveProject;
/// <summary>
/// Форма конфигурации объекта
/// </summary>
public partial class FormLocomotiveConfig : Form
{
/// <summary>
/// объект - прорисовка круизера
/// </summary>
private DrawningBaseLocomotive? _BaseLocomotive;
/// <summary>
/// событе для передачи объекта
/// </summary>
public event LocomotiveDelegate? _LocomotiveDelegate;
/// <summary>
/// Конструктор
/// </summary>
public FormLocomotiveConfig()
{
InitializeComponent();
panelRed.MouseDown += Panel_MouseDown;
panelGreen.MouseDown += Panel_MouseDown;
panelBlue.MouseDown += Panel_MouseDown;
panelYellow.MouseDown += Panel_MouseDown;
panelGray.MouseDown += Panel_MouseDown;
panelBlack.MouseDown += Panel_MouseDown;
panelPurple.MouseDown += Panel_MouseDown;
panelWhite.MouseDown += Panel_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// привязка метода к событию
/// </summary>
/// <param name="LocomotiveDelegate"></param>
public void AddEvent(LocomotiveDelegate LocomotiveDelegate)
{
_LocomotiveDelegate += LocomotiveDelegate;
}
/// <summary>
/// Прорисовка обьекта
/// </summary>
public void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics g = Graphics.FromImage(bmp);
_BaseLocomotive?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
_BaseLocomotive?.SetPosition(5, 5);
_BaseLocomotive?.DrawTransport(g);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Проверка получаемой информации (ее типо на соответсие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object? sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_BaseLocomotive = new DrawningBaseLocomotive((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_BaseLocomotive = new DrawningLocomotive((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxRocketMine.Checked, checkBoxHelipad.Checked);
break;
}
DrawObject();
}
private void Panel_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
{
if (_BaseLocomotive != null)
{
_BaseLocomotive._EntityBaseLocomotive.setBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
private void LabelBodyColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_BaseLocomotive._EntityBaseLocomotive is EntityLocomotive entityLocomotive)
{
entityLocomotive.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
}
DrawObject();
}
private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (_BaseLocomotive is DrawningBaseLocomotive)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
/// <summary>
/// Передача объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_BaseLocomotive != null) { _LocomotiveDelegate?.Invoke(_BaseLocomotive); Close(); }
}
}

View File

@ -1,6 +1,6 @@
namespace LocomativeProject
{
partial class LocomotiveProjectCollection
partial class FormLocomotiveCollection
{
/// <summary>
/// Required designer variable.
@ -30,7 +30,6 @@
{
groupBox1 = new GroupBox();
panelCompany = new Panel();
buttonModifLocomotive = new Button();
buttonAddLocomotive = new Button();
maskedTextBox = new MaskedTextBox();
buttonRefresh = new Button();
@ -69,7 +68,6 @@
//
// panelCompany
//
panelCompany.Controls.Add(buttonModifLocomotive);
panelCompany.Controls.Add(buttonAddLocomotive);
panelCompany.Controls.Add(maskedTextBox);
panelCompany.Controls.Add(buttonRefresh);
@ -82,16 +80,6 @@
panelCompany.Size = new Size(174, 232);
panelCompany.TabIndex = 9;
//
// buttonModifLocomotive
//
buttonModifLocomotive.Location = new Point(15, 38);
buttonModifLocomotive.Name = "buttonModifLocomotive";
buttonModifLocomotive.Size = new Size(150, 43);
buttonModifLocomotive.TabIndex = 2;
buttonModifLocomotive.Text = "Добавление модиф поезда";
buttonModifLocomotive.UseVisualStyleBackColor = true;
buttonModifLocomotive.Click += ButtonModifLocomotive_Click;
//
// buttonAddLocomotive
//
buttonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@ -99,7 +87,7 @@
buttonAddLocomotive.Name = "buttonAddLocomotive";
buttonAddLocomotive.Size = new Size(150, 26);
buttonAddLocomotive.TabIndex = 1;
buttonAddLocomotive.Text = "Добавление поезда";
buttonAddLocomotive.Text = "Добавление локомотива";
buttonAddLocomotive.UseVisualStyleBackColor = true;
buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
//
@ -128,7 +116,7 @@
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
buttonRemoveLocomotive.Size = new Size(150, 23);
buttonRemoveLocomotive.TabIndex = 4;
buttonRemoveLocomotive.Text = "Удалить поезд";
buttonRemoveLocomotive.Text = "Удалить локомотив";
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
//
@ -255,15 +243,15 @@
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// LocomotiveProjectCollection
// FormLocomotiveCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1092, 581);
Controls.Add(pictureBox);
Controls.Add(groupBox1);
Name = "LocomotiveProjectCollection";
Text = "Коллекция Крейсеров";
Name = "FormLocomotiveCollection";
Text = "Коллекция Локомотивов";
groupBox1.ResumeLayout(false);
panelCompany.ResumeLayout(false);
panelCompany.PerformLayout();
@ -278,7 +266,6 @@
private GroupBox groupBox1;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddLocomotive;
private Button buttonModifLocomotive;
private Button buttonRemoveLocomotive;
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;

View File

@ -1,7 +1,4 @@
using LocomativeProject.Drawnings;
using LocomotiveProject;
using LocomotiveProject.CollectionGenericObjects;
using LocomotiveProject.Drawnings;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -11,10 +8,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LocomotiveProject.CollectionGenericObjects;
using LocomotiveProject.Drawnings;
using LocomotiveProject;
namespace LocomativeProject;
public partial class LocomotiveProjectCollection : Form
public partial class FormLocomotiveCollection : Form
{
/// <summary>
/// Хранилище коллекций
@ -27,7 +27,7 @@ public partial class LocomotiveProjectCollection : Form
/// <summary>
/// Консруктор
/// </summary>
public LocomotiveProjectCollection()
public FormLocomotiveCollection()
{
InitializeComponent();
_storageCollection = new();
@ -52,23 +52,24 @@ public partial class LocomotiveProjectCollection : Form
return;
}
Random rnd = new();
DrawningBaseLocomotive DrawningBaseLocomotive;
DrawningBaseLocomotive drawningBaseLocomotive;
switch (type)
{
case nameof(DrawningBaseLocomotive):
DrawningBaseLocomotive = new DrawningBaseLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd));
drawningBaseLocomotive = new DrawningBaseLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd));
break;
case nameof(DrawningLocomotive):
DrawningBaseLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), GetColor(rnd),
drawningBaseLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), GetColor(rnd),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
break;
default:
return;
}
if (_company + DrawningBaseLocomotive != -1)
if (_company + drawningBaseLocomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
@ -91,17 +92,36 @@ public partial class LocomotiveProjectCollection : Form
return color;
}
/// <summary>
/// Кнопка создания обычного крейсера
/// Кнопка добавления крейсера
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBaseLocomotive));
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{
FormLocomotiveConfig form = new FormLocomotiveConfig();
form.Show();
form.AddEvent(setLocomotive);
}
/// <summary>
/// Кнопка создания модиф крейсера
/// Добавление автомобиля в коллекцию
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonModifLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
/// <param name="Locomotive"></param>
private void setLocomotive(DrawningBaseLocomotive Locomotive)
{
if (_company == null || Locomotive == null)
{
return;
}
if (_company + Locomotive != -1)
{
MessageBox.Show("объект добавлен");
pictureBox.Image= _company.Show();
}
else
{
MessageBox.Show("Не удалось добавлять объект");
}
}
/// <summary>
/// Кнопка удаления Крейсера
/// </summary>
@ -143,11 +163,11 @@ public partial class LocomotiveProjectCollection : Form
{
return;
}
DrawningBaseLocomotive baseLocomotive = null;
DrawningBaseLocomotive BaseLocomotive = null;
int counter = 100;
while (baseLocomotive == null)
while (BaseLocomotive == null)
{
baseLocomotive = _company.GetRandomObject();
BaseLocomotive = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
@ -155,12 +175,12 @@ public partial class LocomotiveProjectCollection : Form
}
}
if (baseLocomotive == null)
if (BaseLocomotive == null)
{
return;
}
LocomotiveProjectForm form = new() { SetLocomotive = baseLocomotive };
LocomotiveProjectForm form = new() { SetLocomotive = BaseLocomotive };
form.ShowDialog();
}
@ -171,8 +191,11 @@ public partial class LocomotiveProjectCollection : Form
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company != null)
pictureBox.Image = _company.Show();
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
/// <summary>
///

View 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>

View File

@ -0,0 +1,13 @@
using LocomativeProject.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LocomotiveProject;
/// <summary>
/// Делегат передачи объекта класса-прорисовки
/// </summary>
/// <param name="Locomotive"></param>
public delegate void LocomotiveDelegate(DrawningBaseLocomotive Locomotive);

View File

@ -24,7 +24,7 @@ public class MoveableLocomotive : IMoveableObject
{
get
{
if (_locomotive == null || _locomotive._EntityLocomotive == null || !_locomotive.GetPosX.HasValue || !_locomotive.GetPosY.HasValue)
if (_locomotive == null || _locomotive._EntityBaseLocomotive == null || !_locomotive.GetPosX.HasValue || !_locomotive.GetPosY.HasValue)
{
return null;
}
@ -32,11 +32,11 @@ public class MoveableLocomotive : IMoveableObject
}
}
public int GetStep => (int)(_locomotive?._EntityLocomotive?.Step ?? 0);
public int GetStep => (int)(_locomotive?._EntityBaseLocomotive?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_locomotive == null || _locomotive._EntityLocomotive == null)
if (_locomotive == null || _locomotive._EntityBaseLocomotive == null)
{
return false;
}

View File

@ -13,7 +13,7 @@ namespace LocomotiveProject
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new LocomotiveProjectCollection());
Application.Run(new FormLocomotiveCollection());
}
}
}