Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef7754bdf9 | |||
| 155ebec8ff | |||
| a7027333d8 | |||
| 5a1cdcd4b2 | |||
| 38def0fbc5 | |||
| 88b702d5b5 | |||
| 3f65961713 | |||
| 47dfc705d8 | |||
| 7009f2b1b7 | |||
| 7f15f74c84 | |||
| 630de13d2c | |||
| 75671e0272 | |||
| 11c83fd8b0 | |||
| dded2fe5dc | |||
| 6f35bd337b | |||
| 032bf5d2a2 |
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
@@ -164,5 +164,29 @@ namespace Locomotive
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
||||
public bool Equals(AbstractMap? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_width != other._width) return false;
|
||||
if (_height != other._height) return false;
|
||||
if (_size_x != other._size_x) return false;
|
||||
if (_size_y != other._size_y) return false;
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i,j] != other._map[i,j]) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace Locomotive
|
||||
|
||||
public float Step => _locomotive?.Locomotive?.Step ?? 0;
|
||||
|
||||
public DrawningLocomotive GetLocomotive => _locomotive;
|
||||
|
||||
public void DrawningObject(Graphics g)
|
||||
{
|
||||
_locomotive?.DrawTransport(g);
|
||||
@@ -26,7 +28,6 @@ namespace Locomotive
|
||||
{
|
||||
return _locomotive?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_locomotive?.MoveTransport(direction);
|
||||
@@ -37,5 +38,47 @@ namespace Locomotive
|
||||
_locomotive?.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
public string getInfo() => _locomotive?.getDataForSave();
|
||||
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectLocomotive(data.createDrawningLocomotive());
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherLocomotive = other as DrawningObjectLocomotive;
|
||||
if (otherLocomotive == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var locomotive = _locomotive.Locomotive;
|
||||
var otherLocomotiveLocomotive = otherLocomotive._locomotive.Locomotive;
|
||||
|
||||
if (locomotive.GetType().Name != otherLocomotiveLocomotive.GetType().Name) return false;
|
||||
|
||||
if (locomotive.Speed != otherLocomotiveLocomotive.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (locomotive.Weight != otherLocomotiveLocomotive.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (locomotive.BodyColor != otherLocomotiveLocomotive.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// проверка в случае продвинутого объекта
|
||||
if (locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive && otherLocomotiveLocomotive is EntityWarmlyLocomotive otherEntityWarmlyLocomotive)
|
||||
{
|
||||
if (entityWarmlyLocomotive.ExtraColor != otherEntityWarmlyLocomotive.ExtraColor) return false;
|
||||
if (entityWarmlyLocomotive.Pipe != otherEntityWarmlyLocomotive.Pipe) return false;
|
||||
if (entityWarmlyLocomotive.FuelStorage != otherEntityWarmlyLocomotive.FuelStorage) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
Locomotive/Locomotive/ExtentionLocomotive.cs
Normal file
48
Locomotive/Locomotive/ExtentionLocomotive.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
internal static class ExtentionLocomotive
|
||||
{
|
||||
private static readonly char _separatorForObject = ':';
|
||||
public static string getDataForSave(this DrawningLocomotive drawningLocomotive)
|
||||
{
|
||||
var locomotive = drawningLocomotive.Locomotive;
|
||||
var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}";
|
||||
if (locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{_separatorForObject}{warmlyLocomotive.ExtraColor.Name}{_separatorForObject}{warmlyLocomotive.Pipe}{_separatorForObject}{warmlyLocomotive.FuelStorage}";
|
||||
}
|
||||
|
||||
public static DrawningLocomotive createDrawningLocomotive(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningLocomotive(
|
||||
Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2])
|
||||
);
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawningWarmlyLocomotive(
|
||||
Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5])
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||
this.panelGreen.Location = new System.Drawing.Point(72, 31);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(43, 40);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
@@ -45,13 +46,23 @@
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddLocomotive = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.loadFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.ButtonSortByColor);
|
||||
this.groupBoxTools.Controls.Add(this.ButtonSortByType);
|
||||
this.groupBoxTools.Controls.Add(this.groupBox1);
|
||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
@@ -63,13 +74,23 @@
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddLocomotive);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(580, 0);
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(580, 28);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(220, 546);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(220, 637);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Tools";
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
this.ButtonSortByType.Location = new System.Drawing.Point(7, 456);
|
||||
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||
this.ButtonSortByType.Size = new System.Drawing.Size(207, 29);
|
||||
this.ButtonSortByType.TabIndex = 9;
|
||||
this.ButtonSortByType.Text = "Sort By Type";
|
||||
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.buttonDeleteMap);
|
||||
@@ -137,7 +158,7 @@
|
||||
//
|
||||
this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(42, 502);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(48, 591);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonLeft.TabIndex = 7;
|
||||
@@ -148,7 +169,7 @@
|
||||
//
|
||||
this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(134, 502);
|
||||
this.buttonRight.Location = new System.Drawing.Point(140, 591);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonRight.TabIndex = 7;
|
||||
@@ -159,7 +180,7 @@
|
||||
//
|
||||
this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(88, 502);
|
||||
this.buttonDown.Location = new System.Drawing.Point(94, 591);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonDown.TabIndex = 7;
|
||||
@@ -170,7 +191,7 @@
|
||||
//
|
||||
this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(88, 456);
|
||||
this.buttonUp.Location = new System.Drawing.Point(94, 545);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
@@ -228,19 +249,72 @@
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(580, 546);
|
||||
this.pictureBox.Size = new System.Drawing.Size(580, 637);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.fileToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(800, 28);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
//
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.saveToolStripMenuItem,
|
||||
this.loadToolStripMenuItem});
|
||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
|
||||
this.fileToolStripMenuItem.Text = "File";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
|
||||
this.saveToolStripMenuItem.Text = "Save";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
this.loadToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
|
||||
this.loadToolStripMenuItem.Text = "Load";
|
||||
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
|
||||
//
|
||||
// loadFileDialog
|
||||
//
|
||||
this.loadFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
this.ButtonSortByColor.Location = new System.Drawing.Point(7, 491);
|
||||
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
this.ButtonSortByColor.Size = new System.Drawing.Size(207, 29);
|
||||
this.ButtonSortByColor.TabIndex = 10;
|
||||
this.ButtonSortByColor.Text = "Sort By Color";
|
||||
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// FormMapWithSetLocomotives
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 546);
|
||||
this.ClientSize = new System.Drawing.Size(800, 665);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMapWithSetLocomotives";
|
||||
this.Text = "FormMapWithSetLocomotives";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
@@ -248,7 +322,10 @@
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@@ -271,5 +348,13 @@
|
||||
private Button buttonAddMap;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem fileToolStripMenuItem;
|
||||
private ToolStripMenuItem saveToolStripMenuItem;
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private OpenFileDialog loadFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button ButtonSortByType;
|
||||
private Button ButtonSortByColor;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Serilog;
|
||||
using Serilog.Formatting.Compact;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -21,6 +23,8 @@ namespace Locomotive
|
||||
};
|
||||
/// Объект от коллекции карт
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
|
||||
/// Конструктор
|
||||
public FormMapWithSetLocomotives()
|
||||
{
|
||||
@@ -64,12 +68,14 @@ namespace Locomotive
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
|
||||
Log.Information($"Map {textBoxNewMapName.Text} added");
|
||||
ReloadMaps();
|
||||
}
|
||||
/// Выбор карты
|
||||
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
Log.Information($"Map switched to {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}");
|
||||
}
|
||||
/// Удаление карты
|
||||
private void buttonDeleteMap_Click(object sender, EventArgs e)
|
||||
@@ -81,6 +87,7 @@ namespace Locomotive
|
||||
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?","Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
Log.Information($"Map {listBoxMaps.SelectedItem?.ToString() ?? string.Empty} deleted");
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
@@ -99,15 +106,27 @@ namespace Locomotive
|
||||
return;
|
||||
}
|
||||
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive) != -1)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Object added");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectLocomotive(locomotive) != -1)
|
||||
{
|
||||
MessageBox.Show("Object added");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
Log.Information($"Object {locomotive} added");
|
||||
}
|
||||
|
||||
else
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Failed to add object");
|
||||
}
|
||||
}
|
||||
catch(StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Failed to add object");
|
||||
MessageBox.Show($"Storage overflow error: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Unknown error: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,15 +147,28 @@ namespace Locomotive
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Object removed");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Object removed");
|
||||
Log.Information($"Locomotive at {pos} deleted");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Failed to remove object");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch(LocomotiveNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Failed to remove object");
|
||||
MessageBox.Show($"Delete error: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Unknown error: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
/// Вывод набора
|
||||
private void buttonShowStorage_Click(object sender, EventArgs e)
|
||||
@@ -186,5 +218,61 @@ namespace Locomotive
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Saving success", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
Log.Information($"Saved to {saveFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Saving error: {ex.Message}", "Result",MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (loadFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(loadFileDialog.FileName);
|
||||
MessageBox.Show("Loaded successfully", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
Log.Information($"Loaded from {loadFileDialog.FileName}");
|
||||
ReloadMaps();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Loading failed + {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new LocomotiveCompareByType());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new LocomotiveCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,16 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="loadFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>144, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>311, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// Шаг перемещения объекта
|
||||
public float Step { get; }
|
||||
@@ -19,5 +19,7 @@ namespace Locomotive
|
||||
/// Получение текущей позиции объекта
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
|
||||
// Получение информации по объекту
|
||||
string getInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
78
Locomotive/Locomotive/LocomotiveCompareByColor.cs
Normal file
78
Locomotive/Locomotive/LocomotiveCompareByColor.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
internal class LocomotiveCompareByColor : IComparer<IDrawningObject>
|
||||
{
|
||||
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xLocomotive = x as DrawningObjectLocomotive;
|
||||
var yLocomotive = y as DrawningObjectLocomotive;
|
||||
if (xLocomotive == null && yLocomotive == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xLocomotive == null && yLocomotive != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xLocomotive != null && yLocomotive == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (xLocomotive.GetLocomotive.Locomotive.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.R) != 0)
|
||||
{
|
||||
return xLocomotive.GetLocomotive.Locomotive.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.R);
|
||||
}
|
||||
if (xLocomotive.GetLocomotive.Locomotive.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.G) != 0)
|
||||
{
|
||||
return xLocomotive.GetLocomotive.Locomotive.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.G);
|
||||
}
|
||||
if (xLocomotive.GetLocomotive.Locomotive.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.B) != 0)
|
||||
{
|
||||
return xLocomotive.GetLocomotive.Locomotive.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.B);
|
||||
}
|
||||
|
||||
if (xLocomotive.GetLocomotive.Locomotive is EntityWarmlyLocomotive xWarmlyEntity && yLocomotive.GetLocomotive.Locomotive is EntityWarmlyLocomotive yWarmlyEntity)
|
||||
{
|
||||
if (xWarmlyEntity.ExtraColor.R.CompareTo(yWarmlyEntity.ExtraColor.R) != 0)
|
||||
{
|
||||
return xWarmlyEntity.ExtraColor.R.CompareTo(yWarmlyEntity.ExtraColor.R);
|
||||
}
|
||||
if (xWarmlyEntity.ExtraColor.G.CompareTo(yWarmlyEntity.ExtraColor.G) != 0)
|
||||
{
|
||||
return xWarmlyEntity.ExtraColor.G.CompareTo(yWarmlyEntity.ExtraColor.G);
|
||||
}
|
||||
if (xWarmlyEntity.ExtraColor.B.CompareTo(yWarmlyEntity.ExtraColor.B) != 0)
|
||||
{
|
||||
return xWarmlyEntity.ExtraColor.B.CompareTo(yWarmlyEntity.ExtraColor.B);
|
||||
}
|
||||
}
|
||||
|
||||
var speedCompare = xLocomotive.GetLocomotive.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Locomotive/Locomotive/LocomotiveCompareByType.cs
Normal file
55
Locomotive/Locomotive/LocomotiveCompareByType.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
internal class LocomotiveCompareByType : IComparer<IDrawningObject>
|
||||
{
|
||||
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xLocomotive = x as DrawningObjectLocomotive;
|
||||
var yLocomotive = y as DrawningObjectLocomotive;
|
||||
if (xLocomotive == null && yLocomotive == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xLocomotive == null && yLocomotive != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xLocomotive != null && yLocomotive == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xLocomotive.GetLocomotive.GetType().Name != yLocomotive.GetLocomotive.GetType().Name)
|
||||
{
|
||||
if (xLocomotive.GetLocomotive.GetType().Name == "DrawningLocomotive")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xLocomotive.GetLocomotive.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Locomotive/Locomotive/LocomotiveNotFoundException.cs
Normal file
19
Locomotive/Locomotive/LocomotiveNotFoundException.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
internal class LocomotiveNotFoundException : ApplicationException
|
||||
{
|
||||
public LocomotiveNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public LocomotiveNotFoundException() : base() { }
|
||||
public LocomotiveNotFoundException(string message) : base(message) { }
|
||||
public LocomotiveNotFoundException(string message, Exception exception) :
|
||||
base(message, exception) { }
|
||||
protected LocomotiveNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Locomotive
|
||||
{
|
||||
internal class MapWithSetLocomotivesGeneric <T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// Ширина окна отрисовки
|
||||
@@ -15,9 +15,9 @@ namespace Locomotive
|
||||
/// Высота окна отрисовки
|
||||
private readonly int _pictureHeight;
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
private readonly int _placeSizeWidth = 150;
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
private readonly int _placeSizeHeight = 150;
|
||||
/// Набор объектов
|
||||
private readonly SetLocomotivesGeneric<T> _setLocomotives;
|
||||
/// Карта
|
||||
@@ -138,8 +138,8 @@ namespace Locomotive
|
||||
/// Метод прорисовки объектов
|
||||
private void DrawLocomotives(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
int width = _pictureWidth / _placeSizeWidth - 1;
|
||||
int height = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
int curWidth = 0;
|
||||
int curHeight = 0;
|
||||
@@ -147,7 +147,7 @@ namespace Locomotive
|
||||
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||
{
|
||||
// установка позиции
|
||||
locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
||||
locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 80, _pictureWidth, _pictureHeight);
|
||||
locomotive?.DrawningObject(g);
|
||||
if (curWidth < width) curWidth++;
|
||||
else
|
||||
@@ -158,5 +158,29 @@ namespace Locomotive
|
||||
}
|
||||
}
|
||||
|
||||
/// Получение данных в виде строки
|
||||
public string GetData(char separatorType, char separatorData)
|
||||
{
|
||||
string data = $"{_map.GetType().Name}{separatorType}";
|
||||
foreach (var locomotive in _setLocomotives.GetLocomotives())
|
||||
{
|
||||
data += $"{locomotive.getInfo()}{separatorData}";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/// Загрузка списка из массива строк
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records.Reverse())
|
||||
{
|
||||
_setLocomotives.Insert(DrawningObjectLocomotive.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setLocomotives.SortSet(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -9,7 +10,7 @@ namespace Locomotive
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// Словарь (хранилище) с картами
|
||||
readonly Dictionary<string, MapWithSetLocomotivesGeneric<DrawningObjectLocomotive,
|
||||
readonly Dictionary<string, MapWithSetLocomotivesGeneric<IDrawningObject,
|
||||
AbstractMap>> _mapStorages;
|
||||
/// Возвращение списка названий карт
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
@@ -17,19 +18,25 @@ namespace Locomotive
|
||||
private readonly int _pictureWidth;
|
||||
/// Высота окна отрисовки
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
// Сепараторы
|
||||
private readonly char separatorDict = '|';
|
||||
private readonly char separatorData = ';';
|
||||
|
||||
/// Конструктор
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string,
|
||||
MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>>();
|
||||
MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
/// Добавление карты
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
// Логика для добавления
|
||||
if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
/// Удаление карты
|
||||
public void DelMap(string name)
|
||||
@@ -38,7 +45,7 @@ namespace Locomotive
|
||||
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
|
||||
}
|
||||
/// Доступ к парковке
|
||||
public MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> this[string ind]
|
||||
public MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -48,5 +55,70 @@ namespace Locomotive
|
||||
}
|
||||
}
|
||||
|
||||
/// Сохранение информации по локомотивам в хранилище в файл
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (FileStream fs = new(filename, FileMode.Create))
|
||||
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
|
||||
{
|
||||
sw.WriteLine("MapsCollection");
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
|
||||
sw.WriteLine(
|
||||
$"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Загрузка нформации по локомотивам в депо из файла
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
Log.Warning($"FileNotFoundException {filename}");
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
|
||||
{
|
||||
string curLine = sr.ReadLine();
|
||||
|
||||
if (!curLine.Contains("MapsCollection"))
|
||||
{
|
||||
Log.Warning($"FileFormatException");
|
||||
throw new FileFormatException("Формат данных в файле неправильный");
|
||||
}
|
||||
|
||||
_mapStorages.Clear();
|
||||
while ((curLine = sr.ReadLine()) != null)
|
||||
{
|
||||
var elems = curLine.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
|
||||
switch (elems[1])
|
||||
{
|
||||
case "Simple Map":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Spike Map":
|
||||
map = new SpikeMap();
|
||||
break;
|
||||
case "Rail Map":
|
||||
map = new RailroadMap();
|
||||
break;
|
||||
}
|
||||
|
||||
_mapStorages.Add(elems[0], new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elems[0]].LoadData(elems[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Serilog;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
internal static class Program
|
||||
@@ -10,6 +12,9 @@ namespace Locomotive
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
|
||||
|
||||
Log.Logger = new LoggerConfiguration().WriteTo.File(new Serilog.Formatting.Compact.CompactJsonFormatter(), "C:\\secondCourse\\OOP\\ProjectLomotive\\Locomotive\\log.clef").CreateLogger();
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMapWithSetLocomotives());
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -7,7 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace Locomotive
|
||||
{
|
||||
internal class SetLocomotivesGeneric <T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// Список хранимых объектов
|
||||
private readonly List<T> _places;
|
||||
@@ -30,7 +31,12 @@ namespace Locomotive
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T locomotive, int position)
|
||||
{
|
||||
if (position >= _maxCount|| position < 0) return -1;
|
||||
if (_places.Contains(locomotive)) return -1; // Проверка на уникальность
|
||||
if (position < 0) return -1;
|
||||
if (Count >= _maxCount) {
|
||||
Log.Warning("StorageOverflowException");
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
_places.Insert(position, locomotive);
|
||||
|
||||
return position;
|
||||
@@ -39,8 +45,13 @@ namespace Locomotive
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= _maxCount || position < 0) return null;
|
||||
if (_places[position] is null)
|
||||
{
|
||||
Log.Warning($"LocomotiveNotFoundException at {position}");
|
||||
throw new LocomotiveNotFoundException(position);
|
||||
}
|
||||
T result = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
_places[position] = null;
|
||||
return result;
|
||||
}
|
||||
// Индексатор
|
||||
@@ -61,16 +72,20 @@ namespace Locomotive
|
||||
public IEnumerable<T> GetLocomotives()
|
||||
{
|
||||
foreach (var locomotive in _places)
|
||||
{
|
||||
if (locomotive != null)
|
||||
{
|
||||
yield return locomotive;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
{
|
||||
yield return locomotive;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
20
Locomotive/Locomotive/StorageOverflowException.cs
Normal file
20
Locomotive/Locomotive/StorageOverflowException.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Locomotive
|
||||
{
|
||||
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 context) : base(info, context) { }
|
||||
|
||||
}
|
||||
}
|
||||
17
Locomotive/log.clef
Normal file
17
Locomotive/log.clef
Normal file
@@ -0,0 +1,17 @@
|
||||
{"@t":"2022-11-21T15:23:13.2775821Z","@mt":"Map lalaland added"}
|
||||
{"@t":"2022-11-21T15:23:13.3466012Z","@mt":"Map switched to lalaland"}
|
||||
{"@t":"2022-11-21T15:23:31.6565447Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:23:57.7770111Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:25:01.0533266Z","@mt":"Map lalaland added"}
|
||||
{"@t":"2022-11-21T15:25:01.0794891Z","@mt":"Map switched to lalaland"}
|
||||
{"@t":"2022-11-21T15:25:01.4998647Z","@mt":"Map switched to lalaland"}
|
||||
{"@t":"2022-11-21T15:25:06.1595618Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:25:18.9994738Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:25:31.8129464Z","@mt":"Map lalaland added"}
|
||||
{"@t":"2022-11-21T15:25:31.8344280Z","@mt":"Map switched to lalaland"}
|
||||
{"@t":"2022-11-21T15:25:37.1362070Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:25:46.1930394Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:26:02.0790751Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:26:24.6631252Z","@mt":"Object Locomotive.DrawningWarmlyLocomotive added"}
|
||||
{"@t":"2022-11-21T15:26:31.0236570Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||
{"@t":"2022-11-21T15:26:36.0331011Z","@mt":"Object Locomotive.DrawningWarmlyLocomotive added"}
|
||||
Reference in New Issue
Block a user