Лабораторная работа №1
This commit is contained in:
parent
0455a1fe3f
commit
83216e0433
@ -15,7 +15,7 @@ public class DrawningHoistingCrane
|
|||||||
private int? _pictureWidth;
|
private int? _pictureWidth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Длина окна
|
/// Высота окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureHeight;
|
private int? _pictureHeight;
|
||||||
|
|
||||||
@ -31,17 +31,17 @@ public class DrawningHoistingCrane
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки автомобиля
|
/// Ширина прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawingCarWidth = 80;
|
private readonly int _drawingCarWidth = 115;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки автомобиля
|
/// Высота прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawingCarHeight = 67;
|
private readonly int _drawingCarHeight = 63;
|
||||||
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor)
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform)
|
||||||
{
|
{
|
||||||
EntityHoistingCrane = new EntityHoistingCrane();
|
EntityHoistingCrane = new EntityHoistingCrane();
|
||||||
EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor);
|
EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor, counterweight, platform);
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
@ -61,18 +61,28 @@ public class DrawningHoistingCrane
|
|||||||
|
|
||||||
public bool SetPictureSize(int width, int height)
|
public bool SetPictureSize(int width, int height)
|
||||||
{
|
{
|
||||||
if ((width < _drawingCarWidth) || (height < _drawingCarHeight))
|
// TODO проверка, что объект "влезает" в размеры поля
|
||||||
|
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
|
||||||
|
|
||||||
|
if (_drawingCarHeight > height || _drawingCarWidth > width)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO проверка, что объект "влезает" в размеры поля
|
|
||||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
_pictureWidth = width;
|
||||||
|
|
||||||
|
if(_startPosX.HasValue && (_startPosX.Value + _drawingCarWidth > _pictureWidth))
|
||||||
|
{
|
||||||
|
_startPosX =_pictureWidth - _drawingCarWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_startPosY.HasValue && (_startPosY.Value + _drawingCarHeight > _pictureHeight))
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight - _drawingCarHeight;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,35 +95,29 @@ public class DrawningHoistingCrane
|
|||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
//Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
|
//Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
|
||||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((x + _drawingCarWidth > _pictureWidth) && (y + _drawingCarHeight > _pictureHeight))
|
if (x < 0)
|
||||||
|
x = -x;
|
||||||
|
if (y < 0)
|
||||||
|
y = -y;
|
||||||
|
if(x + _drawingCarWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX = x - _drawingCarWidth;
|
_startPosX = _pictureWidth - _drawingCarWidth;
|
||||||
_startPosY = y - _drawingCarHeight;
|
|
||||||
}
|
|
||||||
else if ((x + _drawingCarWidth <= _pictureWidth) && (y + _drawingCarHeight > _pictureHeight))
|
|
||||||
{
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y - _drawingCarHeight;
|
|
||||||
}
|
|
||||||
else if ((x + _drawingCarWidth > _pictureWidth) && (y + _drawingCarHeight <= _pictureHeight))
|
|
||||||
{
|
|
||||||
_startPosX = x - _drawingCarWidth;
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
|
}
|
||||||
|
if (y + _drawingCarHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight - _drawingCarHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -215,7 +219,11 @@ public class DrawningHoistingCrane
|
|||||||
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
|
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
|
||||||
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
|
gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
|
||||||
|
|
||||||
|
//кран
|
||||||
|
Brush bb = new SolidBrush(EntityHoistingCrane.BodyColor);
|
||||||
|
gr.FillRectangle(bb, _startPosX.Value + 65, _startPosY.Value, 7, 25);
|
||||||
|
gr.FillRectangle(br, _startPosX.Value + 62, _startPosY.Value + 2, 45, 5);
|
||||||
|
gr.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 2, _startPosX.Value + 107, _startPosY.Value + 40);
|
||||||
|
|
||||||
|
|
||||||
//окно
|
//окно
|
||||||
@ -243,6 +251,22 @@ public class DrawningHoistingCrane
|
|||||||
gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
|
gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
|
||||||
gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
|
gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
|
||||||
gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
|
gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
|
||||||
|
|
||||||
|
//противовес
|
||||||
|
if (EntityHoistingCrane.Counterweight)
|
||||||
|
{
|
||||||
|
Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
|
||||||
|
gr.FillRectangle(b, _startPosX.Value + 68, _startPosY.Value + 5, 10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Наличие спусковой платформы
|
||||||
|
if (EntityHoistingCrane.Platform)
|
||||||
|
{
|
||||||
|
Pen n = new Pen(EntityHoistingCrane.AdditionalColor);
|
||||||
|
gr.DrawRectangle(pen, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,19 @@ public class EntityHoistingCrane
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Íàëè÷èå ïðîòèâîâåñà
|
||||||
|
/// </summary>
|
||||||
|
public bool Counterweight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Íàëè÷èå ïëàòôîðìû
|
||||||
|
/// </summary>
|
||||||
|
public bool Platform{ get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Øàã äâèæåíèÿ
|
||||||
|
/// </summary>
|
||||||
public double Step => Speed * 100 / Weight;
|
public double Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
|
|
||||||
@ -37,12 +50,14 @@ public class EntityHoistingCrane
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor)
|
public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform)
|
||||||
{
|
{
|
||||||
this.Speed = Speed;
|
this.Speed = Speed;
|
||||||
this.Weight = Weight;
|
this.Weight = Weight;
|
||||||
this.BodyColor = BodyColor;
|
this.BodyColor = BodyColor;
|
||||||
this.AdditionalColor = AdditionalColor;
|
this.AdditionalColor = AdditionalColor;
|
||||||
|
this.Counterweight = Counterweight;
|
||||||
|
this.Platform = Platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,9 +23,14 @@
|
|||||||
|
|
||||||
Random rand = new();
|
Random rand = new();
|
||||||
_drawningHoistingCrane = new DrawningHoistingCrane();
|
_drawningHoistingCrane = new DrawningHoistingCrane();
|
||||||
_drawningHoistingCrane.Init(rand.Next(100, 300), rand.Next(1000, 3000),
|
_drawningHoistingCrane.Init(
|
||||||
|
rand.Next(100, 300),
|
||||||
|
rand.Next(1000, 3000),
|
||||||
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
|
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
|
||||||
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
|
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
|
||||||
|
Convert.ToBoolean(rand.Next(0,2)),
|
||||||
|
Convert.ToBoolean(rand.Next(0,2))
|
||||||
|
);
|
||||||
_drawningHoistingCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
_drawningHoistingCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
||||||
_drawningHoistingCrane.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
|
_drawningHoistingCrane.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
|
||||||
Draw();
|
Draw();
|
||||||
|
Loading…
Reference in New Issue
Block a user