diff --git a/Battleship/Battleship/DirectionType.cs b/Battleship/Battleship/DirectionType.cs
index 7a4b742..8b60694 100644
--- a/Battleship/Battleship/DirectionType.cs
+++ b/Battleship/Battleship/DirectionType.cs
@@ -1,6 +1,6 @@
namespace Battleship;
///
-///
+/// класс, отвечающий за лево/право/верх/низ
///
public enum DirectionType
{
@@ -24,4 +24,4 @@ public enum DirectionType
///
Right = 4
-}
+}
\ No newline at end of file
diff --git a/Battleship/Battleship/DrawingBattleship.cs b/Battleship/Battleship/DrawingBattleship.cs
index ab9bcb5..e962b11 100644
--- a/Battleship/Battleship/DrawingBattleship.cs
+++ b/Battleship/Battleship/DrawingBattleship.cs
@@ -1,10 +1,9 @@
-namespace Battleship;
+namespace Battleship;
///
/// Класс, отвечающий за отрисовку и перемещение объекта-сущности
///
public class DrawingBattleship
{
-
///
/// Класс-сущность
///
@@ -33,12 +32,12 @@ public class DrawingBattleship
///
/// Ширина прорисовки линкора
///
- private readonly int _drawingBattleshipWidth = 120;
+ private readonly int _drawingBattleshipWidth = 129;
///
/// Высота прорисовки линкора
///
- private readonly int _drawingBattleshipHeight = 80;
+ private readonly int _drawingBattleshipHeight = 40;
///
///
@@ -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;
}
- if (_startPosX + _drawingBattleshipWidth > _pictureWidth)
+ _pictureWidth = width;
+ _pictureHeight = height;
+
+ if (_startPosX.HasValue || _startPosY.HasValue)
{
- _startPosX = _pictureWidth.Value - _drawingBattleshipWidth;
- }
- if (_startPosY + _drawingBattleshipHeight > _pictureHeight)
- {
- _startPosY = _pictureHeight.Value - _drawingBattleshipHeight;
+
+ if (_startPosX + _drawingBattleshipWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawingBattleshipWidth;
+ }
+ else if (_startPosX < 0) _startPosX = 0;
+ if (_startPosY + _drawingBattleshipHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawingBattleshipHeight;
+ }
+ else if (_startPosY < 0) _startPosY = 0;
}
return true;
+
}
///
@@ -99,16 +105,28 @@ 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)
- {
- _startPosX = x;
- _startPosY = y;
- _pictureWidth = width;
- _pictureHeight = height;
- }
+ if (x + _drawingBattleshipWidth > _pictureWidth)
+ {
+ _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;
+
}
///
diff --git a/Battleship/Battleship/EntityBattleship.cs b/Battleship/Battleship/EntityBattleship.cs
index 3c494f9..477cac0 100644
--- a/Battleship/Battleship/EntityBattleship.cs
+++ b/Battleship/Battleship/EntityBattleship.cs
@@ -38,9 +38,6 @@ public class EntityBattleship
///
public double Step => Speed * 100 / Weight;
- ///
- ///
- ///
///
///
///
@@ -58,6 +55,4 @@ public class EntityBattleship
Compartment = compartment;
Tower = tower;
}
-}
-
-
+}
\ No newline at end of file
diff --git a/Battleship/Battleship/FormBattleship.Designer.cs b/Battleship/Battleship/FormBattleship.Designer.cs
index 3d01c38..87379f3 100644
--- a/Battleship/Battleship/FormBattleship.Designer.cs
+++ b/Battleship/Battleship/FormBattleship.Designer.cs
@@ -1,133 +1,132 @@
-namespace Battleship
+namespace Battleship;
+
+partial class FormBattleship
{
- partial class FormBattleship
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
{
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
+ if (disposing && (components != null))
{
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
+ components.Dispose();
}
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- pictureBoxBattleship = new PictureBox();
- buttonCreate = new Button();
- buttonLeft = new Button();
- buttonDown = new Button();
- buttonRight = new Button();
- buttonUp = new Button();
- ((System.ComponentModel.ISupportInitialize)pictureBoxBattleship).BeginInit();
- SuspendLayout();
- //
- // pictureBoxBattleship
- //
- pictureBoxBattleship.Location = new Point(0, 0);
- pictureBoxBattleship.Name = "pictureBoxBattleship";
- pictureBoxBattleship.Size = new Size(957, 559);
- pictureBoxBattleship.TabIndex = 0;
- pictureBoxBattleship.TabStop = false;
- //
- // buttonCreate
- //
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 518);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(94, 29);
- buttonCreate.TabIndex = 0;
- buttonCreate.Text = "Создать";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += buttonCreate_Click;
- //
- // buttonLeft
- //
- buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
- buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(819, 512);
- buttonLeft.Name = "buttonLeft";
- buttonLeft.Size = new Size(35, 35);
- buttonLeft.TabIndex = 3;
- buttonLeft.UseVisualStyleBackColor = true;
- buttonLeft.Click += buttonMove_Click;
- //
- // buttonDown
- //
- buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonDown.BackgroundImage = Properties.Resources.arrowDown;
- buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(860, 512);
- buttonDown.Name = "buttonDown";
- buttonDown.Size = new Size(35, 35);
- buttonDown.TabIndex = 2;
- buttonDown.UseVisualStyleBackColor = true;
- buttonDown.Click += buttonMove_Click;
- //
- // buttonRight
- //
- buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonRight.BackgroundImage = Properties.Resources.arrowRight;
- buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(901, 512);
- buttonRight.Name = "buttonRight";
- buttonRight.Size = new Size(35, 35);
- buttonRight.TabIndex = 4;
- buttonRight.UseVisualStyleBackColor = true;
- buttonRight.Click += buttonMove_Click;
- //
- // buttonUp
- //
- buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonUp.BackgroundImage = Properties.Resources.arrowUp;
- buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(860, 471);
- buttonUp.Name = "buttonUp";
- buttonUp.Size = new Size(35, 35);
- buttonUp.TabIndex = 1;
- buttonUp.UseVisualStyleBackColor = true;
- buttonUp.Click += buttonMove_Click;
- //
- // FormBattleship
- //
- AutoScaleDimensions = new SizeF(8F, 20F);
- AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(957, 559);
- Controls.Add(buttonUp);
- Controls.Add(buttonRight);
- Controls.Add(buttonDown);
- Controls.Add(buttonLeft);
- Controls.Add(buttonCreate);
- Controls.Add(pictureBoxBattleship);
- Name = "FormBattleship";
- Text = "Линкор";
- ((System.ComponentModel.ISupportInitialize)pictureBoxBattleship).EndInit();
- ResumeLayout(false);
- }
-
- #endregion
-
- private PictureBox pictureBoxBattleship;
- private Button buttonCreate;
- private Button buttonDown;
- private Button buttonRight;
- private Button buttonUp;
- private Button buttonLeft;
+ base.Dispose(disposing);
}
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ pictureBoxBattleship = new PictureBox();
+ buttonCreate = new Button();
+ buttonLeft = new Button();
+ buttonDown = new Button();
+ buttonRight = new Button();
+ buttonUp = new Button();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxBattleship).BeginInit();
+ SuspendLayout();
+ //
+ // pictureBoxBattleship
+ //
+ pictureBoxBattleship.Location = new Point(0, 0);
+ pictureBoxBattleship.Name = "pictureBoxBattleship";
+ pictureBoxBattleship.Size = new Size(957, 559);
+ pictureBoxBattleship.TabIndex = 0;
+ pictureBoxBattleship.TabStop = false;
+ //
+ // buttonCreate
+ //
+ buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreate.Location = new Point(12, 518);
+ buttonCreate.Name = "buttonCreate";
+ buttonCreate.Size = new Size(94, 29);
+ buttonCreate.TabIndex = 0;
+ buttonCreate.Text = "Создать";
+ buttonCreate.UseVisualStyleBackColor = true;
+ buttonCreate.Click += buttonCreate_Click;
+ //
+ // buttonLeft
+ //
+ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
+ buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonLeft.Location = new Point(819, 512);
+ buttonLeft.Name = "buttonLeft";
+ buttonLeft.Size = new Size(35, 35);
+ buttonLeft.TabIndex = 3;
+ buttonLeft.UseVisualStyleBackColor = true;
+ buttonLeft.Click += buttonMove_Click;
+ //
+ // buttonDown
+ //
+ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonDown.BackgroundImage = Properties.Resources.arrowDown;
+ buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDown.Location = new Point(860, 512);
+ buttonDown.Name = "buttonDown";
+ buttonDown.Size = new Size(35, 35);
+ buttonDown.TabIndex = 2;
+ buttonDown.UseVisualStyleBackColor = true;
+ buttonDown.Click += buttonMove_Click;
+ //
+ // buttonRight
+ //
+ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonRight.BackgroundImage = Properties.Resources.arrowRight;
+ buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonRight.Location = new Point(901, 512);
+ buttonRight.Name = "buttonRight";
+ buttonRight.Size = new Size(35, 35);
+ buttonRight.TabIndex = 4;
+ buttonRight.UseVisualStyleBackColor = true;
+ buttonRight.Click += buttonMove_Click;
+ //
+ // buttonUp
+ //
+ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonUp.BackgroundImage = Properties.Resources.arrowUp;
+ buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUp.Location = new Point(860, 471);
+ buttonUp.Name = "buttonUp";
+ buttonUp.Size = new Size(35, 35);
+ buttonUp.TabIndex = 1;
+ buttonUp.UseVisualStyleBackColor = true;
+ buttonUp.Click += buttonMove_Click;
+ //
+ // FormBattleship
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(957, 559);
+ Controls.Add(buttonUp);
+ Controls.Add(buttonRight);
+ Controls.Add(buttonDown);
+ Controls.Add(buttonLeft);
+ Controls.Add(buttonCreate);
+ Controls.Add(pictureBoxBattleship);
+ Name = "FormBattleship";
+ Text = "Линкор";
+ ((System.ComponentModel.ISupportInitialize)pictureBoxBattleship).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxBattleship;
+ private Button buttonCreate;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonUp;
+ private Button buttonLeft;
}
\ No newline at end of file
diff --git a/Battleship/Battleship/FormBattleship.cs b/Battleship/Battleship/FormBattleship.cs
index bbdf799..048e106 100644
--- a/Battleship/Battleship/FormBattleship.cs
+++ b/Battleship/Battleship/FormBattleship.cs
@@ -5,7 +5,7 @@
public partial class FormBattleship : Form
{
///
- /// Поле\объект для прорисовки объекта
+ /// Поле/объект для прорисовки объекта
///
private DrawingBattleship? _drawingBattleship; //поля с нижнего подчеркивания
@@ -76,4 +76,4 @@ public partial class FormBattleship : Form
Draw();
}
}
-}
+}
\ No newline at end of file