правки 8 лаб
This commit is contained in:
parent
4b3d7d9694
commit
a8bc30a079
76
Tank/Tank/Drawings/DrawingTankEqutables.cs
Normal file
76
Tank/Tank/Drawings/DrawingTankEqutables.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using global::Tank.Entites;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tank.DrawingObjects;
|
||||
using Tank.Entites;
|
||||
|
||||
namespace Tank.Drawings
|
||||
{
|
||||
internal class DrawiningTankEqutables : IEqualityComparer<DrawingArmoredCar?>
|
||||
{
|
||||
public bool Equals(DrawingArmoredCar? x, DrawingArmoredCar? y)
|
||||
{
|
||||
if (x == null || x.Tank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.Tank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.Tank.Speed != y.Tank.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.Tank.Weight != y.Tank.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.Tank.BodyColor != y.Tank.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawingTank && y is DrawingTank)
|
||||
{
|
||||
if (x.Tank as EntityTank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y.Tank as EntityTank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if ((x.Tank as EntityTank).AdditionalColor != (y.Tank as EntityTank).AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.Tank as EntityTank).BodyKit != (y.Tank as EntityTank).BodyKit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.Tank as EntityTank).Trunk != (y.Tank as EntityTank).Trunk)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.Tank as EntityTank).Line != (y.Tank as EntityTank).Line)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawingArmoredCar obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
40
Tank/Tank/FormArmoredCarCollection.Designer.cs
generated
40
Tank/Tank/FormArmoredCarCollection.Designer.cs
generated
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
@ -55,6 +57,8 @@
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ButtonSortByColor);
|
||||
this.groupBox1.Controls.Add(this.ButtonSortByType);
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
|
||||
@ -62,11 +66,31 @@
|
||||
this.groupBox1.Controls.Add(this.ButtonAddArmoredCar);
|
||||
this.groupBox1.Location = new System.Drawing.Point(579, 0);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(194, 343);
|
||||
this.groupBox1.Size = new System.Drawing.Size(194, 400);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
this.ButtonSortByColor.Location = new System.Drawing.Point(18, 211);
|
||||
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
this.ButtonSortByColor.Size = new System.Drawing.Size(144, 23);
|
||||
this.ButtonSortByColor.TabIndex = 10;
|
||||
this.ButtonSortByColor.Text = "Сортировка по цвету";
|
||||
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
this.ButtonSortByType.Location = new System.Drawing.Point(18, 182);
|
||||
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||
this.ButtonSortByType.Size = new System.Drawing.Size(144, 23);
|
||||
this.ButtonSortByType.TabIndex = 9;
|
||||
this.ButtonSortByType.Text = "Сортировка по типу";
|
||||
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.textBoxStorageName);
|
||||
@ -119,14 +143,14 @@
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(18, 235);
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(18, 292);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(129, 23);
|
||||
this.maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(6, 310);
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(6, 367);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(172, 27);
|
||||
this.ButtonRefreshCollection.TabIndex = 2;
|
||||
@ -136,7 +160,7 @@
|
||||
//
|
||||
// ButtonRemoveArmoredCar
|
||||
//
|
||||
this.ButtonRemoveArmoredCar.Location = new System.Drawing.Point(6, 264);
|
||||
this.ButtonRemoveArmoredCar.Location = new System.Drawing.Point(6, 321);
|
||||
this.ButtonRemoveArmoredCar.Name = "ButtonRemoveArmoredCar";
|
||||
this.ButtonRemoveArmoredCar.Size = new System.Drawing.Size(172, 40);
|
||||
this.ButtonRemoveArmoredCar.TabIndex = 1;
|
||||
@ -146,7 +170,7 @@
|
||||
//
|
||||
// ButtonAddArmoredCar
|
||||
//
|
||||
this.ButtonAddArmoredCar.Location = new System.Drawing.Point(6, 190);
|
||||
this.ButtonAddArmoredCar.Location = new System.Drawing.Point(6, 247);
|
||||
this.ButtonAddArmoredCar.Name = "ButtonAddArmoredCar";
|
||||
this.ButtonAddArmoredCar.Size = new System.Drawing.Size(172, 39);
|
||||
this.ButtonAddArmoredCar.TabIndex = 0;
|
||||
@ -165,9 +189,9 @@
|
||||
// panelStrip
|
||||
//
|
||||
this.panelStrip.Controls.Add(this.StripMenu);
|
||||
this.panelStrip.Location = new System.Drawing.Point(585, 349);
|
||||
this.panelStrip.Location = new System.Drawing.Point(585, 406);
|
||||
this.panelStrip.Name = "panelStrip";
|
||||
this.panelStrip.Size = new System.Drawing.Size(172, 89);
|
||||
this.panelStrip.Size = new System.Drawing.Size(172, 44);
|
||||
this.panelStrip.TabIndex = 2;
|
||||
//
|
||||
// StripMenu
|
||||
@ -255,5 +279,7 @@
|
||||
private ToolStripMenuItem openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog1;
|
||||
private Button ButtonSortByColor;
|
||||
private Button ButtonSortByType;
|
||||
}
|
||||
}
|
@ -132,8 +132,7 @@ namespace Tank
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
@ -213,5 +212,18 @@ namespace Tank
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CompareTank(IComparer<DrawingArmoredCar?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
return;
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
return;
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowTanks();
|
||||
}
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareTank(new TankCompareByType());
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareTank(new TankCompareByColor());
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,6 @@
|
||||
<value>294, 7</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>67</value>
|
||||
<value>39</value>
|
||||
</metadata>
|
||||
</root>
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tank.Exceptions;
|
||||
|
||||
namespace Tank.Generics
|
||||
{
|
||||
@ -17,30 +18,37 @@ namespace Tank.Generics
|
||||
public int Count => _places.Count;
|
||||
|
||||
private readonly int _maxCount;
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(_maxCount);
|
||||
}
|
||||
public bool Insert(T tank)
|
||||
public bool Insert(T tank, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
return Insert(tank, 0);
|
||||
return Insert(tank, 0, equal);
|
||||
}
|
||||
|
||||
public bool Insert(T tank, int position)
|
||||
public bool Insert(T tank, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return false;
|
||||
if (position < 0 || position >= _maxCount)
|
||||
throw new TankNotFoundException(position);
|
||||
|
||||
if (Count >= _maxCount)
|
||||
return false;
|
||||
throw new TankStorageOverflowException(_maxCount);
|
||||
|
||||
if (equal != null && _places.Contains<T>(tank, equal))
|
||||
throw new ApplicationException("Уже есть");
|
||||
|
||||
_places.Insert(0, tank);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return false;
|
||||
if (position < 0 || position > _maxCount || position >= Count)
|
||||
throw new TankNotFoundException(position);
|
||||
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ namespace Tank.Generics
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Сортировка
|
||||
public void Sort(IComparer<T> comparer) => _collection.SortSet(comparer);
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
|
@ -64,6 +64,8 @@ namespace Tank.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
TankCollectionInfo Info = new TankCollectionInfo(name, string.Empty);
|
||||
|
||||
if (_tankStorages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
@ -79,6 +81,8 @@ namespace Tank.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
TankCollectionInfo Info = new TankCollectionInfo(name, string.Empty);
|
||||
|
||||
if (_tankStorages.ContainsKey(name))
|
||||
{
|
||||
_tankStorages.Remove(name);
|
||||
@ -98,6 +102,8 @@ namespace Tank.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
TankCollectionInfo Info = new TankCollectionInfo(ind, string.Empty);
|
||||
|
||||
if (_tankStorages.ContainsKey(ind))
|
||||
{
|
||||
return _tankStorages[ind];
|
||||
@ -125,7 +131,7 @@ namespace Tank.Generics
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||
throw new Exception("Невалидная операция, нет данных для сохранения");
|
||||
}
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
|
30
Tank/Tank/TankCollectionInfo.cs
Normal file
30
Tank/Tank/TankCollectionInfo.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tank
|
||||
{
|
||||
internal class TankCollectionInfo : IEquatable<TankCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
|
||||
public TankCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name?.GetHashCode() ?? 0;
|
||||
}
|
||||
public bool Equals(TankCollectionInfo? other)
|
||||
{
|
||||
if (other == null || Name == null || other.Name == null) return false;
|
||||
if (Name == other?.Name) return true;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
39
Tank/Tank/TankCompareByColor.cs
Normal file
39
Tank/Tank/TankCompareByColor.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tank.DrawingObjects;
|
||||
using Tank.Entites;
|
||||
|
||||
namespace Tank
|
||||
{
|
||||
internal class TankCompareByColor : IComparer<DrawingArmoredCar?>
|
||||
{
|
||||
public int Compare(DrawingArmoredCar? x, DrawingArmoredCar? y)
|
||||
{
|
||||
if (x == null || x.Tank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.Tank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.Tank.BodyColor != y.Tank.BodyColor)
|
||||
{
|
||||
return x.Tank.BodyColor.Name.CompareTo(y.Tank.BodyColor.Name);
|
||||
}
|
||||
if (x.GetType() == y.GetType() && x is DrawingTank)
|
||||
{
|
||||
return (x.Tank as EntityTank).AdditionalColor.Name.CompareTo((y.Tank as EntityTank).AdditionalColor.Name);
|
||||
}
|
||||
var speedCompare = x.Tank.Speed.CompareTo(y.Tank.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.Tank.Weight.CompareTo(y.Tank.Weight);
|
||||
}
|
||||
}
|
||||
}
|
34
Tank/Tank/TankCompareByType.cs
Normal file
34
Tank/Tank/TankCompareByType.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tank.DrawingObjects;
|
||||
|
||||
namespace Tank
|
||||
{
|
||||
internal class TankCompareByType : IComparer<DrawingArmoredCar?>
|
||||
{
|
||||
public int Compare(DrawingArmoredCar? x, DrawingArmoredCar? y)
|
||||
{
|
||||
if (x == null || x.Tank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.Tank == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.Tank.Speed.CompareTo(y.Tank.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.Tank.Weight.CompareTo(y.Tank.Weight);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user