parent
4311f2f59b
commit
0b8b779277
@ -1,108 +0,0 @@
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Drawnings;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Абстракция компании,хранящий коллекцию круизеров
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места(ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер места(высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 120;
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Коллекцияя круизеров
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningBaseLocomotive> _collection = null;
|
||||
/// <summary>
|
||||
/// Вычисление макс кол-ва элементов,который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth / _placeSizeWidth * (_pictureHeight / _placeSizeHeight);
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth">Ширина окна</param>
|
||||
/// <param name="pictureHeight">Высота окна</param>
|
||||
/// <param name="collection">коллекция</param>
|
||||
public AbstractCompany(int picWidth, int pictureHeight,ICollectionGenericObjects<DrawningBaseLocomotive> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
/// <summary>
|
||||
/// перегрузка оператора + для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="cruiser">добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningBaseLocomotive cruiser)
|
||||
{
|
||||
if (company._collection == null)
|
||||
return -1;
|
||||
return company._collection.Insert(cruiser);
|
||||
}
|
||||
/// <summary>
|
||||
/// перегрузка оператора - для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">позиция удаления</param>
|
||||
/// <returns></returns>
|
||||
public static DrawningBaseLocomotive operator -(AbstractCompany company, int position)
|
||||
{
|
||||
if (company._collection == null)
|
||||
return null;
|
||||
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// получение случайног обьекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningBaseLocomotive? GetRandomObject()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
/// <summary>
|
||||
/// вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap? bitmap = new(_pictureWidth,_pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackground(graphics);
|
||||
|
||||
SetObjectPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningBaseLocomotive? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
protected abstract void DrawBackground(Graphics graphics);
|
||||
/// <summary>
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectPosition();
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
namespace LocomativeProject.CollectionGenericObjects;
|
||||
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Кол-во объектов в коллекции
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
/// <summary>
|
||||
/// Установка макс. кол-ва элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true-вставка прошла удачно,false- вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">позиция</param>
|
||||
/// <returns>true-вставка прошла удачно,false- вставка не удалась</returns>
|
||||
int Insert(T obj,int position);
|
||||
/// <summary>
|
||||
/// Удаление обьекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="positon">позиция</param>
|
||||
/// <returns>true-удаление прошло удачно,false- удаление не удалось</returns>
|
||||
T? Remove(int positon);
|
||||
/// <summary>
|
||||
/// получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="positon">позиция</param>
|
||||
/// <returns>Обьект</returns>
|
||||
T? Get(int positon);
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomotiveProject.CollectionGenericObjects;
|
||||
using System;
|
||||
namespace Cruiser.CollectionGenericObjects;
|
||||
|
||||
public class LocomotiveDock : AbstractCompany
|
||||
{
|
||||
public LocomotiveDock(int picWidth, int pictureHeight, ICollectionGenericObjects<DrawningBaseLocomotive> collection) : base(picWidth, pictureHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black,2);
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 10, i * _placeSizeWidth + 190, j * _placeSizeHeight + 10);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 120, i * _placeSizeWidth + 190, j * _placeSizeHeight + 120);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 10, i * _placeSizeWidth + 20, j * _placeSizeHeight + 120);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition()
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int curWidth = 0;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection?.Get(i) != null)
|
||||
{
|
||||
_collection?.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i).SetPosition(_placeSizeWidth * curWidth + 30, curHeight * _placeSizeHeight + 35);
|
||||
}
|
||||
if (curHeight < height - 1)
|
||||
curHeight++;
|
||||
else
|
||||
{
|
||||
curHeight = 0;
|
||||
curWidth++;
|
||||
}
|
||||
if (curWidth > width - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomotiveProject.CollectionGenericObjects;
|
||||
|
||||
namespace Cruiser.CollectionGenericObjects;
|
||||
|
||||
public class LocomotiveSharingService : AbstractCompany
|
||||
{
|
||||
public LocomotiveSharingService(int picWidth, int pictureHeight, ICollectionGenericObjects<DrawningBaseLocomotive> collection) : base(picWidth, pictureHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black,2);
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 10, i * _placeSizeWidth + 190, j * _placeSizeHeight + 10);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 120, i * _placeSizeWidth + 190, j * _placeSizeHeight + 120);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 10, i * _placeSizeWidth + 20, j * _placeSizeHeight + 120);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition()
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int curWidth = 0;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection?.Get(i) != null)
|
||||
{
|
||||
_collection?.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i).SetPosition(_placeSizeWidth * curWidth + 30, curHeight * _placeSizeHeight + 35);
|
||||
}
|
||||
if (curHeight < height - 1)
|
||||
curHeight++;
|
||||
else
|
||||
{
|
||||
curHeight = 0;
|
||||
curWidth++;
|
||||
}
|
||||
if (curWidth > width - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
namespace LocomativeProject.CollectionGenericObjects;
|
||||
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private T[] _collection;
|
||||
|
||||
public int Count => _collection.Length;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T>();
|
||||
}
|
||||
|
||||
public T? Get(int positon)
|
||||
{
|
||||
if (positon <= Count || positon > 0)
|
||||
{
|
||||
return _collection[positon];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null )
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
if (_collection[position]== null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = position; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (int i = Count -1; i > 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0) return null;
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
T obj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
namespace LocomativeProject
|
||||
{
|
||||
partial class FormLocomotiveCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBox1 = new GroupBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveLocomotive = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonModifLocomotive = new Button();
|
||||
buttonAddLocomotive = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(buttonRefresh);
|
||||
groupBox1.Controls.Add(buttonGoToCheck);
|
||||
groupBox1.Controls.Add(buttonRemoveLocomotive);
|
||||
groupBox1.Controls.Add(maskedTextBox);
|
||||
groupBox1.Controls.Add(buttonModifLocomotive);
|
||||
groupBox1.Controls.Add(buttonAddLocomotive);
|
||||
groupBox1.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBox1.Dock = DockStyle.Right;
|
||||
groupBox1.Location = new Point(912, 0);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(180, 581);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Location = new Point(32, 530);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(124, 39);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Location = new Point(32, 349);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(124, 39);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// buttonRemoveLocomotive
|
||||
//
|
||||
buttonRemoveLocomotive.Location = new Point(18, 207);
|
||||
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
||||
buttonRemoveLocomotive.Size = new Size(150, 23);
|
||||
buttonRemoveLocomotive.TabIndex = 4;
|
||||
buttonRemoveLocomotive.Text = "Удалить поезд";
|
||||
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(18, 178);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(150, 23);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonModifLocomotive
|
||||
//
|
||||
buttonModifLocomotive.Location = new Point(18, 102);
|
||||
buttonModifLocomotive.Name = "buttonModifLocomotive";
|
||||
buttonModifLocomotive.Size = new Size(150, 43);
|
||||
buttonModifLocomotive.TabIndex = 2;
|
||||
buttonModifLocomotive.Text = "Добавление модиф поезда";
|
||||
buttonModifLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonModifLocomotive.Click += ButtonModifLocomotive_Click;
|
||||
//
|
||||
// buttonAddLocomotive
|
||||
//
|
||||
buttonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddLocomotive.Location = new Point(18, 62);
|
||||
buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||
buttonAddLocomotive.Size = new Size(150, 23);
|
||||
buttonAddLocomotive.TabIndex = 1;
|
||||
buttonAddLocomotive.Text = "Добавление поезда";
|
||||
buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
|
||||
//
|
||||
// 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(18, 22);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(150, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(912, 581);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormLocomotiveCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1092, 581);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormLocomotiveCollection";
|
||||
Text = "Коллекция Крейсеров";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddLocomotive;
|
||||
private Button buttonModifLocomotive;
|
||||
private Button buttonRemoveLocomotive;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
using Cruiser.CollectionGenericObjects;
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomotiveProject.CollectionGenericObjects;
|
||||
using LocomotiveProject.Drawnings;
|
||||
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 LocomativeProject
|
||||
{
|
||||
public partial class FormLocomotiveCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
/// <summary>
|
||||
/// Консруктор
|
||||
/// </summary>
|
||||
public FormLocomotiveCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new LocomotiveDock(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningBaseLocomotive>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type"> тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Random rnd = new();
|
||||
DrawningBaseLocomotive drawningBaseLocomotive;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBaseLocomotive):
|
||||
drawningBaseLocomotive = new DrawningBaseLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd));
|
||||
break;
|
||||
case nameof(DrawningLocomotive):
|
||||
drawningBaseLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), GetColor(rnd),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company + drawningBaseLocomotive != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение рандом цвета
|
||||
/// </summary>
|
||||
/// <param name="rnd"></param>
|
||||
/// <returns></returns>
|
||||
private static Color GetColor(Random rnd)
|
||||
{
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(255, 256));
|
||||
ColorDialog dialog = new ColorDialog();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
/// <summary>
|
||||
/// Кнопка создания обычного крейсера
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBaseLocomotive));
|
||||
/// <summary>
|
||||
/// Кнопка создания модиф крейсера
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonModifLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
|
||||
/// <summary>
|
||||
/// Кнопка удаления Крейсера
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Кнопка отправить на полигон для испытаний
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningBaseLocomotive baseLocomotive = null;
|
||||
int counter = 100;
|
||||
while (baseLocomotive == null)
|
||||
{
|
||||
baseLocomotive = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (baseLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LocomotiveProjectForm form = new() { SetLocomotive = baseLocomotive };
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Кнопка обновления компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows7.0</TargetFramework>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace LocomativeProject
|
||||
{
|
||||
partial class LocomotiveProjectForm
|
||||
partial class LocomotiveProject
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -28,7 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LocomotiveProjectForm));
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LocomotiveProject));
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreateBaseLocomotive = new System.Windows.Forms.Button();
|
@ -15,25 +15,13 @@ using LocomativeProject.MovementStrategy;
|
||||
|
||||
namespace LocomativeProject
|
||||
{
|
||||
public partial class LocomotiveProjectForm : Form
|
||||
public partial class LocomotiveProject : Form
|
||||
{
|
||||
private DrawningBaseLocomotive? _drawningLocomotive;
|
||||
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawningBaseLocomotive SetLocomotive
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningLocomotive = value;
|
||||
_drawningLocomotive.SetPictureSize(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
comboBox1.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public LocomotiveProjectForm()
|
||||
public LocomotiveProject()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
@ -11,7 +11,7 @@ namespace LocomativeProject
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormLocomotiveCollection());
|
||||
Application.Run(new LocomotiveProject());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user