Этап 3.1 - добавлены проверки

This commit is contained in:
Дамир Нугаев 2022-11-01 23:32:20 +04:00
parent 36451baa69
commit 4498a36c12
4 changed files with 47 additions and 33 deletions

View File

@ -44,7 +44,7 @@
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.groupBox2.SuspendLayout();
@ -187,10 +187,10 @@
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBoxNewMapName);
this.groupBox2.Controls.Add(this.buttonDeleteMap);
this.groupBox2.Controls.Add(this.listBoxMaps);
this.groupBox2.Controls.Add(this.buttonAddMap);
this.groupBox2.Controls.Add(this.maskedTextBox1);
this.groupBox2.Controls.Add(this.comboBoxSelectorMap);
this.groupBox2.Location = new System.Drawing.Point(605, 26);
this.groupBox2.Name = "groupBox2";
@ -229,12 +229,12 @@
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// maskedTextBox1
// textBoxNewMapName
//
this.maskedTextBox1.Location = new System.Drawing.Point(8, 26);
this.maskedTextBox1.Name = "maskedTextBox1";
this.maskedTextBox1.Size = new System.Drawing.Size(125, 27);
this.maskedTextBox1.TabIndex = 1;
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 26);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(125, 27);
this.textBoxNewMapName.TabIndex = 5;
//
// FormMapWithSetDoubleDeckerBus
//
@ -273,6 +273,6 @@
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private Button buttonAddMap;
private MaskedTextBox maskedTextBox1;
private TextBox textBoxNewMapName;
}
}

View File

@ -16,7 +16,8 @@ namespace Bus
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{"Простая карта", new SimpleMap() }
{"Простая карта", new SimpleMap() },
{"Водная карта", new MyMap() },
};
private readonly MapsCollection _mapsCollection;
@ -135,7 +136,7 @@ namespace Bus
{
return;
}
pictureBox.Image = _mapBusCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonShowOnMap_Click(object sender, EventArgs e)
@ -144,7 +145,7 @@ namespace Bus
{
return;
}
pictureBox.Image = _mapBusCollectionGeneric.ShowOnMap();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void ButtonMove_Click(object sender, EventArgs e)

View File

@ -25,12 +25,21 @@ namespace Bus
public void AddMap(string name, AbstractMap map)
{
// TODO Прописать логику для добавления
if (_mapStorages.ContainsKey(name)) return; //уникальное имя
else
{
_mapStorages.Add(name, new MapWithSetDoubleDeckerBusGeneric<DrawingObjectBus, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
public void DelMap(string name)
{
// TODO Прописать логику для удаления
if (_mapStorages.ContainsKey(name))
{
_mapStorages.Remove(name);
}
}
public MapWithSetDoubleDeckerBusGeneric<DrawingObjectBus, AbstractMap> this[string ind]
@ -38,7 +47,8 @@ namespace Bus
get
{
// TODO Продумать логику получения объекта
return null;
_mapStorages.TryGetValue(ind, out var MapWithSetDoubleDeckerBusGeneric);
return MapWithSetDoubleDeckerBusGeneric;
}
}

View File

@ -26,45 +26,48 @@ namespace Bus
return Insert(bus, 0);
}
private bool isCorrectPosition(int position)
{
return 0 <= position && position < _maxCount;
}
public int Insert(T bus, int position)
{
if (position < 0 || position >= _maxCount || BusPlaces == _maxCount)
if (!isCorrectPosition(position))
{
return -1;
}
BusPlaces++;
while (_places[position] != null)
{
for (int i = _places.Count - 1; i > 0; --i)
{
if (_places[i] == null && _places[i - 1] != null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
}
_places[position] = bus;
_places.Insert(position, bus);
return position;
}
public T Remove(int position)
{
if (position < 0 || position >= _maxCount) return null;
T savedBus = _places[position];
_places[position] = null;
return savedBus;
if (position < 0 || position >= _maxCount)
{
return null;
}
var result = _places[position];
_places.RemoveAt(position);
return result;
}
public T this[int position]
{
get
{
return _places[position];
if (position >= 0 && position < _maxCount && position < Count)
{
return _places[position];
}
else
{
return null;
}
}
set
{
// todo
Insert(value, position);
}
}