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

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

View File

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

View File

@ -27,12 +27,12 @@ namespace WarmlyShip
_map = map; _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); 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); return map._setShips.Remove(position);
} }
@ -116,7 +116,7 @@ namespace WarmlyShip
if (_setShips.Get(i) != null ) if (_setShips.Get(i) != null )
{ {
int temp = 0; 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).SetObject((_pictureWidth / _placeSizeWidth - (i % (_pictureWidth / _placeSizeWidth)) - 1) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight + temp, _pictureWidth, _pictureHeight);
_setShips.Get(i).DrawningObject(g); _setShips.Get(i).DrawningObject(g);
} }

View File

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