Compare commits

..

No commits in common. "lab3" and "main" have entirely different histories.
lab3 ... main

24 changed files with 0 additions and 1379 deletions

28
.gitignore vendored
View File

@ -398,31 +398,3 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
# Common IntelliJ Platform excludes
# User specific
**/.idea/**/workspace.xml
**/.idea/**/tasks.xml
**/.idea/shelf/*
**/.idea/dictionaries
**/.idea/httpRequests/
# Sensitive or high-churn files
**/.idea/**/dataSources/
**/.idea/**/dataSources.ids
**/.idea/**/dataSources.xml
**/.idea/**/dataSources.local.xml
**/.idea/**/sqlDataSources.xml
**/.idea/**/dynamic.xml
# Rider
# Rider auto-generates .iml files, and contentModel.xml
**/.idea/**/*.iml
**/.idea/**/contentModel.xml
**/.idea/**/modules.xml
[Pp]ackages/
.idea/
Thumbs.db
Desktop.ini
.DS_Store

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectricLocomotive", "lab1\ElectricLocomotive.csproj", "{1873D890-4FFF-4880-BEA6-DFF8127E35CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1873D890-4FFF-4880-BEA6-DFF8127E35CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1873D890-4FFF-4880-BEA6-DFF8127E35CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1873D890-4FFF-4880-BEA6-DFF8127E35CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1873D890-4FFF-4880-BEA6-DFF8127E35CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CFC6C768-9D70-4856-A850-6C5A15A7C83C}
EndGlobalSection
EndGlobal

View File

@ -1,30 +0,0 @@
using System.Drawing.Drawing2D;
namespace ElectricLocomotive;
public class DrawingElectricLocomotiv : DrawingLocomotiv
{
public DrawingElectricLocomotiv(int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor) : base(speed, weight, width,
height, mainColor, dopColor)
{
if (EntityLocomotiv != null)
{
EntityLocomotiv = new EntityElectricLocomotiv(speed, weight, batteryColor, rogaColor, mainColor, dopColor);
}
}
public override void DrawLoco(Graphics g)
{
if (EntityLocomotiv == null) return;
base.DrawLoco(g);
if (EntityLocomotiv is not EntityElectricLocomotiv electricLocomotiv) return;
SolidBrush batteryBrush = new(electricLocomotiv.BatteryColor);
Pen rogaPen = new(electricLocomotiv.RogaColor);
//Roga
g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15));
g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY));
//battery
Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) };
g.FillPolygon(batteryBrush, batteryPoints);
}
}

View File

@ -1,138 +0,0 @@
using ElectricLocomotive;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectricLocomotive
{
public class DrawingLocomotiv
{
public EntityLocomotiv? EntityLocomotiv { get; protected set; }
protected int _pictureWidth;
protected int _pictureHeight;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _vehicleWidth;
public int GetHeight => _vehicleHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _vehicleWidth = 170;
protected readonly int _vehicleHeight = 110;
public IMoveableObject GetMoveableObject => new DrawingObjectLocomotiv(this);
public DrawingLocomotiv(int speed, double weight,int width,int height, Color mainColor, Color dopColor)
{
if (width <= _vehicleWidth || height <= _vehicleHeight) {
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityLocomotiv = new EntityLocomotiv(speed, weight, mainColor, dopColor);
}
protected DrawingLocomotiv(int speed, double weight,int width,int height, int vehicleHeight, int vehicleWidth, Color mainColor, Color dopColor)
{
if (width <= _vehicleWidth || height <= _vehicleHeight) {
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityLocomotiv = new EntityLocomotiv(speed, weight, mainColor, dopColor);
}
public bool CanMove(DirectionType direction)
{
if (EntityLocomotiv == null)
return false;
return direction switch
{
DirectionType.Left => _startPosX - EntityLocomotiv.Step > 0,
DirectionType.Up => _startPosY - EntityLocomotiv.Step > 0,
DirectionType.Right => _startPosX + EntityLocomotiv.Step < _pictureWidth,
DirectionType.Down => _startPosY -+ EntityLocomotiv.Step < _pictureHeight
};
}
public void SetPosition(int x,int y)
{
if (EntityLocomotiv == null) return;
_startPosX = x;
_startPosY = y;
if (x + _vehicleWidth >= _pictureWidth || y + _vehicleHeight >= _pictureHeight)
{
_startPosX = 1;
_startPosY = 1;
}
}
public void MoveTransport(DirectionType direction)
{
if (EntityLocomotiv == null) return;
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityLocomotiv.Step > 0)
{
_startPosX -= (int)EntityLocomotiv.Step;
}
break;
case DirectionType.Right:
if (_startPosX + EntityLocomotiv.Step + _vehicleWidth < _pictureWidth)
{
_startPosX += (int)EntityLocomotiv.Step;
}
break;
case DirectionType.Up:
if (_startPosY - EntityLocomotiv.Step > 0)
{
_startPosY -= (int)EntityLocomotiv.Step;
}
break;
case DirectionType.Down:
if (_startPosY + EntityLocomotiv.Step + _vehicleHeight < _pictureHeight)
{
_startPosY += (int)EntityLocomotiv.Step;
}
break;
}
}
public virtual void DrawLoco(Graphics g)
{
if (EntityLocomotiv == null) return;
Pen penBody = new(EntityLocomotiv.ColorBody, 3);
Pen penWindow = new(EntityLocomotiv.ColorWindow, 3);
SolidBrush doorBrush = new(EntityLocomotiv.ColorFillBody);
Pen penWheel = new(EntityLocomotiv.ColorBody, 2);
//Body
g.DrawRectangle(penBody, _startPosX, _startPosY + _vehicleHeight - 50, _vehicleWidth - 10, _vehicleHeight - 80);
Point[] upBodyPoints = { new Point(_startPosX, _startPosY + 60), new Point(_startPosX + 10, _startPosY + 30), new Point(_startPosX + 150, _startPosY + 30), new Point(_startPosX + 160, _startPosY + 60) };
g.DrawPolygon(penBody, upBodyPoints);
//Door
g.DrawRectangle(penBody, _startPosX + _vehicleWidth / 2 - 15, _startPosY + 45, _vehicleWidth / 10, _vehicleHeight / 2 - 10);
g.FillRectangle(doorBrush, _startPosX + _vehicleWidth / 2 - 14, _startPosY + 46, _vehicleWidth / 10 - 1, _vehicleHeight / 2 - 12);
//Windows
int xWindow = _startPosX + 15;
int yWindow = _startPosY + 37;
for (int i = 0; i < 2; i++)
{
g.DrawRectangle(penWindow, xWindow, yWindow, 15, 15);
xWindow += 25;
}
xWindow += 35;
for (int i = 0; i < 2; i++)
{
g.DrawRectangle(penWindow, xWindow, yWindow, 15, 15);
xWindow += 25;
}
//wheels
int xWheel = _startPosX + 5;
int yWheel = _startPosY + _vehicleHeight - 20;
for (int i = 0; i < 4; i++)
{
g.DrawEllipse(penWheel, xWheel, yWheel, 20, 20);
xWheel += 40;
}
}
}
}

View File

@ -1,23 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="FormLocomotivCollection.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@ -1,12 +0,0 @@
namespace ElectricLocomotive;
public class EntityElectricLocomotiv : EntityLocomotiv
{
public Color BatteryColor { get; private set; }
public Color RogaColor { get; private set; }
public EntityElectricLocomotiv(int speed,double weight, Color batteryColor, Color rogaColor, Color mainColor, Color dopColor) : base(speed, weight, mainColor, dopColor)
{
BatteryColor = batteryColor;
RogaColor = rogaColor;
}
}

View File

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectricLocomotive
{
public class EntityLocomotiv
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public Color ColorBody = Color.Black;
public Color ColorWindow = Color.Blue;
public readonly Color ColorFillBody = Color.White;
public EntityLocomotiv(int speed,double weight, Color mainColor, Color dopColor)
{
Speed = speed;
Weight = weight;
ColorBody = mainColor;
ColorWindow = dopColor;
}
}
}

View File

@ -1,178 +0,0 @@
namespace ElectricLocomotive {
partial class FormLocomotiv {
/// <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() {
locoBox = new PictureBox();
moveRightButton = new Button();
moveDownButton = new Button();
moveLeftButton = new Button();
moveUpButton = new Button();
paintLocoButton = new Button();
paintElectricLocoButton = new Button();
movesBox = new ComboBox();
moveButton = new Button();
selectLocoButton = new Button();
((System.ComponentModel.ISupportInitialize)locoBox).BeginInit();
SuspendLayout();
//
// locoBox
//
locoBox.Dock = DockStyle.Fill;
locoBox.Location = new Point(0, 0);
locoBox.Name = "locoBox";
locoBox.Size = new Size(1265, 731);
locoBox.SizeMode = PictureBoxSizeMode.AutoSize;
locoBox.TabIndex = 0;
locoBox.TabStop = false;
//
// moveRightButton
//
moveRightButton.Location = new Point(1168, 647);
moveRightButton.Margin = new Padding(0);
moveRightButton.Name = "moveRightButton";
moveRightButton.Size = new Size(76, 60);
moveRightButton.TabIndex = 4;
moveRightButton.Text = "Вправо";
moveRightButton.UseVisualStyleBackColor = true;
moveRightButton.Click += MoveSideButton_Click;
//
// moveDownButton
//
moveDownButton.Location = new Point(1083, 647);
moveDownButton.Margin = new Padding(0);
moveDownButton.Name = "moveDownButton";
moveDownButton.Size = new Size(76, 60);
moveDownButton.TabIndex = 3;
moveDownButton.Text = "Вниз";
moveDownButton.UseVisualStyleBackColor = true;
moveDownButton.Click += MoveSideButton_Click;
//
// moveLeftButton
//
moveLeftButton.Location = new Point(997, 647);
moveLeftButton.Margin = new Padding(0);
moveLeftButton.Name = "moveLeftButton";
moveLeftButton.Size = new Size(76, 60);
moveLeftButton.TabIndex = 2;
moveLeftButton.Text = "Влево";
moveLeftButton.UseVisualStyleBackColor = true;
moveLeftButton.Click += MoveSideButton_Click;
//
// moveUpButton
//
moveUpButton.Location = new Point(1083, 571);
moveUpButton.Margin = new Padding(0);
moveUpButton.Name = "moveUpButton";
moveUpButton.Size = new Size(76, 60);
moveUpButton.TabIndex = 1;
moveUpButton.Text = "Вверх";
moveUpButton.UseVisualStyleBackColor = true;
moveUpButton.Click += MoveSideButton_Click;
//
// paintLocoButton
//
paintLocoButton.Location = new Point(36, 643);
paintLocoButton.Name = "paintLocoButton";
paintLocoButton.Size = new Size(179, 68);
paintLocoButton.TabIndex = 0;
paintLocoButton.Text = "Нарисовать локомотив";
paintLocoButton.UseVisualStyleBackColor = true;
paintLocoButton.Click += PaintLocoButton_click;
//
// paintElectricLocoButton
//
paintElectricLocoButton.Location = new Point(250, 647);
paintElectricLocoButton.Name = "paintElectricLocoButton";
paintElectricLocoButton.Size = new Size(189, 64);
paintElectricLocoButton.TabIndex = 5;
paintElectricLocoButton.Text = "Нарисовать электровоз";
paintElectricLocoButton.UseVisualStyleBackColor = true;
paintElectricLocoButton.Click += PaintElectricLocoButton_click;
//
// movesBox
//
movesBox.FormattingEnabled = true;
movesBox.Items.AddRange(new object[] { "Довести до края", "Довести до центра" });
movesBox.Location = new Point(1093, 12);
movesBox.Name = "movesBox";
movesBox.Size = new Size(151, 28);
movesBox.TabIndex = 6;
//
// moveButton
//
moveButton.Location = new Point(1093, 58);
moveButton.Name = "moveButton";
moveButton.Size = new Size(151, 29);
moveButton.TabIndex = 7;
moveButton.Text = "Шаг";
moveButton.UseVisualStyleBackColor = true;
moveButton.Click += MoveButton_Click;
//
// selectLocoButton
//
selectLocoButton.Location = new Point(491, 647);
selectLocoButton.Name = "selectLocoButton";
selectLocoButton.Size = new Size(198, 64);
selectLocoButton.TabIndex = 8;
selectLocoButton.Text = "Выбрать локомотив";
selectLocoButton.UseVisualStyleBackColor = true;
selectLocoButton.Click += selectLocoButton_Click;
//
// FormLocomotiv
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1265, 731);
Controls.Add(selectLocoButton);
Controls.Add(moveButton);
Controls.Add(movesBox);
Controls.Add(paintElectricLocoButton);
Controls.Add(moveRightButton);
Controls.Add(moveDownButton);
Controls.Add(moveLeftButton);
Controls.Add(moveUpButton);
Controls.Add(paintLocoButton);
Controls.Add(locoBox);
FormBorderStyle = FormBorderStyle.FixedSingle;
Name = "FormLocomotiv";
StartPosition = FormStartPosition.CenterScreen;
Text = "Лабораторная работа 1";
((System.ComponentModel.ISupportInitialize)locoBox).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button paintLocoButton;
private Button moveRightButton;
private Button moveDownButton;
private Button moveLeftButton;
private Button moveUpButton;
private PictureBox locoBox;
private Button paintElectricLocoButton;
private ComboBox movesBox;
private Button moveButton;
private Button selectLocoButton;
}
}

View File

@ -1,108 +0,0 @@
using ElectricLocomotive;
namespace ElectricLocomotive {
public partial class FormLocomotiv : Form {
private DrawingLocomotiv? _drawingLocomotiv;
private AbstractStrategy? _abstractStrategy;
public DrawingLocomotiv? SelectedLocomotiv { get; private set; }
public FormLocomotiv() {
InitializeComponent();
_abstractStrategy = null;
SelectedLocomotiv = null;
}
private void Draw() {
if (_drawingLocomotiv == null) return;
Bitmap bmp = new(locoBox.Width, locoBox.Height);
Graphics g = Graphics.FromImage(bmp);
_drawingLocomotiv.DrawLoco(g);
locoBox.Image = bmp;
}
private void PaintLocoButton_click(object sender, EventArgs e) {
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
color = dialog.Color;
_drawingLocomotiv = new DrawingLocomotiv(random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor);
_drawingLocomotiv.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void PaintElectricLocoButton_click(object sender, EventArgs e) {
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color batteryColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color rogaColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
color = dialog.Color;
if (dialog.ShowDialog() == DialogResult.OK)
dopColor = dialog.Color;
_drawingLocomotiv = new DrawingElectricLocomotiv(random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor, batteryColor, rogaColor);
_drawingLocomotiv.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void MoveSideButton_Click(object sender, EventArgs e) {
if (_drawingLocomotiv == null) return;
Control button = sender as Control;
string name = button.Name;
switch (name) {
case "moveUpButton":
_drawingLocomotiv.MoveTransport(DirectionType.Up);
break;
case "moveDownButton":
_drawingLocomotiv.MoveTransport(DirectionType.Down);
break;
case "moveLeftButton":
_drawingLocomotiv.MoveTransport(DirectionType.Left);
break;
case "moveRightButton":
_drawingLocomotiv.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void MoveButton_Click(object sender, EventArgs e) {
if (_drawingLocomotiv == null)
return;
if (movesBox.Enabled) {
_abstractStrategy = movesBox.SelectedIndex
switch {
0 => new MoveToEdge(),
1 => new MoveToCenter(),
_ => null,
};
if (_abstractStrategy == null) {
return;
}
_abstractStrategy.SetData(new
DrawingObjectLocomotiv(_drawingLocomotiv), locoBox.Width,
locoBox.Height);
movesBox.Enabled = false;
}
if (_abstractStrategy == null) {
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish) {
movesBox.Enabled = true;
_abstractStrategy = null;
}
}
private void selectLocoButton_Click(object sender, EventArgs e) {
SelectedLocomotiv = _drawingLocomotiv;
DialogResult = DialogResult.OK;
}
}
}

View File

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

@ -1,121 +0,0 @@
using System.ComponentModel;
namespace ElectricLocomotive;
partial class FormLocomotivCollection {
/// <summary>
/// Required designer variable.
/// </summary>
private 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() {
toolsBox = new GroupBox();
refreshCollection = new Button();
deleteLoco = new Button();
input = new TextBox();
addLocomotiv = new Button();
collectionPictureBox = new PictureBox();
toolsBox.SuspendLayout();
((ISupportInitialize)collectionPictureBox).BeginInit();
SuspendLayout();
//
// toolsBox
//
toolsBox.Controls.Add(refreshCollection);
toolsBox.Controls.Add(deleteLoco);
toolsBox.Controls.Add(input);
toolsBox.Controls.Add(addLocomotiv);
toolsBox.Location = new Point(944, 12);
toolsBox.Name = "toolsBox";
toolsBox.Size = new Size(309, 707);
toolsBox.TabIndex = 0;
toolsBox.TabStop = false;
toolsBox.Text = "Инструменты";
//
// refreshCollection
//
refreshCollection.Location = new Point(19, 324);
refreshCollection.Name = "refreshCollection";
refreshCollection.Size = new Size(271, 59);
refreshCollection.TabIndex = 3;
refreshCollection.Text = "Обновить коллекцию";
refreshCollection.UseVisualStyleBackColor = true;
refreshCollection.Click += refreshCollection_Click;
//
// deleteLoco
//
deleteLoco.Location = new Point(21, 199);
deleteLoco.Name = "deleteLoco";
deleteLoco.Size = new Size(271, 59);
deleteLoco.TabIndex = 2;
deleteLoco.Text = "Удалить электровоз";
deleteLoco.UseVisualStyleBackColor = true;
deleteLoco.Click += deleteLoco_Click;
//
// input
//
input.Location = new Point(51, 152);
input.Name = "input";
input.Size = new Size(214, 27);
input.TabIndex = 1;
//
// addLocomotiv
//
addLocomotiv.Location = new Point(21, 40);
addLocomotiv.Name = "addLocomotiv";
addLocomotiv.Size = new Size(271, 59);
addLocomotiv.TabIndex = 0;
addLocomotiv.Text = "Добавить электровоз";
addLocomotiv.UseVisualStyleBackColor = true;
addLocomotiv.Click += addLocomotiv_Click;
//
// collectionPictureBox
//
collectionPictureBox.Location = new Point(12, 12);
collectionPictureBox.Name = "collectionPictureBox";
collectionPictureBox.Size = new Size(933, 707);
collectionPictureBox.TabIndex = 1;
collectionPictureBox.TabStop = false;
//
// FormLocomotivCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1265, 731);
Controls.Add(collectionPictureBox);
Controls.Add(toolsBox);
Name = "FormLocomotivCollection";
Text = "Набор локомотивов";
toolsBox.ResumeLayout(false);
toolsBox.PerformLayout();
((ISupportInitialize)collectionPictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox toolsBox;
private TextBox input;
private Button addLocomotiv;
private PictureBox collectionPictureBox;
private Button refreshCollection;
private Button deleteLoco;
}

View File

@ -1,42 +0,0 @@
namespace ElectricLocomotive;
public partial class FormLocomotivCollection : Form {
private readonly LocosGenericCollection<DrawingLocomotiv, DrawingObjectLocomotiv> _locos;
public FormLocomotivCollection() {
InitializeComponent();
_locos = new(collectionPictureBox.Width, collectionPictureBox.Height);
}
private void addLocomotiv_Click(object sender, EventArgs e) {
FormLocomotiv form = new();
if (form.ShowDialog() == DialogResult.OK) {
if (_locos + form.SelectedLocomotiv != null) {
MessageBox.Show("Объект добавлен");
collectionPictureBox.Image = _locos.ShowLocos();
}
else {
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void deleteLoco_Click(object sender, EventArgs e) {
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) {
return;
}
int pos = Convert.ToInt32(input.Text);
if (_locos - pos != null) {
MessageBox.Show("Объект удален");
collectionPictureBox.Image = _locos.ShowLocos();
}
else {
MessageBox.Show("Не удалось удалить объект");
}
}
private void refreshCollection_Click(object sender, EventArgs e) {
collectionPictureBox.Image = _locos.ShowLocos();
}
}

View File

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

@ -1,76 +0,0 @@
namespace ElectricLocomotive;
public class LocosGenericCollection <T, U> where T : DrawingLocomotiv where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 170;
private readonly int _placeSizeHeight = 110;
private readonly SetGeneric<T> _collection;
public LocosGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static int operator +(LocosGenericCollection<T, U> collect, T?
obj)
{
if (obj == null) return -1;
return collect?._collection.Insert(obj) ?? -1;
}
public static bool operator -(LocosGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
return collect._collection.Remove(pos);
}
return false;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
public Bitmap ShowLocos()
{
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)
{
for (int i = 0; i < _collection.Count; i++) {
DrawingLocomotiv locomotiv = _collection.Get(i);
if (locomotiv != null) {
int inRow = _pictureWidth / _placeSizeWidth;
locomotiv.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight);
locomotiv.DrawLoco(g);
}
}
}
}

View File

@ -1,52 +0,0 @@
namespace ElectricLocomotive;
public 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 electricLocomotiv)
{
if (_places[Count - 1] != null)
return -1;
return Insert(electricLocomotiv, 0);
}
public int Insert(T electricLocomotiv, int position)
{
if (!(position >= 0 && position < Count))
return -1;
if (_places[position] != null) {
int ind = position;
while (ind < Count && _places[ind] != null)
ind++;
if (ind == Count)
return -1;
for (int i = ind - 1; i >= position; i--)
_places[i + 1] = _places[i];
}
_places[position] = electricLocomotiv;
return position;
}
public bool Remove(int position)
{
if (!(position >= 0 && position < Count) || _places[position] == null)
return false;
_places[position] = null;
return true;
}
public T? Get(int position)
{
if (!(position >= 0 && position < Count))
return null;
return _places[position];
}
}

View File

@ -1,79 +0,0 @@
namespace ElectricLocomotive;
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectricLocomotive
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -1,29 +0,0 @@
namespace ElectricLocomotive;
public class DrawingObjectLocomotiv : IMoveableObject
{
private readonly DrawingLocomotiv? _drawingLocomotiv = null;
public DrawingObjectLocomotiv(DrawingLocomotiv drawingLocomotiv)
{
_drawingLocomotiv = drawingLocomotiv;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawingLocomotiv == null || _drawingLocomotiv.EntityLocomotiv ==
null)
{
return null;
}
return new ObjectParameters(_drawingLocomotiv.GetPosX,
_drawingLocomotiv.GetPosY, _drawingLocomotiv.GetWidth, _drawingLocomotiv.GetHeight);
}
}
public int GetStep => (int)(_drawingLocomotiv?.EntityLocomotiv?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawingLocomotiv?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawingLocomotiv?.MoveTransport(direction);
}

View File

@ -1,12 +0,0 @@
namespace ElectricLocomotive;
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}

View File

@ -1,50 +0,0 @@
namespace ElectricLocomotive;
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -1,39 +0,0 @@
namespace ElectricLocomotive;
public class MoveToEdge: AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder < FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - (FieldWidth-1);
if (Math.Abs(diffX) > GetStep())
{
if (diffX < 0)
{
MoveRight();
}
}
var diffY = objParams.DownBorder - (FieldHeight-1);
if (Math.Abs(diffY) > GetStep())
{
if (diffY < 0)
{
MoveDown();
}
}
}
}

View File

@ -1,29 +0,0 @@
namespace ElectricLocomotive;
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}

View File

@ -1,8 +0,0 @@
namespace ElectricLocomotive;
public enum Status
{
NotInit = 1,
InProgress = 2,
Finish = 3
}

View File

@ -1,17 +0,0 @@
namespace ElectricLocomotive
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormLocomotivCollection());
}
}
}