10 Commits
LABA2 ... LABA7

Author SHA1 Message Date
Daniel
931ccb2599 искл 2022-12-23 01:31:29 +04:00
Daniel
beb635889b . 2022-12-23 01:28:21 +04:00
Daniel
01d98db116 дописал исключение 2022-12-23 01:13:22 +04:00
Daniel
122a5dbfe1 готово 2022-12-23 00:48:39 +04:00
Daniel
cc983c3272 6 лабораторная по сохранению 2022-12-13 01:49:12 +04:00
Daniel
dcaf120503 5 лаба 2022-12-12 23:38:47 +04:00
Daniel
2a53b2840c Финальный этап - завершение формочки 2022-11-29 02:16:22 +04:00
Daniel
ed2a685f66 2 этап. Класс MapsCollection 2022-11-29 01:53:02 +04:00
Daniel
6806a3c9ca Этап1. смена массива на список 2022-11-29 01:44:43 +04:00
Daniel
19b93bd2ee 3 лаба 2022-11-28 22:39:41 +04:00
30 changed files with 1903 additions and 494 deletions

Binary file not shown.

View File

@@ -4,16 +4,12 @@ using System.Text;
namespace WinFormsApp1
{
internal enum Direction
public enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,
Right = 4,
DRDiagonal = 5,
DLDiagonal = 6,
ULDiagonal = 7,
URDiagonal = 8
}
}

View File

@@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tractors;
namespace WinFormsApp1
{
@@ -23,6 +24,10 @@ namespace WinFormsApp1
return _tractor?.GetCurrentPosition() ?? default;
}
public string GetInfo() => _tractor?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectTractor(data.CreateDrawingTraktor());
public void MoveObject(Direction direction)
{
_tractor?.MoveTransport(direction);

View File

@@ -7,7 +7,7 @@ using System.Drawing;
namespace WinFormsApp1
{
class EntityTractor
public class EntityTractor
{
/// <summary>
/// Скорость
@@ -20,7 +20,7 @@ namespace WinFormsApp1
/// <summary>
/// Цвет кузова
/// </summary>
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
@@ -34,5 +34,12 @@ namespace WinFormsApp1
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
public static EntityTractor Creator(string data)
{
string[] strs = data.Split(':');
return new EntityTractor(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinFormsApp1;
namespace WinFormsApp1
{
internal static class ExtentionTraktor
{
private static readonly char _separatorForObject = ':';
public static TractorDraw CreateDrawingTraktor(this string info)
{
string[] strs = info.Split(_separatorForObject);
if (strs.Length == 3)
{
return new TractorDraw(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 6)
{
return new MultiTraktorDraw(
Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
Color.FromName(strs[2]), Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]));
}
return null;
}
public static string GetDataForSave(this TractorDraw drawingTraktor)
{
var traktor = drawingTraktor.Tractor;
var str = $"{traktor.Speed}{_separatorForObject}{traktor.Weight}{_separatorForObject}{traktor.BodyColor.Name}";
if (traktor is not MultiTraktor multiTraktor)
{
return str;
}
return $"{str}{_separatorForObject}{multiTraktor.DopColor.Name}{_separatorForObject}{multiTraktor.dopAhead}{_separatorForObject}{multiTraktor.dopBehind}";
}
}
}

View File

@@ -1,210 +0,0 @@

namespace WinFormsApp1
{
partial class FormMap
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxTractor = new System.Windows.Forms.PictureBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.comboBoxSelectionMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxTractor
//
this.pictureBoxTractor.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxTractor.Location = new System.Drawing.Point(0, 0);
this.pictureBoxTractor.Name = "pictureBoxTractor";
this.pictureBoxTractor.Size = new System.Drawing.Size(800, 424);
this.pictureBoxTractor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxTractor.TabIndex = 0;
this.pictureBoxTractor.TabStop = false;
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 424);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(800, 26);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(73, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 20);
this.toolStripStatusLabelWeight.Text = "вес";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(42, 20);
this.toolStripStatusLabelBodyColor.Text = "Цвет";
this.toolStripStatusLabelBodyColor.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(0, 378);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(682, 296);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(649, 332);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(682, 332);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(718, 332);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonCreateModif
//
this.buttonCreateModif.Location = new System.Drawing.Point(111, 378);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(129, 27);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// comboBoxSelectionMap
//
this.comboBoxSelectionMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectionMap.FormattingEnabled = true;
this.comboBoxSelectionMap.Items.AddRange(new object[] {
"Простая карта",
"Поле"});
this.comboBoxSelectionMap.Location = new System.Drawing.Point(0, 0);
this.comboBoxSelectionMap.Name = "comboBoxSelectionMap";
this.comboBoxSelectionMap.Size = new System.Drawing.Size(194, 28);
this.comboBoxSelectionMap.TabIndex = 8;
this.comboBoxSelectionMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectionMap_SelectedIndexChanged);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboBoxSelectionMap);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxTractor);
this.Controls.Add(this.statusStrip1);
this.Name = "FormMap";
this.Text = "FormMap";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBoxTractor;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBodyColor;
private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.Button buttonUp;
private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonDown;
private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonCreateModif;
private System.Windows.Forms.ComboBox comboBoxSelectionMap;
}
}

View File

@@ -1,90 +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 WinFormsApp1
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
//Заполнение информации по объекту
private void SetData(TractorDraw tractor)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {tractor.Tractor.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {tractor.Tractor.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {tractor.Tractor.BodyColor.Name}";
pictureBoxTractor.Image = _abstractMap.CreateMap(pictureBoxTractor.Width, pictureBoxTractor.Height,
new DrawningObjectTractor(tractor));
}
//Логика кнопки Создать
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
var tractor = new TractorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
SetData(tractor);
}
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBoxTractor.Image = _abstractMap?.MoveObject(dir);
}
// Обработка нажатия кнопки "Модификация"
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random random = new Random();
var _Tractor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
SetData(_Tractor);
}
private void comboBoxSelectionMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectionMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Поле":
_abstractMap = new FieldMap();
break;
}
}
}
}

View File

@@ -1,63 +0,0 @@
<root>
<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="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@@ -0,0 +1,356 @@
using System.Windows.Forms;
namespace WinFormsApp1
{
partial class FormMapWithSetTraktor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveTraktor = new System.Windows.Forms.Button();
this.buttonAddTraktor = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBox1.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.groupBoxMaps);
this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonDown);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonUp);
this.groupBox1.Controls.Add(this.buttonShowOnMap);
this.groupBox1.Controls.Add(this.buttonShowStorage);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonRemoveTraktor);
this.groupBox1.Controls.Add(this.buttonAddTraktor);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(596, 24);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Size = new System.Drawing.Size(219, 515);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(7, 20);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(200, 244);
this.groupBoxMaps.TabIndex = 2;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 15;
this.listBoxMaps.Location = new System.Drawing.Point(6, 109);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(188, 94);
this.listBoxMaps.TabIndex = 4;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 215);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(188, 23);
this.buttonDeleteMap.TabIndex = 3;
this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(6, 80);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(188, 23);
this.buttonAddMap.TabIndex = 2;
this.buttonAddMap.Text = " Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 22);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(188, 23);
this.textBoxNewMapName.TabIndex = 1;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Поле"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 52);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Tractors.Properties.Resources.RkYIe2_6DuQ;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(126, 442);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(35, 30);
this.buttonRight.TabIndex = 10;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Tractors.Properties.Resources.MbV2DYU_nPM;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(91, 442);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(35, 30);
this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Tractors.Properties.Resources.Hhxt4dLqV5g;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(56, 442);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(35, 30);
this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Tractors.Properties.Resources._2EdzyM4iEKw;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(91, 412);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(35, 30);
this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 380);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(207, 22);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(7, 353);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(207, 22);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 298);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(207, 23);
this.maskedTextBoxPosition.TabIndex = 11;
//
// buttonRemoveTraktor
//
this.buttonRemoveTraktor.Location = new System.Drawing.Point(7, 325);
this.buttonRemoveTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRemoveTraktor.Name = "buttonRemoveTraktor";
this.buttonRemoveTraktor.Size = new System.Drawing.Size(207, 24);
this.buttonRemoveTraktor.TabIndex = 2;
this.buttonRemoveTraktor.Text = "Удалить трактор";
this.buttonRemoveTraktor.UseVisualStyleBackColor = true;
this.buttonRemoveTraktor.Click += new System.EventHandler(this.ButtonRemoveTraktor_Click);
//
// buttonAddTraktor
//
this.buttonAddTraktor.Location = new System.Drawing.Point(7, 269);
this.buttonAddTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonAddTraktor.Name = "buttonAddTraktor";
this.buttonAddTraktor.Size = new System.Drawing.Size(207, 25);
this.buttonAddTraktor.TabIndex = 1;
this.buttonAddTraktor.Text = "Добавить трактор";
this.buttonAddTraktor.UseVisualStyleBackColor = true;
this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddTraktor_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(596, 515);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// menuStrip
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.файлToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(815, 24);
this.menuStrip.TabIndex = 2;
this.menuStrip.Text = "menuStrip1";
//
// файлToolStripMenuItem
//
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.файлToolStripMenuItem.Name = айлToolStripMenuItem";
this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
this.файлToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog1";
this.openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
this.saveFileDialog.Filter = "txt file | *.txt";
//
//
// FormMapWithSetTraktor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(815, 538);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormMapWithSetTraktor";
this.Text = "Автобус";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private GroupBox groupBox1;
private PictureBox pictureBox;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRemoveTraktor;
private Button buttonAddTraktor;
private ComboBox comboBoxSelectorMap;
private Button buttonRight;
private Button buttonDown;
private Button buttonLeft;
private Button buttonUp;
private GroupBox groupBoxMaps;
private Button buttonDeleteMap;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
private ListBox listBoxMaps;
private MenuStrip menuStrip;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
}
}

View File

@@ -0,0 +1,297 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1;
namespace WinFormsApp1
{
public partial class FormMapWithSetTraktor : Form
{
private MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap> _mapTraktorCollectionGeneric;
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{"Простая карта", new SimpleMap() },
{"Поле", new FieldMap() }
};
private readonly MapsCollection _mapsCollection;
private readonly ILogger _logger;
public FormMapWithSetTraktor(ILogger<FormMapWithSetTraktor> logger)
{
InitializeComponent();
_logger = logger;
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var item in _mapsDict)
{
comboBoxSelectorMap.Items.Add(item.Key);
}
}
public FormMapWithSetTraktor()
{
}
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Поле":
map = new FieldMap();
break;
}
if (map != null)
{
_mapTraktorCollectionGeneric = new MapWithSetTraktorGeneric<DrawningObjectTractor, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapTraktorCollectionGeneric = null;
}
}
private void ButtonAddTraktor_Click(object sender, EventArgs e)
{
var formBusConfig = new FormTraktorConfig();
formBusConfig.AddEvent(AddTraktor);
formBusConfig.Show();
}
private void AddTraktor(TractorDraw traktor)
{
try
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
DrawningObjectTractor boat = new(traktor);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0)
{
MessageBox.Show("Объект добавлен");
_logger.LogInformation("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogInformation("Не удалось добавить объект");
}
}
catch (StorageOverflowException ex)
{
_logger.LogWarning($"Ошибка, переполнение хранилища: {0}", ex.Message);
MessageBox.Show($"Ошибка, хранилище переполнено: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (ArgumentException ex)
{
_logger.LogWarning("Ошибка добавления");
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonRemoveTraktor_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
try
{
var deletedTraktor = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
if (deletedTraktor != null)
{
MessageBox.Show("Объект удален");
_logger.LogInformation("Из текущей карты удален объект {@traktor}", deletedTraktor);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
_logger.LogWarning("Не удалось добавить объект по позиции {0} равен null", pos);
MessageBox.Show("Не удалось удалить объект");
}
}
catch (TraktorNotFoundException ex)
{
_logger.LogWarning("Ошибка удаления: {0}", ex.Message);
MessageBox.Show($"Ошибка удаления: {ex.Message}");
}
catch (Exception ex)
{
_logger.LogWarning("Неизвестная ошибка удаления: {0}", ex.Message);
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
}
}
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapTraktorCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapTraktorCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapTraktorCollectionGeneric == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBox.Image = _mapTraktorCollectionGeneric.MoveObject(dir);
}
private void buttonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
_logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text);
}
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
_logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
}
private void buttonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
_logger.LogInformation("Удалена карта {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
}
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_mapsCollection.SaveData(saveFileDialog.FileName);
_logger.LogInformation("Загрузка данных из файла '{0}' прошла успешно", openFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogInformation("Не удалось загрузить файл '{0}'. Текст ошибки: {1}", openFileDialog.FileName, ex.Message);
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_mapsCollection.LoadData(openFileDialog.FileName);
MessageBox.Show("Загрузка данных прошла успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
catch (Exception ex)
{
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -40,6 +40,7 @@ namespace WinFormsApp1
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectedTractor = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -156,11 +157,22 @@ namespace WinFormsApp1
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// buttonSelectedTractor
//
this.buttonSelectedTractor.Location = new System.Drawing.Point(262, 372);
this.buttonSelectedTractor.Name = "buttonSelectedTractor";
this.buttonSelectedTractor.Size = new System.Drawing.Size(89, 35);
this.buttonSelectedTractor.TabIndex = 8;
this.buttonSelectedTractor.Text = "Выбрать";
this.buttonSelectedTractor.UseVisualStyleBackColor = true;
this.buttonSelectedTractor.Click += new System.EventHandler(this.buttonSelectedTractor_Click);
//
// FormTractor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSelectedTractor);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
@@ -192,6 +204,7 @@ namespace WinFormsApp1
private System.Windows.Forms.Button buttonDown;
private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonCreateModif;
private System.Windows.Forms.Button buttonSelectedTractor;
}
}

View File

@@ -14,6 +14,7 @@ namespace WinFormsApp1
{
private TractorDraw _Tractor;
public TractorDraw SelectedTractor { get; private set; }
public FormTractor()
{
InitializeComponent();
@@ -39,8 +40,13 @@ namespace WinFormsApp1
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
_Tractor = new TractorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
SetData();
Color color = 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;
}
_Tractor = new TractorDraw(random.Next(100, 300), random.Next(1000, 2000), color); SetData();
Draw();
}
@@ -76,18 +82,33 @@ namespace WinFormsApp1
Draw();
}
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random random = new Random();
_Tractor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor, true, true);
SetData();
Draw();
}
private void buttonSelectedTractor_Click(object sender, EventArgs e)
{
SelectedTractor = _Tractor;
DialogResult = DialogResult.OK;
}
}
}

358
WinFormsApp1/FormTraktorConfig.Designer.cs generated Normal file
View File

@@ -0,0 +1,358 @@
using System.Windows.Forms;
namespace WinFormsApp1
{
partial class FormTraktorConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.labelHardObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxBehind = new System.Windows.Forms.CheckBox();
this.checkBoxAhead = new System.Windows.Forms.CheckBox();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.panel1 = new System.Windows.Forms.Panel();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelHardObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Controls.Add(this.checkBoxBehind);
this.groupBoxConfig.Controls.Add(this.checkBoxAhead);
this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(423, 197);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelHardObject
//
this.labelHardObject.AllowDrop = true;
this.labelHardObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelHardObject.Location = new System.Drawing.Point(314, 127);
this.labelHardObject.Name = "labelHardObject";
this.labelHardObject.Size = new System.Drawing.Size(94, 40);
this.labelHardObject.TabIndex = 8;
this.labelHardObject.Text = "Продвинутый";
this.labelHardObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelHardObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.AllowDrop = true;
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(238, 127);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(70, 40);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelPurple);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelGray);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(238, 22);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(170, 102);
this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(123, 58);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(30, 30);
this.panelPurple.TabIndex = 2;
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(87, 58);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(30, 30);
this.panelBlack.TabIndex = 1;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(123, 22);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(30, 30);
this.panelYellow.TabIndex = 1;
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(51, 58);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(30, 30);
this.panelGray.TabIndex = 1;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.SystemColors.HotTrack;
this.panelBlue.Location = new System.Drawing.Point(87, 22);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(30, 30);
this.panelBlue.TabIndex = 1;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(15, 58);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(30, 30);
this.panelWhite.TabIndex = 1;
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.SeaGreen;
this.panelGreen.Location = new System.Drawing.Point(51, 22);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(30, 30);
this.panelGreen.TabIndex = 1;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(15, 22);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(30, 30);
this.panelRed.TabIndex = 0;
//
// checkBoxBehind
//
this.checkBoxBehind.AutoSize = true;
this.checkBoxBehind.Location = new System.Drawing.Point(17, 116);
this.checkBoxBehind.Name = "checkBoxBehind";
this.checkBoxBehind.Size = new System.Drawing.Size(219, 19);
this.checkBoxBehind.TabIndex = 5;
this.checkBoxBehind.Text = "Признак наличия рыхлителя сзади";
this.checkBoxBehind.UseVisualStyleBackColor = true;
//
// checkBoxAhead
//
this.checkBoxAhead.AutoSize = true;
this.checkBoxAhead.Location = new System.Drawing.Point(17, 91);
this.checkBoxAhead.Name = "checkBoxAhead";
this.checkBoxAhead.Size = new System.Drawing.Size(216, 19);
this.checkBoxAhead.TabIndex = 4;
this.checkBoxAhead.Text = "Прищнак наличия ковша спереди";
this.checkBoxAhead.UseVisualStyleBackColor = true;
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(17, 70);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(26, 15);
this.labelWeight.TabIndex = 3;
this.labelWeight.Text = "Вес";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(17, 41);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(59, 15);
this.labelSpeed.TabIndex = 2;
this.labelSpeed.Text = "Скорость";
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(82, 62);
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(120, 23);
this.numericUpDownWeight.TabIndex = 1;
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(82, 33);
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(120, 23);
this.numericUpDownSpeed.TabIndex = 0;
//
// panel1
//
this.panel1.AllowDrop = true;
this.panel1.Controls.Add(this.labelDopColor);
this.panel1.Controls.Add(this.labelColor);
this.panel1.Controls.Add(this.pictureBoxObject);
this.panel1.Location = new System.Drawing.Point(454, 31);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(246, 197);
this.panel1.TabIndex = 1;
this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.Panel1_DragDrop);
this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.Panel1_DragEnter);
//
// labelDopColor
//
this.labelDopColor.AllowDrop = true;
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelDopColor.Location = new System.Drawing.Point(88, 8);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(78, 29);
this.labelDopColor.TabIndex = 10;
this.labelDopColor.Text = "Доп. цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter);
//
// labelColor
//
this.labelColor.AllowDrop = true;
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(12, 8);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(70, 29);
this.labelColor.TabIndex = 9;
this.labelColor.Text = "Цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(12, 43);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(231, 151);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(480, 234);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(561, 234);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormTraktorConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(770, 317);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.panel1);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormTraktorConfig";
this.Text = "FormTraktorConfig";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private CheckBox checkBoxBehind;
private CheckBox checkBoxAhead;
private Label labelWeight;
private Label labelSpeed;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelHardObject;
private Label labelSimpleObject;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelYellow;
private Panel panelGray;
private Panel panelBlue;
private Panel panelWhite;
private Panel panelGreen;
private Panel panelRed;
private Panel panel1;
private Label labelDopColor;
private Label labelColor;
private PictureBox pictureBoxObject;
private Button buttonAdd;
private Button buttonCancel;
}
}

View File

@@ -0,0 +1,148 @@
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 WinFormsApp1
{
public partial class FormTraktorConfig : Form
{
TractorDraw _traktor = null;
private event TraktorDelegate EventAddTraktor;
public FormTraktorConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (object sender, EventArgs a) => Close();
}
private void labelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void DrawTraktor()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_traktor?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_traktor?.DrawEntity(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(TraktorDelegate ev)
{
if (EventAddTraktor == null)
{
EventAddTraktor = new TraktorDelegate(ev);
}
else
{
EventAddTraktor += ev;
}
}
private void Panel1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void Panel1_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_traktor = new TractorDraw((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, labelColor.BackColor);
break;
case "labelHardObject":
_traktor = new MultiTraktorDraw((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, labelColor.BackColor, labelDopColor.BackColor,
checkBoxAhead.Checked, checkBoxBehind.Checked);
break;
}
DrawTraktor();
}
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)
{
var color = e.Data.GetData(typeof(Color));
if (color != null)
{
(sender as Label).BackColor = (Color)color;
}
if (_traktor != null)
{
_traktor.Tractor.BodyColor = (Color)color;
DrawTraktor();
}
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (_traktor != null && _traktor.Tractor is MultiTraktor entityBulldozer)
{
entityBulldozer.DopColor = (Color)e.Data.GetData(typeof(Color));
DrawTraktor();
}
}
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
EventAddTraktor?.Invoke(_traktor);
Close();
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -25,5 +25,7 @@ namespace WinFormsApp1
void DrawningObject(Graphics g);
/// Получение текущей позиции объекта
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
string GetInfo();
}
}

View File

@@ -13,8 +13,8 @@ namespace WinFormsApp1
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 180;
private readonly int _placeSizeHeight = 150;
private readonly int _placeSizeWidth = 250;
private readonly int _placeSizeHeight = 250;
private readonly SetTraktorGeneric<T> _setTraktors;
private readonly U _map;
@@ -28,9 +28,9 @@ namespace WinFormsApp1
_map = map;
}
public static int operator +(MapWithSetTraktorGeneric<T, U> map, T bus)
public static int operator +(MapWithSetTraktorGeneric<T, U> map, T traktor)
{
return map._setTraktors.Insert(bus);
return map._setTraktors.Insert(traktor);
}
public static T operator -(MapWithSetTraktorGeneric<T, U> map, int position)
@@ -50,13 +50,9 @@ namespace WinFormsApp1
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setTraktors.Count; i++)
foreach (var traktor in _setTraktors.GetTraktor())
{
var bus = _setTraktors.Get(i);
if (bus != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, bus);
}
return _map.CreateMap(_pictureWidth, _pictureHeight, traktor);
}
return new(_pictureWidth, _pictureHeight);
}
@@ -75,14 +71,14 @@ namespace WinFormsApp1
int j = _setTraktors.Count - 1;
for (int i = 0; i < _setTraktors.Count; i++)
{
if (_setTraktors.Get(i) == null)
if (_setTraktors[i] == null)
{
for (; j > i; j--)
{
var bus = _setTraktors.Get(j);
if (bus != null)
var traktor = _setTraktors[j];
if (traktor != null)
{
_setTraktors.Insert(bus, i);
_setTraktors.Insert(traktor, i);
_setTraktors.Remove(j);
break;
}
@@ -113,18 +109,18 @@ namespace WinFormsApp1
private void DrawTraktors(Graphics g)
{
int widthEl = _pictureWidth / _placeSizeWidth;
int heightEl = _pictureHeight / _placeSizeHeight;
int curWidth = 0;
int curWidth = 1;
int curHeight = 0;
for (int i = _setTraktors.Count; i >= 0; i--)
foreach (var traktor in _setTraktors.GetTraktor())
{
_setTraktors.Get(i)?.SetObject(
_pictureWidth - _placeSizeWidth * curWidth - 20,
curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight);
_setTraktors.Get(i)?.DrawningObject(g);
traktor?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 130,
curHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
traktor?.DrawningObject(g);
if (curWidth < widthEl)
curWidth++;
@@ -137,7 +133,24 @@ namespace WinFormsApp1
{
return;
}
}
}
public string GetData(char separatorType, char separatorData)
{
string data = $"{_map.GetType().Name}{separatorType}";
foreach (var traktor in _setTraktors.GetTraktor())
{
data += $"{traktor.GetInfo()}{separatorData}";
}
return data;
}
public void LoadData(string[] records)
{
foreach (var rec in records)
{
_setTraktors.Insert(DrawningObjectTractor.Create(rec) as T);
}
}
}

View File

@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinFormsApp1
{
internal class MapsCollection
{
readonly Dictionary<string, MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>> _mapStorages;
public List<string> Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly char separatorDict = '|';
private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddMap(string name, AbstractMap map)
{
if (_mapStorages.ContainsKey(name)) return; //уникальное имя
else
{
_mapStorages.Add(name, new MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
public void DelMap(string name)
{
if (_mapStorages.ContainsKey(name))
{
_mapStorages.Remove(name);
}
}
public MapWithSetTraktorGeneric<IDrawningObject, AbstractMap> this[string ind]
{
get
{
_mapStorages.TryGetValue(ind, out var result);
return result;
}
}
private static void WriteToFile(string text, FileStream stream)
{
byte[] info = new UTF8Encoding(true).GetBytes(text);
stream.Write(info, 0, info.Length);
}
public void SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter fs = new(filename))
{
fs.Write($"MapsCollection{Environment.NewLine}");
foreach (var storage in _mapStorages)
{
fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
}
}
}
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
throw new FileNotFoundException("Файл не найден");
}
using (StreamReader sr = new(filename))
{
string str = "";
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
throw new FileFormatException("Формат данных в файле неправильный");
}
//очищаем записи
_mapStorages.Clear();
while ((str = sr.ReadLine()) != null)
{
var elem = str.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
case "Простая карта":
map = new SimpleMap();
break;
case "Поле":
map = new FieldMap();
break;
}
_mapStorages.Add(elem[0], new MapWithSetTraktorGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
}
}
}
}

View File

@@ -7,15 +7,14 @@ namespace WinFormsApp1
{
internal class MultiTraktor : EntityTractor
{
public Color DopColor { get; private set; }
/// Инициализация свойств
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес трактора</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor)
public Color DopColor { get; set; }
public bool dopAhead { get; private set; }
public bool dopBehind { get; private set; }
public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor, bool dopahead, bool dopbehind) : base(speed, weight, bodyColor)
{
DopColor = dopColor;
dopAhead = dopahead;
dopBehind = dopbehind;
}
}
}

View File

@@ -7,16 +7,14 @@ namespace WinFormsApp1
{
class MultiTraktorDraw : TractorDraw
{
/// Инициализация свойств
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес трактора</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="trktrWidth">Ширина отрисовки автомобиля</param>
/// <param name="trktrHeight">Высота отрисовки автомобиля</param>
public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor, 188, 100)
public void SetDopColor(Color color)
{
Tractor = new MultiTraktor(speed, weight, bodyColor, dopColor);
((MultiTraktor)Tractor).DopColor = color;
}
public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor, bool dopahead, bool dopbehind) : base(speed, weight, bodyColor, 188, 100)
{
Tractor = new MultiTraktor(speed, weight, bodyColor, dopColor, dopahead, dopbehind);
}
public override void DrawEntity(Graphics g)
@@ -25,6 +23,10 @@ namespace WinFormsApp1
{
return;
}
if (!DrawCheck())
{
return;
}
Pen pen_Black_1pxl = new Pen(Color.Black, 1);
Pen pen_Black_2pxl = new Pen(Color.Black, 2);
Brush brBlack = new SolidBrush(Color.Black);
@@ -38,48 +40,54 @@ namespace WinFormsApp1
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 8, 4, 35);
g.DrawRectangle(pen_Black_1pxl, startPosX + 33, startPosY + 34, 10, 15);
point1 = new PointF(startPosX, startPosY + 8);
point2 = new PointF(startPosX + 33, startPosY + 41);
point3 = new PointF(startPosX + 33, startPosY + 34);
point4 = new PointF(startPosX + 7, startPosY + 8);
PointF[] curvePoints =
if (multiTraktor.dopBehind)
{
point1 = new PointF(startPosX, startPosY + 8);
point2 = new PointF(startPosX + 33, startPosY + 41);
point3 = new PointF(startPosX + 33, startPosY + 34);
point4 = new PointF(startPosX + 7, startPosY + 8);
PointF[] curvePoints =
{
point1,
point2,
point3,
point4
};
g.FillPolygon(dopBrush, curvePoints);
g.DrawPolygon(pen_Black_1pxl, curvePoints);
g.FillPolygon(dopBrush, curvePoints);
g.DrawPolygon(pen_Black_1pxl, curvePoints);
point1 = new PointF(startPosX + 6, startPosY + 8 + 15);
point2 = new PointF(startPosX + 6, startPosY + 8 + 35);
point3 = new PointF(startPosX + 26, startPosY + 8 + 35);
PointF[] curvePoints2 =
{
point1 = new PointF(startPosX + 6, startPosY + 8 + 15);
point2 = new PointF(startPosX + 6, startPosY + 8 + 35);
point3 = new PointF(startPosX + 26, startPosY + 8 + 35);
PointF[] curvePoints2 =
{
point1,
point2,
point3
};
g.FillPolygon(dopBrush, curvePoints2);
g.DrawPolygon(pen_Black_1pxl, curvePoints2);
g.FillPolygon(dopBrush, curvePoints2);
g.DrawPolygon(pen_Black_1pxl, curvePoints2);
}
startPosX += 43;
base.DrawEntity(g);
startPosX -= 43;
point1 = new PointF(startPosX + 43 + 102, startPosY + 30);
point2 = new PointF(startPosX + 43 + 102, startPosY + 65);
point3 = new PointF(startPosX + 43 + 137, startPosY + 65);
PointF[] curvePoints3 =
if (multiTraktor.dopAhead)
{
point1 = new PointF(startPosX + 43 + 102, startPosY + 30);
point2 = new PointF(startPosX + 43 + 102, startPosY + 65);
point3 = new PointF(startPosX + 43 + 137, startPosY + 65);
PointF[] curvePoints3 =
{
point1,
point2,
point3
};
g.FillPolygon(dopBrush, curvePoints3);
g.DrawPolygon(pen_Black_1pxl, curvePoints3);
g.FillPolygon(dopBrush, curvePoints3);
g.DrawPolygon(pen_Black_1pxl, curvePoints3);
}
}
}
}

View File

@@ -1,5 +1,10 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -14,10 +19,30 @@ namespace WinFormsApp1
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMap());
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetTraktor>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormMapWithSetTraktor>()
.AddLogging(option =>
{
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: "appsettings.json").Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
}
}

View File

@@ -9,13 +9,15 @@ namespace WinFormsApp1
internal class SetTraktorGeneric<T>
where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
private readonly List<T> _places;
public int Count => _places.Count;
private readonly int _maxCount;
private int TractorPlaces = 0;
public SetTraktorGeneric(int count)
{
_places = new T[count];
_maxCount = count;
_places = new List<T>(); ;
}
public int Insert(T tractor)
@@ -25,38 +27,66 @@ namespace WinFormsApp1
public int Insert(T tractor, int position)
{
if (position < 0 || position >= _places.Length || TractorPlaces == _places.Length)
if (position > _maxCount && position < 0)
{
return -1;
}
TractorPlaces++;
while (_places[position] != null)
if (_places.Contains(tractor))
{
for (int i = _places.Length - 1; i > 0; --i)
{
if (_places[i] == null && _places[i - 1] != null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
throw new ArgumentException($"Объект {tractor} уже есть в наборе");
}
_places[position] = tractor;
if (Count == _maxCount)
{
throw new StorageOverflowException(_maxCount);
}
_places.Insert(position, tractor);
return position;
}
public T Remove(int position)
{
if (position < 0 || position >= _places.Length) return null;
T savedTractor = _places[position];
_places[position] = null;
return savedTractor;
if (position < 0 || position >= _maxCount)
{
return null;
}
var result = _places[position];
_places.RemoveAt(position);
return result;
}
public T Get(int position)
public T this[int position]
{
if (position < 0 || position >= _places.Length) return null;
return _places[position];
get
{
if (position >= 0 && position < _maxCount && position < Count)
{
return _places[position];
}
else
{
return null;
}
}
set
{
Insert(value, position);
}
}
public IEnumerable<T> GetTraktor()
{
foreach (var traktor in _places)
{
if (traktor != null)
{
yield return traktor;
}
else
{
yield break;
}
}
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace WinFormsApp1
{
[Serializable]
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) { }
}
}

View File

@@ -7,7 +7,7 @@ using System.Drawing;
namespace WinFormsApp1
{
class TractorDraw
public class TractorDraw
{
//Сущность
@@ -90,38 +90,19 @@ namespace WinFormsApp1
startPosY -= Tractor.Step;
}
break;
case Direction.DRDiagonal:
if (startPosX + entWidth + Tractor.Step < pictureWidth && startPosY + entHeight + Tractor.Step < pictureHeight)
{
startPosX += Tractor.Step;
startPosY += Tractor.Step;
}
break;
case Direction.DLDiagonal:
if (startPosY + entHeight + Tractor.Step < pictureHeight && startPosX - 10 - Tractor.Step > 0)
{
startPosY += Tractor.Step;
startPosX -= Tractor.Step;
}
break;
case Direction.URDiagonal:
if (startPosY - Tractor.Step > 0 && startPosX + entWidth + Tractor.Step < pictureWidth)
{
startPosY -= Tractor.Step;
startPosX += Tractor.Step;
}
break;
case Direction.ULDiagonal:
if (startPosY - Tractor.Step > 0 && startPosX - 10 - Tractor.Step > 0)
{
startPosY -= Tractor.Step;
startPosX -= Tractor.Step;
}
break;
}
}
public bool DrawCheck()
{
if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
{
return false;
}
return true;
}
//Отрисовка сущности
public virtual void DrawEntity(Graphics g)
{

View File

@@ -2,10 +2,37 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.LoggerConfiguration.ConditionExtensions" Version="1.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinFormsApp1
{
public delegate void TraktorDelegate(TractorDraw traktor);
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace WinFormsApp1
{
internal class TraktorNotFoundException : ApplicationException
{
public TraktorNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
public TraktorNotFoundException() : base() { }
public TraktorNotFoundException(string message) : base(message) { }
public TraktorNotFoundException(string message, Exception exception) : base(message, exception) { }
protected TraktorNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@@ -0,0 +1,19 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "File",
"Args": {
"outputTemplate": "{Timestamp:HH:mm:ss. zzz} [{Level}] {Message} {Exception} {NewLine}",
"path": "D:/log.txt",
"fileSizeLimitBytes": 2147483648
}
}
],
"Properties": {
"Application": "Serilog-Demo"
}
}
}

13
WinFormsApp1/nlog.config Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
autoReload ="true" internalLogLevel ="Info">
<targets>
<target xsi:type="File" name ="tofile" fileName ="tankerlog-${shortdate}.log"/>
</targets>
<rules>
<logger name ="*" minlevel ="Debug" writeTo ="toFile" />
</rules>
</nlog>
</configuration>