Compare commits
No commits in common. "lab7" and "main" have entirely different histories.
28
.gitignore
vendored
28
.gitignore
vendored
@ -398,31 +398,3 @@ FodyWeavers.xsd
|
|||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.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
|
|
@ -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
|
|
@ -1,44 +0,0 @@
|
|||||||
using System.Drawing.Drawing2D;
|
|
||||||
|
|
||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public class DrawingElectricLocomotiv : DrawingLocomotiv
|
|
||||||
{
|
|
||||||
public bool isBattery;
|
|
||||||
public bool isRoga;
|
|
||||||
public DrawingElectricLocomotiv(int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor,bool isBattery, bool isRoga) : base(speed, weight, width,
|
|
||||||
height, mainColor, dopColor)
|
|
||||||
{
|
|
||||||
this.isBattery = isBattery;
|
|
||||||
this.isRoga = isRoga;
|
|
||||||
if (EntityLocomotiv != null)
|
|
||||||
{
|
|
||||||
EntityLocomotiv = new EntityElectricLocomotiv(speed, weight, batteryColor, rogaColor, mainColor, dopColor, isRoga, isBattery);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ChangeAddColor(Color col)
|
|
||||||
{
|
|
||||||
((EntityElectricLocomotiv)EntityLocomotiv).BatteryColor = col;
|
|
||||||
((EntityElectricLocomotiv)EntityLocomotiv).RogaColor = col;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
if (this.isRoga)
|
|
||||||
{
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isBattery)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,151 +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 void ChangeColor(Color col)
|
|
||||||
{
|
|
||||||
if (EntityLocomotiv == null)
|
|
||||||
return;
|
|
||||||
EntityLocomotiv.ColorBody = col;
|
|
||||||
EntityLocomotiv.ColorWindow = col;
|
|
||||||
}
|
|
||||||
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 void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
|
|
||||||
{
|
|
||||||
_pictureHeight = pictureBoxHeight;
|
|
||||||
_pictureWidth = pictureBoxWidth;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public static class ExtentionDrawingLocomotiv
|
|
||||||
{
|
|
||||||
public static DrawingLocomotiv? CreateDrawingLoco(this string info, char
|
|
||||||
separatorForObject, int width, int height)
|
|
||||||
{
|
|
||||||
string[] strs = info.Split(separatorForObject);
|
|
||||||
if (strs.Length == 4)
|
|
||||||
{
|
|
||||||
return new DrawingLocomotiv(Convert.ToInt32(strs[0]),
|
|
||||||
Convert.ToInt32(strs[1]), width, height,Color.FromName(strs[2]), Color.FromName(strs[3]));
|
|
||||||
}
|
|
||||||
if (strs.Length == 8)
|
|
||||||
{
|
|
||||||
return new DrawingElectricLocomotiv(
|
|
||||||
Convert.ToInt32(strs[0]),
|
|
||||||
Convert.ToInt32(strs[1]),
|
|
||||||
width, height,
|
|
||||||
Color.FromName(strs[2]),
|
|
||||||
Color.FromName(strs[3]),
|
|
||||||
Color.FromName(strs[4]),
|
|
||||||
Color.FromName(strs[5]),
|
|
||||||
Convert.ToBoolean(strs[6]),
|
|
||||||
Convert.ToBoolean(strs[7])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetDataForSave(this DrawingLocomotiv drawingLoco,
|
|
||||||
char separatorForObject)
|
|
||||||
{
|
|
||||||
var loco = drawingLoco.EntityLocomotiv;
|
|
||||||
if (loco == null)
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
var str =
|
|
||||||
$"{loco.Speed}{separatorForObject}{loco.Weight}" +
|
|
||||||
$"{separatorForObject}{loco.ColorBody.Name}" +
|
|
||||||
$"{separatorForObject}{loco.ColorWindow.Name}";
|
|
||||||
if (loco is not EntityElectricLocomotiv electricLocomotiv)
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return
|
|
||||||
$"{str}{separatorForObject}{electricLocomotiv.BatteryColor.Name}{separatorForObject}" +
|
|
||||||
$"{electricLocomotiv.RogaColor.Name}{separatorForObject}" +
|
|
||||||
$"{electricLocomotiv.isBattery}{separatorForObject}{electricLocomotiv.isRoga}";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +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>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
|
|
||||||
<PackageReference Include="Serilog" Version="3.1.2-dev-02097" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00968" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,16 +0,0 @@
|
|||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public class EntityElectricLocomotiv : EntityLocomotiv
|
|
||||||
{
|
|
||||||
public Color BatteryColor { get; set; }
|
|
||||||
public Color RogaColor { get; set; }
|
|
||||||
public bool isRoga;
|
|
||||||
public bool isBattery;
|
|
||||||
public EntityElectricLocomotiv(int speed,double weight, Color batteryColor, Color rogaColor, Color mainColor, Color dopColor, bool isRoga, bool isBattery) : base(speed, weight, mainColor, dopColor)
|
|
||||||
{
|
|
||||||
BatteryColor = batteryColor;
|
|
||||||
RogaColor = rogaColor;
|
|
||||||
this.isRoga = isRoga;
|
|
||||||
this.isBattery = isBattery;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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; set; }
|
|
||||||
public double Weight { get; 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace ElectricLocomotive.Exceptions;
|
|
||||||
|
|
||||||
public class LocoNotFoundException : ApplicationException
|
|
||||||
{
|
|
||||||
public LocoNotFoundException(int i) : base($"Не найден объект попозиции {i}") { }
|
|
||||||
public LocoNotFoundException() : base() { }
|
|
||||||
public LocoNotFoundException(string message) : base(message) { }
|
|
||||||
public LocoNotFoundException(string message, Exception exception) :
|
|
||||||
base(message, exception) { }
|
|
||||||
protected LocoNotFoundException(SerializationInfo info,
|
|
||||||
StreamingContext contex) : base(info, contex) { }
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
|
|
||||||
namespace ElectricLocomotive.Exceptions;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class StorageOverflowException: ApplicationException
|
|
||||||
{
|
|
||||||
|
|
||||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
|
||||||
public StorageOverflowException() : base() { }
|
|
||||||
public StorageOverflowException(string message) : base(message) { }
|
|
||||||
public StorageOverflowException(string message, Exception exception)
|
|
||||||
: base(message, exception) { }
|
|
||||||
protected StorageOverflowException(SerializationInfo info,
|
|
||||||
StreamingContext contex) : base(info, contex) { }
|
|
||||||
}
|
|
350
lab1/FormLocoConfig.Designer.cs
generated
350
lab1/FormLocoConfig.Designer.cs
generated
@ -1,350 +0,0 @@
|
|||||||
namespace ElectricLocomotive {
|
|
||||||
partial class FormLocoConfig {
|
|
||||||
/// <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() {
|
|
||||||
mainGroupBox = new GroupBox();
|
|
||||||
checkBoxBattery = new CheckBox();
|
|
||||||
checkBoxRoga = new CheckBox();
|
|
||||||
labelAdvanced = new Label();
|
|
||||||
labelSimple = new Label();
|
|
||||||
groupBoxColors = new GroupBox();
|
|
||||||
panelPurple = new Panel();
|
|
||||||
panelYellow = new Panel();
|
|
||||||
panelBlack = new Panel();
|
|
||||||
panelBlue = new Panel();
|
|
||||||
panelGray = new Panel();
|
|
||||||
panelGreen = new Panel();
|
|
||||||
panelWhite = new Panel();
|
|
||||||
panelRed = new Panel();
|
|
||||||
numericUpDownWeight = new NumericUpDown();
|
|
||||||
numericUpDownSpeed = new NumericUpDown();
|
|
||||||
label2 = new Label();
|
|
||||||
label1 = new Label();
|
|
||||||
rightPanel = new Panel();
|
|
||||||
labelAddColor = new Label();
|
|
||||||
labelColor = new Label();
|
|
||||||
pictureBox = new PictureBox();
|
|
||||||
buttonAdd = new Button();
|
|
||||||
buttonCancel = new Button();
|
|
||||||
mainGroupBox.SuspendLayout();
|
|
||||||
groupBoxColors.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
|
||||||
rightPanel.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// mainGroupBox
|
|
||||||
//
|
|
||||||
mainGroupBox.Controls.Add(checkBoxBattery);
|
|
||||||
mainGroupBox.Controls.Add(checkBoxRoga);
|
|
||||||
mainGroupBox.Controls.Add(labelAdvanced);
|
|
||||||
mainGroupBox.Controls.Add(labelSimple);
|
|
||||||
mainGroupBox.Controls.Add(groupBoxColors);
|
|
||||||
mainGroupBox.Controls.Add(numericUpDownWeight);
|
|
||||||
mainGroupBox.Controls.Add(numericUpDownSpeed);
|
|
||||||
mainGroupBox.Controls.Add(label2);
|
|
||||||
mainGroupBox.Controls.Add(label1);
|
|
||||||
mainGroupBox.Location = new Point(12, 12);
|
|
||||||
mainGroupBox.Name = "mainGroupBox";
|
|
||||||
mainGroupBox.Size = new Size(656, 289);
|
|
||||||
mainGroupBox.TabIndex = 0;
|
|
||||||
mainGroupBox.TabStop = false;
|
|
||||||
mainGroupBox.Text = "Параметры";
|
|
||||||
//
|
|
||||||
// checkBoxBattery
|
|
||||||
//
|
|
||||||
checkBoxBattery.AutoSize = true;
|
|
||||||
checkBoxBattery.Location = new Point(25, 194);
|
|
||||||
checkBoxBattery.Name = "checkBoxBattery";
|
|
||||||
checkBoxBattery.Size = new Size(215, 24);
|
|
||||||
checkBoxBattery.TabIndex = 8;
|
|
||||||
checkBoxBattery.Text = "Признак наличия батарей";
|
|
||||||
checkBoxBattery.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// checkBoxRoga
|
|
||||||
//
|
|
||||||
checkBoxRoga.AutoSize = true;
|
|
||||||
checkBoxRoga.Location = new Point(25, 150);
|
|
||||||
checkBoxRoga.Name = "checkBoxRoga";
|
|
||||||
checkBoxRoga.Size = new Size(199, 24);
|
|
||||||
checkBoxRoga.TabIndex = 7;
|
|
||||||
checkBoxRoga.Text = "Признак наличия рогов";
|
|
||||||
checkBoxRoga.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// labelAdvanced
|
|
||||||
//
|
|
||||||
labelAdvanced.BorderStyle = BorderStyle.FixedSingle;
|
|
||||||
labelAdvanced.Location = new Point(498, 231);
|
|
||||||
labelAdvanced.Name = "labelAdvanced";
|
|
||||||
labelAdvanced.Size = new Size(141, 44);
|
|
||||||
labelAdvanced.TabIndex = 6;
|
|
||||||
labelAdvanced.Text = "Продвинутый";
|
|
||||||
labelAdvanced.TextAlign = ContentAlignment.MiddleCenter;
|
|
||||||
//
|
|
||||||
// labelSimple
|
|
||||||
//
|
|
||||||
labelSimple.BorderStyle = BorderStyle.FixedSingle;
|
|
||||||
labelSimple.Location = new Point(323, 231);
|
|
||||||
labelSimple.Name = "labelSimple";
|
|
||||||
labelSimple.Size = new Size(141, 44);
|
|
||||||
labelSimple.TabIndex = 5;
|
|
||||||
labelSimple.Text = "Простой";
|
|
||||||
labelSimple.TextAlign = ContentAlignment.MiddleCenter;
|
|
||||||
labelSimple.MouseDown += labelSimple_MouseDown;
|
|
||||||
//
|
|
||||||
// groupBoxColors
|
|
||||||
//
|
|
||||||
groupBoxColors.Controls.Add(panelPurple);
|
|
||||||
groupBoxColors.Controls.Add(panelYellow);
|
|
||||||
groupBoxColors.Controls.Add(panelBlack);
|
|
||||||
groupBoxColors.Controls.Add(panelBlue);
|
|
||||||
groupBoxColors.Controls.Add(panelGray);
|
|
||||||
groupBoxColors.Controls.Add(panelGreen);
|
|
||||||
groupBoxColors.Controls.Add(panelWhite);
|
|
||||||
groupBoxColors.Controls.Add(panelRed);
|
|
||||||
groupBoxColors.Location = new Point(323, 26);
|
|
||||||
groupBoxColors.Name = "groupBoxColors";
|
|
||||||
groupBoxColors.Size = new Size(316, 192);
|
|
||||||
groupBoxColors.TabIndex = 4;
|
|
||||||
groupBoxColors.TabStop = false;
|
|
||||||
groupBoxColors.Text = "Цвета";
|
|
||||||
//
|
|
||||||
// panelPurple
|
|
||||||
//
|
|
||||||
panelPurple.BackColor = Color.Purple;
|
|
||||||
panelPurple.Location = new Point(239, 114);
|
|
||||||
panelPurple.Name = "panelPurple";
|
|
||||||
panelPurple.Size = new Size(60, 56);
|
|
||||||
panelPurple.TabIndex = 3;
|
|
||||||
//
|
|
||||||
// panelYellow
|
|
||||||
//
|
|
||||||
panelYellow.BackColor = Color.Yellow;
|
|
||||||
panelYellow.Location = new Point(239, 38);
|
|
||||||
panelYellow.Name = "panelYellow";
|
|
||||||
panelYellow.Size = new Size(60, 56);
|
|
||||||
panelYellow.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// panelBlack
|
|
||||||
//
|
|
||||||
panelBlack.BackColor = Color.Black;
|
|
||||||
panelBlack.Location = new Point(159, 114);
|
|
||||||
panelBlack.Name = "panelBlack";
|
|
||||||
panelBlack.Size = new Size(60, 56);
|
|
||||||
panelBlack.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// panelBlue
|
|
||||||
//
|
|
||||||
panelBlue.BackColor = Color.Navy;
|
|
||||||
panelBlue.Location = new Point(159, 38);
|
|
||||||
panelBlue.Name = "panelBlue";
|
|
||||||
panelBlue.Size = new Size(60, 56);
|
|
||||||
panelBlue.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// panelGray
|
|
||||||
//
|
|
||||||
panelGray.BackColor = Color.Gray;
|
|
||||||
panelGray.Location = new Point(81, 114);
|
|
||||||
panelGray.Name = "panelGray";
|
|
||||||
panelGray.Size = new Size(60, 56);
|
|
||||||
panelGray.TabIndex = 5;
|
|
||||||
//
|
|
||||||
// panelGreen
|
|
||||||
//
|
|
||||||
panelGreen.BackColor = Color.Green;
|
|
||||||
panelGreen.Location = new Point(81, 38);
|
|
||||||
panelGreen.Name = "panelGreen";
|
|
||||||
panelGreen.Size = new Size(60, 56);
|
|
||||||
panelGreen.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// panelWhite
|
|
||||||
//
|
|
||||||
panelWhite.BackColor = Color.White;
|
|
||||||
panelWhite.Location = new Point(6, 114);
|
|
||||||
panelWhite.Name = "panelWhite";
|
|
||||||
panelWhite.Size = new Size(60, 56);
|
|
||||||
panelWhite.TabIndex = 2;
|
|
||||||
//
|
|
||||||
// panelRed
|
|
||||||
//
|
|
||||||
panelRed.BackColor = Color.Red;
|
|
||||||
panelRed.Location = new Point(6, 38);
|
|
||||||
panelRed.Name = "panelRed";
|
|
||||||
panelRed.Size = new Size(60, 56);
|
|
||||||
panelRed.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// numericUpDownWeight
|
|
||||||
//
|
|
||||||
numericUpDownWeight.Location = new Point(113, 82);
|
|
||||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
|
||||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
|
||||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
|
||||||
numericUpDownWeight.Size = new Size(75, 27);
|
|
||||||
numericUpDownWeight.TabIndex = 3;
|
|
||||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
|
||||||
//
|
|
||||||
// numericUpDownSpeed
|
|
||||||
//
|
|
||||||
numericUpDownSpeed.Location = new Point(113, 42);
|
|
||||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
|
||||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
|
||||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
|
||||||
numericUpDownSpeed.Size = new Size(75, 27);
|
|
||||||
numericUpDownSpeed.TabIndex = 2;
|
|
||||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
|
||||||
//
|
|
||||||
// label2
|
|
||||||
//
|
|
||||||
label2.AutoSize = true;
|
|
||||||
label2.Location = new Point(19, 82);
|
|
||||||
label2.Name = "label2";
|
|
||||||
label2.Size = new Size(33, 20);
|
|
||||||
label2.TabIndex = 1;
|
|
||||||
label2.Text = "Вес";
|
|
||||||
//
|
|
||||||
// label1
|
|
||||||
//
|
|
||||||
label1.AutoSize = true;
|
|
||||||
label1.Location = new Point(19, 42);
|
|
||||||
label1.Name = "label1";
|
|
||||||
label1.Size = new Size(73, 20);
|
|
||||||
label1.TabIndex = 0;
|
|
||||||
label1.Text = "Скорость";
|
|
||||||
//
|
|
||||||
// rightPanel
|
|
||||||
//
|
|
||||||
rightPanel.AllowDrop = true;
|
|
||||||
rightPanel.Controls.Add(labelAddColor);
|
|
||||||
rightPanel.Controls.Add(labelColor);
|
|
||||||
rightPanel.Controls.Add(pictureBox);
|
|
||||||
rightPanel.Location = new Point(689, 21);
|
|
||||||
rightPanel.Name = "rightPanel";
|
|
||||||
rightPanel.Size = new Size(348, 234);
|
|
||||||
rightPanel.TabIndex = 1;
|
|
||||||
rightPanel.DragDrop += rightPanel_DragDrop;
|
|
||||||
rightPanel.DragEnter += rightPanel_DragEnter;
|
|
||||||
//
|
|
||||||
// labelAddColor
|
|
||||||
//
|
|
||||||
labelAddColor.AllowDrop = true;
|
|
||||||
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
|
|
||||||
labelAddColor.Location = new Point(184, 12);
|
|
||||||
labelAddColor.Name = "labelAddColor";
|
|
||||||
labelAddColor.Size = new Size(149, 40);
|
|
||||||
labelAddColor.TabIndex = 2;
|
|
||||||
labelAddColor.Text = "Доп. Цвет";
|
|
||||||
labelAddColor.TextAlign = ContentAlignment.MiddleCenter;
|
|
||||||
labelAddColor.DragDrop += labelAddColor_DragDrop;
|
|
||||||
labelAddColor.DragEnter += labelAddColor_DragEnter;
|
|
||||||
//
|
|
||||||
// labelColor
|
|
||||||
//
|
|
||||||
labelColor.AllowDrop = true;
|
|
||||||
labelColor.BorderStyle = BorderStyle.FixedSingle;
|
|
||||||
labelColor.Location = new Point(16, 12);
|
|
||||||
labelColor.Name = "labelColor";
|
|
||||||
labelColor.Size = new Size(149, 40);
|
|
||||||
labelColor.TabIndex = 1;
|
|
||||||
labelColor.Text = "Цвет";
|
|
||||||
labelColor.TextAlign = ContentAlignment.MiddleCenter;
|
|
||||||
labelColor.DragDrop += labelColor_DragDrop;
|
|
||||||
labelColor.DragEnter += labelColor_DragEnter;
|
|
||||||
//
|
|
||||||
// pictureBox
|
|
||||||
//
|
|
||||||
pictureBox.Location = new Point(16, 55);
|
|
||||||
pictureBox.Name = "pictureBox";
|
|
||||||
pictureBox.Size = new Size(317, 165);
|
|
||||||
pictureBox.TabIndex = 0;
|
|
||||||
pictureBox.TabStop = false;
|
|
||||||
//
|
|
||||||
// buttonAdd
|
|
||||||
//
|
|
||||||
buttonAdd.Location = new Point(689, 266);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
|
||||||
buttonAdd.Size = new Size(165, 35);
|
|
||||||
buttonAdd.TabIndex = 2;
|
|
||||||
buttonAdd.Text = "Добавить";
|
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
|
||||||
buttonAdd.Click += buttonAdd_Click;
|
|
||||||
//
|
|
||||||
// buttonCancel
|
|
||||||
//
|
|
||||||
buttonCancel.Location = new Point(872, 266);
|
|
||||||
buttonCancel.Name = "buttonCancel";
|
|
||||||
buttonCancel.Size = new Size(165, 35);
|
|
||||||
buttonCancel.TabIndex = 3;
|
|
||||||
buttonCancel.Text = "Отмена";
|
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// FormLocoConfig
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(1053, 313);
|
|
||||||
Controls.Add(buttonCancel);
|
|
||||||
Controls.Add(buttonAdd);
|
|
||||||
Controls.Add(rightPanel);
|
|
||||||
Controls.Add(mainGroupBox);
|
|
||||||
Name = "FormLocoConfig";
|
|
||||||
Text = "Создание объекта";
|
|
||||||
mainGroupBox.ResumeLayout(false);
|
|
||||||
mainGroupBox.PerformLayout();
|
|
||||||
groupBoxColors.ResumeLayout(false);
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
|
||||||
rightPanel.ResumeLayout(false);
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private GroupBox mainGroupBox;
|
|
||||||
private Label label1;
|
|
||||||
private Label label2;
|
|
||||||
private NumericUpDown numericUpDownSpeed;
|
|
||||||
private Label labelSimple;
|
|
||||||
private GroupBox groupBoxColors;
|
|
||||||
private NumericUpDown numericUpDownWeight;
|
|
||||||
private Label labelAdvanced;
|
|
||||||
private Panel panelYellow;
|
|
||||||
private Panel panelBlue;
|
|
||||||
private Panel panelGreen;
|
|
||||||
private Panel panelRed;
|
|
||||||
private Panel panelPurple;
|
|
||||||
private Panel panelBlack;
|
|
||||||
private Panel panelGray;
|
|
||||||
private Panel panelWhite;
|
|
||||||
private CheckBox checkBoxBattery;
|
|
||||||
private CheckBox checkBoxRoga;
|
|
||||||
private Panel rightPanel;
|
|
||||||
private Label labelAddColor;
|
|
||||||
private Label labelColor;
|
|
||||||
private PictureBox pictureBox;
|
|
||||||
private Button buttonAdd;
|
|
||||||
private Button buttonCancel;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,125 +0,0 @@
|
|||||||
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 ElectricLocomotive {
|
|
||||||
public partial class FormLocoConfig : Form {
|
|
||||||
DrawingLocomotiv? _loco = null;
|
|
||||||
private event Action<DrawingLocomotiv>? EventAddLoco;
|
|
||||||
public void AddEvent(Action<DrawingLocomotiv> ev) {
|
|
||||||
if (EventAddLoco == null) {
|
|
||||||
EventAddLoco = ev;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
EventAddLoco += ev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public FormLocoConfig() {
|
|
||||||
InitializeComponent();
|
|
||||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelRed.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelGray.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
|
||||||
labelSimple.MouseDown += LabelObject_MouseDown;
|
|
||||||
labelAdvanced.MouseDown += LabelObject_MouseDown;
|
|
||||||
buttonCancel.Click += (s, e) => Close();
|
|
||||||
}
|
|
||||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e) {
|
|
||||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
|
||||||
DragDropEffects.Move | DragDropEffects.Copy);
|
|
||||||
}
|
|
||||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e) {
|
|
||||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
|
||||||
}
|
|
||||||
private void DrawLoco() {
|
|
||||||
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
|
||||||
_loco?.SetPosition(5, 5);
|
|
||||||
_loco?.DrawLoco(gr);
|
|
||||||
pictureBox.Image = bmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void labelSimple_MouseDown(object sender, MouseEventArgs e) {
|
|
||||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
|
||||||
DragDropEffects.Move | DragDropEffects.Copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rightPanel_DragEnter(object sender, DragEventArgs e) {
|
|
||||||
|
|
||||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) {
|
|
||||||
e.Effect = DragDropEffects.Copy;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
e.Effect = DragDropEffects.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rightPanel_DragDrop(object sender, DragEventArgs e) {
|
|
||||||
switch (e.Data?.GetData(DataFormats.Text).ToString()) {
|
|
||||||
case "labelSimple":
|
|
||||||
_loco = new DrawingLocomotiv((int)numericUpDownSpeed.Value,
|
|
||||||
(int)numericUpDownWeight.Value, pictureBox.Width,
|
|
||||||
pictureBox.Height, Color.Black, Color.Yellow);
|
|
||||||
break;
|
|
||||||
case "labelAdvanced":
|
|
||||||
_loco = new DrawingElectricLocomotiv((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, pictureBox.Width,
|
|
||||||
pictureBox.Height, Color.Black, Color.Yellow, Color.Aqua, Color.Black,checkBoxRoga.Checked, checkBoxBattery.Checked);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
labelColor.BackColor = Color.Empty;
|
|
||||||
labelAddColor.BackColor = Color.Empty;
|
|
||||||
DrawLoco();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e) {
|
|
||||||
EventAddLoco?.Invoke(_loco);
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void labelColor_DragEnter(object sender, DragEventArgs e) {
|
|
||||||
if (e.Data.GetDataPresent(typeof(Color))) {
|
|
||||||
e.Effect = DragDropEffects.Copy;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
e.Effect = DragDropEffects.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void labelColor_DragDrop(object sender, DragEventArgs e) {
|
|
||||||
if (_loco == null)
|
|
||||||
return;
|
|
||||||
labelColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
|
||||||
_loco.ChangeColor(labelColor.BackColor);
|
|
||||||
DrawLoco();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void labelAddColor_DragEnter(object sender, DragEventArgs e) {
|
|
||||||
if (e.Data.GetDataPresent(typeof(Color))) {
|
|
||||||
e.Effect = DragDropEffects.Copy;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
e.Effect = DragDropEffects.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void labelAddColor_DragDrop(object sender, DragEventArgs e) {
|
|
||||||
if ((_loco == null) || (_loco is DrawingElectricLocomotiv == false))
|
|
||||||
return;
|
|
||||||
labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
|
||||||
((DrawingElectricLocomotiv)_loco).ChangeAddColor(labelAddColor.BackColor);
|
|
||||||
DrawLoco();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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>
|
|
178
lab1/FormLocomotiv.Designer.cs
generated
178
lab1/FormLocomotiv.Designer.cs
generated
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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,true, true);
|
|
||||||
_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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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>
|
|
243
lab1/FormLocomotivCollection.Designer.cs
generated
243
lab1/FormLocomotivCollection.Designer.cs
generated
@ -1,243 +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();
|
|
||||||
collectionGroupBoxes = new GroupBox();
|
|
||||||
storageListBox = new ListBox();
|
|
||||||
delStorageButton = new Button();
|
|
||||||
addStorageButton = new Button();
|
|
||||||
storageIndexInput = new TextBox();
|
|
||||||
refreshCollection = new Button();
|
|
||||||
deleteLoco = new Button();
|
|
||||||
locoIndexInput = new TextBox();
|
|
||||||
addLocomotiv = new Button();
|
|
||||||
collectionPictureBox = new PictureBox();
|
|
||||||
menuStrip1 = new MenuStrip();
|
|
||||||
toolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
loadFileDialog = new OpenFileDialog();
|
|
||||||
saveFileDialog = new SaveFileDialog();
|
|
||||||
toolsBox.SuspendLayout();
|
|
||||||
collectionGroupBoxes.SuspendLayout();
|
|
||||||
((ISupportInitialize)collectionPictureBox).BeginInit();
|
|
||||||
menuStrip1.SuspendLayout();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// toolsBox
|
|
||||||
//
|
|
||||||
toolsBox.Controls.Add(collectionGroupBoxes);
|
|
||||||
toolsBox.Controls.Add(refreshCollection);
|
|
||||||
toolsBox.Controls.Add(deleteLoco);
|
|
||||||
toolsBox.Controls.Add(locoIndexInput);
|
|
||||||
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 = "Инструменты";
|
|
||||||
//
|
|
||||||
// collectionGroupBoxes
|
|
||||||
//
|
|
||||||
collectionGroupBoxes.Controls.Add(storageListBox);
|
|
||||||
collectionGroupBoxes.Controls.Add(delStorageButton);
|
|
||||||
collectionGroupBoxes.Controls.Add(addStorageButton);
|
|
||||||
collectionGroupBoxes.Controls.Add(storageIndexInput);
|
|
||||||
collectionGroupBoxes.Location = new Point(7, 38);
|
|
||||||
collectionGroupBoxes.Name = "collectionGroupBoxes";
|
|
||||||
collectionGroupBoxes.Size = new Size(296, 325);
|
|
||||||
collectionGroupBoxes.TabIndex = 5;
|
|
||||||
collectionGroupBoxes.TabStop = false;
|
|
||||||
collectionGroupBoxes.Text = "Наборы";
|
|
||||||
//
|
|
||||||
// storageListBox
|
|
||||||
//
|
|
||||||
storageListBox.FormattingEnabled = true;
|
|
||||||
storageListBox.ItemHeight = 20;
|
|
||||||
storageListBox.Location = new Point(14, 139);
|
|
||||||
storageListBox.Name = "storageListBox";
|
|
||||||
storageListBox.Size = new Size(271, 124);
|
|
||||||
storageListBox.TabIndex = 7;
|
|
||||||
storageListBox.SelectedIndexChanged += storagesListBox_SelectedIndexChanged;
|
|
||||||
//
|
|
||||||
// delStorageButton
|
|
||||||
//
|
|
||||||
delStorageButton.Location = new Point(14, 278);
|
|
||||||
delStorageButton.Name = "delStorageButton";
|
|
||||||
delStorageButton.Size = new Size(271, 32);
|
|
||||||
delStorageButton.TabIndex = 6;
|
|
||||||
delStorageButton.Text = "Удалить набор";
|
|
||||||
delStorageButton.UseVisualStyleBackColor = true;
|
|
||||||
delStorageButton.Click += delStorageButton_Click;
|
|
||||||
//
|
|
||||||
// addStorageButton
|
|
||||||
//
|
|
||||||
addStorageButton.Location = new Point(14, 87);
|
|
||||||
addStorageButton.Name = "addStorageButton";
|
|
||||||
addStorageButton.Size = new Size(271, 31);
|
|
||||||
addStorageButton.TabIndex = 5;
|
|
||||||
addStorageButton.Text = "Добавить набор";
|
|
||||||
addStorageButton.UseVisualStyleBackColor = true;
|
|
||||||
addStorageButton.Click += addStorageButton_Click;
|
|
||||||
//
|
|
||||||
// storageIndexInput
|
|
||||||
//
|
|
||||||
storageIndexInput.Location = new Point(14, 41);
|
|
||||||
storageIndexInput.Name = "storageIndexInput";
|
|
||||||
storageIndexInput.Size = new Size(271, 27);
|
|
||||||
storageIndexInput.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// refreshCollection
|
|
||||||
//
|
|
||||||
refreshCollection.Location = new Point(21, 642);
|
|
||||||
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, 559);
|
|
||||||
deleteLoco.Name = "deleteLoco";
|
|
||||||
deleteLoco.Size = new Size(271, 59);
|
|
||||||
deleteLoco.TabIndex = 2;
|
|
||||||
deleteLoco.Text = "Удалить электровоз";
|
|
||||||
deleteLoco.UseVisualStyleBackColor = true;
|
|
||||||
deleteLoco.Click += deleteLoco_Click;
|
|
||||||
//
|
|
||||||
// locoIndexInput
|
|
||||||
//
|
|
||||||
locoIndexInput.Location = new Point(53, 512);
|
|
||||||
locoIndexInput.Name = "locoIndexInput";
|
|
||||||
locoIndexInput.Size = new Size(214, 27);
|
|
||||||
locoIndexInput.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// addLocomotiv
|
|
||||||
//
|
|
||||||
addLocomotiv.Location = new Point(21, 431);
|
|
||||||
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, 38);
|
|
||||||
collectionPictureBox.Name = "collectionPictureBox";
|
|
||||||
collectionPictureBox.Size = new Size(933, 681);
|
|
||||||
collectionPictureBox.TabIndex = 1;
|
|
||||||
collectionPictureBox.TabStop = false;
|
|
||||||
//
|
|
||||||
// menuStrip1
|
|
||||||
//
|
|
||||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
|
||||||
menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem });
|
|
||||||
menuStrip1.Location = new Point(0, 0);
|
|
||||||
menuStrip1.Name = "menuStrip1";
|
|
||||||
menuStrip1.Size = new Size(1265, 28);
|
|
||||||
menuStrip1.TabIndex = 3;
|
|
||||||
menuStrip1.Text = "menuStrip1";
|
|
||||||
//
|
|
||||||
// toolStripMenuItem
|
|
||||||
//
|
|
||||||
toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
|
||||||
toolStripMenuItem.Name = "toolStripMenuItem";
|
|
||||||
toolStripMenuItem.Size = new Size(59, 24);
|
|
||||||
toolStripMenuItem.Text = "Файл";
|
|
||||||
//
|
|
||||||
// SaveToolStripMenuItem
|
|
||||||
//
|
|
||||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
|
||||||
SaveToolStripMenuItem.Size = new Size(166, 26);
|
|
||||||
SaveToolStripMenuItem.Text = "Сохранить";
|
|
||||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
|
||||||
//
|
|
||||||
// LoadToolStripMenuItem
|
|
||||||
//
|
|
||||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
|
||||||
LoadToolStripMenuItem.Size = new Size(166, 26);
|
|
||||||
LoadToolStripMenuItem.Text = "Загрузить";
|
|
||||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
|
||||||
//
|
|
||||||
// loadFileDialog
|
|
||||||
//
|
|
||||||
loadFileDialog.FileName = "openFileDialog4";
|
|
||||||
loadFileDialog.Filter = "txt file | *.txt";
|
|
||||||
//
|
|
||||||
// saveFileDialog
|
|
||||||
//
|
|
||||||
saveFileDialog.Filter = "txt file | *.txt";
|
|
||||||
//
|
|
||||||
// FormLocomotivCollection
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(1265, 731);
|
|
||||||
Controls.Add(collectionPictureBox);
|
|
||||||
Controls.Add(toolsBox);
|
|
||||||
Controls.Add(menuStrip1);
|
|
||||||
MainMenuStrip = menuStrip1;
|
|
||||||
Name = "FormLocomotivCollection";
|
|
||||||
Text = "Набор локомотивов";
|
|
||||||
toolsBox.ResumeLayout(false);
|
|
||||||
toolsBox.PerformLayout();
|
|
||||||
collectionGroupBoxes.ResumeLayout(false);
|
|
||||||
collectionGroupBoxes.PerformLayout();
|
|
||||||
((ISupportInitialize)collectionPictureBox).EndInit();
|
|
||||||
menuStrip1.ResumeLayout(false);
|
|
||||||
menuStrip1.PerformLayout();
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private GroupBox toolsBox;
|
|
||||||
private TextBox locoIndexInput;
|
|
||||||
private Button addLocomotiv;
|
|
||||||
private PictureBox collectionPictureBox;
|
|
||||||
private Button refreshCollection;
|
|
||||||
private Button deleteLoco;
|
|
||||||
private GroupBox collectionGroupBoxes;
|
|
||||||
private Button delStorageButton;
|
|
||||||
private Button addStorageButton;
|
|
||||||
private TextBox storageIndexInput;
|
|
||||||
private ListBox storageListBox;
|
|
||||||
private MenuStrip menuStrip1;
|
|
||||||
private ToolStripMenuItem toolStripMenuItem;
|
|
||||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
|
||||||
private OpenFileDialog loadFileDialog;
|
|
||||||
private SaveFileDialog saveFileDialog;
|
|
||||||
}
|
|
@ -1,171 +0,0 @@
|
|||||||
using System.Windows.Forms;
|
|
||||||
using ElectricLocomotive.Exceptions;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public partial class FormLocomotivCollection : Form {
|
|
||||||
private readonly LocosGenericStorage _storage;
|
|
||||||
public FormLocomotivCollection() {
|
|
||||||
InitializeComponent();
|
|
||||||
_storage = new(collectionPictureBox.Width, collectionPictureBox.Height);
|
|
||||||
}
|
|
||||||
private void ReloadObjects() {
|
|
||||||
int index = storageListBox.SelectedIndex;
|
|
||||||
storageListBox.Items.Clear();
|
|
||||||
for (int i = 0; i < _storage.Keys.Count; i++) {
|
|
||||||
storageListBox.Items.Add(_storage.Keys[i]);
|
|
||||||
}
|
|
||||||
if (storageListBox.Items.Count > 0 && (index == -1 || index
|
|
||||||
>= storageListBox.Items.Count)) {
|
|
||||||
storageListBox.SelectedIndex = 0;
|
|
||||||
}
|
|
||||||
else if (storageListBox.Items.Count > 0 && index > -1 &&
|
|
||||||
index < storageListBox.Items.Count) {
|
|
||||||
storageListBox.SelectedIndex = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addLocomotiv_Click(object sender, EventArgs e) {
|
|
||||||
if (storageListBox.SelectedIndex == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var obj = _storage[storageListBox.SelectedItem.ToString() ?? string.Empty];
|
|
||||||
if (obj == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FormLocoConfig form = new();
|
|
||||||
form.Show();
|
|
||||||
Action<DrawingLocomotiv>? monorailDelegate = new((m) => {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bool q = obj + m;
|
|
||||||
MessageBox.Show("Объект добавлен");
|
|
||||||
Log.Information($"Добавлен объект в коллекцию {storageListBox.SelectedItem.ToString() ?? string.Empty}");
|
|
||||||
m.ChangePictureBoxSize(collectionPictureBox.Width, collectionPictureBox.Height);
|
|
||||||
collectionPictureBox.Image = obj.ShowLocos();
|
|
||||||
}
|
|
||||||
catch (StorageOverflowException ex)
|
|
||||||
{
|
|
||||||
Log.Warning($"Коллекция {storageListBox.SelectedItem.ToString() ?? string.Empty} переполнена");
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
form.AddEvent(monorailDelegate);
|
|
||||||
}
|
|
||||||
private void deleteLoco_Click(object sender, EventArgs e) {
|
|
||||||
if (storageListBox.SelectedIndex == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var obj = _storage[storageListBox.SelectedItem.ToString() ??
|
|
||||||
string.Empty];
|
|
||||||
if (obj == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int pos = Convert.ToInt32(locoIndexInput.Text);
|
|
||||||
var q = obj - pos;
|
|
||||||
MessageBox.Show("Объект удален");
|
|
||||||
Log.Information($"Удален объект из коллекции {storageListBox.SelectedItem.ToString() ?? string.Empty} по номеру {pos}");
|
|
||||||
collectionPictureBox.Image = obj.ShowLocos();
|
|
||||||
}
|
|
||||||
catch(LocoNotFoundException ex)
|
|
||||||
{
|
|
||||||
Log.Warning($"Не получилось удалить объект из коллекции {storageListBox.SelectedItem.ToString() ?? string.Empty}");
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
catch(FormatException ex)
|
|
||||||
{
|
|
||||||
Log.Warning($"Было введено не число");
|
|
||||||
MessageBox.Show("Введите число");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshCollection_Click(object sender, EventArgs e) {
|
|
||||||
if (storageListBox.SelectedIndex == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var obj = _storage[storageListBox.SelectedItem.ToString() ??
|
|
||||||
string.Empty];
|
|
||||||
if (obj == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
collectionPictureBox.Image = obj.ShowLocos();
|
|
||||||
}
|
|
||||||
private void storagesListBox_SelectedIndexChanged(object sender, EventArgs e) {
|
|
||||||
collectionPictureBox.Image =
|
|
||||||
_storage[storageListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowLocos();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void delStorageButton_Click(object sender, EventArgs e) {
|
|
||||||
if (storageListBox.SelectedIndex == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show($"Удалить объект{storageListBox.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
|
||||||
MessageBoxIcon.Question) == DialogResult.Yes) {
|
|
||||||
string name = storageListBox.SelectedItem.ToString() ?? string.Empty;
|
|
||||||
_storage.DelSet(name);
|
|
||||||
ReloadObjects();
|
|
||||||
Log.Information($"Удален набор: {name}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addStorageButton_Click(object sender, EventArgs e) {
|
|
||||||
if (string.IsNullOrEmpty(storageIndexInput.Text)) {
|
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_storage.AddSet(storageIndexInput.Text);
|
|
||||||
ReloadObjects();
|
|
||||||
Log.Information($"Добавлен набор: {storageIndexInput.Text}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK) {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_storage.SaveData(saveFileDialog.FileName);
|
|
||||||
MessageBox.Show("Сохранение прошло успешно",
|
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
Log.Information($"Файл {saveFileDialog.FileName} успешно сохранен");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Warning("Не удалось сохранить");
|
|
||||||
MessageBox.Show($"Не сохранилось: {ex.Message}",
|
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
||||||
if (loadFileDialog.ShowDialog() == DialogResult.OK) {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_storage.LoadData(loadFileDialog.FileName);
|
|
||||||
MessageBox.Show("Загрузка прошла успешно",
|
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
Log.Information($"Файл {loadFileDialog.FileName} успешно загружен");
|
|
||||||
foreach (var collection in _storage.Keys)
|
|
||||||
{
|
|
||||||
storageListBox.Items.Add(collection);
|
|
||||||
}
|
|
||||||
ReloadObjects();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Warning("Не удалось загрузить");
|
|
||||||
MessageBox.Show($"Не загрузилось: {ex.Message}",
|
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +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>
|
|
||||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>17, 17</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="loadFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>323, 17</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>481, 17</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
|
@ -1,77 +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 IEnumerable<T?> GetLocos => _collection.GetElectricLocos();
|
|
||||||
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 bool operator +(LocosGenericCollection<T, U> collect, T?
|
|
||||||
obj)
|
|
||||||
{
|
|
||||||
if (obj == null) return false;
|
|
||||||
|
|
||||||
return collect?._collection.Insert(obj) ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T? operator -(LocosGenericCollection<T, U> collect, int
|
|
||||||
pos)
|
|
||||||
{
|
|
||||||
T? obj = collect._collection[pos];
|
|
||||||
collect._collection.Remove(pos);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
public U? GetU(int pos)
|
|
||||||
{
|
|
||||||
return (U?)_collection[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)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
foreach(var electricLoco in _collection.GetElectricLocos())
|
|
||||||
{
|
|
||||||
if (electricLoco != null)
|
|
||||||
{
|
|
||||||
int inRow = _pictureWidth / _placeSizeWidth;
|
|
||||||
electricLoco.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight);
|
|
||||||
electricLoco.DrawLoco(g);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,137 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public class LocosGenericStorage
|
|
||||||
{
|
|
||||||
readonly Dictionary<string, LocosGenericCollection<DrawingLocomotiv, DrawingObjectLocomotiv>> _electricLocoStorages;
|
|
||||||
public List<string> Keys => _electricLocoStorages.Keys.ToList();
|
|
||||||
|
|
||||||
private readonly int _pictureWidth;
|
|
||||||
|
|
||||||
private readonly int _pictureHeight;
|
|
||||||
private static readonly char _separatorForKeyValue = '|';
|
|
||||||
|
|
||||||
private readonly char _separatorRecords = ';';
|
|
||||||
|
|
||||||
private static readonly char _separatorForObject = ':';
|
|
||||||
|
|
||||||
public LocosGenericStorage(int pictureWidth, int pictureHeight)
|
|
||||||
{
|
|
||||||
_electricLocoStorages = new Dictionary<string,
|
|
||||||
LocosGenericCollection<DrawingLocomotiv, DrawingObjectLocomotiv>>();
|
|
||||||
_pictureWidth = pictureWidth;
|
|
||||||
_pictureHeight = pictureHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddSet(string name)
|
|
||||||
{
|
|
||||||
_electricLocoStorages.Add(name, new LocosGenericCollection<DrawingLocomotiv, DrawingObjectLocomotiv> (_pictureWidth, _pictureHeight));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DelSet(string name)
|
|
||||||
{
|
|
||||||
if (!_electricLocoStorages.ContainsKey(name))
|
|
||||||
return;
|
|
||||||
_electricLocoStorages.Remove(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocosGenericCollection<DrawingLocomotiv, DrawingObjectLocomotiv>? this[string ind]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_electricLocoStorages.ContainsKey(ind))
|
|
||||||
return _electricLocoStorages[ind];
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool SaveData(string filename)
|
|
||||||
{
|
|
||||||
if (File.Exists(filename))
|
|
||||||
{
|
|
||||||
File.Delete(filename);
|
|
||||||
}
|
|
||||||
StringBuilder data = new();
|
|
||||||
foreach (KeyValuePair<string,
|
|
||||||
LocosGenericCollection<DrawingLocomotiv, DrawingObjectLocomotiv>> record in _electricLocoStorages)
|
|
||||||
{
|
|
||||||
StringBuilder records = new();
|
|
||||||
foreach (DrawingLocomotiv? elem in record.Value.GetLocos)
|
|
||||||
{
|
|
||||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
|
||||||
}
|
|
||||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.Length == 0)
|
|
||||||
{
|
|
||||||
throw new Exception("Невалиданя операция, нет данных длясохранения");
|
|
||||||
}
|
|
||||||
string toWrite = $"LocoStorage{Environment.NewLine}{data}";
|
|
||||||
var strs = toWrite.Split(new char[] { '\n', '\r' },
|
|
||||||
StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
|
|
||||||
using (StreamWriter sw = new(filename))
|
|
||||||
{
|
|
||||||
foreach (var str in strs)
|
|
||||||
{
|
|
||||||
sw.WriteLine(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public bool LoadData(string filename)
|
|
||||||
{
|
|
||||||
if (!File.Exists(filename))
|
|
||||||
{
|
|
||||||
throw new Exception("Файл не найден");
|
|
||||||
}
|
|
||||||
using (StreamReader sr = new(filename))
|
|
||||||
{
|
|
||||||
string str = sr.ReadLine();
|
|
||||||
var strs = str.Split(new char[] { '\n', '\r' },
|
|
||||||
StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (strs == null || strs.Length == 0)
|
|
||||||
{
|
|
||||||
throw new Exception("Нет данных для загрузки");
|
|
||||||
}
|
|
||||||
if (!strs[0].StartsWith("LocoStorage"))
|
|
||||||
{
|
|
||||||
throw new Exception("Неверный формат данных");
|
|
||||||
}
|
|
||||||
_electricLocoStorages.Clear();
|
|
||||||
do
|
|
||||||
{
|
|
||||||
string[] record = str.Split(_separatorForKeyValue,
|
|
||||||
StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (record.Length != 2)
|
|
||||||
{
|
|
||||||
str = sr.ReadLine();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
LocosGenericCollection<DrawingLocomotiv, DrawingObjectLocomotiv>
|
|
||||||
collection = new(_pictureWidth, _pictureHeight);
|
|
||||||
string[] set = record[1].Split(_separatorRecords,
|
|
||||||
StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
foreach (string elem in set)
|
|
||||||
{
|
|
||||||
DrawingLocomotiv? monorail =
|
|
||||||
elem?.CreateDrawingLoco(_separatorForObject, _pictureWidth, _pictureHeight);
|
|
||||||
if (monorail != null)
|
|
||||||
{
|
|
||||||
if (!(collection + monorail))
|
|
||||||
{
|
|
||||||
throw new Exception("Ошибка добавления в коллекцию");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_electricLocoStorages.Add(record[0], collection);
|
|
||||||
|
|
||||||
str = sr.ReadLine();
|
|
||||||
} while (str != null);
|
|
||||||
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
using ElectricLocomotive.Exceptions;
|
|
||||||
|
|
||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public class SetGeneric <T> where T : class
|
|
||||||
{
|
|
||||||
private readonly List<T?> _places;
|
|
||||||
|
|
||||||
public int Count => _places.Count;
|
|
||||||
private readonly int _maxCount;
|
|
||||||
|
|
||||||
public SetGeneric(int count)
|
|
||||||
{
|
|
||||||
_maxCount = count;
|
|
||||||
_places = new List<T>(count);
|
|
||||||
}
|
|
||||||
public bool Insert(T electricLocomotiv)
|
|
||||||
{
|
|
||||||
if (_places.Count == _maxCount)
|
|
||||||
throw new StorageOverflowException(_maxCount);
|
|
||||||
Insert(electricLocomotiv, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Insert(T electricLocomotiv, int position)
|
|
||||||
{
|
|
||||||
if (_places.Count == _maxCount)
|
|
||||||
throw new StorageOverflowException(_maxCount);
|
|
||||||
|
|
||||||
if (!(position >= 0 && position <= Count))
|
|
||||||
return false;
|
|
||||||
_places.Insert(position, electricLocomotiv);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Remove(int position)
|
|
||||||
{
|
|
||||||
if (!(position >= 0 && position < Count))
|
|
||||||
throw new LocoNotFoundException(position);
|
|
||||||
_places.RemoveAt(position);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T? this[int position]
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
if (!(position >= 0 && position < Count))
|
|
||||||
return null;
|
|
||||||
return _places[position];
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
|
||||||
return;
|
|
||||||
_places.Insert(position, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public IEnumerable<T?> GetElectricLocos(int? maxElectricLocos = null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _places.Count; ++i)
|
|
||||||
{
|
|
||||||
yield return _places[i];
|
|
||||||
if (maxElectricLocos.HasValue && i == maxElectricLocos.Value)
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public interface IMoveableObject
|
|
||||||
{
|
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
|
||||||
|
|
||||||
int GetStep { get; }
|
|
||||||
|
|
||||||
bool CheckCanMove(DirectionType direction);
|
|
||||||
|
|
||||||
void MoveObject(DirectionType direction);
|
|
||||||
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
namespace ElectricLocomotive;
|
|
||||||
|
|
||||||
public enum Status
|
|
||||||
{
|
|
||||||
NotInit = 1,
|
|
||||||
InProgress = 2,
|
|
||||||
Finish = 3
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace ElectricLocomotive
|
|
||||||
{
|
|
||||||
internal static class Program
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
|
||||||
.WriteTo.File("log.txt")
|
|
||||||
.MinimumLevel.Debug()
|
|
||||||
.CreateLogger();
|
|
||||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
|
||||||
Application.EnableVisualStyles();
|
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
|
||||||
Application.Run(new FormLocomotivCollection());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user