diff --git a/WinFormsLabRad1/WinFormsLabRad1/DrawningTankZU.cs b/WinFormsLabRad1/WinFormsLabRad1/DrawningTankZU.cs index abc82fb..0a6a3db 100644 --- a/WinFormsLabRad1/WinFormsLabRad1/DrawningTankZU.cs +++ b/WinFormsLabRad1/WinFormsLabRad1/DrawningTankZU.cs @@ -71,7 +71,11 @@ namespace WinFormsLabRad1 public bool SetPictureSize(int width, int height) { // TODO проверка, что объект "влезает" в размеры поля - // Паша - написать проверку + // Паша - написаЛ проверку: + if (width <= _drawningTankWidth || height <= _drawningTankHeight) + { + return false; + } // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена _pictureWidth = width; _pictureHeight = height; @@ -85,15 +89,72 @@ namespace WinFormsLabRad1 /// Координата Y public void SetPosition(int x, int y) { + int endx = x + _drawningTankWidth; + + int endy = y + _drawningTankHeight; + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы - // Паша - написать проверку + // Паша - написаЛ проверку // то надо изменить координаты, чтобы он оставался в этих границах - _startPosX = x; - _startPosY = y; + if (endx > _pictureWidth || x < 0 || endy > _pictureHeight || y<0) + { + x = 0; + y = 0; + } + else + { + _startPosX = x; + _startPosY = y; + } + + } + public bool MoveTransport(DirectionType direction) + { + if (EntityTankZU == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return false; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntityTankZU.Step > 0) + { + _startPosX -= (int)EntityTankZU.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntityTankZU.Step > 0) + { + _startPosY -= (int)EntityTankZU.Step; + } + return true; + // вправо + case DirectionType.Right: + //TODO прописать логику сдвига в право + //Паша - НаписаЛ + if (_startPosX.Value + EntityTankZU.Step < _pictureWidth) + { + _startPosX += (int)EntityTankZU.Step; + } + return true; + //вниз + case DirectionType.Down: + //TODO прописать логику сдвига в вниз + //Паша - НаписаЛ + if (_startPosY.Value + EntityTankZU.Step < _pictureHeight) + { + _startPosY += (int)EntityTankZU.Step; + } + return true; + default: + return false; + } } } } diff --git a/WinFormsLabRad1/WinFormsLabRad1/Form1.Designer.cs b/WinFormsLabRad1/WinFormsLabRad1/Form1.Designer.cs index b2e2b1e..000261e 100644 --- a/WinFormsLabRad1/WinFormsLabRad1/Form1.Designer.cs +++ b/WinFormsLabRad1/WinFormsLabRad1/Form1.Designer.cs @@ -3,12 +3,12 @@ partial class Form1 { /// - /// Required designer variable. + /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// - /// Clean up any resources being used. + /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) @@ -23,8 +23,8 @@ #region Windows Form Designer generated code /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. /// private void InitializeComponent() { @@ -36,4 +36,4 @@ #endregion } -} +} \ No newline at end of file diff --git a/WinFormsLabRad1/WinFormsLabRad1/Form1.cs b/WinFormsLabRad1/WinFormsLabRad1/Form1.cs index e5e691a..9a28ff1 100644 --- a/WinFormsLabRad1/WinFormsLabRad1/Form1.cs +++ b/WinFormsLabRad1/WinFormsLabRad1/Form1.cs @@ -1,3 +1,13 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + namespace WinFormsLabRad1 { public partial class Form1 : Form diff --git a/WinFormsLabRad1/WinFormsLabRad1/WinFormsLabRad1.csproj b/WinFormsLabRad1/WinFormsLabRad1/WinFormsLabRad1.csproj index 663fdb8..460f449 100644 --- a/WinFormsLabRad1/WinFormsLabRad1/WinFormsLabRad1.csproj +++ b/WinFormsLabRad1/WinFormsLabRad1/WinFormsLabRad1.csproj @@ -2,7 +2,7 @@ WinExe - net8.0-windows + net8.0-windows7.0 enable true enable