Изменение SetPictureSize и SetPosition
This commit is contained in:
parent
337cc0b7e4
commit
e89bd91679
@ -1,6 +1,6 @@
|
||||
namespace Battleship;
|
||||
/// <summary>
|
||||
///
|
||||
/// класс, отвечающий за лево/право/верх/низ
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
|
@ -4,7 +4,6 @@
|
||||
/// </summary>
|
||||
public class DrawingBattleship
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
@ -33,12 +32,12 @@ public class DrawingBattleship
|
||||
/// <summary>
|
||||
/// Ширина прорисовки линкора
|
||||
/// </summary>
|
||||
private readonly int _drawingBattleshipWidth = 120;
|
||||
private readonly int _drawingBattleshipWidth = 129;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки линкора
|
||||
/// </summary>
|
||||
private readonly int _drawingBattleshipHeight = 80;
|
||||
private readonly int _drawingBattleshipHeight = 40;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -72,23 +71,30 @@ public class DrawingBattleship
|
||||
{
|
||||
//TODO проверка, что объект "влезает" в размеры поля
|
||||
//если влезает, сохраняем границы и корректируем позицию объекта, если она уже была установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth <= _drawingBattleshipWidth || _pictureHeight <= _drawingBattleshipHeight)
|
||||
|
||||
if (_drawingBattleshipWidth > width || _drawingBattleshipHeight > height)
|
||||
{
|
||||
_pictureHeight = null;
|
||||
_pictureWidth = null;
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
if (_startPosX.HasValue || _startPosY.HasValue)
|
||||
{
|
||||
|
||||
if (_startPosX + _drawingBattleshipWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth.Value - _drawingBattleshipWidth;
|
||||
_startPosX = _pictureWidth - _drawingBattleshipWidth;
|
||||
}
|
||||
else if (_startPosX < 0) _startPosX = 0;
|
||||
if (_startPosY + _drawingBattleshipHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight.Value - _drawingBattleshipHeight;
|
||||
_startPosY = _pictureHeight - _drawingBattleshipHeight;
|
||||
}
|
||||
else if (_startPosY < 0) _startPosY = 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -99,15 +105,27 @@ public class DrawingBattleship
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
if (x >= 0 && x + _drawingBattleshipWidth <= width && y >= 0 && y + _drawingBattleshipWidth <= height)
|
||||
|
||||
if (x + _drawingBattleshipWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_startPosX = _pictureWidth - _drawingBattleshipWidth;
|
||||
}
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
|
||||
if (y + _drawingBattleshipHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawingBattleshipHeight;
|
||||
}
|
||||
else if (y < 0) _startPosY = 0;
|
||||
else _startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,6 @@ public class EntityBattleship
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
@ -59,5 +56,3 @@ public class EntityBattleship
|
||||
Tower = tower;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
5
Battleship/Battleship/FormBattleship.Designer.cs
generated
5
Battleship/Battleship/FormBattleship.Designer.cs
generated
@ -1,5 +1,5 @@
|
||||
namespace Battleship
|
||||
{
|
||||
namespace Battleship;
|
||||
|
||||
partial class FormBattleship
|
||||
{
|
||||
/// <summary>
|
||||
@ -130,4 +130,3 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
public partial class FormBattleship : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле\объект для прорисовки объекта
|
||||
/// Поле/объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawingBattleship? _drawingBattleship; //поля с нижнего подчеркивания
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user