From 9e57fd3aeb2b06bfcbb50d5e7da39decaf5b2b14 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Thu, 13 Oct 2022 14:36:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=8B=D1=85=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?=20=D0=B7=D0=B0=20=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20?= =?UTF-8?q?=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarPlanes/WarPlanes/AbstractMap.cs | 18 +++++++++--------- WarPlanes/WarPlanes/DrawningObject.cs | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/WarPlanes/WarPlanes/AbstractMap.cs b/WarPlanes/WarPlanes/AbstractMap.cs index bd9fd14..a9a4765 100644 --- a/WarPlanes/WarPlanes/AbstractMap.cs +++ b/WarPlanes/WarPlanes/AbstractMap.cs @@ -32,17 +32,17 @@ namespace WarPlanes } public Bitmap MoveObject(Direction direction) { - // TODO проверка, что объект может переместится в требуемом направлении - float xStep = 0; - float yStep = 0; RectangleF rectObject = _drawningObject.GetCurrentPosition(); - if (direction == Direction.Up) yStep = -_drawningObject.Step; - else if (direction == Direction.Down) yStep = +_drawningObject.Step; - else if (direction == Direction.Left) xStep = -_drawningObject.Step; - else if (direction == Direction.Right) xStep = _drawningObject.Step; - rectObject.X += xStep; - rectObject.Y += yStep; + if (direction == Direction.Up) rectObject.Y -= _drawningObject.Step; + else if (direction == Direction.Down) rectObject.Y += _drawningObject.Step; + else if (direction == Direction.Left) rectObject.X -= _drawningObject.Step; + else if (direction == Direction.Right) rectObject.X += _drawningObject.Step; + + if(rectObject.X < 0 || rectObject.Right >= _width || rectObject.Y < 0 || rectObject.Bottom >= _height) + { + return DrawMapWithObject(); + } if (isCollision(rectObject)) { _drawningObject.MoveObject(direction); diff --git a/WarPlanes/WarPlanes/DrawningObject.cs b/WarPlanes/WarPlanes/DrawningObject.cs index ea25915..b2253d8 100644 --- a/WarPlanes/WarPlanes/DrawningObject.cs +++ b/WarPlanes/WarPlanes/DrawningObject.cs @@ -29,7 +29,6 @@ void IDrawningObject.DrawningObject(Graphics g) { _warplane.DrawTransport(g); - // TODO } } } \ No newline at end of file