Окончательно поправил
This commit is contained in:
parent
1e5b226b10
commit
87888ff403
@ -32,20 +32,20 @@ namespace Monorail.Generics
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static T? operator +(MonorailGenericCollection<T,U> collect, T? obj)
|
||||
public static int operator +(MonorailGenericCollection<T,U> 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<T, U> collect, int
|
||||
public static bool operator -(MonorailGenericCollection<T, U> 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)
|
||||
|
@ -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<string, MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> _monorailStorages;
|
||||
public List<string> Keys => _monorailStorages.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public MonorailGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_monorailStorages = new Dictionary<string,
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_monorailStorages.Add(name, new MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> (_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_monorailStorages.ContainsKey(name) == null)
|
||||
return;
|
||||
_monorailStorages.Remove(name);
|
||||
}
|
||||
|
||||
public MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_monorailStorages.ContainsKey(ind))
|
||||
return _monorailStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user