diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs
index e041212..5bc9243 100644
--- a/ProjectTank/ProjectTank/DrawningTank.cs
+++ b/ProjectTank/ProjectTank/DrawningTank.cs
@@ -27,11 +27,11 @@ public class DrawningTank
///
/// Ширина прорисовки танка
///
- private readonly int _drawningCarWidth = 110;
+ private readonly int _drawningTankWidth = 200;
///
/// Высота прорисовки танка
///
- private readonly int _drawningCarHeight = 60;
+ private readonly int _drawningTankHeight = 100;
///
/// Инициализация свойств
///
@@ -61,28 +61,44 @@ public class DrawningTank
/// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
public bool SetPictureSize(int width, int height)
{
- // TODO проверка, что объект "влезает" в размеры поля
- // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
- _pictureWidth = width;
- _pictureHeight = height;
- return true;
- }
+ if (_drawningTankWidth < width && _drawningTankHeight < height)
+ {
+ _pictureWidth = width; _pictureHeight = height;
+
+ {
+ if (_startPosX.HasValue&&_startPosY.HasValue)
+
+ SetPosition(_startPosX.Value, _startPosY.Value);
+ }
+ return true;
+ }
+ return false;
+ }
+
+
+
+
///
/// Установка позиции
///
/// Координата X
/// Координата Y
+
+
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
- // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
- // то надо изменить координаты, чтобы он оставался в этих границах
-
- _startPosX = x;
- _startPosY = y;
+ if (x < 0 || x + _drawningTankWidth > _pictureWidth || y < 0 || y + _drawningTankHeight > _pictureHeight)
+ {
+ _startPosX = _pictureWidth - _drawningTankWidth; _startPosY = _pictureHeight - _drawningTankHeight;
+ } else
+ {
+ _startPosX = x;
+ _startPosY = y;
+ }
}
///
/// Изменение направления перемещения
@@ -113,20 +129,22 @@ public class DrawningTank
_startPosY -= (int)EntityTank.Step;
}
return true;
- // вправо
- case DirectionType.Right:
- if (_startPosX.Value + EntityTank.Step + _drawningCarWidth <= _pictureWidth)
- {
- _startPosX += (int)EntityTank.Step;
- }
- return true;
- //вниз
+
+ // вниз
case DirectionType.Down:
- if (_startPosY.Value + EntityTank.Step + _drawningCarHeight <= _pictureHeight)
+ if (_startPosY.Value + EntityTank.Step + _drawningTankHeight < _pictureHeight)
{
_startPosY += (int)EntityTank.Step;
}
return true;
+
+ // вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + EntityTank.Step + _drawningTankWidth < _pictureWidth)
+ {
+ _startPosX += (int)EntityTank.Step;
+ }
+ return true;
default:
return false;
}
@@ -146,16 +164,54 @@ public class DrawningTank
Brush additionalBrush = new
SolidBrush(EntityTank.AdditionalColor);
- //границы танка + гусеницы
- g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 35, 40, 10);
- g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 35, 5, 5);
- g.DrawEllipse(pen, _startPosX.Value + 23, _startPosY.Value + 37, 2, 2);
- g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 37, 2, 2);
- g.DrawEllipse(pen, _startPosX.Value + 37, _startPosY.Value + 37, 2, 2);
- g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 37, 2, 2);
- g.DrawEllipse(pen, _startPosX.Value + 52, _startPosY.Value + 35, 5, 5);
+ //границы танка + гусеницы + пулемёт + башня с оружием
+ g.DrawRectangle(pen, _startPosX.Value + 85, _startPosY.Value + 39, 55, 17);
+ g.DrawRectangle(pen, _startPosX.Value + 49, _startPosY.Value + 56, 137, 13);
+
+ g.DrawEllipse(pen, _startPosX.Value + 37, _startPosY.Value + 59, 160, 35);
+ g.DrawEllipse(pen, _startPosX.Value + 88, _startPosY.Value + 65, 29, 23);
+ g.DrawEllipse(pen, _startPosX.Value + 148, _startPosY.Value + 65, 29, 23);
+ g.DrawEllipse(pen, _startPosX.Value + 128, _startPosY.Value + 73, 18, 15);
+ g.DrawEllipse(pen, _startPosX.Value + 108, _startPosY.Value + 73, 18, 15);
+ g.DrawEllipse(pen, _startPosX.Value + 88, _startPosY.Value + 73, 18, 15);
+
+ g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 42, 85, 8);
+
+ g.DrawRectangle(pen, _startPosX.Value + 101, _startPosY.Value + 27, 24, 12);
+ g.DrawRectangle(pen, _startPosX.Value + 109, _startPosY.Value + 9, 5, 18);
+ g.DrawRectangle(pen, _startPosX.Value + 91, _startPosY.Value + 13, 19, 5);
+
+
+ //танк
+ Brush br = new SolidBrush(EntityTank.BodyColor);
+ g.FillRectangle(br, _startPosX.Value + 85, _startPosY.Value + 39, 55, 17);
+ g.FillRectangle(br, _startPosX.Value + 49, _startPosY.Value + 56, 137, 13);
+
+
+ Brush brDBlue = new SolidBrush(Color.DarkBlue);
+ g.FillEllipse(brDBlue, _startPosX.Value + 37, _startPosY.Value + 59, 160, 35);
+
+
+
+ //гусеницы
+ Brush brBlue = new SolidBrush(Color.LightBlue);
+ g.FillEllipse(brBlue, _startPosX.Value + 56, _startPosY.Value + 65, 29, 23);
+ g.FillEllipse(brBlue, _startPosX.Value + 148, _startPosY.Value + 65, 29, 23);
+ g.FillEllipse(brBlue, _startPosX.Value + 128, _startPosY.Value + 73, 18, 15);
+ g.FillEllipse(brBlue, _startPosX.Value + 108, _startPosY.Value + 73, 18, 15);
+ g.FillEllipse(brBlue, _startPosX.Value + 88, _startPosY.Value + 73, 18, 15);
+
+ if (EntityTank.GunTurret)
+ {
+ g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 42, 85, 8);
+ }
+
+ if (EntityTank.MachineGun)
+ {
+ g.FillRectangle(additionalBrush, _startPosX.Value + 101, _startPosY.Value + 27, 24, 12);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 109, _startPosY.Value + 9, 5, 18);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 91, _startPosY.Value + 13, 19, 5);
+ }
- g.DrawRectangle(pen, _startPosX.Value + 34, _startPosY.Value + 29, 46, 3);
- g.DrawRectangle(pen, _startPosX.Value + 32, _startPosY.Value + 25, 17, 6);
}
}
\ No newline at end of file