Готовая лаба
This commit is contained in:
parent
5a9b1fb6ae
commit
d53c9971d2
@ -59,11 +59,13 @@ public class DrawningWarmlyLocomotive
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
if (width >= _drawningLocomotiveWidth && height >= _drawningLocomotiveHeight) {
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
@ -76,10 +78,28 @@ public class DrawningWarmlyLocomotive
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if((x + _drawningLocomotiveWidth > _pictureWidth ) && (y + _drawningLocomotiveHeight > _pictureHeight))
|
||||
{
|
||||
_startPosX = x - _drawningLocomotiveWidth;
|
||||
_startPosY = y - _drawningLocomotiveHeight;
|
||||
}
|
||||
else if((x + _drawningLocomotiveWidth <= _pictureWidth) && (y + _drawningLocomotiveHeight > _pictureHeight))
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y - _drawningLocomotiveHeight;
|
||||
}
|
||||
else if ((x + _drawningLocomotiveWidth > _pictureWidth) && (y + _drawningLocomotiveHeight <= _pictureHeight))
|
||||
{
|
||||
_startPosX = x - _drawningLocomotiveWidth;
|
||||
_startPosY = y;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
@ -111,14 +131,14 @@ public class DrawningWarmlyLocomotive
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityWarmlyLocomotive.Step < _pictureWidth)
|
||||
if (_startPosX.Value + EntityWarmlyLocomotive.Step + _drawningLocomotiveWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityWarmlyLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityWarmlyLocomotive.Step < _pictureHeight)
|
||||
if (_startPosY.Value + EntityWarmlyLocomotive.Step + _drawningLocomotiveHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityWarmlyLocomotive.Step;
|
||||
}
|
||||
|
@ -43,10 +43,10 @@ namespace WarmlyLocomotive
|
||||
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)));
|
||||
_drawningWarmlyLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width,
|
||||
pictureBoxWarmlyLocomotive.Height);
|
||||
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
_drawningWarmlyLocomotive.SetPictureSize(
|
||||
pictureBoxWarmlyLocomotive.Width,
|
||||
pictureBoxWarmlyLocomotive.Height);
|
||||
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user