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