PIBD-11 Ryabov I.V. LabWork01 Simple #1

Closed
ilyaryabovv wants to merge 3 commits from LabWork01 into main
3 changed files with 31 additions and 20 deletions
Showing only changes of commit b6615f1c12 - Show all commits

View File

@ -1,14 +1,10 @@

namespace ProjectStormtrooper;
namespace ProjectStormtrooper;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingStormtrooper
{
public EntityStormtrooper? EntityStormtrooper { get; private set; }
/// <summary>
/// Ширина окна
/// </summary>
@ -74,6 +70,25 @@ public class DrawingStormtrooper
if (width < _drawningStormtrooperWidth || height < _drawningStormtrooperHeight) return false;
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX != null && _startPosY != null)
{
if (_startPosX + _drawningStormtrooperWidth > _pictureWidth)
{
_startPosX = -_drawningStormtrooperWidth + _pictureWidth;
}
else if (_startPosX < 0)
{
_startPosX = 0;
}
if (_startPosY + _drawningStormtrooperHeight > _pictureHeight)
{
_startPosY = -_drawningStormtrooperHeight + _pictureHeight;
}
else if (_startPosY < 0)
{
_startPosY = 0;
}
}
return true;
}
/// <summary>
@ -93,15 +108,22 @@ public class DrawingStormtrooper
{
_startPosX = x - (x + _drawningStormtrooperWidth - _pictureWidth);
}
else if (x < 0)
{
_startPosX = 0;
}
else
{
_startPosX = x;
}
if (y + _drawningStormtrooperHeight > _pictureHeight)
{
_startPosY = y - (y + _drawningStormtrooperHeight - _pictureHeight);
}
else if (y < 0)
{
_startPosY = 0;
}
else
{
_startPosY = y;

View File

@ -5,7 +5,6 @@
/// </summary>
public class EntityStormtrooper
{
/// <summary>
/// Скорость
/// </summary>
@ -26,7 +25,6 @@ public class EntityStormtrooper
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия двигателей
/// </summary>
@ -47,8 +45,6 @@ public class EntityStormtrooper
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// </summary>

View File

@ -1,5 +1,4 @@

namespace ProjectStormtrooper
namespace ProjectStormtrooper
{
/// <summary>
/// Форма работы с объектом "Бомбардировщик"
@ -45,7 +44,6 @@ namespace ProjectStormtrooper
{
Random random = new();
_drawningStormtrooper = new DrawingStormtrooper();
_drawningStormtrooper.Init(random.Next(100, 300), random.Next(1000,
3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
@ -54,16 +52,12 @@ namespace ProjectStormtrooper
random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawningStormtrooper.SetPictureSize(pictureBoxStormtrooper.Width,
pictureBoxStormtrooper.Height);
_drawningStormtrooper.SetPosition(random.Next(10, 100), random.Next(10,
100));
_drawningStormtrooper.SetPictureSize(pictureBoxStormtrooper.Width,pictureBoxStormtrooper.Height);
_drawningStormtrooper.SetPosition(random.Next(10, 100), random.Next(10,100));
Draw();
}
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>
@ -101,6 +95,5 @@ namespace ProjectStormtrooper
Draw();
}
}
}
}