Внесла некоторые изменения

This commit is contained in:
Hells Hound 2022-10-04 23:32:55 +04:00
parent 4b867003e2
commit e8e0bd9329
5 changed files with 61 additions and 47 deletions

View File

@ -32,17 +32,22 @@ namespace AircraftCarrier
}
public Bitmap MoveObject(Direction direction)
{
if (true)
if (_drawingObject != null)
{
_drawingObject.MoveObject(direction);
}
(float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition();
if (true)
{
_drawingObject.MoveObject(direction);
}
(float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition();
if (Check(Left, Right, Top, Bottom) != 0)
{
_drawingObject.MoveObject(GetOpositDirection(direction));
if (Check(Left, Right, Top, Bottom) != 0)
{
_drawingObject.MoveObject(GetOpositDirection(direction));
}
return DrawMapWithObject();
}
return DrawMapWithObject();
return null;
}
private Direction GetOpositDirection(Direction dir)

View File

@ -61,7 +61,7 @@ namespace AircraftCarrier
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectWarship warship = new(form.SelectedWarship);
if (_mapWarshipsCollectionGeneric + warship)
if (_mapWarshipsCollectionGeneric + warship >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet();
@ -88,7 +88,7 @@ namespace AircraftCarrier
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapWarshipsCollectionGeneric - pos)
if (_mapWarshipsCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet();
@ -118,7 +118,11 @@ namespace AircraftCarrier
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
////
if(_mapWarshipsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение

View File

@ -46,7 +46,7 @@ namespace AircraftCarrier
{
color = dialog.Color;
}
_warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}

View File

@ -26,11 +26,11 @@ namespace AircraftCarrier
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeWidth = 120;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
private readonly int _placeSizeHeight = 50;
/// <summary>
/// Набор объектов
/// </summary>
@ -60,7 +60,7 @@ namespace AircraftCarrier
/// <param name="map"></param>
/// <param name="warship"></param>
/// <returns></returns>
public static bool operator +(MapWithSetWarshipsGeneric<T, U> map, T warship)
public static int operator +(MapWithSetWarshipsGeneric<T, U> map, T warship)
{
return map._setWarships.Insert(warship);
}
@ -70,7 +70,7 @@ namespace AircraftCarrier
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns></returns>
public static bool operator -(MapWithSetWarshipsGeneric<T, U> map, int position)
public static T operator -(MapWithSetWarshipsGeneric<T, U> map, int position)
{
return map._setWarships.Remove(position);
}
@ -149,7 +149,8 @@ namespace AircraftCarrier
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
Pen pen = new(Color.Black, 2);
g.FillRectangle(Brushes.Aqua, 0, 0, _pictureWidth, _pictureHeight);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
@ -165,15 +166,12 @@ namespace AircraftCarrier
/// <param name="g"></param>
private void DrawWarships(Graphics g)
{
int countInLine = _pictureWidth / _placeSizeWidth;
int maxLeft = (countInLine - 1) * _placeSizeWidth;
//for (int i = 0; i < _setWarships.Count; i++)
for (int i = 0; i < _setWarships.Count; i++)
{
for (int k = 0; k < _pictureWidth / _placeSizeWidth; k++)
{
for (int l = 0; l < _pictureHeight / _placeSizeHeight + 1; ++l)
{
_setWarships.Get(i)?.SetObject(k * _placeSizeWidth, l * _placeSizeHeight, _pictureWidth, _pictureHeight);
}
}
_setWarships.Get(i)?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
_setWarships.Get(i)?.DrawningObject(g);
}
}

View File

@ -34,15 +34,9 @@ namespace AircraftCarrier
/// </summary>
/// <param name="warship">Добавляемый военный корабль</param>
/// <returns></returns>
public bool Insert(T warship)
public int Insert(T warship)
{
if(Count >= 5 ) return false;
for(int i = Count - 1; i >= 0; i--)
{
_places[i + 1] = _places[i];
}
_places[0] = warship;
return true;
return Insert(warship, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -50,36 +44,49 @@ namespace AircraftCarrier
/// <param name="warship">Добавляемый военный корабль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T warship, int position)
public int Insert(T warship, int position)
{
if(position >= _places.Length) return false;
if (_places[position] != null)
int EmptyElement = -1;
if (position >= Count || position < 0) return -1;
if (_places[position] == null)
{
for(int i = position + 1; i < _places.Length; i++)
{
_places[position] = warship;
return 1;
}
else if (_places[position] != null)
{
for (int i = position + 1; i < Count; i++)
if (_places[i] == null)
{
for(int j = i - 1; j >= position; j--)
{
_places[j + 1] = _places[j];
}
EmptyElement = i;
break;
}
}
}
if (EmptyElement == -1)
return -1;
for (int i = EmptyElement; i > position; i--)
_places[i] = _places[i - 1];
}
_places[position] = warship;
return true;
return 1;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
public T Remove(int position)
{
if(position >= _places.Length) return false;
if (position >= Count || position < 0 || _places[position] == null)
return null;
T deleted = _places[position];
_places[position] = null;
return true;
return deleted;
}
/// <summary>
/// Получение объекта из набора по позиции