Завершение 3 лабы
This commit is contained in:
parent
0245de20ce
commit
f7feca445e
@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ElectricLocomotive;
|
using ElectricLocomotive;
|
||||||
using ProjectElectricLocomotive.Entities;
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
using ProjectElectricLocomotive.Properties;
|
using ProjectElectricLocomotive.Properties;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
@ -180,5 +181,10 @@ namespace ProjectElectricLocomotive.DrawingObjects
|
|||||||
Direction.Down => _startPosY + EntityLocomotive.Step < _pictureHeight,
|
Direction.Down => _startPosY + EntityLocomotive.Step < _pictureHeight,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new
|
||||||
|
DrawingObjectLocomotive(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace ElectricLocomotive
|
namespace ElectricLocomotive
|
||||||
{
|
{
|
||||||
partial class ElectricLocomotive
|
partial class FormElectricLocomotive
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -39,6 +39,7 @@ namespace ElectricLocomotive
|
|||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonCreateLocomotive = new Button();
|
buttonCreateLocomotive = new Button();
|
||||||
buttonStep = new Button();
|
buttonStep = new Button();
|
||||||
|
button1 = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -157,13 +158,24 @@ namespace ElectricLocomotive
|
|||||||
buttonStep.TabIndex = 8;
|
buttonStep.TabIndex = 8;
|
||||||
buttonStep.Text = "Шаг";
|
buttonStep.Text = "Шаг";
|
||||||
buttonStep.UseVisualStyleBackColor = true;
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
buttonStep.Click += buttonStep_Click;
|
buttonStep.Click += buttonStrategyStep_Click;
|
||||||
//
|
//
|
||||||
// ElectricLocomotive
|
// button1
|
||||||
|
//
|
||||||
|
button1.Location = new Point(256, 365);
|
||||||
|
button1.Name = "button1";
|
||||||
|
button1.Size = new Size(206, 64);
|
||||||
|
button1.TabIndex = 9;
|
||||||
|
button1.Text = "Выбрать локомотив";
|
||||||
|
button1.UseVisualStyleBackColor = true;
|
||||||
|
button1.Click += ButtonSelectLocomotive_Click;
|
||||||
|
//
|
||||||
|
// FormElectricLocomotive
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(847, 441);
|
ClientSize = new Size(847, 441);
|
||||||
|
Controls.Add(button1);
|
||||||
Controls.Add(buttonStep);
|
Controls.Add(buttonStep);
|
||||||
Controls.Add(buttonCreateLocomotive);
|
Controls.Add(buttonCreateLocomotive);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
@ -174,9 +186,10 @@ namespace ElectricLocomotive
|
|||||||
Controls.Add(buttonCreateElectricLocomotive);
|
Controls.Add(buttonCreateElectricLocomotive);
|
||||||
Controls.Add(pictureBoxElectricLocomotive);
|
Controls.Add(pictureBoxElectricLocomotive);
|
||||||
Margin = new Padding(2);
|
Margin = new Padding(2);
|
||||||
Name = "ElectricLocomotive";
|
Name = "FormElectricLocomotive";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "ElectricLocomotive";
|
Text = "ElectricLocomotive";
|
||||||
|
Load += ElectricLocomotive_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
@ -193,5 +206,6 @@ namespace ElectricLocomotive
|
|||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonCreateLocomotive;
|
private Button buttonCreateLocomotive;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
|
private Button button1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,24 +1,22 @@
|
|||||||
|
|
||||||
using ProjectElectricLocomotive;
|
|
||||||
using ProjectElectricLocomotive.DrawingObjects;
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
using ProjectElectricLocomotive.MovementStrategy;
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
using ProjectElectricLocomotive;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace ElectricLocomotive
|
namespace ElectricLocomotive
|
||||||
|
|
||||||
{
|
{
|
||||||
public partial class ElectricLocomotive : Form
|
public partial class FormElectricLocomotive : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
private DrawingLocomotive? _drawningLocomotive;
|
private DrawingLocomotive? _drawningLocomotive;
|
||||||
|
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawingLocomotive? SelectedLocomotive { get; private set; }
|
||||||
public ElectricLocomotive()
|
public FormElectricLocomotive()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedLocomotive = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningLocomotive == null)
|
if (_drawningLocomotive == null)
|
||||||
@ -30,29 +28,44 @@ namespace ElectricLocomotive
|
|||||||
_drawningLocomotive.DrawTransport(gr);
|
_drawningLocomotive.DrawTransport(gr);
|
||||||
pictureBoxElectricLocomotive.Image = bmp;
|
pictureBoxElectricLocomotive.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
|
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_drawningLocomotive = new DrawingElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000),
|
Color color = 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)),
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = colorDialog.Color;
|
||||||
|
}
|
||||||
|
_drawningLocomotive = new DrawingElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCreateLocomotive_Click(object sender, EventArgs e)
|
private void buttonCreateLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random random = new();
|
||||||
_drawningLocomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
ColorDialog dialog = new();
|
||||||
_drawningLocomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
Draw();
|
{
|
||||||
|
color = dialog.Color;
|
||||||
}
|
}
|
||||||
|
_drawningLocomotive = new DrawingLocomotive(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), color,
|
||||||
|
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
|
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
}
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningLocomotive == null)
|
if (_drawningLocomotive == null)
|
||||||
@ -77,8 +90,7 @@ namespace ElectricLocomotive
|
|||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||||
private void buttonStep_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
if (_drawningLocomotive == null)
|
if (_drawningLocomotive == null)
|
||||||
{
|
{
|
||||||
@ -96,9 +108,7 @@ namespace ElectricLocomotive
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(new
|
_abstractStrategy.SetData(new DrawingObjectLocomotive(_drawningLocomotive), pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
DrawingObjectLocomotive(_drawningLocomotive), pictureBoxElectricLocomotive.Width,
|
|
||||||
pictureBoxElectricLocomotive.Height);
|
|
||||||
comboBoxStrategy.Enabled = false;
|
comboBoxStrategy.Enabled = false;
|
||||||
}
|
}
|
||||||
if (_abstractStrategy == null)
|
if (_abstractStrategy == null)
|
||||||
@ -113,15 +123,22 @@ namespace ElectricLocomotive
|
|||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pictureBoxElectricLocomotive_Click(object sender, EventArgs e)
|
private void pictureBoxElectricLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private void ElectricLocomotive_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedLocomotive = _drawningLocomotive;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
140
ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
140
ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
generated
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
namespace ProjectElectricLocomotive
|
||||||
|
{
|
||||||
|
partial class FormLocomotiveCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
panelLocomotiveCollection = new Panel();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
ButtonRefreshCollection = new Button();
|
||||||
|
ButtonRemoveLocomotive = new Button();
|
||||||
|
ButtonAddLocomotive = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
LabelOnPanel = new Label();
|
||||||
|
panelLocomotiveCollection.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// panelLocomotiveCollection
|
||||||
|
//
|
||||||
|
panelLocomotiveCollection.AccessibleDescription = "";
|
||||||
|
panelLocomotiveCollection.AccessibleName = "";
|
||||||
|
panelLocomotiveCollection.Controls.Add(LabelOnPanel);
|
||||||
|
panelLocomotiveCollection.Controls.Add(maskedTextBoxNumber);
|
||||||
|
panelLocomotiveCollection.Controls.Add(ButtonRefreshCollection);
|
||||||
|
panelLocomotiveCollection.Controls.Add(ButtonRemoveLocomotive);
|
||||||
|
panelLocomotiveCollection.Controls.Add(ButtonAddLocomotive);
|
||||||
|
panelLocomotiveCollection.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
panelLocomotiveCollection.Location = new Point(594, 2);
|
||||||
|
panelLocomotiveCollection.Name = "panelLocomotiveCollection";
|
||||||
|
panelLocomotiveCollection.Size = new Size(208, 448);
|
||||||
|
panelLocomotiveCollection.TabIndex = 0;
|
||||||
|
panelLocomotiveCollection.Tag = "Инструменты";
|
||||||
|
panelLocomotiveCollection.Paint += panelLocomotiveCollection_Paint;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(40, 74);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(123, 23);
|
||||||
|
maskedTextBoxNumber.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(3, 194);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(194, 43);
|
||||||
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
ButtonRefreshCollection.Text = " Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveLocomotive
|
||||||
|
//
|
||||||
|
ButtonRemoveLocomotive.Location = new Point(3, 138);
|
||||||
|
ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
|
||||||
|
ButtonRemoveLocomotive.Size = new Size(194, 39);
|
||||||
|
ButtonRemoveLocomotive.TabIndex = 1;
|
||||||
|
ButtonRemoveLocomotive.Text = "Удалить локомотив";
|
||||||
|
ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddLocomotive
|
||||||
|
//
|
||||||
|
ButtonAddLocomotive.Location = new Point(3, 15);
|
||||||
|
ButtonAddLocomotive.Name = "ButtonAddLocomotive";
|
||||||
|
ButtonAddLocomotive.Size = new Size(194, 39);
|
||||||
|
ButtonAddLocomotive.TabIndex = 0;
|
||||||
|
ButtonAddLocomotive.Text = "Добавить локомотив";
|
||||||
|
ButtonAddLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddLocomotive.Click += ButtonAddLocomotive_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(2, 2);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(589, 448);
|
||||||
|
pictureBoxCollection.TabIndex = 1;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// LabelOnPanel
|
||||||
|
//
|
||||||
|
LabelOnPanel.AutoSize = true;
|
||||||
|
LabelOnPanel.Location = new Point(3, -3);
|
||||||
|
LabelOnPanel.Name = "LabelOnPanel";
|
||||||
|
LabelOnPanel.Size = new Size(83, 15);
|
||||||
|
LabelOnPanel.TabIndex = 4;
|
||||||
|
LabelOnPanel.Text = "Инструменты";
|
||||||
|
LabelOnPanel.Click += LabelOnPanel_Click;
|
||||||
|
//
|
||||||
|
// FormLocomotiveCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(panelLocomotiveCollection);
|
||||||
|
Name = "FormLocomotiveCollection";
|
||||||
|
Text = "Набор локомотивов";
|
||||||
|
Load += FormLocomotiveCollection_Load;
|
||||||
|
panelLocomotiveCollection.ResumeLayout(false);
|
||||||
|
panelLocomotiveCollection.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Panel panelLocomotiveCollection;
|
||||||
|
private Button ButtonAddLocomotive;
|
||||||
|
private Button ButtonRemoveLocomotive;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private Label LabelOnPanel;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using ElectricLocomotive;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ProjectElectricLocomotive.Generics;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive
|
||||||
|
{
|
||||||
|
public partial class FormLocomotiveCollection : Form
|
||||||
|
{
|
||||||
|
private readonly LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
||||||
|
public FormLocomotiveCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_locomotives = new LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormElectricLocomotive form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_locomotives + form.SelectedLocomotive != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (_locomotives - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
|
||||||
|
}
|
||||||
|
private void FormLocomotiveCollection_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
private void LabelOnPanel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
private void panelLocomotiveCollection_Paint(object sender, PaintEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
@ -8,40 +8,15 @@ using ProjectElectricLocomotive.MovementStrategy;
|
|||||||
|
|
||||||
namespace ProjectElectricLocomotive.Generics
|
namespace ProjectElectricLocomotive.Generics
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Параметризованный класс для набора объектов DrawningCar
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
/// <typeparam name="U"></typeparam>
|
|
||||||
internal class LocomotivesGenericCollection<T, U>
|
internal class LocomotivesGenericCollection<T, U>
|
||||||
where T : DrawingObjects
|
where T : DrawingLocomotive
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Ширина окна прорисовки
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
/// <summary>
|
|
||||||
/// Высота окна прорисовки
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
/// <summary>
|
private readonly int _placeSizeWidth = 200;
|
||||||
/// Размер занимаемого объектом места (ширина)
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _placeSizeWidth = 210;
|
|
||||||
/// <summary>
|
|
||||||
/// Размер занимаемого объектом места (высота)
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _placeSizeHeight = 90;
|
private readonly int _placeSizeHeight = 90;
|
||||||
/// <summary>
|
|
||||||
/// Набор объектов
|
|
||||||
/// </summary>
|
|
||||||
private readonly SetGeneric<T> _collection;
|
private readonly SetGeneric<T> _collection;
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="picWidth"></param>
|
|
||||||
/// <param name="picHeight"></param>
|
|
||||||
public LocomotivesGenericCollection(int picWidth, int picHeight)
|
public LocomotivesGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
@ -50,51 +25,26 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
/// <summary>
|
public static int operator + (LocomotivesGenericCollection<T, U> collect, T? locomotive)
|
||||||
/// Перегрузка оператора сложения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="collect"></param>
|
|
||||||
/// <param name="obj"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool operator +(LocomotivesGenericCollection<T, U> collect, T?
|
|
||||||
obj)
|
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (locomotive == null)
|
||||||
{
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect?._collection.Insert(locomotive) ?? -1;
|
||||||
|
}
|
||||||
|
public static bool operator - (LocomotivesGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? locomotive = collect._collection.Get(pos);
|
||||||
|
if (locomotive != null)
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return collect?._collection.Insert(obj) ?? false;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Перегрузка оператора вычитания
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="collect"></param>
|
|
||||||
/// <param name="pos"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static T? operator -(LocomotivesGenericCollection<T, U> collect, int
|
|
||||||
pos)
|
|
||||||
{
|
|
||||||
T? obj = collect._collection.Get(pos);
|
|
||||||
if (obj != null)
|
|
||||||
{
|
|
||||||
collect._collection.Remove(pos);
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Получение объекта IMoveableObject
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pos"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
/// <summary>
|
public Bitmap ShowLocomotives()
|
||||||
/// Вывод всего набора объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public Bitmap ShowCars()
|
|
||||||
{
|
{
|
||||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
@ -102,10 +52,6 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
DrawObjects(gr);
|
DrawObjects(gr);
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Метод отрисовки фона
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
private void DrawBackground(Graphics g)
|
private void DrawBackground(Graphics g)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.Black, 3);
|
Pen pen = new(Color.Black, 3);
|
||||||
@ -122,17 +68,21 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Метод прорисовки объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
|
int HLoco = _pictureHeight / _placeSizeHeight;
|
||||||
|
int Wloco = _pictureWidth / _placeSizeWidth;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
{
|
{
|
||||||
// TODO получение объекта
|
T? type = _collection.Get(i);
|
||||||
// TODO установка позиции
|
if (type != null)
|
||||||
// TODO прорисовка объекта
|
{
|
||||||
|
type.SetPosition(
|
||||||
|
(int)(i / HLoco * _placeSizeWidth),
|
||||||
|
(HLoco - 1) * _placeSizeHeight - (int)(i % HLoco * _placeSizeHeight)
|
||||||
|
);
|
||||||
|
type?.DrawTransport(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,6 @@ namespace ProjectElectricLocomotive.MovementStrategy
|
|||||||
private readonly int _y;
|
private readonly int _y;
|
||||||
private readonly int _width;
|
private readonly int _width;
|
||||||
private readonly int _height;
|
private readonly int _height;
|
||||||
/// <summary>
|
|
||||||
/// Левая граница
|
|
||||||
/// </summary>
|
|
||||||
public int LeftBorder => _x;
|
public int LeftBorder => _x;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя граница
|
/// Верхняя граница
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
|
using ProjectElectricLocomotive;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace ElectricLocomotive
|
namespace ElectricLocomotive
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new ElectricLocomotive());
|
Application.Run(new FormLocomotiveCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,74 +6,59 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectElectricLocomotive.Generics
|
namespace ProjectElectricLocomotive.Generics
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Параметризованный набор объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
internal class SetGeneric<T>
|
internal class SetGeneric<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Массив объектов, которые храним
|
|
||||||
/// </summary>
|
|
||||||
private readonly T?[] _places;
|
private readonly T?[] _places;
|
||||||
/// <summary>
|
|
||||||
/// Количество объектов в массиве
|
|
||||||
/// </summary>
|
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Length;
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="count"></param>
|
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_places = new T?[count];
|
||||||
}
|
}
|
||||||
/// <summary>
|
public int Insert(T locomotive)
|
||||||
/// Добавление объекта в набор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="car">Добавляемый автомобиль</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Insert(T car)
|
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
return Insert(locomotive, 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
public int Insert(T locomotive, int position)
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="car">Добавляемый автомобиль</param>
|
|
||||||
/// <param name="position">Позиция</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Insert(T car, int position)
|
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
int Full = 0;
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
int temp = 0;
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
for (int i = position; i < Count; i++)
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
{
|
||||||
// TODO вставка по позиции
|
if (_places[i] != null) Full++;
|
||||||
_places[position] = car;
|
}
|
||||||
return true;
|
if (Full == Count - position - 1)
|
||||||
|
return -1;
|
||||||
|
if (position < Count && position >= 0)
|
||||||
|
{
|
||||||
|
for (int j = position; j < Count; j++)
|
||||||
|
{
|
||||||
|
if (_places[j] == null)
|
||||||
|
{
|
||||||
|
temp = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = temp; i > position; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
_places[position] = locomotive;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position >= Count || position < 0)
|
||||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||||
|
return false;
|
||||||
|
_places[position] = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
public T Get(int position)
|
||||||
/// Получение объекта из набора по позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public T? Get(int position)
|
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position < 0 || position >= Count) return null;
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user