Compare commits

..

No commits in common. "Laba8" and "main" have entirely different histories.
Laba8 ... main

41 changed files with 0 additions and 3182 deletions

View File

@ -1,73 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldHeight = height;
FieldWidth = width;
}
public void MakeStep()
{
if (_state != Status.InProgress)
return;
if (IsTargetDestination())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(Direction.Left);
protected bool MoveRight() => MoveTo(Direction.Right);
protected bool MoveUp() => MoveTo(Direction.Up);
protected bool MoveDown() => MoveTo(Direction.Down);
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectParameters;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestination();
private bool MoveTo(Direction direction)
{
if (_state != Status.InProgress)
return false;
if (_moveableObject?.CheckCanMove(direction) ?? false)
{
_moveableObject.MoveObject(direction);
return true;
}
return false;
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.Entities
{
public class BaseTanker
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public BaseTanker(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
public void ChangeBodyColor(Color bodyColor)
{
BodyColor = bodyColor;
}
}
}

View File

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

View File

@ -1,95 +0,0 @@
using Lab.Generics;
using Lab.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab.DrawningObjects;
namespace Lab.Generics
{
internal class CarsGenericCollection<T, U>
where T : DrawTanker
where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 110;
private readonly int _placeSizeHeight = 80;
private readonly SetGeneric<T> _collection;
public IEnumerable<T?> GetCars => _collection.GetCars();
public CarsGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static bool operator +(CarsGenericCollection<T, U> collect, T?
obj)
{
if (obj == null)
{
return false;
}
return (bool)collect?._collection.Insert(obj, new DrawiningTankerEqutables());
}
public static T? operator -(CarsGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
public void Sort(IComparer<T> comparer) => _collection.SortSet(comparer);
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowCars()
{
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 / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int i = 0;
foreach (var tank in _collection.GetCars())
{
if (tank != null)
{
tank.SetPosition(i % (width) * _placeSizeWidth, (height - i / width - 1) * _placeSizeHeight);
tank.DrawTransport(g);
}
i++;
}
}
}
}

View File

@ -1,131 +0,0 @@
using Lab.DrawningObjects;
using Lab.MovementStrategy;
using Lab.Generics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Lab.Generics
{
internal class CarsGenericStorage
{
readonly Dictionary<TankerCollectionInfo, CarsGenericCollection<DrawTanker, DrawingObjectTanker>> _carStorages;
public List<TankerCollectionInfo> Keys => _carStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private static readonly char _separatorForKeyValue = '|';
private readonly char _separatorRecords = ';';
private static readonly char _separatorForObject = ':';
public CarsGenericStorage(int pictureWidth, int pictureHeight)
{
_carStorages = new Dictionary<TankerCollectionInfo, CarsGenericCollection<DrawTanker, DrawingObjectTanker>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
TankerCollectionInfo Info = new TankerCollectionInfo(name, string.Empty);
if (_carStorages.ContainsKey(Info)) return;
_carStorages[Info] = new CarsGenericCollection<DrawTanker, DrawingObjectTanker>(_pictureWidth, _pictureHeight);
}
public void DelSet(string name)
{
TankerCollectionInfo Info = new TankerCollectionInfo(name, string.Empty);
if (!_carStorages.ContainsKey(Info)) return;
_carStorages.Remove(Info);
}
public CarsGenericCollection<DrawTanker, DrawingObjectTanker>?
this[string ind]
{
get
{
TankerCollectionInfo Info = new TankerCollectionInfo(ind, string.Empty);
if (_carStorages.ContainsKey(Info)) return _carStorages[Info];
return null;
}
}
public void SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<TankerCollectionInfo, CarsGenericCollection<DrawTanker, DrawingObjectTanker>> record in _carStorages)
{
StringBuilder records = new();
foreach (DrawTanker? elem in record.Value.GetCars)
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
}
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
throw new Exception("Невалидная операция, нет данных для сохранения");
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.WriteLine("CarStorage");
writer.Write(data.ToString());
}
}
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
throw new Exception("Файл не найден");
}
using (StreamReader reader = new StreamReader(filename))
{
string checker = reader.ReadLine();
if (checker == null)
throw new Exception("Нет данных для загрузки");
if (!checker.StartsWith("CarStorage"))
throw new Exception("Неверный формат ввода");
_carStorages.Clear();
string strs;
bool firstinit = true;
while ((strs = reader.ReadLine()) != null)
{
if (strs == null && firstinit)
throw new Exception("Нет данных для загрузки");
if (strs == null )
break;
firstinit = false;
string name = strs.Split('|')[0];
CarsGenericCollection<DrawTanker, DrawingObjectTanker> collection = new(_pictureWidth, _pictureHeight);
foreach (string data in strs.Split('|')[1].Split(';'))
{
DrawTanker? car =
data?.CreateDrawTanker(_separatorForObject, _pictureWidth, _pictureHeight);
if (car != null)
{
try {_ = collection + car; }
catch (CarNotFoundException e)
{
throw e;
}
catch (StorageOverflowException e)
{
throw e;
}
}
}
_carStorages.Add(new TankerCollectionInfo(name, string.Empty), collection);
}
}
}
}
}

View File

@ -1,287 +0,0 @@
namespace Lab
{
partial class CollectionsFrame
{
/// <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()
{
panel1 = new Panel();
SortColorButton = new Button();
SortTypeButton = new Button();
panel2 = new Panel();
DeleteCollectButton = new Button();
CollectionListBox = new ListBox();
AddCollectButton = new Button();
SetTextBox = new TextBox();
label2 = new Label();
UpdateButton = new Button();
DeleteButton = new Button();
AddButton = new Button();
CarTextBox = new TextBox();
label1 = new Label();
menuStrip1 = new MenuStrip();
StripMenu = new ToolStripMenuItem();
SaveItem = new ToolStripMenuItem();
LoadItem = new ToolStripMenuItem();
DrawTank = new PictureBox();
openFileDialog = new OpenFileDialog();
saveFileDialog = new SaveFileDialog();
panel1.SuspendLayout();
panel2.SuspendLayout();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)DrawTank).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(SortColorButton);
panel1.Controls.Add(SortTypeButton);
panel1.Controls.Add(panel2);
panel1.Controls.Add(UpdateButton);
panel1.Controls.Add(DeleteButton);
panel1.Controls.Add(AddButton);
panel1.Controls.Add(CarTextBox);
panel1.Controls.Add(label1);
panel1.Controls.Add(menuStrip1);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(550, 0);
panel1.Name = "panel1";
panel1.Size = new Size(250, 514);
panel1.TabIndex = 0;
//
// SortColorButton
//
SortColorButton.Location = new Point(19, 301);
SortColorButton.Name = "SortColorButton";
SortColorButton.Size = new Size(208, 29);
SortColorButton.TabIndex = 8;
SortColorButton.Text = "Сортировка по цвету";
SortColorButton.UseVisualStyleBackColor = true;
SortColorButton.Click += ButtonSortByColor_Click;
//
// SortTypeButton
//
SortTypeButton.Location = new Point(19, 266);
SortTypeButton.Name = "SortTypeButton";
SortTypeButton.Size = new Size(208, 29);
SortTypeButton.TabIndex = 7;
SortTypeButton.Text = "Сортировка по типу";
SortTypeButton.UseVisualStyleBackColor = true;
SortTypeButton.Click += ButtonSortByType_Click;
//
// panel2
//
panel2.Controls.Add(DeleteCollectButton);
panel2.Controls.Add(CollectionListBox);
panel2.Controls.Add(AddCollectButton);
panel2.Controls.Add(SetTextBox);
panel2.Controls.Add(label2);
panel2.Location = new Point(16, 38);
panel2.Name = "panel2";
panel2.Size = new Size(214, 217);
panel2.TabIndex = 5;
//
// DeleteCollectButton
//
DeleteCollectButton.Location = new Point(3, 181);
DeleteCollectButton.Name = "DeleteCollectButton";
DeleteCollectButton.Size = new Size(208, 29);
DeleteCollectButton.TabIndex = 4;
DeleteCollectButton.Text = "Удалить набор";
DeleteCollectButton.UseVisualStyleBackColor = true;
DeleteCollectButton.Click += ButtonDelObject_Click;
//
// CollectionListBox
//
CollectionListBox.FormattingEnabled = true;
CollectionListBox.ItemHeight = 20;
CollectionListBox.Location = new Point(3, 91);
CollectionListBox.Name = "CollectionListBox";
CollectionListBox.Size = new Size(208, 84);
CollectionListBox.TabIndex = 3;
CollectionListBox.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
//
// AddCollectButton
//
AddCollectButton.Location = new Point(3, 56);
AddCollectButton.Name = "AddCollectButton";
AddCollectButton.Size = new Size(208, 29);
AddCollectButton.TabIndex = 2;
AddCollectButton.Text = "Добавить набор";
AddCollectButton.UseVisualStyleBackColor = true;
AddCollectButton.Click += ButtonAddObject_Click;
//
// SetTextBox
//
SetTextBox.Location = new Point(2, 23);
SetTextBox.Name = "SetTextBox";
SetTextBox.Size = new Size(209, 27);
SetTextBox.TabIndex = 1;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(3, 0);
label2.Name = "label2";
label2.Size = new Size(66, 20);
label2.TabIndex = 0;
label2.Text = "Наборы";
//
// UpdateButton
//
UpdateButton.Location = new Point(6, 465);
UpdateButton.Name = "UpdateButton";
UpdateButton.Size = new Size(228, 37);
UpdateButton.TabIndex = 4;
UpdateButton.Text = "Обновить коллекцию";
UpdateButton.UseVisualStyleBackColor = true;
UpdateButton.Click += ButtonRefreshCollection_Click;
//
// DeleteButton
//
DeleteButton.Location = new Point(6, 422);
DeleteButton.Name = "DeleteButton";
DeleteButton.Size = new Size(228, 37);
DeleteButton.TabIndex = 3;
DeleteButton.Text = "Удалить автомобиль";
DeleteButton.UseVisualStyleBackColor = true;
DeleteButton.Click += ButtonRemoveCar_Click;
//
// AddButton
//
AddButton.Location = new Point(6, 346);
AddButton.Name = "AddButton";
AddButton.Size = new Size(228, 37);
AddButton.TabIndex = 2;
AddButton.Text = "Добавить автомобиль";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += ButtonAddCar_Click;
//
// CarTextBox
//
CarTextBox.Location = new Point(6, 389);
CarTextBox.Name = "CarTextBox";
CarTextBox.Size = new Size(228, 27);
CarTextBox.TabIndex = 1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(144, 0);
label1.Name = "label1";
label1.Size = new Size(103, 20);
label1.TabIndex = 0;
label1.Text = "Инструменты";
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { StripMenu });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(250, 28);
menuStrip1.TabIndex = 6;
menuStrip1.Text = "menuStrip1";
//
// StripMenu
//
StripMenu.DropDownItems.AddRange(new ToolStripItem[] { SaveItem, LoadItem });
StripMenu.Name = "StripMenu";
StripMenu.Size = new Size(59, 24);
StripMenu.Text = "Файл";
//
// SaveItem
//
SaveItem.Name = "SaveItem";
SaveItem.Size = new Size(166, 26);
SaveItem.Text = "Сохранить";
SaveItem.Click += SaveToolStripMenuItem_Click;
//
// LoadItem
//
LoadItem.Name = "LoadItem";
LoadItem.Size = new Size(166, 26);
LoadItem.Text = "Загрузить";
LoadItem.Click += LoadToolStripMenuItem_Click;
//
// DrawTank
//
DrawTank.Dock = DockStyle.Fill;
DrawTank.Location = new Point(0, 0);
DrawTank.Name = "DrawTank";
DrawTank.Size = new Size(550, 514);
DrawTank.TabIndex = 1;
DrawTank.TabStop = false;
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog1";
//
// CollectionsFrame
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 514);
Controls.Add(DrawTank);
Controls.Add(panel1);
MainMenuStrip = menuStrip1;
Name = "CollectionsFrame";
Text = "Гаражи бензовозов";
panel1.ResumeLayout(false);
panel1.PerformLayout();
panel2.ResumeLayout(false);
panel2.PerformLayout();
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)DrawTank).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button UpdateButton;
private Button DeleteButton;
private Button AddButton;
private TextBox CarTextBox;
private Label label1;
private PictureBox DrawTank;
private Panel panel2;
private Button DeleteCollectButton;
private ListBox CollectionListBox;
private Button AddCollectButton;
private TextBox SetTextBox;
private Label label2;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private MenuStrip menuStrip1;
private ToolStripMenuItem StripMenu;
private ToolStripMenuItem SaveItem;
private ToolStripMenuItem LoadItem;
private Button SortColorButton;
private Button SortTypeButton;
}
}

View File

@ -1,228 +0,0 @@
using Lab.DrawningObjects;
using Lab.Generics;
using Lab.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;
using Microsoft.Extensions.Logging;
using System.Drawing.Text;
namespace Lab
{
public partial class CollectionsFrame : Form
{
private readonly CarsGenericStorage _storage;
private readonly ILogger _logger;
public CollectionsFrame(ILogger<CollectionsFrame> logger)
{
InitializeComponent();
_storage = new CarsGenericStorage(DrawTank.Width, DrawTank.Height);
_logger = logger;
}
private void ReloadObjects()
{
int index = CollectionListBox.SelectedIndex;
CollectionListBox.Items.Clear();
foreach (var key in _storage.Keys)
{
CollectionListBox.Items.Add(key.Name);
}
if (CollectionListBox.Items.Count > 0 && (index == -1 || index
>= CollectionListBox.Items.Count))
{
CollectionListBox.SelectedIndex = 0;
}
else if (CollectionListBox.Items.Count > 0 && index > -1 &&
index < CollectionListBox.Items.Count)
{
CollectionListBox.SelectedIndex = index;
}
}
private void ButtonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(SetTextBox.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("Пустое название набора");
return;
}
_storage.AddSet(SetTextBox.Text);
ReloadObjects();
_logger.LogInformation($"Добавлен набор: {SetTextBox.Text}");
}
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
DrawTank.Image = _storage[CollectionListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowCars();
}
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (CollectionListBox.SelectedIndex == -1)
{
_logger.LogWarning("Удаление невыбранного набора");
return;
}
string name = CollectionListBox.SelectedItem.ToString() ?? string.Empty;
if (MessageBox.Show($"Удалить объект {name}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(CollectionListBox.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
_logger.LogInformation($"Удален набор: {name}");
}
}
private void AddTanker(DrawTanker tanker)
{
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
_logger.LogWarning("Добавление пустого объекта");
return;
}
try
{
_ = obj + tanker;
MessageBox.Show("Объект добавлен");
DrawTank.Image = obj.ShowCars();
_logger.LogInformation($"Добавлен объект в набор {CollectionListBox.SelectedItem.ToString()}");
}
catch (ArgumentException ex)
{
MessageBox.Show("Такой объект уже существует");
_logger.LogWarning($"{ex.Message} в наборе {CollectionListBox.SelectedItem.ToString()}");
}
catch (Exception ex)
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning($"{ex.Message} в наборе {CollectionListBox.SelectedItem.ToString()}");
}
}
private void ButtonAddCar_Click(object sender, EventArgs e)
{
if (CollectionListBox.SelectedIndex == -1)
{
return;
}
FormTankerConfig form = new FormTankerConfig();
form.Show();
form.AddEvent(AddTanker);
}
private void ButtonRemoveCar_Click(object sender, EventArgs e)
{
if (CollectionListBox.SelectedIndex == -1)
{
_logger.LogWarning("Удаление объекта из несуществующего набора");
return;
}
var obj = _storage[CollectionListBox.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(CarTextBox.Text);
try
{
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
DrawTank.Image = obj.ShowCars();
_logger.LogInformation($"Удален объект из набора {CollectionListBox.SelectedItem.ToString()}");
}
else
{
MessageBox.Show("Не удалось удалить объект");
_logger.LogWarning($"Не удалось удалить объект из набора {CollectionListBox.SelectedItem.ToString()}");
}
}
catch (CarNotFoundException ex)
{
MessageBox.Show(ex.Message);
_logger.LogWarning($"{ex.Message} из набора {CollectionListBox.SelectedItem.ToString()}");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
if (CollectionListBox.SelectedIndex == -1)
{
return;
}
var obj = _storage[CollectionListBox.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
DrawTank.Image = obj.ShowCars();
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_storage.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Сохранение наборов в файл {saveFileDialog.FileName}");
}
catch (Exception ex)
{
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_storage.LoadData(openFileDialog.FileName);
ReloadObjects();
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Загрузились наборы из файла {openFileDialog.FileName}");
}
catch (Exception ex)
{
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}");
}
}
}
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareTanker(new TankerCompareByType());
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareTanker(new TankerCompareByColor());
private void CompareTanker(IComparer<DrawTanker?> comparer)
{
if (CollectionListBox.SelectedIndex == -1)
return;
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
return;
obj.Sort(comparer);
DrawTank.Image = obj.ShowCars();
}
}
}

View File

@ -1,129 +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>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>344, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>187, 17</value>
</metadata>
</root>

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab
{
public enum Direction
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -1,51 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab.Entities;
namespace Lab.DrawningObjects
{
public class DrawGasolineTanker : DrawTanker
{
public DrawGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) : base(speed, weight, bodyColor, width, height)
{
if (_gasolineTanker != null)
{
_gasolineTanker = new GasolineTanker(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
}
}
public void SetAddColor(Color color)
{
(_gasolineTanker as GasolineTanker).ChangeAddColor(color);
}
public override void DrawTransport(Graphics g)
{
if (_gasolineTanker is not GasolineTanker Gasoline)
return;
base.DrawTransport(g);
if (Gasoline.BodyKit)
{
Brush bodyBrush = new SolidBrush(Gasoline.AdditionalColor);
g.FillEllipse(bodyBrush, 10 + _startPosX, 10 + _startPosY, 70, 30);
}
if (Gasoline.SportLine)
{
Brush lineBrush = new SolidBrush(Gasoline.AdditionalColor);
g.FillRectangle(lineBrush, 15 + _startPosX, 45 + _startPosY, 20, 5);
g.FillRectangle(lineBrush, 40 + _startPosX, 45 + _startPosY, 20, 5);
g.FillRectangle(lineBrush, 65 + _startPosX, 45 + _startPosY, 20, 5);
}
if (Gasoline.Wing)
{
Brush lightBrush = new SolidBrush(Gasoline.AdditionalColor);
g.FillRectangle(lightBrush, 87 + _startPosX, 5 + _startPosY, 5, 5);
}
}
}
}

View File

@ -1,131 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.Pkcs;
using System.Text;
using System.Threading.Tasks;
using Lab.Entities;
using Lab.MovementStrategy;
namespace Lab.DrawningObjects
{
public class DrawTanker
{
public BaseTanker? _gasolineTanker { get; protected set; }
protected int _pictureWidth;
protected int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _carWidth = 100;
protected readonly int _carHeight = 80;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _carWidth;
public int GetHeight => _carHeight;
public bool CanMove(Direction direction)
{
if (_gasolineTanker == null)
return false;
return direction switch
{
Direction.Left => _startPosX - _gasolineTanker.Step > 0,
Direction.Up => _startPosY - _gasolineTanker.Step > 0,
Direction.Right => _startPosX + _carWidth + _gasolineTanker.Step < _pictureWidth,
Direction.Down => _startPosY + _carHeight + _gasolineTanker.Step < _pictureHeight,
_ => false
};
}
// Конструктор класса
public DrawTanker(int speed, double weight, Color bodyColor, int width, int height)
{
_pictureHeight = height;
_pictureWidth = width;
_gasolineTanker = new BaseTanker(speed, weight, bodyColor);
}
public DrawTanker(int speed, double weight, Color bodyColor, int width, int height, int carWidth, int carHeight)
{
_pictureHeight = height;
_pictureWidth = width;
_carHeight = carHeight;
_carWidth = carWidth;
_gasolineTanker = new BaseTanker(speed, weight, bodyColor);
}
public void SetBaseColor(Color bodyColor)
{
_gasolineTanker.ChangeBodyColor(bodyColor);
}
public void SetPosition(int x, int y)
{
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(Direction direction)
{
if (!CanMove(direction) || _gasolineTanker == null)
return;
switch (direction)
{
case Direction.Left:
{
if (_startPosX - _gasolineTanker.Step > 0)
{
_startPosX -= (int)_gasolineTanker.Step;
}
}
break;
case Direction.Up:
{
if (_startPosY - _gasolineTanker.Step > 0)
{
_startPosY -= (int)_gasolineTanker.Step;
}
}
break;
case Direction.Right:
{
if (_startPosX + _carWidth + _gasolineTanker.Step < _pictureWidth)
{
_startPosX += (int)_gasolineTanker.Step;
}
}
break;
case Direction.Down:
{
if (_startPosY + _gasolineTanker.Step + _carHeight < _pictureHeight)
{
_startPosY += (int)_gasolineTanker.Step;
}
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (_gasolineTanker == null)
return;
Pen pen = new(_gasolineTanker.BodyColor, 2);
Brush brush = new SolidBrush(_gasolineTanker.BodyColor);
// Отрисовка корпуса
g.FillRectangle(brush, 10 + _startPosX, 40 + _startPosY, 90, 20);
g.FillRectangle(brush, 80 + _startPosX, 10 + _startPosY, 20, 40);
// Отрисовка колесиков
g.FillEllipse(brush, 10 + _startPosX, 60 + _startPosY, 20, 20);
g.FillEllipse(brush, 30 + _startPosX, 60 + _startPosY, 20, 20);
g.FillEllipse(brush, 80 + _startPosX, 60 + _startPosY, 20, 20);
}
public IMoveableObject GetMoveableObject => new DrawingObjectTanker(this);
}
}

View File

@ -1,32 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab.DrawningObjects;
namespace Lab.MovementStrategy
{
public class DrawingObjectTanker : IMoveableObject
{
private readonly DrawTanker? _drawTanker = null;
public DrawingObjectTanker(DrawTanker drawTanker )
{
_drawTanker = drawTanker;
}
public ObjectParameters? GetObjectParameters
{
get
{
if (_drawTanker == null || _drawTanker._gasolineTanker == null)
return null;
return new ObjectParameters(_drawTanker.GetPosX, _drawTanker.GetPosY, _drawTanker.GetWidth, _drawTanker.GetHeight);
}
}
public int GetStep => (int)(_drawTanker?._gasolineTanker?.Step ?? 0);
public bool CheckCanMove(Direction direction) => _drawTanker?.CanMove(direction) ?? false;
public void MoveObject(Direction direction) => _drawTanker?.MoveTransport(direction);
}
}

View File

@ -1,67 +0,0 @@
using Lab.DrawningObjects;
using Lab.Entities;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab
{
internal class DrawiningTankerEqutables : IEqualityComparer<DrawTanker?>
{
public bool Equals(DrawTanker? x, DrawTanker? y)
{
if (x == null || x._gasolineTanker == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y._gasolineTanker == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType() != y.GetType())
{
return false;
}
if (x._gasolineTanker.Speed != y._gasolineTanker.Speed)
{
return false;
}
if (x._gasolineTanker.Weight != y._gasolineTanker.Weight)
{
return false;
}
if (x._gasolineTanker.BodyColor != y._gasolineTanker.BodyColor)
{
return false;
}
if (x is DrawGasolineTanker && y is DrawGasolineTanker)
{
if ((x._gasolineTanker as GasolineTanker).AdditionalColor != (y._gasolineTanker as GasolineTanker).AdditionalColor)
{
return false;
}
if ((x._gasolineTanker as GasolineTanker).Wing != (y._gasolineTanker as GasolineTanker).Wing)
{
return false;
}
if ((x._gasolineTanker as GasolineTanker).BodyKit != (y._gasolineTanker as GasolineTanker).BodyKit)
{
return false;
}
if ((x._gasolineTanker as GasolineTanker).SportLine != (y._gasolineTanker as GasolineTanker).SportLine)
{
return false;
}
}
return true;
}
public int GetHashCode([DisallowNull]DrawTanker obj)
{
return obj.GetHashCode();
}
}
}

View File

@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab.Entities;
using Lab.DrawningObjects;
namespace Lab
{
public static class ExtentionDrawingTanker
{
public static DrawTanker? CreateDrawTanker(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawTanker(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 7)
{
return new DrawGasolineTanker(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]),
Color.FromName(strs[2]),
Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]),
Convert.ToBoolean(strs[6]), width, height);
}
return null;
}
public static string GetDataForSave(this DrawTanker tanker, char separatorForObject)
{
var Tanker = tanker._gasolineTanker;
if (Tanker == null)
{
return string.Empty;
}
var str = $"{Tanker.Speed}{separatorForObject}{Tanker.Weight}{separatorForObject}{Tanker.BodyColor.Name}";
if (Tanker is not GasolineTanker gasTanker)
{
return str;
}
return $"{str}{separatorForObject}{gasTanker.AdditionalColor.Name}{separatorForObject}{gasTanker.BodyKit}{separatorForObject}{gasTanker.Wing}{separatorForObject}{gasTanker.SportLine}";
}
}
}

View File

@ -1,386 +0,0 @@
namespace Lab
{
partial class FormTankerConfig
{
/// <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()
{
settingPanel = new Panel();
UpdateLabel = new Label();
BaseLabel = new Label();
label4 = new Label();
panel1 = new Panel();
PurplePanel = new Panel();
BlackPanel = new Panel();
GrayPanel = new Panel();
WhitePanel = new Panel();
YellowPanel = new Panel();
BluePanel = new Panel();
GreenPanel = new Panel();
RedPanel = new Panel();
SportLineCheck = new CheckBox();
WingCheck = new CheckBox();
BodyKitCheck = new CheckBox();
label3 = new Label();
WeightNumeric = new NumericUpDown();
label2 = new Label();
SpeedNumeric = new NumericUpDown();
label1 = new Label();
panel10 = new Panel();
TankerDraw = new PictureBox();
AddColorLabel = new Label();
BaseColorLabel = new Label();
AddButton = new Button();
CancelButton = new Button();
settingPanel.SuspendLayout();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)WeightNumeric).BeginInit();
((System.ComponentModel.ISupportInitialize)SpeedNumeric).BeginInit();
panel10.SuspendLayout();
((System.ComponentModel.ISupportInitialize)TankerDraw).BeginInit();
SuspendLayout();
//
// settingPanel
//
settingPanel.Controls.Add(UpdateLabel);
settingPanel.Controls.Add(BaseLabel);
settingPanel.Controls.Add(label4);
settingPanel.Controls.Add(panel1);
settingPanel.Controls.Add(SportLineCheck);
settingPanel.Controls.Add(WingCheck);
settingPanel.Controls.Add(BodyKitCheck);
settingPanel.Controls.Add(label3);
settingPanel.Controls.Add(WeightNumeric);
settingPanel.Controls.Add(label2);
settingPanel.Controls.Add(SpeedNumeric);
settingPanel.Controls.Add(label1);
settingPanel.Location = new Point(10, 11);
settingPanel.Name = "settingPanel";
settingPanel.Size = new Size(638, 305);
settingPanel.TabIndex = 0;
//
// UpdateLabel
//
UpdateLabel.BorderStyle = BorderStyle.FixedSingle;
UpdateLabel.Location = new Point(454, 217);
UpdateLabel.Name = "UpdateLabel";
UpdateLabel.Size = new Size(110, 50);
UpdateLabel.TabIndex = 11;
UpdateLabel.Text = "Продвинутый";
UpdateLabel.TextAlign = ContentAlignment.MiddleCenter;
UpdateLabel.MouseDown += LabelObject_MouseDown;
//
// BaseLabel
//
BaseLabel.BorderStyle = BorderStyle.FixedSingle;
BaseLabel.Location = new Point(321, 217);
BaseLabel.Name = "BaseLabel";
BaseLabel.Size = new Size(110, 50);
BaseLabel.TabIndex = 10;
BaseLabel.Text = "Простой";
BaseLabel.TextAlign = ContentAlignment.MiddleCenter;
BaseLabel.MouseDown += LabelObject_MouseDown;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(321, 25);
label4.Name = "label4";
label4.Size = new Size(42, 20);
label4.TabIndex = 9;
label4.Text = "Цвет";
//
// panel1
//
panel1.Controls.Add(PurplePanel);
panel1.Controls.Add(BlackPanel);
panel1.Controls.Add(GrayPanel);
panel1.Controls.Add(WhitePanel);
panel1.Controls.Add(YellowPanel);
panel1.Controls.Add(BluePanel);
panel1.Controls.Add(GreenPanel);
panel1.Controls.Add(RedPanel);
panel1.Location = new Point(321, 48);
panel1.Name = "panel1";
panel1.Size = new Size(243, 125);
panel1.TabIndex = 8;
panel1.Tag = "";
//
// PurplePanel
//
PurplePanel.BackColor = Color.Purple;
PurplePanel.Location = new Point(182, 65);
PurplePanel.Name = "PurplePanel";
PurplePanel.Size = new Size(50, 50);
PurplePanel.TabIndex = 1;
//
// BlackPanel
//
BlackPanel.BackColor = Color.Black;
BlackPanel.Location = new Point(126, 65);
BlackPanel.Name = "BlackPanel";
BlackPanel.Size = new Size(50, 50);
BlackPanel.TabIndex = 1;
//
// GrayPanel
//
GrayPanel.BackColor = Color.Gray;
GrayPanel.Location = new Point(70, 65);
GrayPanel.Name = "GrayPanel";
GrayPanel.Size = new Size(50, 50);
GrayPanel.TabIndex = 1;
//
// WhitePanel
//
WhitePanel.BackColor = Color.White;
WhitePanel.Location = new Point(14, 65);
WhitePanel.Name = "WhitePanel";
WhitePanel.Size = new Size(50, 50);
WhitePanel.TabIndex = 1;
//
// YellowPanel
//
YellowPanel.BackColor = Color.Yellow;
YellowPanel.Location = new Point(182, 9);
YellowPanel.Name = "YellowPanel";
YellowPanel.Size = new Size(50, 50);
YellowPanel.TabIndex = 1;
//
// BluePanel
//
BluePanel.BackColor = Color.Blue;
BluePanel.Location = new Point(126, 9);
BluePanel.Name = "BluePanel";
BluePanel.Size = new Size(50, 50);
BluePanel.TabIndex = 1;
//
// GreenPanel
//
GreenPanel.BackColor = Color.Green;
GreenPanel.Location = new Point(70, 9);
GreenPanel.Name = "GreenPanel";
GreenPanel.Size = new Size(50, 50);
GreenPanel.TabIndex = 1;
//
// RedPanel
//
RedPanel.BackColor = Color.Red;
RedPanel.Location = new Point(14, 9);
RedPanel.Name = "RedPanel";
RedPanel.Size = new Size(50, 50);
RedPanel.TabIndex = 0;
//
// SportLineCheck
//
SportLineCheck.AutoSize = true;
SportLineCheck.Location = new Point(43, 243);
SportLineCheck.Name = "SportLineCheck";
SportLineCheck.Size = new Size(163, 24);
SportLineCheck.TabIndex = 7;
SportLineCheck.Text = "Гоночные полоски";
SportLineCheck.UseVisualStyleBackColor = true;
//
// WingCheck
//
WingCheck.AutoSize = true;
WingCheck.Location = new Point(43, 196);
WingCheck.Name = "WingCheck";
WingCheck.Size = new Size(90, 24);
WingCheck.TabIndex = 6;
WingCheck.Text = "Мигалка";
WingCheck.UseVisualStyleBackColor = true;
//
// BodyKitCheck
//
BodyKitCheck.AutoSize = true;
BodyKitCheck.Location = new Point(43, 149);
BodyKitCheck.Name = "BodyKitCheck";
BodyKitCheck.Size = new Size(74, 24);
BodyKitCheck.TabIndex = 5;
BodyKitCheck.Text = "Обвес";
BodyKitCheck.UseVisualStyleBackColor = true;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(43, 91);
label3.Name = "label3";
label3.Size = new Size(33, 20);
label3.TabIndex = 4;
label3.Text = "Вес";
//
// WeightNumeric
//
WeightNumeric.Location = new Point(122, 89);
WeightNumeric.Name = "WeightNumeric";
WeightNumeric.Size = new Size(150, 27);
WeightNumeric.TabIndex = 3;
WeightNumeric.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(43, 48);
label2.Name = "label2";
label2.Size = new Size(73, 20);
label2.TabIndex = 2;
label2.Text = "Скорость";
//
// SpeedNumeric
//
SpeedNumeric.Location = new Point(122, 46);
SpeedNumeric.Name = "SpeedNumeric";
SpeedNumeric.Size = new Size(150, 27);
SpeedNumeric.TabIndex = 1;
SpeedNumeric.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(2, 10);
label1.Name = "label1";
label1.Size = new Size(90, 20);
label1.TabIndex = 0;
label1.Text = "Параметры";
//
// panel10
//
panel10.AllowDrop = true;
panel10.Controls.Add(TankerDraw);
panel10.Location = new Point(654, 86);
panel10.Name = "panel10";
panel10.Size = new Size(318, 172);
panel10.TabIndex = 1;
panel10.DragDrop += PanelObject_DragDrop;
panel10.DragEnter += PanelObject_DragEnter;
//
// TankerDraw
//
TankerDraw.Location = new Point(3, 3);
TankerDraw.Name = "TankerDraw";
TankerDraw.Size = new Size(312, 166);
TankerDraw.TabIndex = 14;
TankerDraw.TabStop = false;
//
// AddColorLabel
//
AddColorLabel.AllowDrop = true;
AddColorLabel.BorderStyle = BorderStyle.FixedSingle;
AddColorLabel.Location = new Point(849, 16);
AddColorLabel.Name = "AddColorLabel";
AddColorLabel.Size = new Size(120, 40);
AddColorLabel.TabIndex = 13;
AddColorLabel.Text = "Доп. цвет";
AddColorLabel.TextAlign = ContentAlignment.MiddleCenter;
AddColorLabel.DragDrop += LabelColor_DragDrop;
AddColorLabel.DragEnter += LabelColor_DragEnter;
//
// BaseColorLabel
//
BaseColorLabel.AllowDrop = true;
BaseColorLabel.BorderStyle = BorderStyle.FixedSingle;
BaseColorLabel.Location = new Point(657, 16);
BaseColorLabel.Name = "BaseColorLabel";
BaseColorLabel.Size = new Size(120, 40);
BaseColorLabel.TabIndex = 12;
BaseColorLabel.Text = "Цвет";
BaseColorLabel.TextAlign = ContentAlignment.MiddleCenter;
BaseColorLabel.DragDrop += LabelColor_DragDrop;
BaseColorLabel.DragEnter += LabelColor_DragEnter;
//
// AddButton
//
AddButton.Location = new Point(657, 266);
AddButton.Name = "AddButton";
AddButton.Size = new Size(127, 42);
AddButton.TabIndex = 2;
AddButton.Text = "Добавить";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += ButtonOk_Click;
//
// CancelButton
//
CancelButton.Location = new Point(842, 266);
CancelButton.Name = "CancelButton";
CancelButton.Size = new Size(127, 42);
CancelButton.TabIndex = 3;
CancelButton.Text = "Отмена";
CancelButton.UseVisualStyleBackColor = true;
//
// FormTankerConfig
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(987, 320);
Controls.Add(CancelButton);
Controls.Add(AddColorLabel);
Controls.Add(AddButton);
Controls.Add(BaseColorLabel);
Controls.Add(panel10);
Controls.Add(settingPanel);
Name = "FormTankerConfig";
Text = "FormTankerConfig";
settingPanel.ResumeLayout(false);
settingPanel.PerformLayout();
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)WeightNumeric).EndInit();
((System.ComponentModel.ISupportInitialize)SpeedNumeric).EndInit();
panel10.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)TankerDraw).EndInit();
ResumeLayout(false);
}
#endregion
private Panel settingPanel;
private Label label3;
private NumericUpDown WeightNumeric;
private Label label2;
private NumericUpDown SpeedNumeric;
private Label label1;
private CheckBox BodyKitCheck;
private CheckBox SportLineCheck;
private CheckBox WingCheck;
private Label label4;
private Panel panel1;
private Panel PurplePanel;
private Panel BlackPanel;
private Panel GrayPanel;
private Panel WhitePanel;
private Panel YellowPanel;
private Panel BluePanel;
private Panel GreenPanel;
private Panel RedPanel;
private Label UpdateLabel;
private Label BaseLabel;
private Panel panel10;
private PictureBox TankerDraw;
private Label AddColorLabel;
private Label BaseColorLabel;
private Button AddButton;
private Button CancelButton;
}
}

View File

@ -1,144 +0,0 @@
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Lab.DrawningObjects;
using Lab.Entities;
using Lab.Generics;
using Lab.MovementStrategy;
using Lab.Properties;
namespace Lab
{
public partial class FormTankerConfig : Form
{
DrawTanker? _tanker = null;
private event Action<DrawTanker> EventAddTanker;
public FormTankerConfig()
{
InitializeComponent();
BlackPanel.MouseDown += PanelColor_MouseDown;
WhitePanel.MouseDown += PanelColor_MouseDown;
PurplePanel.MouseDown += PanelColor_MouseDown;
YellowPanel.MouseDown += PanelColor_MouseDown;
GreenPanel.MouseDown += PanelColor_MouseDown;
RedPanel.MouseDown += PanelColor_MouseDown;
BluePanel.MouseDown += PanelColor_MouseDown;
GrayPanel.MouseDown += PanelColor_MouseDown;
CancelButton.Click += (s, e) => Close();
}
public void DrawTanker()
{
Bitmap bmp = new(TankerDraw.Width, TankerDraw.Height);
Graphics g = Graphics.FromImage(bmp);
_tanker?.SetPosition(5, 5);
if (_tanker is DrawGasolineTanker drawGasolineTanker)
drawGasolineTanker.DrawTransport(g);
else
_tanker?.DrawTransport(g);
TankerDraw.Image = bmp;
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "BaseLabel":
_tanker = new DrawTanker((int)SpeedNumeric.Value,
(int)WeightNumeric.Value, Color.White, TankerDraw.Width,
TankerDraw.Height);
break;
case "UpdateLabel":
_tanker = new DrawGasolineTanker((int)SpeedNumeric.Value,
(int)WeightNumeric.Value, Color.White, Color.Black, BodyKitCheck.Checked,
WingCheck.Checked, SportLineCheck.Checked, TankerDraw.Width,
TankerDraw.Height);
break;
}
DrawTanker();
}
public void AddEvent(Action<DrawTanker> ev)
{
if (EventAddTanker == null)
{
EventAddTanker = ev;
}
else
{
EventAddTanker += ev;
}
}
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddTanker?.Invoke(_tanker);
Close();
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_tanker == null)
return;
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
switch (((Label)sender).Name)
{
case "BaseColorLabel":
_tanker.SetBaseColor((Color)e.Data.GetData(typeof(Color)));
break;
case "AddColorLabel":
if (_tanker is DrawGasolineTanker)
{
(_tanker as DrawGasolineTanker).SetAddColor((Color)e.Data.GetData(typeof(Color)));
}
break;
}
DrawTanker();
}
}
}

View File

@ -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>

190
Lab/Frame.Designer.cs generated
View File

@ -1,190 +0,0 @@
namespace Lab
{
partial class Frame
{
/// <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()
{
DrawCar = new PictureBox();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
Right = new Button();
Left = new Button();
Down = new Button();
Up = new Button();
buttonCreateGasolineTanker = new Button();
CreateBaseCarButton = new Button();
ChooseCar = new Button();
((System.ComponentModel.ISupportInitialize)DrawCar).BeginInit();
SuspendLayout();
//
// DrawCar
//
DrawCar.Dock = DockStyle.Fill;
DrawCar.Location = new Point(0, 0);
DrawCar.Name = "DrawCar";
DrawCar.Size = new Size(882, 553);
DrawCar.TabIndex = 1;
DrawCar.TabStop = false;
//
// comboBoxStrategy
//
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
comboBoxStrategy.Location = new Point(719, 27);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 9;
//
// buttonStep
//
buttonStep.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonStep.Location = new Point(776, 72);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(94, 29);
buttonStep.TabIndex = 8;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += ButtonStep_Click;
//
// Right
//
Right.BackgroundImage = Properties.Resources.Right;
Right.BackgroundImageLayout = ImageLayout.Zoom;
Right.Location = new Point(840, 512);
Right.Name = "Right";
Right.Size = new Size(30, 30);
Right.TabIndex = 6;
Right.Text = "→";
Right.UseVisualStyleBackColor = true;
Right.Click += ButtonMove_Click;
//
// Left
//
Left.BackgroundImage = Properties.Resources.Left;
Left.BackgroundImageLayout = ImageLayout.Zoom;
Left.Location = new Point(768, 512);
Left.Name = "Left";
Left.Size = new Size(30, 30);
Left.TabIndex = 4;
Left.Text = "←";
Left.UseVisualStyleBackColor = true;
Left.Click += ButtonMove_Click;
//
// Down
//
Down.BackgroundImage = Properties.Resources.Down;
Down.BackgroundImageLayout = ImageLayout.Zoom;
Down.Location = new Point(804, 512);
Down.Name = "Down";
Down.Size = new Size(30, 30);
Down.TabIndex = 5;
Down.Text = "↓";
Down.UseVisualStyleBackColor = true;
Down.Click += ButtonMove_Click;
//
// Up
//
Up.BackgroundImage = Properties.Resources.Up;
Up.BackgroundImageLayout = ImageLayout.Zoom;
Up.Location = new Point(804, 476);
Up.Name = "Up";
Up.Size = new Size(30, 30);
Up.TabIndex = 3;
Up.Text = "↑";
Up.UseVisualStyleBackColor = true;
Up.Click += ButtonMove_Click;
//
// buttonCreateGasolineTanker
//
buttonCreateGasolineTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateGasolineTanker.Location = new Point(218, 442);
buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker";
buttonCreateGasolineTanker.Size = new Size(200, 100);
buttonCreateGasolineTanker.TabIndex = 7;
buttonCreateGasolineTanker.Text = "Создать красивый бензовоз";
buttonCreateGasolineTanker.UseVisualStyleBackColor = true;
buttonCreateGasolineTanker.Click += CreateGasolineTankerButton_Click;
//
// CreateBaseCarButton
//
CreateBaseCarButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
CreateBaseCarButton.Location = new Point(12, 441);
CreateBaseCarButton.Name = "CreateBaseCarButton";
CreateBaseCarButton.Size = new Size(200, 100);
CreateBaseCarButton.TabIndex = 2;
CreateBaseCarButton.Text = "Создать простой бензовоз";
CreateBaseCarButton.UseVisualStyleBackColor = true;
CreateBaseCarButton.Click += CreateCarButton_Click;
//
// ChooseCar
//
ChooseCar.Location = new Point(776, 149);
ChooseCar.Name = "ChooseCar";
ChooseCar.Size = new Size(94, 52);
ChooseCar.TabIndex = 10;
ChooseCar.Text = "Выбрать машину";
ChooseCar.UseVisualStyleBackColor = true;
ChooseCar.Click += ButtonSelectTank_Click;
//
// Frame
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 553);
Controls.Add(ChooseCar);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonStep);
Controls.Add(buttonCreateGasolineTanker);
Controls.Add(Right);
Controls.Add(Down);
Controls.Add(Left);
Controls.Add(Up);
Controls.Add(CreateBaseCarButton);
Controls.Add(DrawCar);
Name = "Frame";
StartPosition = FormStartPosition.CenterScreen;
Text = "GasolineTanker";
((System.ComponentModel.ISupportInitialize)DrawCar).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox DrawCar;
private ComboBox comboBoxStrategy;
private Button buttonStep;
private Button Right;
private Button Left;
private Button Down;
private Button Up;
private Button buttonCreateGasolineTanker;
private Button CreateBaseCarButton;
private Button button2;
private Button AddTanker;
private Button ChooseCar;
}
}

View File

@ -1,121 +0,0 @@
using Lab.DrawningObjects;
using Lab.MovementStrategy;
using Lab;
using System.Drawing;
namespace Lab
{
public partial class Frame : Form
{
private DrawTanker? _drawingTanker;
private AbstractStrategy? _abstractStrategy;
public DrawTanker? SelectedCar { get; private set; }
public Frame()
{
InitializeComponent();
_abstractStrategy = null;
SelectedCar = null;
}
private void Draw()
{
if (_drawingTanker == null)
return;
Bitmap bitmap = new(DrawCar.Width, DrawCar.Height);
Graphics g = Graphics.FromImage(bitmap);
_drawingTanker.DrawTransport(g);
DrawCar.Image = bitmap;
}
private void CreateGasolineTankerButton_Click(object sender, EventArgs e)
{
Random rnd = new();
Color mainColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
mainColor = dialog.Color;
}
Color addColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
if (dialog.ShowDialog() == DialogResult.OK)
{
addColor = dialog.Color;
}
_drawingTanker = new DrawGasolineTanker(rnd.Next(100, 200), rnd.Next(2000, 4000),
mainColor, addColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)),
DrawCar.Width, DrawCar.Height);
_drawingTanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
Draw();
}
private void CreateCarButton_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawingTanker = new DrawTanker(rnd.Next(100, 200), rnd.Next(2000, 4000), color,
DrawCar.Width, DrawCar.Height);
_drawingTanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingTanker == null)
return;
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "Up":
_drawingTanker.MoveTransport(Direction.Up); break;
case "Down":
_drawingTanker.MoveTransport(Direction.Down); break;
case "Left":
_drawingTanker.MoveTransport(Direction.Left); break;
case "Right":
_drawingTanker.MoveTransport(Direction.Right); break;
}
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawingTanker == null)
return;
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null
};
if (_abstractStrategy == null)
return;
_abstractStrategy.SetData(_drawingTanker.GetMoveableObject, DrawCar.Width, DrawCar.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
return;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
private void ButtonSelectTank_Click(object sender, EventArgs e)
{
SelectedCar = _drawingTanker;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -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>

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.Entities
{
public class GasolineTanker : BaseTanker
{
public Color AdditionalColor { get; private set; }
public bool BodyKit { get; private set; }
public bool Wing { get; private set; }
public bool SportLine { get; private set; }
public GasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine;
}
public void ChangeAddColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectParameters { get; }
int GetStep { get; }
bool CheckCanMove(Direction direction);
void MoveObject(Direction direction);
}
}

View File

@ -1,40 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34009.444
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab", "Lab.csproj", "{7EA8E822-6F7A-476A-9281-CBCB69B9CAD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7EA8E822-6F7A-476A-9281-CBCB69B9CAD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EA8E822-6F7A-476A-9281-CBCB69B9CAD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EA8E822-6F7A-476A-9281-CBCB69B9CAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EA8E822-6F7A-476A-9281-CBCB69B9CAD8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {01673CC0-0038-41A0-BBEB-C63858590694}
EndGlobalSection
EndGlobal

View File

@ -1,48 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.MovementStrategy
{
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestination()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
var diffY = objParams.DownBorder - FieldHeight;
if (diffX >= 0)
{
MoveDown();
}
else if (diffY >= 0)
{
MoveRight();
}
else if (Math.Abs(diffX) > Math.Abs(diffY))
{
MoveRight();
}
else
{
MoveDown();
}
}
}
}

View File

@ -1,54 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.MovementStrategy
{
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestination()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x; // Левая граница
public int TopBorder => _y; // Верхняя граница
public int RightBorder => _width + _x; // Правая граница
public int DownBorder => _height + _y; // Нижняя граница
public int ObjectMiddleHorizontal => _x + _width / 2; // Середина по горизонтали
public int ObjectMiddleVertical => _y + _height / 2; // Середина по вертикали
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -1,42 +0,0 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
namespace Lab
{
internal static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<CollectionsFrame>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<CollectionsFrame>().AddLogging(option =>
{
string[] path = Directory.GetCurrentDirectory().Split('\\');
string pathNeed = "";
for (int i = 0; i < path.Length - 3; i++)
{
pathNeed += path[i] + "\\";
}
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true).Build();
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
}
}

View File

@ -1,103 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Lab.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lab.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Down {
get {
object obj = ResourceManager.GetObject("Down", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Left {
get {
object obj = ResourceManager.GetObject("Left", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Right {
get {
object obj = ResourceManager.GetObject("Right", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Up {
get {
object obj = ResourceManager.GetObject("Up", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -1,133 +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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Arrows\Down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Left" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Arrows\Left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Arrows\Right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Arrows\Up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -1,87 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab.Generics
{
internal class SetGeneric<T> where T : class
{
private readonly List<T?> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(_maxCount);
}
public bool Insert(T car, IEqualityComparer<T?>? equal = null)
{
return Insert(car, 0, equal);
}
public bool Insert(T car, int position, IEqualityComparer<T?>? equal = null)
{
if (position < 0 || position >= _maxCount)
throw new CarNotFoundException(position);
if (Count >= _maxCount)
throw new StorageOverflowException(position);
if (equal != null)
{
foreach (var i in _places)
{
if (equal.Equals(i, car))
throw new ArgumentException($"Объект {car} уже существует");
}
}
_places.Insert(0, car);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position > _maxCount || position >= Count)
throw new CarNotFoundException(position);
_places.RemoveAt(position);
return true;
}
public T? this[int position]
{
get
{
if (position < 0 || position > _maxCount)
return null;
if (_places.Count <= position)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
if (_places.Count <= position)
return;
_places[position] = value;
}
}
public IEnumerable<T?> GetCars(int? maxCars = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxCars.HasValue && i == maxCars.Value)
{
yield break;
}
}
}
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab
{
public enum Status
{
NotInit = 0,
InProgress = 1,
Finish = 2
}
}

View File

@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Lab
{
[Serializable] internal class StorageOverflowException : ApplicationException
{
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
public StorageOverflowException() : base() { }
public StorageOverflowException(string message) : base(message) { }
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab.DrawningObjects;
using Lab.Generics;
namespace Lab
{
internal class TankerCollectionInfo : IEquatable<TankerCollectionInfo>
{
public string Name { get; private set; }
public string Description { get; private set; }
public TankerCollectionInfo(string name, string description)
{
Name = name;
Description = description;
}
public bool Equals(TankerCollectionInfo? other)
{
if (other == null || Name == null || other.Name == null) return false;
if (Name == other.Name) return true;
throw new NotImplementedException();
}
public override int GetHashCode()
{
return Name?.GetHashCode() ?? 0;
}
}
}

View File

@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab.DrawningObjects;
using Lab.Entities;
namespace Lab
{
internal class TankerCompareByColor : IComparer<DrawTanker?>
{
public int Compare(DrawTanker? x, DrawTanker? y)
{
if (x == null || x._gasolineTanker == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y._gasolineTanker == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x._gasolineTanker.BodyColor != y._gasolineTanker.BodyColor)
{
return x._gasolineTanker.BodyColor.Name.CompareTo(y._gasolineTanker.BodyColor.Name);
}
if (x.GetType() == y.GetType() && x is DrawGasolineTanker)
{
return (x._gasolineTanker as GasolineTanker).AdditionalColor.Name.CompareTo((y._gasolineTanker as GasolineTanker).AdditionalColor.Name);
}
var speedCompare = x._gasolineTanker.Speed.CompareTo(y._gasolineTanker.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x._gasolineTanker.Weight.CompareTo(y._gasolineTanker.Weight);
}
}
}

View File

@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab.DrawningObjects;
namespace Lab
{
internal class TankerCompareByType : IComparer<DrawTanker?>
{
public int Compare(DrawTanker? x, DrawTanker? y)
{
if (x == null || x._gasolineTanker == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y._gasolineTanker == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x._gasolineTanker.Speed.CompareTo(y._gasolineTanker.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x._gasolineTanker.Weight.CompareTo(y._gasolineTanker.Weight);
}
}
}

View File

@ -1,20 +0,0 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/log_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "GasolineTanker"
}
}
}