Лабораторная работа №3

This commit is contained in:
sqdselo 2024-03-31 22:08:27 +04:00
parent 7fe1682f7b
commit 0be2471e88
12 changed files with 672 additions and 182 deletions

View File

@ -0,0 +1,90 @@
using HoistingCrane.Drawning;
using System;
namespace HoistingCrane.CollectionGenericObjects
{
public abstract class AbstractCompany
{
/// <summary>
/// Ширина ячейки гаража
/// </summary>
protected readonly int _placeSizeWidth = 150;
/// <summary>
/// Высота ячейки гаража
/// </summary>
protected readonly int _placeSizeHeight = 90;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int pictureHeight;
/// <summary>
/// Коллекция автомобилей
/// </summary>
protected ICollectionGenericObjects<DrawningTrackedVehicle>? arr = null;
/// <summary>
/// Максимальное количество гаражей
/// </summary>
private int GetMaxCount
{
get
{
return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth);
}
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedVehicle> array)
{
pictureWidth = picWidth;
pictureHeight = picHeight;
arr = array;
arr.SetMaxCount = GetMaxCount;
}
public static bool operator +(AbstractCompany company, DrawningTrackedVehicle car)
{
return company.arr?.Insert(car) ?? false;
}
public static bool operator -(AbstractCompany company, int position)
{
return company.arr?.Remove(position) ?? false;
}
public DrawningTrackedVehicle? GetRandomObject()
{
Random rnd = new();
return arr?.Get(rnd.Next(GetMaxCount));
}
/// <summary>
/// Вывод всей коллекции
/// </summary>
/// <returns></returns>
public Bitmap? Show()
{
Bitmap bitmap = new(pictureWidth, pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics);
SetObjectsPosition();
for (int i = 0; i < (arr?.Count ?? 0); i++)
{
DrawningTrackedVehicle? obj = arr?.Get(i);
obj?.DrawTransport(graphics);
}
return bitmap;
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
protected abstract void DrawBackgound(Graphics g);
/// <summary>
/// Расстановка объектов
/// </summary>
protected abstract void SetObjectsPosition();
}
}

View File

@ -0,0 +1,59 @@
using HoistingCrane.Drawning;
using System;
namespace HoistingCrane.CollectionGenericObjects
{
public class CarSharingService : AbstractCompany
{
public CarSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedVehicle> array) : base(picWidth, picHeight, array)
{
}
protected override void DrawBackgound(Graphics g)
{
int width = pictureWidth / _placeSizeWidth;
int height = pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 3);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15 + _placeSizeWidth - 55, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15, j * _placeSizeHeight - _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int countWidth = pictureWidth / _placeSizeWidth;
int countHeight = pictureHeight / _placeSizeHeight;
int currentPosWidth = 0;
int currentPosHeight = 0;
for (int i = 0; i < (arr?.Count ?? 0); i++)
{
if (arr?.Get(i) != null)
{
arr?.Get(i)?.SetPictureSize(pictureWidth, pictureHeight);
arr?.Get(i)?.SetPosition(_placeSizeWidth * currentPosWidth + 25, currentPosHeight * _placeSizeHeight + 15);
}
if (currentPosWidth < countWidth-1)
currentPosWidth++;
else
{
currentPosWidth = 0;
currentPosHeight++;
}
if (currentPosHeight > countHeight - 1)
{
break;
}
}
}
}
}

View File

@ -1,51 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane.CollectionGenericObjects
{
internal interface ICollectionGenericObjects<T>
public interface ICollectionGenericObjects<T>
where T: class
{
/// <summary>
/// Колличество объектов в коллекции
/// Кол-во объектов в коллекции
/// </summary>
int Count { get; }
/// <summary>
/// Максимальная вместимость коллекции("гаража")
/// Максимальное количество элементов
/// </summary>
int SetMaxCount { set; }
/// <summary>
/// Добавление элемента в коллекцию на свободную позицию
/// Добавление элемента в коллекцию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <param name="obj"></param>
/// <returns></returns>
bool Insert(T obj);
/// <summary>
/// Добавление элемента в коллекцию на конкретное место
/// Добавление элемента в коллекцию на определенную позицию
/// </summary>
/// <param name="obj">Добовляемый объект</param>
/// <param name="pos">Позиция объекта</param>
/// <param name="obj"></param>
/// <param name="position"></param>
/// <returns></returns>
bool Insert(T obj, int pos);
bool Insert(T obj, int position);
/// <summary>
/// Удаление конкретного элемента коллекции
/// Удаление элемента из коллекции по его позиции
/// </summary>
/// <param name="pos">Номер позиции</param>
/// <param name="position"></param>
/// <returns></returns>
bool Remove(int pos);
/// <summary>
/// Получение элемента коллекции по индексу
/// </summary>
/// <param name="pos">Индекс элемента</param>
/// <returns></returns>
T? Get(int pos);
bool Remove(int position);
T? Get(int position);
}
}

View File

@ -1,101 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane.CollectionGenericObjects
{
internal class MassivGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
public class MassivGenericObjects<T> : ICollectionGenericObjects<T> where T : class
{
/// <summary>
/// Создание массива типа <T>
/// </summary>
private T[] array;
/// <summary>
/// Конструктор класса
/// </summary>
private T?[] arr;
public MassivGenericObjects()
{
array = Array.Empty<T>();
arr = Array.Empty<T?>();
}
/// <summary>
/// Кол-во элементов массива
/// </summary>
public int Count => array.Length;
public int SetMaxCount { set { if (value > 0) array = new T[value]; } }
public T? Get(int pos)
public int Count
{
return array[pos];
get { return arr.Length; }
}
public int SetMaxCount
{
set
{
if (value > 0)
{
arr = new T?[value];
}
}
}
public T? Get(int position)
{
if(position >= 0 && position < arr.Length)
{
return arr[position];
}
return null;
}
/// <summary>
/// Вставка элемента в свободную позицию(с начала)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public bool Insert(T obj)
{
for(int i = 0; i < Count; i++)
{
if (array[i] == null) return true;
}
return false;
}
/// <summary>
/// Вставка элемента в конкретную позицию
/// </summary>
/// <param name="obj"></param>
/// <param name="pos"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public bool Insert(T obj, int pos)
{
bool flag = false;
if (array[pos] == null)
{
array[pos] = obj;
if (arr[i] == null) {
arr[i] = obj;
return true;
}
if (array[pos] != null)
{
for(int i = pos; i < Count; i++)
{
if (array[i] == null)
{
flag = true;
array[i] = obj;
return true;
}
}
if(flag == false)
{
for(int i = pos; i > 0; i--)
{
if (array[i] == null)
{
array[i] = obj;
return true;
}
}
}
}
return false;
}
public bool Remove(int pos)
public bool Insert(T obj, int position)
{
if (array[pos] != null)
// Проверка позиции
if (position < Count && position >= 0)
{
if (arr[position] == null)
{
arr[position] = obj;
}
else
{
int flag = -1;
for (int i = position + 1; i < arr.Length; i++)
{
if (arr[i] == null)
{
flag = 1;
arr[i] = obj;
break;
}
}
if (flag == -1 && position != 0)
{
for (int i = position - 1; i >= 0; i--)
{
if (arr[i] == null)
{
arr[i] = obj;
break;
}
}
}
}
}
return false;
}
public bool Remove(int position)
{
if(position < 0 || position >= arr.Length || arr[position] == null)
{
return false;
}
arr[position] = null;
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,173 @@
namespace HoistingCrane
{
partial class FormCarCollection
{
/// <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();
buttonGoToChek = new Button();
buttonRefresh = new Button();
buttonDeleteCar = new Button();
maskedTextBox = new MaskedTextBox();
comboBoxSelectorCompany = new ComboBox();
buttonCreateTrackedVehicle = new Button();
buttonCreateHoistingCrane = new Button();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonGoToChek);
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonDeleteCar);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(buttonCreateTrackedVehicle);
groupBoxTools.Controls.Add(buttonCreateHoistingCrane);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(716, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(210, 450);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonGoToChek
//
buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToChek.Location = new Point(12, 298);
buttonGoToChek.Name = "buttonGoToChek";
buttonGoToChek.Size = new Size(192, 34);
buttonGoToChek.TabIndex = 6;
buttonGoToChek.Text = "Передать на тесты";
buttonGoToChek.UseVisualStyleBackColor = true;
buttonGoToChek.Click += buttonGoToChek_Click;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(12, 375);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(192, 34);
buttonRefresh.TabIndex = 5;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
// buttonDeleteCar
//
buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDeleteCar.Location = new Point(12, 233);
buttonDeleteCar.Name = "buttonDeleteCar";
buttonDeleteCar.Size = new Size(192, 34);
buttonDeleteCar.TabIndex = 4;
buttonDeleteCar.Text = "Удалить автомобиль";
buttonDeleteCar.UseVisualStyleBackColor = true;
buttonDeleteCar.Click += buttonDeleteCar_Click;
//
// maskedTextBox
//
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBox.Location = new Point(12, 204);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(192, 23);
maskedTextBox.TabIndex = 3;
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(12, 28);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(192, 23);
comboBoxSelectorCompany.TabIndex = 2;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
//
// buttonCreateTrackedVehicle
//
buttonCreateTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonCreateTrackedVehicle.Location = new Point(12, 129);
buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
buttonCreateTrackedVehicle.Size = new Size(192, 34);
buttonCreateTrackedVehicle.TabIndex = 1;
buttonCreateTrackedVehicle.Text = "Добавить гусеничную машину";
buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
buttonCreateTrackedVehicle.Click += buttonCreateTrackedVehicle_Click;
//
// buttonCreateHoistingCrane
//
buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonCreateHoistingCrane.Location = new Point(12, 89);
buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
buttonCreateHoistingCrane.Size = new Size(192, 34);
buttonCreateHoistingCrane.TabIndex = 0;
buttonCreateHoistingCrane.Text = "Добавить подъемный кран";
buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(716, 450);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormCarCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(926, 450);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormCarCollection";
Text = "FormCarCollections";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private Button buttonCreateHoistingCrane;
private Button buttonCreateTrackedVehicle;
private ComboBox comboBoxSelectorCompany;
private Button buttonRefresh;
private Button buttonDeleteCar;
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;
private Button buttonGoToChek;
}
}

View File

@ -0,0 +1,131 @@
using HoistingCrane.CollectionGenericObjects;
using HoistingCrane.Drawning;
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 HoistingCrane
{
public partial class FormCarCollection : Form
{
private AbstractCompany? _company;
public FormCarCollection()
{
InitializeComponent();
}
private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassivGenericObjects<DrawningTrackedVehicle>());
break;
}
}
private void CreateObject(string type)
{
DrawningTrackedVehicle drawning;
if (_company == null) return;
Random rand = new();
switch (type)
{
case nameof(DrawningHoistingCrane):
drawning = new DrawningHoistingCrane(rand.Next(100, 300), rand.Next(1000, 3000), GetColor(rand), GetColor(rand), true, true);
break;
case nameof(DrawningTrackedVehicle):
drawning = new DrawningTrackedVehicle(rand.Next(100, 300), rand.Next(1000, 3000), GetColor(rand));
break;
default:
return;
}
if (_company + drawning)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private static Color GetColor(Random random)
{
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;
}
return color;
}
private void buttonCreateHoistingCrane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningHoistingCrane));
private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
private void buttonDeleteCar_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos)
{
MessageBox.Show("Объект удален!");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void buttonRefresh_Click(object sender, EventArgs e)
{
if (_company == null) return;
pictureBox.Image = _company.Show();
}
private void buttonGoToChek_Click(object sender, EventArgs e)
{
if (_company == null) return;
DrawningTrackedVehicle? car = null;
int count = 100;
while (car == null)
{
car = _company.GetRandomObject();
count--;
if (count <= 0) break;
}
if (car == null) return;
FormHoistingCrane form = new()
{
SetCar = car
};
form.ShowDialog();
}
}
}

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

@ -21,12 +21,10 @@ namespace HoistingCrane
private void InitializeComponent()
{
pictureBoxHoistingCrane = new PictureBox();
buttonCreateHoistingCrane = new Button();
ButtonLeft = new Button();
ButtonRight = new Button();
ButtonUp = new Button();
ButtonDown = new Button();
buttonCreateTrackedVehicle = new Button();
comboStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).BeginInit();
@ -41,17 +39,6 @@ namespace HoistingCrane
pictureBoxHoistingCrane.TabIndex = 0;
pictureBoxHoistingCrane.TabStop = false;
//
// buttonCreateHoistingCrane
//
buttonCreateHoistingCrane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateHoistingCrane.Location = new Point(0, 492);
buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
buttonCreateHoistingCrane.Size = new Size(188, 23);
buttonCreateHoistingCrane.TabIndex = 1;
buttonCreateHoistingCrane.Text = "Создать подъемный кран";
buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
buttonCreateHoistingCrane.Click += ButtonCreateHoistingCrane_Click;
//
// ButtonLeft
//
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
@ -100,17 +87,6 @@ namespace HoistingCrane
ButtonDown.UseVisualStyleBackColor = true;
ButtonDown.Click += ButtonMove_Click;
//
// buttonCreateTrackedVehicle
//
buttonCreateTrackedVehicle.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateTrackedVehicle.Location = new Point(203, 492);
buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
buttonCreateTrackedVehicle.Size = new Size(194, 23);
buttonCreateTrackedVehicle.TabIndex = 6;
buttonCreateTrackedVehicle.Text = "Создать гусеничную машину";
buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
buttonCreateTrackedVehicle.Click += buttonCreateTrackedVehicle_Click;
//
// comboStrategy
//
comboStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -138,12 +114,10 @@ namespace HoistingCrane
ClientSize = new Size(818, 515);
Controls.Add(buttonStrategyStep);
Controls.Add(comboStrategy);
Controls.Add(buttonCreateTrackedVehicle);
Controls.Add(ButtonDown);
Controls.Add(ButtonUp);
Controls.Add(ButtonRight);
Controls.Add(ButtonLeft);
Controls.Add(buttonCreateHoistingCrane);
Controls.Add(pictureBoxHoistingCrane);
Name = "FormHoistingCrane";
Text = "Подъемный кран";
@ -154,12 +128,10 @@ namespace HoistingCrane
// #endregion
private PictureBox pictureBoxHoistingCrane;
private Button buttonCreateHoistingCrane;
private Button ButtonLeft;
private Button ButtonRight;
private Button ButtonUp;
private Button ButtonDown;
private Button buttonCreateTrackedVehicle;
private ComboBox comboStrategy;
private Button buttonStrategyStep;
}

View File

@ -14,6 +14,17 @@ namespace HoistingCrane
_abstractStrategy = null;
}
public DrawningTrackedVehicle? SetCar
{
set
{
_drawning = value;
_drawning?.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
comboStrategy.Enabled = true;
Draw();
}
}
private void Draw()
{
Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
@ -22,55 +33,6 @@ namespace HoistingCrane
pictureBoxHoistingCrane.Image = bmp;
}
/// <summary>
/// Создать подъемный кран
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateHoistingCrane_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningHoistingCrane));
}
/// <summary>
/// Создать бронебойную машину
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningTrackedVehicle));
}
private void CreateObject(string type)
{
Random rand = new();
switch (type)
{
case nameof(DrawningHoistingCrane):
_drawning = new DrawningHoistingCrane(rand.Next(100, 300), rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)), true, true);
break;
case nameof(DrawningTrackedVehicle):
_drawning = new DrawningTrackedVehicle(rand.Next(100, 300), rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
break;
default:
return;
}
_drawning.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
_drawning.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
comboStrategy.Enabled = true;
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawning == null) { return; }

View File

@ -8,6 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="CollectionGenericObjects\MassivGenericObjects.cs~RF2955bcc.TMP" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@ -11,7 +11,8 @@ namespace HoistingCrane
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormHoistingCrane());
Application.Run(new FormCarCollection());
}
}
}

BIN
Безымянный.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB