Revert "Revert "0.3""
This reverts commit 4120e4751f4f765243959480c2f20e3afd59f80d.
This commit is contained in:
parent
4120e4751f
commit
660f9be57c
@ -1,4 +1,5 @@
|
||||
using Bulldoser.Entities;
|
||||
using Bulldoser.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -28,6 +29,8 @@ namespace Bulldoser.Drawings
|
||||
public int GetWidth => _tractWidth;
|
||||
public int GetHeight => _tractHeight;
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectTractor(this);
|
||||
|
||||
public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
|
||||
{
|
||||
if (width < _tractWidth || heigth < _tractHeight)
|
||||
|
34
Bulldoser/Bulldoser/Form1.Designer.cs
generated
34
Bulldoser/Bulldoser/Form1.Designer.cs
generated
@ -1,6 +1,6 @@
|
||||
namespace Bulldoser
|
||||
{
|
||||
partial class Form1
|
||||
partial class FormBulldoser
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -28,7 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBulldoser));
|
||||
pictureBoxBulldoser = new PictureBox();
|
||||
buttonCreateBulldoser = new Button();
|
||||
buttonRight = new Button();
|
||||
@ -38,7 +38,10 @@
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonCreateTractor = new Button();
|
||||
buttonStep = new Button();
|
||||
fileSystemWatcher1 = new FileSystemWatcher();
|
||||
buttonSelectTransport = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBulldoser).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)fileSystemWatcher1).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxBulldoser
|
||||
@ -63,7 +66,7 @@
|
||||
buttonCreateBulldoser.TabIndex = 1;
|
||||
buttonCreateBulldoser.Text = "Создать бульдозер";
|
||||
buttonCreateBulldoser.UseVisualStyleBackColor = true;
|
||||
buttonCreateBulldoser.Click += buttonCreateBulldoser_Click;
|
||||
buttonCreateBulldoser.Click += buttonCreateBulldozer_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
@ -157,11 +160,27 @@
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// Form1
|
||||
// fileSystemWatcher1
|
||||
//
|
||||
fileSystemWatcher1.EnableRaisingEvents = true;
|
||||
fileSystemWatcher1.SynchronizingObject = this;
|
||||
//
|
||||
// buttonSelectTransport
|
||||
//
|
||||
buttonSelectTransport.Location = new Point(785, 78);
|
||||
buttonSelectTransport.Name = "buttonSelectTransport";
|
||||
buttonSelectTransport.Size = new Size(88, 34);
|
||||
buttonSelectTransport.TabIndex = 9;
|
||||
buttonSelectTransport.Text = "Выбор";
|
||||
buttonSelectTransport.UseVisualStyleBackColor = true;
|
||||
buttonSelectTransport.Click += ButtonSelect_Tractor_Click;
|
||||
//
|
||||
// FormBulldoser
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(buttonSelectTransport);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(buttonCreateTractor);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
@ -171,10 +190,11 @@
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreateBulldoser);
|
||||
Controls.Add(pictureBoxBulldoser);
|
||||
Name = "Form1";
|
||||
Name = "FormBulldoser";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Form1";
|
||||
Text = "Создать транспорт";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBulldoser).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)fileSystemWatcher1).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -190,5 +210,7 @@
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonCreateTractor;
|
||||
private Button buttonStep;
|
||||
private FileSystemWatcher fileSystemWatcher1;
|
||||
private Button buttonSelectTransport;
|
||||
}
|
||||
}
|
@ -3,18 +3,18 @@ using Bulldoser.MovementStrategy;
|
||||
|
||||
namespace Bulldoser
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
public partial class FormBulldoser : Form
|
||||
{
|
||||
|
||||
private DrawingTractor? _drawingTractor;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
public Form1()
|
||||
public DrawingTractor? SelectedTractor { get; private set; }
|
||||
public FormBulldoser()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedTractor = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingTractor == null)
|
||||
@ -26,29 +26,40 @@ namespace Bulldoser
|
||||
_drawingTractor.DrawTransport(gr);
|
||||
pictureBoxBulldoser.Image = bmp;
|
||||
}
|
||||
|
||||
private void buttonCreateBulldoser_Click(object sender, EventArgs e)
|
||||
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_drawingTractor = new DrawingBulldoser(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog colorDialog = new ColorDialog();
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = colorDialog.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = colorDialog.Color;
|
||||
}
|
||||
_drawingTractor = new DrawingBulldoser(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxBulldoser.Width, pictureBoxBulldoser.Height);
|
||||
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreateTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog colorDialog = new ColorDialog();
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = colorDialog.Color;
|
||||
}
|
||||
_drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000), color,
|
||||
pictureBoxBulldoser.Width, pictureBoxBulldoser.Height);
|
||||
_drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTractor == null)
|
||||
@ -73,7 +84,6 @@ namespace Bulldoser
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTractor == null)
|
||||
@ -92,15 +102,14 @@ namespace Bulldoser
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectTractor(_drawingTractor), pictureBoxBulldoser.Width,
|
||||
_abstractStrategy.SetData(_drawingTractor.GetMoveableObject, pictureBoxBulldoser.Width,
|
||||
pictureBoxBulldoser.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
@ -109,7 +118,10 @@ namespace Bulldoser
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ButtonSelect_Tractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedTractor = _drawingTractor;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
<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="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>
|
||||
@ -406,4 +406,7 @@
|
||||
SqQBINQfkf7yz6ev/zEzM7Ok/f7hf5jEhMkgDZ7VAAAAAElFTkSuQmCC
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="fileSystemWatcher1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
125
Bulldoser/Bulldoser/Form2.Designer.cs
generated
Normal file
125
Bulldoser/Bulldoser/Form2.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
||||
namespace Bulldoser
|
||||
{
|
||||
partial class FormTractorCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxCollections = new PictureBox();
|
||||
groupBoxTools = new GroupBox();
|
||||
maskedTextBoxNumbers = new MaskedTextBox();
|
||||
buttonUpdateCollection = new Button();
|
||||
buttonRemoveTransport = new Button();
|
||||
buttonAddTransport = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).BeginInit();
|
||||
groupBoxTools.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollections
|
||||
//
|
||||
pictureBoxCollections.Location = new Point(12, 6);
|
||||
pictureBoxCollections.Name = "pictureBoxCollections";
|
||||
pictureBoxCollections.Size = new Size(570, 432);
|
||||
pictureBoxCollections.TabIndex = 1;
|
||||
pictureBoxCollections.TabStop = false;
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(maskedTextBoxNumbers);
|
||||
groupBoxTools.Controls.Add(buttonUpdateCollection);
|
||||
groupBoxTools.Controls.Add(buttonRemoveTransport);
|
||||
groupBoxTools.Controls.Add(buttonAddTransport);
|
||||
groupBoxTools.Location = new Point(588, 6);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(200, 432);
|
||||
groupBoxTools.TabIndex = 2;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxNumbers
|
||||
//
|
||||
maskedTextBoxNumbers.Location = new Point(6, 106);
|
||||
maskedTextBoxNumbers.Margin = new Padding(3, 2, 3, 2);
|
||||
maskedTextBoxNumbers.Mask = "0";
|
||||
maskedTextBoxNumbers.Name = "maskedTextBoxNumbers";
|
||||
maskedTextBoxNumbers.Size = new Size(188, 23);
|
||||
maskedTextBoxNumbers.TabIndex = 5;
|
||||
//
|
||||
// buttonUpdateCollection
|
||||
//
|
||||
buttonUpdateCollection.Location = new Point(6, 220);
|
||||
buttonUpdateCollection.Name = "buttonUpdateCollection";
|
||||
buttonUpdateCollection.Size = new Size(188, 40);
|
||||
buttonUpdateCollection.TabIndex = 3;
|
||||
buttonUpdateCollection.Text = "Обновление коллекции";
|
||||
buttonUpdateCollection.UseVisualStyleBackColor = true;
|
||||
buttonUpdateCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// buttonRemoveTransport
|
||||
//
|
||||
buttonRemoveTransport.Location = new Point(6, 152);
|
||||
buttonRemoveTransport.Name = "buttonRemoveTransport";
|
||||
buttonRemoveTransport.Size = new Size(188, 40);
|
||||
buttonRemoveTransport.TabIndex = 2;
|
||||
buttonRemoveTransport.Text = "Удалить транспорт";
|
||||
buttonRemoveTransport.UseVisualStyleBackColor = true;
|
||||
buttonRemoveTransport.Click += ButtonRemoveTractor_Click;
|
||||
//
|
||||
// buttonAddTransport
|
||||
//
|
||||
buttonAddTransport.Location = new Point(6, 39);
|
||||
buttonAddTransport.Name = "buttonAddTransport";
|
||||
buttonAddTransport.Size = new Size(188, 47);
|
||||
buttonAddTransport.TabIndex = 0;
|
||||
buttonAddTransport.Text = "Добавить транспорт";
|
||||
buttonAddTransport.UseVisualStyleBackColor = true;
|
||||
buttonAddTransport.Click += ButtonAddTractor_Click;
|
||||
//
|
||||
// FormTractorCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(pictureBoxCollections);
|
||||
Name = "FormTractorCollection";
|
||||
Text = "Набор автомобилей";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollections).EndInit();
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollections;
|
||||
private GroupBox groupBoxTools;
|
||||
private Button buttonUpdateCollection;
|
||||
private Button buttonRemoveTransport;
|
||||
private Button buttonAddTransport;
|
||||
private MaskedTextBox maskedTextBoxNumbers;
|
||||
}
|
||||
}
|
65
Bulldoser/Bulldoser/Form2.cs
Normal file
65
Bulldoser/Bulldoser/Form2.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using Bulldoser.Drawings;
|
||||
using Bulldoser.Generic;
|
||||
using Bulldoser.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Bulldoser
|
||||
{
|
||||
public partial class FormTractorCollection : Form
|
||||
{
|
||||
private readonly TractorGenericCollection<DrawingTractor, DrawingObjectTractor> _Tractors;
|
||||
public FormTractorCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_Tractors = new TractorGenericCollection<DrawingTractor, DrawingObjectTractor>(pictureBoxCollections.Width,
|
||||
pictureBoxCollections.Height);
|
||||
}
|
||||
private void ButtonAddTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_Tractors == null) return;
|
||||
FormBulldoser form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
//проверяем, удалось ли нам загрузить объект
|
||||
if (_Tractors + form.SelectedTractor != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollections.Image = _Tractors.ShowTractors();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumbers.Text);
|
||||
if (_Tractors - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollections.Image = _Tractors.ShowTractors();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollections.Image = _Tractors.ShowTractors();
|
||||
}
|
||||
}
|
||||
}
|
120
Bulldoser/Bulldoser/Form2.resx
Normal file
120
Bulldoser/Bulldoser/Form2.resx
Normal 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>
|
95
Bulldoser/Bulldoser/Generic/BulldoserGenericCollection.cs
Normal file
95
Bulldoser/Bulldoser/Generic/BulldoserGenericCollection.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using Bulldoser.Drawings;
|
||||
using Bulldoser.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bulldoser.Generic
|
||||
{
|
||||
public class TractorGenericCollection<T, U> where T : DrawingTractor where U : IMoveableObject
|
||||
{
|
||||
//ширина /высота окна
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
//ширина /высота занимаемого места
|
||||
private readonly int _placeSizeWidth = 170;
|
||||
private readonly int _placeSizeHeight = 130;
|
||||
/// Набор объектов
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public TractorGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
|
||||
// высчитываем размер массива для setgeneric
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// Перегрузка оператора сложения
|
||||
public static int operator +(TractorGenericCollection<T, U> collect, T tract)
|
||||
{
|
||||
if (tract == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(tract);
|
||||
}
|
||||
public static T? operator -(TractorGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
// получение объекта imoveableObj
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
/// Вывод всего набора объектов
|
||||
public Bitmap ShowTractors()
|
||||
{
|
||||
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 / 3, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int HeightObjCount = _pictureHeight / _placeSizeHeight;
|
||||
int WidthObjCount = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
T t = _collection.Get(i);
|
||||
if (t != null)
|
||||
{
|
||||
{
|
||||
t.SetPosition((_collection.Count - i - 1) % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth,
|
||||
(_collection.Count - i - 1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
|
||||
t.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
Bulldoser/Bulldoser/Generic/SetGeneric.cs
Normal file
67
Bulldoser/Bulldoser/Generic/SetGeneric.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bulldoser.Generic
|
||||
{
|
||||
public class SetGeneric<T> where T : class
|
||||
{
|
||||
private readonly T[] _places;
|
||||
public int Count => _places.Length;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
public int Insert(T tract)
|
||||
{
|
||||
return Insert(tract, 0);
|
||||
}
|
||||
public int Insert(T tract, int position)
|
||||
{
|
||||
int NoEmpty = 0, temp = 0;
|
||||
for (int i = position; i < Count; i++)
|
||||
{
|
||||
if (_places[i] != null) NoEmpty++;
|
||||
}
|
||||
if (NoEmpty == Count - position - 1) return -1;
|
||||
|
||||
if (position < Count && position >= 0)
|
||||
{
|
||||
for (int j = position; j < Count; j++)
|
||||
{
|
||||
if (_places[j] == null)
|
||||
{
|
||||
temp = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// shift right
|
||||
for (int i = temp; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = tract;
|
||||
return position;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
return null;
|
||||
|
||||
T tmp = _places[position];
|
||||
_places[position] = null;
|
||||
return tmp;
|
||||
}
|
||||
//Получение объекта из набора по позиции
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Bulldoser
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormTractorCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user