Последний фикс

This commit is contained in:
Макс Бондаренко 2022-10-29 18:06:35 +04:00
parent e641141175
commit d29a47f44e
4 changed files with 38 additions and 23 deletions

View File

@ -30,13 +30,20 @@ namespace WarmlyShip
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
_warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_warmlyShip = new DrawingWarmlyShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
@ -65,11 +72,20 @@ namespace WarmlyShip
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random random = new Random();
_warmlyShip = new DrawningMotorShip(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_warmlyShip = new DrawningMotorShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}

View File

@ -55,7 +55,7 @@ namespace WarmlyShip
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectShip ship = new(form.SelectedShip);
if (_mapShipCollectionGeneric + ship)
if (_mapShipCollectionGeneric + ship == 1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();
@ -73,13 +73,12 @@ namespace WarmlyShip
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapShipCollectionGeneric - pos)
if (_mapShipCollectionGeneric - pos == 1)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();

View File

@ -27,12 +27,12 @@ namespace WarmlyShip
_map = map;
}
public static bool operator +(MapWithSetShipGeneric<T, U> map, T ship)
public static int operator +(MapWithSetShipGeneric<T, U> map, T ship)
{
return map._setShips.Insert(ship);
}
public static bool operator -(MapWithSetShipGeneric<T, U> map, int position)
public static int operator -(MapWithSetShipGeneric<T, U> map, int position)
{
return map._setShips.Remove(position);
}
@ -116,7 +116,7 @@ namespace WarmlyShip
if (_setShips.Get(i) != null )
{
int temp = 0;
if (_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top < 75) temp = (int)(_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top) / 2;
if (_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top < 75) temp = (int)(_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top);
_setShips.Get(i).SetObject((_pictureWidth / _placeSizeWidth - (i % (_pictureWidth / _placeSizeWidth)) - 1) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight + temp, _pictureWidth, _pictureHeight);
_setShips.Get(i).DrawningObject(g);
}

View File

@ -24,7 +24,7 @@ namespace WarmlyShip
return false;
}
public bool Insert(T ship)
public int Insert(T ship)
{
if (CanInsert(0))
{
@ -37,14 +37,14 @@ namespace WarmlyShip
}
}
_places[0] = ship;
return true;
return 1;
}
return false;
return 0;
}
public bool Insert(T ship, int position)
public int Insert(T ship, int position)
{
if (position < 0 || position > _places.Length) return false;
if (position < 0 || position > _places.Length) return 0;
if (_places[position] != null && CanInsert(position))
{
for (int i = _places.Length - 1; i > position; --i)
@ -57,13 +57,13 @@ namespace WarmlyShip
}
}
_places[position] = ship;
return true;
return 1;
}
public bool Remove(int position)
public int Remove(int position)
{
_places[position] = null;
return true;
return 1;
}
public T Get(int position)