From c0643d773681ea4212d13efa6157af9c5b0fcd4f Mon Sep 17 00:00:00 2001 From: Mr-Sulfate Date: Sat, 15 Feb 2025 11:00:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=B5=D1=82=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- carCAR/Car.cs | 2 +- carCAR/DrawningSportcar.cs | 146 ++++++++++++++++++++++++++++++++++++- 2 files changed, 143 insertions(+), 5 deletions(-) diff --git a/carCAR/Car.cs b/carCAR/Car.cs index b0ff7af..eb5c31d 100644 --- a/carCAR/Car.cs +++ b/carCAR/Car.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace ProjectSportCar { - public class EntitySportcar + public class EntitySportCar { //скорость public int Speed { get; private set; } diff --git a/carCAR/DrawningSportcar.cs b/carCAR/DrawningSportcar.cs index 5a2528b..0482f03 100644 --- a/carCAR/DrawningSportcar.cs +++ b/carCAR/DrawningSportcar.cs @@ -1,13 +1,151 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectSportCar -{ - public class DrawningSportcar - { +namespace ProjectSportCar; +public class DrawningSportCar +{ + + public EntitySportCar? EntitySportCar { get; private set; } + + private int? _pictureWidth; + + private int? _pictureHeight; + + private int? _startPosX; + + private int? _startPosY; + + private readonly int _drawningCarWidth = 110; + + private readonly int _drawningCarHeight = 60; + + public void Init(int speed, double weight, Color bodyColor, Color +additionalColor, bool bodyKit, bool wing, bool sportLine) + { + EntitySportCar = new EntitySportCar(); + EntitySportCar.Init(speed, weight, bodyColor, additionalColor, + bodyKit, wing, sportLine); + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; } + + + + public bool SetPictureSize(int width, int height) + { + // Задаём размеры + int addWidth = 120; + int addHeight = 100; + + if (_startPosX.HasValue && _startPosY.HasValue) // проверка на вшивость №1 + { + if (_startPosX.Value >= 0 && _startPosY.Value >= 0 && // проверка на вшивость №2 + _startPosX.Value + addWidth <= width && + _startPosY.Value + addHeight <= height) + { + _pictureWidth = width; + _pictureHeight = height; + return true; + } + } + return false; + } + + + + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + int addX = 60; + int addY = 50; + + if (addX+x>_pictureWidth.Value || addX + x < 0 + || addY+y>_pictureHeight.Value || addY+y< 0) + { + _startPosX = _pictureWidth.Value/2; + _startPosY = _pictureHeight.Value / 2; + } + else + { + _startPosX = x; + _startPosY = y; + } + + } + + public bool MoveTransport(DirectionType direction) + { + if (EntitySportCar == null || !_startPosX.HasValue || + !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntitySportCar.Step > 0) + { + _startPosX -= (int)EntitySportCar.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntitySportCar.Step > 0) + { + _startPosY -= (int)EntitySportCar.Step; + } + return true; + // вправо + case DirectionType.Right: + if (_startPosX.Value + EntitySportCar.Step < _pictureWidth) + { + _startPosX += (int)EntitySportCar.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value + EntitySportCar.Step < _pictureHeight) + { + _startPosY += (int)EntitySportCar.Step; + } + return true; + default: + return false; + } + } + + // public void DrawTransport(Graphics g) + // { + // if (EntitySportCar == null || !_startPosX.HasValue || + // !_startPosY.HasValue) + // { + // return; + // } + + // Pen pen = new(Color.Black); + // Brush additionalBrush = new + // SolidBrush(EntitySportCar.AdditionalColor); + + + + //if (EntitySportCar.BodyKit) + // { + // g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 40, + // 70, 40); + // } + // } } +