Фулл третья лаба
This commit is contained in:
parent
7a9cd6dcd2
commit
d8f53d52d1
@ -75,7 +75,6 @@ namespace Liner.Drawing
|
|||||||
g.FillPolygon(bottomBrush, bottom);
|
g.FillPolygon(bottomBrush, bottom);
|
||||||
g.DrawPolygon(pen, bottom);//рисуем нижний корпус
|
g.DrawPolygon(pen, bottom);//рисуем нижний корпус
|
||||||
if (liner.SwimmingPool) { g.FillPolygon(poolBrush, pool); }//рисуем бассейн
|
if (liner.SwimmingPool) { g.FillPolygon(poolBrush, pool); }//рисуем бассейн
|
||||||
g.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Liner.Entities;
|
using Liner.Entities;
|
||||||
|
using Liner.MovingStrategies;
|
||||||
|
|
||||||
namespace Liner.Drawing
|
namespace Liner.Drawing
|
||||||
{
|
{
|
||||||
@ -54,6 +55,10 @@ namespace Liner.Drawing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int GetHeight => _linerHeight;
|
public int GetHeight => _linerHeight;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawingLiner
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawingObjectLiner(this);
|
||||||
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
@ -125,7 +130,6 @@ namespace Liner.Drawing
|
|||||||
}
|
}
|
||||||
g.FillPolygon(bottomBrush, bottom);
|
g.FillPolygon(bottomBrush, bottom);
|
||||||
g.DrawPolygon(pen, bottom);//рисуем нижний корпус
|
g.DrawPolygon(pen, bottom);//рисуем нижний корпус
|
||||||
g.Dispose();
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Проверка, что объект может переместится по указанному направлению
|
/// Проверка, что объект может переместится по указанному направлению
|
||||||
|
123
Liner/FormLinerCollection.Designer.cs
generated
Normal file
123
Liner/FormLinerCollection.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
namespace Liner
|
||||||
|
{
|
||||||
|
partial class FormLinerCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
groupBoxTools = new GroupBox();
|
||||||
|
buttonRefreshCollection = new Button();
|
||||||
|
buttonDeleteLiner = new Button();
|
||||||
|
textBoxNumber = new TextBox();
|
||||||
|
buttonAddLiner = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
groupBoxTools.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||||
|
groupBoxTools.Controls.Add(buttonDeleteLiner);
|
||||||
|
groupBoxTools.Controls.Add(textBoxNumber);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddLiner);
|
||||||
|
groupBoxTools.Location = new Point(739, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(211, 565);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Tools";
|
||||||
|
//
|
||||||
|
// buttonRefreshCollection
|
||||||
|
//
|
||||||
|
buttonRefreshCollection.Location = new Point(11, 258);
|
||||||
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
|
buttonRefreshCollection.Size = new Size(194, 40);
|
||||||
|
buttonRefreshCollection.TabIndex = 3;
|
||||||
|
buttonRefreshCollection.Text = "Refresh Collection";
|
||||||
|
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// buttonDeleteLiner
|
||||||
|
//
|
||||||
|
buttonDeleteLiner.Location = new Point(11, 117);
|
||||||
|
buttonDeleteLiner.Name = "buttonDeleteLiner";
|
||||||
|
buttonDeleteLiner.Size = new Size(194, 40);
|
||||||
|
buttonDeleteLiner.TabIndex = 2;
|
||||||
|
buttonDeleteLiner.Text = "Delete Liner";
|
||||||
|
buttonDeleteLiner.UseVisualStyleBackColor = true;
|
||||||
|
buttonDeleteLiner.Click += buttonRemoveLiner_Click;
|
||||||
|
//
|
||||||
|
// textBoxNumber
|
||||||
|
//
|
||||||
|
textBoxNumber.Location = new Point(41, 77);
|
||||||
|
textBoxNumber.Name = "textBoxNumber";
|
||||||
|
textBoxNumber.Size = new Size(139, 23);
|
||||||
|
textBoxNumber.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// buttonAddLiner
|
||||||
|
//
|
||||||
|
buttonAddLiner.Location = new Point(11, 22);
|
||||||
|
buttonAddLiner.Name = "buttonAddLiner";
|
||||||
|
buttonAddLiner.Size = new Size(194, 40);
|
||||||
|
buttonAddLiner.TabIndex = 0;
|
||||||
|
buttonAddLiner.Text = "Add Liner";
|
||||||
|
buttonAddLiner.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddLiner.Click += buttonAddLiner_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(2, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(731, 565);
|
||||||
|
pictureBoxCollection.TabIndex = 1;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormLinerCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(951, 568);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Name = "FormLinerCollection";
|
||||||
|
Text = "Liner Collection";
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private TextBox textBoxNumber;
|
||||||
|
private Button buttonAddLiner;
|
||||||
|
private Button buttonRefreshCollection;
|
||||||
|
private Button buttonDeleteLiner;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
}
|
||||||
|
}
|
88
Liner/FormLinerCollection.cs
Normal file
88
Liner/FormLinerCollection.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
using Liner.Drawing;
|
||||||
|
using Liner.Generics;
|
||||||
|
using Liner.MovingStrategies;
|
||||||
|
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 Liner
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса DrawingLiner
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormLinerCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly LinerGenericCollection<DrawingLiner, DrawingObjectLiner> _liners;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormLinerCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_liners = new LinerGenericCollection<DrawingLiner,
|
||||||
|
DrawingObjectLiner>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonAddLiner_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
MainScreen form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_liners + form.SelectedLiner != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _liners.ShowLiners();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonRemoveLiner_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(textBoxNumber.Text);
|
||||||
|
if (_liners - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _liners.ShowLiners();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _liners.ShowLiners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
Liner/FormLinerCollection.resx
Normal file
120
Liner/FormLinerCollection.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>
|
156
Liner/Generics/LinerGenericCollection.cs
Normal file
156
Liner/Generics/LinerGenericCollection.cs
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
using Liner.MovingStrategies;
|
||||||
|
using Liner.Drawing;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Liner.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
public class LinerGenericCollection<T, U>
|
||||||
|
where T : DrawingLiner
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 100;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 80;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public LinerGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int? operator +(LinerGenericCollection<T, U> collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect?._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(LinerGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowLiners()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawObjects(gr);
|
||||||
|
DrawBackground(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
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; j++)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
/*int iX = ((_pictureWidth / _placeSizeWidth) - 1) * _placeSizeWidth;
|
||||||
|
int iY = 0;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
_collection.Get(i)?.SetPosition(iX,iY);
|
||||||
|
_collection.Get(i)?.DrawTransport(g);
|
||||||
|
if(_collection.Get(i) != null)
|
||||||
|
{
|
||||||
|
iY += _placeSizeHeight;
|
||||||
|
if(iY + _placeSizeHeight >= _pictureHeight)
|
||||||
|
{
|
||||||
|
iY = 0;
|
||||||
|
iX -= _placeSizeWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
int iX = ((_pictureWidth / _placeSizeWidth) - 1) * _placeSizeWidth;
|
||||||
|
int iY = 0;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
_collection.Get(i)?.SetPosition(iX,iY);
|
||||||
|
_collection.Get(i)?.DrawTransport(g);
|
||||||
|
iX -= _placeSizeWidth;
|
||||||
|
if(iX < 0)
|
||||||
|
{
|
||||||
|
iX = ((_pictureWidth / _placeSizeWidth) - 1) * _placeSizeWidth;
|
||||||
|
iY += _placeSizeHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
111
Liner/Generics/SetGeneric.cs
Normal file
111
Liner/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Liner.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly T?[] _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Length;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="liner">Добавляемый лайнер</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T liner)
|
||||||
|
{
|
||||||
|
int nulli = 0;
|
||||||
|
while (_places[nulli] != null)
|
||||||
|
{
|
||||||
|
nulli++;
|
||||||
|
if(nulli == _places.Length)
|
||||||
|
{
|
||||||
|
return -1; // нет пустого места
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//сдвиг
|
||||||
|
for(int i = nulli; i > 0; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
_places[0] = liner;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="liner">Добавляемый лайнер</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T liner, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _places.Length)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
int nulli = position;
|
||||||
|
while (_places[nulli] != null)
|
||||||
|
{
|
||||||
|
nulli++;
|
||||||
|
if (nulli == _places.Length)
|
||||||
|
{
|
||||||
|
return -1; // нет пустого места
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_places[position] = liner;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _places.Length)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _places.Length)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
Liner/MainScreen.Designer.cs
generated
13
Liner/MainScreen.Designer.cs
generated
@ -37,6 +37,7 @@
|
|||||||
buttonCreateBigLiner = new Button();
|
buttonCreateBigLiner = new Button();
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonStep = new Button();
|
buttonStep = new Button();
|
||||||
|
buttonSelectLiner = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -140,11 +141,22 @@
|
|||||||
buttonStep.UseVisualStyleBackColor = true;
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
buttonStep.Click += buttonStep_Click;
|
buttonStep.Click += buttonStep_Click;
|
||||||
//
|
//
|
||||||
|
// buttonSelectLiner
|
||||||
|
//
|
||||||
|
buttonSelectLiner.Location = new Point(856, 93);
|
||||||
|
buttonSelectLiner.Name = "buttonSelectLiner";
|
||||||
|
buttonSelectLiner.Size = new Size(75, 23);
|
||||||
|
buttonSelectLiner.TabIndex = 9;
|
||||||
|
buttonSelectLiner.Text = "Select Liner";
|
||||||
|
buttonSelectLiner.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectLiner.Click += buttonSelectLiner_Click;
|
||||||
|
//
|
||||||
// MainScreen
|
// MainScreen
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(984, 661);
|
ClientSize = new Size(984, 661);
|
||||||
|
Controls.Add(buttonSelectLiner);
|
||||||
Controls.Add(buttonStep);
|
Controls.Add(buttonStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonCreateBigLiner);
|
Controls.Add(buttonCreateBigLiner);
|
||||||
@ -172,5 +184,6 @@
|
|||||||
private Button buttonCreateBigLiner;
|
private Button buttonCreateBigLiner;
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
|
private Button buttonSelectLiner;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
using Liner.Drawing;
|
using Liner.Drawing;
|
||||||
using Liner.Entities;
|
using Liner.Entities;
|
||||||
using Liner.MovingStrategies;
|
using Liner.MovingStrategies;
|
||||||
|
using System.Drawing;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
||||||
|
|
||||||
namespace Liner
|
namespace Liner
|
||||||
{
|
{
|
||||||
@ -16,12 +18,18 @@ namespace Liner
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Âûáðàííûé ëàéíåð
|
||||||
|
/// </summary>
|
||||||
|
public DrawingLiner? SelectedLiner { get; private set; }
|
||||||
|
/// <summary>
|
||||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MainScreen()
|
public MainScreen()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
|
SelectedLiner = null;
|
||||||
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ìåòîä ïðîðèñîâêè ëàéíåðà
|
/// Ìåòîä ïðîðèñîâêè ëàéíåðà
|
||||||
@ -36,17 +44,15 @@ namespace Liner
|
|||||||
gr.Clear(Color.White);
|
gr.Clear(Color.White);
|
||||||
_drawingLiner.DrawTransport(gr);
|
_drawingLiner.DrawTransport(gr);
|
||||||
pictureBoxLiner.Image = bmp;
|
pictureBoxLiner.Image = bmp;
|
||||||
gr.Dispose();
|
|
||||||
}
|
}
|
||||||
private void buttonCreateLiner_Click(object sender, EventArgs e)
|
private void buttonCreateLiner_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
|
Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
_drawingLiner = new DrawingLiner(random.Next(100, 300),
|
_drawingLiner = new DrawingLiner(random.Next(100, 300),
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000), mainColor, addColor,
|
||||||
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)),
|
|
||||||
pictureBoxLiner.Width, pictureBoxLiner.Height);
|
pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
_drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
@ -80,12 +86,15 @@ namespace Liner
|
|||||||
private void buttonCreateBigLiner_Click(object sender, EventArgs e)
|
private void buttonCreateBigLiner_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
|
Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
addColor = dialog.Color;
|
||||||
|
}
|
||||||
_drawingLiner = new DrawingBigLiner(random.Next(100, 300),
|
_drawingLiner = new DrawingBigLiner(random.Next(100, 300),
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000), mainColor, addColor,
|
||||||
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)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
Convert.ToBoolean(random.Next(1, 2)),
|
Convert.ToBoolean(random.Next(1, 2)),
|
||||||
pictureBoxLiner.Width, pictureBoxLiner.Height);
|
pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
@ -128,5 +137,11 @@ namespace Liner
|
|||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void buttonSelectLiner_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedLiner = _drawingLiner;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,5 +35,4 @@ namespace Liner.MovingStrategies
|
|||||||
public void MoveObject(DirectionType direction) =>
|
public void MoveObject(DirectionType direction) =>
|
||||||
_drawingLiner?.MoveTransport(direction);
|
_drawingLiner?.MoveTransport(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,43 @@ namespace Liner
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new MainScreen());
|
Application.Run(new FormLinerCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user