From cfb33cac96729dbfb74ca9d91c8f8dfa1a338810 Mon Sep 17 00:00:00 2001 From: Basha Date: Mon, 15 Jan 2024 23:40:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8,=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20=D0=92?= =?UTF-8?q?=D0=B8=D0=BD=D0=A4=D0=BE=D1=80=D0=BC=D1=83,=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BD=D0=B5=D0=BB=D1=8C=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2,=20=D0=BF=D0=B5=D1=80=D0=B5=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D1=8E=20=D0=92=D0=A1.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WinFormsLabRad1/DrawningTankZU.cs | 69 +++++++++++++++++-- .../WinFormsLabRad1/Form1.Designer.cs | 10 +-- WinFormsLabRad1/WinFormsLabRad1/Form1.cs | 10 +++ .../WinFormsLabRad1/WinFormsLabRad1.csproj | 2 +- 4 files changed, 81 insertions(+), 10 deletions(-) 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