почти
This commit is contained in:
parent
c86b27a7dd
commit
738a825709
@ -55,21 +55,27 @@ public class DrawingSeaplane
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
||||
if (width < _drawningPlaneWidth || height < _drawningPlaneHeight) return false;
|
||||
if (width < _drawningPlaneWidth || height < _drawningPlaneHeight) { return false; };
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null || _startPosY != null)
|
||||
{
|
||||
if (_startPosX + _drawningPlaneWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _startPosX - (_startPosX + _drawningPlaneWidth - _pictureWidth);
|
||||
_startPosX = -_drawningPlaneWidth + _pictureWidth;
|
||||
}
|
||||
else if (_startPosX < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
else if (_startPosX < 0) _startPosX = 0;
|
||||
if (_startPosY + _drawningPlaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _startPosY - (_startPosY + _drawningPlaneHeight - _pictureHeight);
|
||||
_startPosY = -_drawningPlaneHeight + _pictureHeight;
|
||||
}
|
||||
else if (_startPosY < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
else if (_startPosY < 0) _startPosY = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -88,16 +94,29 @@ public class DrawingSeaplane
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
if (x + _drawningPlaneWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = x - (x + _drawningPlaneWidth - _pictureWidth);
|
||||
_startPosX = _pictureWidth - _drawningPlaneWidth;
|
||||
}
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
else if (x < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
}
|
||||
|
||||
if (y + _drawningPlaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = y - (y + _drawningPlaneHeight - _pictureHeight);
|
||||
_startPosY = _pictureHeight - _drawningPlaneHeight;
|
||||
}
|
||||
else if (y < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = y;
|
||||
}
|
||||
else if (y < 0) _startPosY = 0;
|
||||
else _startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
|
@ -17,7 +17,22 @@ namespace Seaplane
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningSeaplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningSeaplane.DrawTransport(gr);
|
||||
pictureBoxSeaplane.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
@ -28,10 +43,40 @@ namespace Seaplane
|
||||
_drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||
_drawningSeaplane.SetPosition(random.Next(10,100),random.Next(10,100));
|
||||
|
||||
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningSeaplane.DrawTransport(gr);
|
||||
pictureBoxSeaplane.Image = bmp;
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningSeaplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningSeaplane.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningSeaplane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningSeaplane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningSeaplane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user