PIbd-21 Bakalskaya E.D. LabWork03 BASE #4

Closed
ekallin wants to merge 1 commits from LabWork03 into LabWork02
12 changed files with 588 additions and 39 deletions
Showing only changes of commit 0e251a1527 - Show all commits

View File

@ -9,9 +9,6 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectElectricLocomotive.MovementStrategy
{
/// <summary>
/// Абстрактный класс стратегии
/// </summary>
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;

View File

@ -33,7 +33,7 @@ namespace ProjectElectricLocomotive.DrawingObjects
if (electricLocomotive.Horns)
{
//horns
g.FillRectangle(blackBrush, _startPosX + 30, _startPosY + 15, 20, 5);
g.FillRectangle(additionalBrush, _startPosX + 30, _startPosY + 15, 20, 5);
g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 10);
g.DrawLine(pen, _startPosX + 50, _startPosY + 10, _startPosX + 45, _startPosY);
g.DrawLine(pen, _startPosX + 45, _startPosY + 15, _startPosX + 50, _startPosY + 10);

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.Entities;
using ProjectElectricLocomotive.MovementStrategy;
using ProjectElectricLocomotive.Properties;
namespace ProjectElectricLocomotive.DrawingObjects
@ -29,6 +30,7 @@ namespace ProjectElectricLocomotive.DrawingObjects
public int GetWidth => _locoWidth;
public int GetHeight => _locoHeight;
public IMoveableObject GetMoveableObject => new DrawingObjectLocomotive(this);
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
{
if (width < _locoWidth || heigth < _locoHeight)

View File

@ -1,6 +1,6 @@
namespace ElectricLocomotive
{
partial class ElectricLocomotive
partial class FormElectricLocomotive
{
/// <summary>
/// Required designer variable.
@ -37,6 +37,7 @@
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonCreateLocomotive = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
this.ButtonSelect_Locomotive = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxElectricLocomotive)).BeginInit();
this.SuspendLayout();
//
@ -44,8 +45,9 @@
//
this.pictureBoxElectricLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxElectricLocomotive.Location = new System.Drawing.Point(0, 0);
this.pictureBoxElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive";
this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(1242, 512);
this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(994, 520);
this.pictureBoxElectricLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxElectricLocomotive.TabIndex = 0;
this.pictureBoxElectricLocomotive.TabStop = false;
@ -54,9 +56,10 @@
//
this.buttonCreateElectricLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateElectricLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateElectricLocomotive.Location = new System.Drawing.Point(16, 442);
this.buttonCreateElectricLocomotive.Location = new System.Drawing.Point(13, 442);
this.buttonCreateElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(272, 52);
this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateElectricLocomotive.TabIndex = 1;
this.buttonCreateElectricLocomotive.Text = "Создать электролокомотив";
this.buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
@ -67,9 +70,10 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(1098, 464);
this.buttonLeft.Location = new System.Drawing.Point(878, 481);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(2);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.Size = new System.Drawing.Size(24, 24);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
@ -79,9 +83,10 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowUP;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(1144, 415);
this.buttonUp.Location = new System.Drawing.Point(915, 442);
this.buttonUp.Margin = new System.Windows.Forms.Padding(2);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.Size = new System.Drawing.Size(24, 24);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
@ -91,9 +96,10 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(1188, 464);
this.buttonRight.Location = new System.Drawing.Point(950, 481);
this.buttonRight.Margin = new System.Windows.Forms.Padding(2);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.Size = new System.Drawing.Size(24, 24);
this.buttonRight.TabIndex = 4;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
@ -103,9 +109,10 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(1144, 464);
this.buttonDown.Location = new System.Drawing.Point(915, 481);
this.buttonDown.Margin = new System.Windows.Forms.Padding(2);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.Size = new System.Drawing.Size(24, 24);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
@ -118,18 +125,20 @@
this.comboBoxStrategy.Items.AddRange(new object[] {
"MoveToCenter",
"MoveToRightCorner"});
this.comboBoxStrategy.Location = new System.Drawing.Point(1058, 12);
this.comboBoxStrategy.Location = new System.Drawing.Point(846, 10);
this.comboBoxStrategy.Margin = new System.Windows.Forms.Padding(2);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(160, 33);
this.comboBoxStrategy.Size = new System.Drawing.Size(129, 28);
this.comboBoxStrategy.TabIndex = 6;
//
// buttonCreateLocomotive
//
this.buttonCreateLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateLocomotive.Location = new System.Drawing.Point(333, 442);
this.buttonCreateLocomotive.Location = new System.Drawing.Point(266, 442);
this.buttonCreateLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateLocomotive.Name = "buttonCreateLocomotive";
this.buttonCreateLocomotive.Size = new System.Drawing.Size(272, 52);
this.buttonCreateLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateLocomotive.TabIndex = 7;
this.buttonCreateLocomotive.Text = "Создать локомотив";
this.buttonCreateLocomotive.UseVisualStyleBackColor = true;
@ -139,19 +148,34 @@
//
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonStep.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonStep.Location = new System.Drawing.Point(1079, 65);
this.buttonStep.Location = new System.Drawing.Point(863, 52);
this.buttonStep.Margin = new System.Windows.Forms.Padding(2);
this.buttonStep.Name = "buttonStep";
this.buttonStep.Size = new System.Drawing.Size(125, 56);
this.buttonStep.Size = new System.Drawing.Size(100, 45);
this.buttonStep.TabIndex = 8;
this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true;
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
//
// ElectricLocomotive
// ButtonSelect_Locomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.ButtonSelect_Locomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonSelect_Locomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonSelect_Locomotive.Location = new System.Drawing.Point(863, 113);
this.ButtonSelect_Locomotive.Margin = new System.Windows.Forms.Padding(2);
this.ButtonSelect_Locomotive.Name = "ButtonSelect_Locomotive";
this.ButtonSelect_Locomotive.Size = new System.Drawing.Size(100, 61);
this.ButtonSelect_Locomotive.TabIndex = 9;
this.ButtonSelect_Locomotive.Text = "Выбор локо";
this.ButtonSelect_Locomotive.UseVisualStyleBackColor = true;
this.ButtonSelect_Locomotive.Click += new System.EventHandler(this.ButtonSelect_Locomotive_Click);
//
// FormElectricLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1242, 512);
this.ClientSize = new System.Drawing.Size(994, 520);
this.Controls.Add(this.ButtonSelect_Locomotive);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateLocomotive);
this.Controls.Add(this.comboBoxStrategy);
@ -161,7 +185,8 @@
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonCreateElectricLocomotive);
this.Controls.Add(this.pictureBoxElectricLocomotive);
this.Name = "ElectricLocomotive";
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "FormElectricLocomotive";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ElectricLocomotive";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxElectricLocomotive)).EndInit();
@ -181,5 +206,6 @@
private ComboBox comboBoxStrategy;
private Button buttonCreateLocomotive;
private Button buttonStep;
private Button ButtonSelect_Locomotive;
}
}

View File

@ -2,19 +2,23 @@ using ProjectElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
using System;
using System.Windows.Forms;
namespace ElectricLocomotive
{
public partial class ElectricLocomotive : Form
public partial class FormElectricLocomotive : Form
{
private DrawingLocomotive? _drawingLocomotive;
private AbstractStrategy? _abstractStrategy;
public DrawingLocomotive? SelectedLocomotive { get; private set; }
public ElectricLocomotive()
public FormElectricLocomotive()
{
InitializeComponent();
_abstractStrategy = null;
SelectedLocomotive = null;
}
private void Draw()
@ -32,9 +36,23 @@ namespace ElectricLocomotive
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
{
Random random = new Random();
_drawingLocomotive = new DrawingElectricLocomotive(random.Next(100, 300),random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog colorDialog = new ColorDialog();
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;
}
_drawingLocomotive = new DrawingElectricLocomotive(random.Next(100, 300),random.Next(1000, 3000),color, dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
@ -44,8 +62,13 @@ namespace ElectricLocomotive
private void buttonCreateLocomotive_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_drawingLocomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000),
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));
ColorDialog colorDialog = new ColorDialog();
if (colorDialog.ShowDialog() == DialogResult.OK)
{
color = colorDialog.Color;
}
_drawingLocomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), color,
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
Draw();
@ -94,15 +117,14 @@ namespace ElectricLocomotive
{
return;
}
_abstractStrategy.SetData(new
DrawingObjectLocomotive(_drawingLocomotive), pictureBoxElectricLocomotive.Width,
_abstractStrategy.SetData(_drawingLocomotive.GetMoveableObject, pictureBoxElectricLocomotive.Width,
pictureBoxElectricLocomotive.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
@ -111,5 +133,11 @@ namespace ElectricLocomotive
_abstractStrategy = null;
}
}
private void ButtonSelect_Locomotive_Click(object sender, EventArgs e)
{
SelectedLocomotive = _drawingLocomotive;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,133 @@
namespace ProjectElectricLocomotive
{
partial class FormLocomotiveCollections
{
/// <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.Instruments = new System.Windows.Forms.Panel();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveLocomotive = new System.Windows.Forms.Button();
this.ButtonAddLocomotive = new System.Windows.Forms.Button();
this.pictureBoxCollections = new System.Windows.Forms.PictureBox();
this.Instruments.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).BeginInit();
this.SuspendLayout();
//
// Instruments
//
this.Instruments.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.Instruments.AutoSize = true;
this.Instruments.Controls.Add(this.maskedTextBoxNumber);
this.Instruments.Controls.Add(this.ButtonRefreshCollection);
this.Instruments.Controls.Add(this.ButtonRemoveLocomotive);
this.Instruments.Controls.Add(this.ButtonAddLocomotive);
this.Instruments.Location = new System.Drawing.Point(435, -40);
this.Instruments.Name = "Instruments";
this.Instruments.Size = new System.Drawing.Size(191, 451);
this.Instruments.TabIndex = 0;
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(42, 123);
this.maskedTextBoxNumber.Mask = "0";
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
this.maskedTextBoxNumber.TabIndex = 4;
//
// ButtonRefreshCollection
//
this.ButtonRefreshCollection.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ButtonRefreshCollection.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonRefreshCollection.Location = new System.Drawing.Point(29, 249);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 36);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить все";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveLocomotive
//
this.ButtonRemoveLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ButtonRemoveLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(29, 179);
this.ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 36);
this.ButtonRemoveLocomotive.TabIndex = 1;
this.ButtonRemoveLocomotive.Text = "Удалить локо";
this.ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
this.ButtonRemoveLocomotive.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
//
// ButtonAddLocomotive
//
this.ButtonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonAddLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonAddLocomotive.Location = new System.Drawing.Point(29, 52);
this.ButtonAddLocomotive.Name = "ButtonAddLocomotive";
this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 36);
this.ButtonAddLocomotive.TabIndex = 0;
this.ButtonAddLocomotive.Text = "Добавить локо";
this.ButtonAddLocomotive.UseVisualStyleBackColor = true;
this.ButtonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
//
// pictureBoxCollections
//
this.pictureBoxCollections.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.pictureBoxCollections.Location = new System.Drawing.Point(-3, -2);
this.pictureBoxCollections.Name = "pictureBoxCollections";
this.pictureBoxCollections.Size = new System.Drawing.Size(458, 373);
this.pictureBoxCollections.TabIndex = 1;
this.pictureBoxCollections.TabStop = false;
//
// FormLocomotiveCollections
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(626, 370);
this.Controls.Add(this.pictureBoxCollections);
this.Controls.Add(this.Instruments);
this.Name = "FormLocomotiveCollections";
this.Text = "Набор локомотивов";
this.Instruments.ResumeLayout(false);
this.Instruments.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Panel Instruments;
private Button ButtonRefreshCollection;
private Button ButtonRemoveLocomotive;
private Button ButtonAddLocomotive;
private PictureBox pictureBoxCollections;
private MaskedTextBox maskedTextBoxNumber;
}
}

View File

@ -0,0 +1,70 @@
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.Generics;
using ProjectElectricLocomotive.MovementStrategy;
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 ProjectElectricLocomotive
{
public partial class FormLocomotiveCollections : Form
{
private readonly LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
public FormLocomotiveCollections()
{
InitializeComponent();
_locomotives = new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(pictureBoxCollections.Width,
pictureBoxCollections.Height);
}
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{
if (_locomotives == null) return;
FormElectricLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK)
{
//проверяем, удалось ли нам загрузить объект
if (_locomotives + form.SelectedLocomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollections.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("Объект удален");
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
}
}
}

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

@ -11,9 +11,7 @@ namespace ProjectElectricLocomotive.MovementStrategy
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
namespace ProjectElectricLocomotive.Generics
{
internal class LocomotiveGenericCollection<T, U> where T : DrawingLocomotive where U : IMoveableObject
{
//ширина/высота окна
private readonly int _pictureWidth;
private readonly int _pictureHeight;
//ширина/высота занимаемого места
private readonly int _placeSizeWidth = 85;
private readonly int _placeSizeHeight = 50;
/// Набор объектов
private readonly SetGeneric<T> _collection;
public LocomotiveGenericCollection(int picWidth, int picHeight)
{
// немного странная логика, что-то я пока ее не особо понимаю, зачем нам ААААА дошло...
// высчитываем размер массива для setgeneric
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// Перегрузка оператора сложения
public static int operator +(LocomotiveGenericCollection<T, U> collect, T loco)
{
if (loco == null)
{
return -1;
}
return collect._collection.Insert(loco);
}
/// Перегрузка оператора вычитания
public static T operator -(LocomotiveGenericCollection<T, U> collect, int pos)
{
return collect._collection.Remove(pos);
}
// получение объекта imoveableObj
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
/// Вывод всего набора объектов
public Bitmap ShowLocomotives()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
int HeightObjCount = _pictureHeight / _placeSizeHeight;
int WidthObjCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
{
T? type = _collection.Get(i);
if (type != null)
{
type.SetPosition(
(int)(i / HeightObjCount * _placeSizeWidth),
(HeightObjCount - 1) * _placeSizeHeight - (int)(i % HeightObjCount * _placeSizeHeight)
);
type?.DrawTransport(g);
}
}
}
}
}

View File

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

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.Generics
{
internal class SetGeneric<T> where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
public SetGeneric(int count)
{
_places = new T[count];
}
/// Добавление объекта в набор
public int Insert(T loco)
{
return Insert(loco, 0);
}
public int Insert(T loco, int position)
{
int NoEmpty = 0, temp = 0;
for (int i = position; i < Count; i++)
{
if (_places[i] != null) NoEmpty++;
}
if (NoEmpty == Count - position - 1) return -1;
if (position < Count && position >= 0)
{
for (int j = position; j < Count; j++)
{
if (_places[j] == null)
{
temp = j;
break;
}
}
// shift right
for (int i = temp; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = loco;
return position;
}
return -1;
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент //
}
public T Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= Count || position < 0)
return null;
T tmp = _places[position];
_places[position] = null;
return tmp;
}
//Получение объекта из набора по позиции
public T Get(int position)
{
// TODO проверка позиции
if (position < 0 || position >= Count) return null;
return _places[position];
}
}
}