Третья лабораторная работа
This commit is contained in:
parent
51a5cd33ae
commit
9234b2fcf9
@ -34,13 +34,13 @@ namespace MotorBoat
|
||||
// TODO проверка, что объект может переместится в требуемом направлении
|
||||
(float leftX, float topY, float rightX, float bottomY) = _drawningObject.GetCurrentPosition();
|
||||
bool can = true;
|
||||
|
||||
//координаты в системе массива
|
||||
int topYinS = Convert.ToInt32((topY) / _size_y);
|
||||
int rightXinS = Convert.ToInt32((rightX) / _size_x);
|
||||
int leftXinS = Convert.ToInt32((leftX) / _size_x);
|
||||
int bottomYinS = Convert.ToInt32(bottomY / _size_y);
|
||||
|
||||
int stepinS = 0;
|
||||
int stepinS = 0;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
|
@ -9,29 +9,23 @@ namespace MotorBoat
|
||||
internal class DrawningObjectBoat : IDrawningObject
|
||||
{
|
||||
private DrawningBoat _boat = null;
|
||||
|
||||
public DrawningObjectBoat(DrawningBoat boat)
|
||||
{
|
||||
_boat = boat;
|
||||
}
|
||||
|
||||
public float Step => _boat?.Boat?.Step ?? 0;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _boat?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_boat?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_boat.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
void IDrawningObject.DrawningObject(Graphics g)
|
||||
{
|
||||
_boat.DrawTransport(g);
|
||||
|
@ -12,22 +12,11 @@ namespace MotorBoat
|
||||
{
|
||||
public partial class FormMapWithSetBoats : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private MapWithSetBoatsGeneric<DrawningObjectBoat, AbstractMap> _mapBoatsCollectionGeneric;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetBoats()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
@ -53,11 +42,6 @@ namespace MotorBoat
|
||||
_mapBoatsCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
@ -79,11 +63,6 @@ namespace MotorBoat
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
@ -105,11 +84,6 @@ namespace MotorBoat
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
@ -118,11 +92,6 @@ namespace MotorBoat
|
||||
}
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
@ -131,18 +100,12 @@ namespace MotorBoat
|
||||
}
|
||||
pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapBoatsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
|
@ -9,7 +9,6 @@ namespace MotorBoat
|
||||
internal class SetBoatsGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
|
||||
private readonly T[] _places;
|
||||
public int Count => _places.Length;
|
||||
public SetBoatsGeneric(int count)
|
||||
@ -18,8 +17,6 @@ namespace MotorBoat
|
||||
}
|
||||
public int Insert(T boat)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
//return true;
|
||||
return Insert(boat, 0);
|
||||
}
|
||||
public int Insert(T boat, int position)
|
||||
@ -34,28 +31,25 @@ namespace MotorBoat
|
||||
return position;
|
||||
}
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int findEmptyPos = -1;
|
||||
int EmptyPos = -1;
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
findEmptyPos = i;
|
||||
EmptyPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (findEmptyPos < 0) return -1;
|
||||
if (EmptyPos < 0) return -1;
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
for (int i = findEmptyPos; i > position; i--)
|
||||
for (int i = EmptyPos; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
// вставка по позиции
|
||||
_places[position] = boat;
|
||||
return position;
|
||||
// TODO вставка по позиции
|
||||
_places[position] = boat;
|
||||
//return true;
|
||||
}
|
||||
public T Remove(int position)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user