From 87888ff4038070f0d945cb1846d3f2339bc8f143 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Fri, 13 Oct 2023 12:23:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BA=D0=BE=D0=BD=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Monorail/MonorailGenericCollection.cs | 12 ++--- Monorail/Monorail/MonorailGenericStorage.cs | 51 ------------------- Monorail/Monorail/SetGeneric.cs | 12 ++--- 3 files changed, 12 insertions(+), 63 deletions(-) delete mode 100644 Monorail/Monorail/MonorailGenericStorage.cs diff --git a/Monorail/Monorail/MonorailGenericCollection.cs b/Monorail/Monorail/MonorailGenericCollection.cs index 9333f98..7361407 100644 --- a/Monorail/Monorail/MonorailGenericCollection.cs +++ b/Monorail/Monorail/MonorailGenericCollection.cs @@ -32,20 +32,20 @@ namespace Monorail.Generics _collection = new SetGeneric(width * height); } - public static T? operator +(MonorailGenericCollection collect, T? obj) + public static int operator +(MonorailGenericCollection collect, T? obj) { if (obj == null) - return null; - return collect?._collection.Insert(obj) ?? null; + return -1; + return collect?._collection.Insert(obj) ?? -1; } - public static T? operator -(MonorailGenericCollection collect, int + public static bool operator -(MonorailGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); if (obj != null) - collect._collection.Remove(pos); - return obj; + return collect._collection.Remove(pos); + return false; } public U? GetU(int pos) diff --git a/Monorail/Monorail/MonorailGenericStorage.cs b/Monorail/Monorail/MonorailGenericStorage.cs deleted file mode 100644 index 88b1715..0000000 --- a/Monorail/Monorail/MonorailGenericStorage.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Monorail.DrawningObjects; -using Monorail.Generics; -using Monorail.MovementStrategy; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Monorail -{ - internal class MonorailGenericStorage - { - readonly Dictionary> _monorailStorages; - public List Keys => _monorailStorages.Keys.ToList(); - - private readonly int _pictureWidth; - - private readonly int _pictureHeight; - - public MonorailGenericStorage(int pictureWidth, int pictureHeight) - { - _monorailStorages = new Dictionary>(); - _pictureWidth = pictureWidth; - _pictureHeight = pictureHeight; - } - - public void AddSet(string name) - { - _monorailStorages.Add(name, new MonorailGenericCollection (_pictureWidth, _pictureHeight)); - } - - public void DelSet(string name) - { - if (_monorailStorages.ContainsKey(name) == null) - return; - _monorailStorages.Remove(name); - } - - public MonorailGenericCollection? this[string ind] - { - get - { - if (_monorailStorages.ContainsKey(ind)) - return _monorailStorages[ind]; - return null; - } - } - } -} diff --git a/Monorail/Monorail/SetGeneric.cs b/Monorail/Monorail/SetGeneric.cs index 7f055ee..5e314c2 100644 --- a/Monorail/Monorail/SetGeneric.cs +++ b/Monorail/Monorail/SetGeneric.cs @@ -18,29 +18,29 @@ namespace Monorail.Generics _places = new T?[count]; } - public T? Insert(T monorail) + public int Insert(T monorail) { if (_places[Count-1] != null) - return null; + return -1; return Insert(monorail, 0); } - public T? Insert(T monorail, int position) + public int Insert(T monorail, int position) { if (!(position >= 0 && position < Count)) - return null; + return -1; if (_places[position] != null) { int ind = position; while (ind < Count && _places[ind] != null) ind++; if (ind == Count) - return null; + return -1; for (int i = ind - 1; i >= position; i--) _places[i + 1] = _places[i]; } _places[position] = monorail; - return monorail; + return position; } public bool Remove(int position) {