From 25753f7cacfcbb41928fdf541a5e8f317e354569 Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Tue, 26 Sep 2023 12:43:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8,=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B0=20=D1=80=D0=B8?= =?UTF-8?q?=D1=81=D1=83=D0=BD=D0=BE=D0=BA,=20=D1=87=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=B2=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D1=81=D1=8C=20=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D0=B5=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/Battleship.cs | 7 +- Battleship/Battleship/DrawningBattleship.cs | 254 ++++++-------------- Battleship/Battleship/EntityBattleship.cs | 27 +-- 3 files changed, 88 insertions(+), 200 deletions(-) diff --git a/Battleship/Battleship/Battleship.cs b/Battleship/Battleship/Battleship.cs index 7f4a32a..93b0e84 100644 --- a/Battleship/Battleship/Battleship.cs +++ b/Battleship/Battleship/Battleship.cs @@ -34,11 +34,8 @@ namespace Battleship _drawningBattleship = new DrawningBattleship(); _drawningBattleship.Init(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxBattleship.Width, pictureBoxBattleship.Height); _drawningBattleship.SetPosition(random.Next(10, 100), diff --git a/Battleship/Battleship/DrawningBattleship.cs b/Battleship/Battleship/DrawningBattleship.cs index 7e58412..f538086 100644 --- a/Battleship/Battleship/DrawningBattleship.cs +++ b/Battleship/Battleship/DrawningBattleship.cs @@ -34,35 +34,39 @@ namespace Battleship /// /// Ширина прорисовки автомобиля /// - private readonly int _buttleshipWidth = 150; - + private readonly int _buttleshipWidth = 175; /// /// Высота прорисовки автомобиля /// - private readonly int _buttleshipHeight = 70; - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Цвет кузова - /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы - /// Ширина картинки - /// Высота картинки - /// true - объект создан, false - проверка не пройдена, - ///нельзя создать объект в этих размерах -public bool Init(int speed, double weight, Color bodyColor, Color -additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) + private readonly int _buttleshipHeight = 80; + ///// + ///// Инициализация свойств + ///// + ///// Скорость + ///// Вес + ///// Цвет кузова + ///// Дополнительный цвет + ///// Признак наличия обвеса + ///// Признак наличия антикрыла + ///// Признак наличия гоночной полосы + ///// Ширина картинки + ///// Высота картинки + ///// true - объект создан, false - проверка не пройдена, + /////нельзя создать объект в этих размерах + + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool tower, bool section, int width, int height) { // TODO: Продумать проверки + if(width < _buttleshipWidth || height < _buttleshipHeight) + { + return false; + } + _pictureWidth = width; _pictureHeight = height; EntityBattleship = new EntityBattleship(); - EntityBattleship.Init(speed, weight, bodyColor, additionalColor, - bodyKit, wing, sportLine); + EntityBattleship.Init(speed, weight, bodyColor, additionalColor, + tower, section); return true; } /// @@ -73,8 +77,11 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) public void SetPosition(int x, int y) { // TODO: Изменение x, y - _startPosX = x; - _startPosY = y; + if (x >= 0 && x + _buttleshipWidth <= _pictureWidth && y >= 0 && y + _buttleshipHeight <= _pictureHeight) + { + _startPosX = x; + _startPosY = y; + } } /// /// Изменение направления перемещения @@ -86,6 +93,7 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) { return; } + switch (direction) { //влево @@ -104,16 +112,14 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) break; // вправо case DirectionType.Right: - // TODO: Продумать логику - if (_startPosX + _buttleshipWidth + EntityBattleship.Step < 800) + if (_startPosX + _buttleshipWidth + EntityBattleship.Step < _pictureWidth) { _startPosX += (int)EntityBattleship.Step; } break; //вниз case DirectionType.Down: - // TODO: Продумать логику - if (_startPosY + _buttleshipHeight + EntityBattleship.Step < 450) + if (_startPosY + _buttleshipHeight + EntityBattleship.Step < _pictureHeight) { _startPosY += (int)EntityBattleship.Step; } @@ -134,173 +140,59 @@ additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) Brush additionalBrush = new SolidBrush(EntityBattleship.AdditionalColor); - //корпус линкора - Brush Brush = new - SolidBrush(EntityBattleship.AdditionalColor); + //основа + Brush mainBrush = new SolidBrush(EntityBattleship.BodyColor); Point[] hull = new Point[] { - new Point(_startPosX + 40, _startPosY + 20), - new Point(_startPosX + 150, _startPosY + 20), - new Point(_startPosX + 180, _startPosY + 55), - new Point(_startPosX + 150, _startPosY + 90), - new Point(_startPosX + 40, _startPosY + 90), + new Point(_startPosX + 10, _startPosY + 0), + new Point(_startPosX + 120, _startPosY + 0), + new Point(_startPosX + 160, _startPosY + 35), + new Point(_startPosX + 120, _startPosY + 70), + new Point(_startPosX + 10, _startPosY + 70), }; - g.FillPolygon(Brush, hull); + g.FillPolygon(mainBrush, hull); g.DrawPolygon(pen, hull); - //блоки - - Brush blockBrush2 = new - SolidBrush(Color.Gray); - g.FillRectangle(blockBrush2, _startPosX + 100, _startPosY + 35, 20, 40); - g.DrawRectangle(pen, _startPosX + 100, _startPosY+35, 20, 40); + Brush blockBrush = new + SolidBrush(Color.DimGray); + g.FillRectangle(blockBrush, _startPosX + 70, _startPosY + 15, 20, 40); + g.DrawRectangle(pen, _startPosX + 70, _startPosY + 15, 20, 40); - Brush blockBrush1 = new - SolidBrush(EntityBattleship.BodyColor); - g.FillRectangle(blockBrush1, _startPosX + 70, _startPosY + 45, 30, 20); - g.DrawRectangle(pen, _startPosX + 70, _startPosY + 45, 30, 20); + g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 25, 30, 20); + g.DrawRectangle(pen, _startPosX + 40, _startPosY + 25, 30, 20); - g.FillEllipse(blockBrush1, _startPosX + 130, _startPosY + 40, 30, 30); - g.DrawEllipse(pen, _startPosX + 130, _startPosY + 40, 30, 30); - - //орудийная башня - Brush towerBrush = new - SolidBrush(EntityBattleship.AdditionalColor); - g.FillRectangle(towerBrush, _startPosX + 138, _startPosY + 48, 15, 15); - g.DrawRectangle(pen, _startPosX + 138, _startPosY + 48, 15, 15); - Brush gunBrush = new - SolidBrush(Color.Black); - g.FillRectangle(gunBrush, _startPosX + 153, _startPosY + 52, 55, 6); - g.DrawRectangle(pen, _startPosX + 153, _startPosY + 52, 55, 6); + g.FillEllipse(additionalBrush, _startPosX + 100, _startPosY + 20, 30, 30); + g.DrawEllipse(pen, _startPosX + 100, _startPosY + 20, 30, 30); //для ускорения Brush speedBrush = new - SolidBrush(Color.Orange); - g.FillRectangle(speedBrush, _startPosX + 35, _startPosY + 30, 5, 20); - g.DrawRectangle(pen, _startPosX + 35, _startPosY + 30, 5, 20); - g.FillRectangle(speedBrush, _startPosX + 35, _startPosY + 60, 5, 20); - g.DrawRectangle(pen, _startPosX + 35, _startPosY + 60, 5, 20); + SolidBrush(Color.Gold); + g.FillRectangle(speedBrush, _startPosX + 5, _startPosY + 10, 5, 20); + g.DrawRectangle(pen, _startPosX + 5, _startPosY + 10, 5, 20); + g.FillRectangle(speedBrush, _startPosX + 5, _startPosY + 40, 5, 20); + g.DrawRectangle(pen, _startPosX + 5, _startPosY + 40, 5, 20); + //орудийная башня + if (EntityBattleship.Tower) + { + Brush baseBrush = new SolidBrush(Color.White); + g.FillRectangle(baseBrush, _startPosX + 108, _startPosY + 28, 15, 15); + g.DrawRectangle(pen, _startPosX + 108, _startPosY + 28, 15, 15); + Brush gunBrush = new SolidBrush(Color.Black); + g.FillRectangle(gunBrush, _startPosX + 123, _startPosY + 32, 47, 6); + g.DrawRectangle(pen, _startPosX + 123, _startPosY + 32, 55, 6); + } //отсеки под ракеты - Brush sectionBrush = new - SolidBrush(Color.Gray); - g.FillRectangle(sectionBrush, _startPosX + 50, _startPosY + 90, 40, 10); - g.DrawRectangle(pen, _startPosX + 50, _startPosY + 90, 40, 10); - g.FillRectangle(sectionBrush, _startPosX + 100, _startPosY + 90, 40, 10); - g.DrawRectangle(pen, _startPosX + 100, _startPosY + 90, 40, 10); - - - - // обвесы - // if (EntityBattleship.BodyKit) - // { - // g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20); - // g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, - // 20); - // g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, - // 20, 40); - // g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, - // 15); - // g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, - // 15, 15); - // g.FillEllipse(additionalBrush, _startPosX + 90, - // _startPosY, 20, 20); - // g.FillEllipse(additionalBrush, _startPosX + 90, - // _startPosY + 40, 20, 20); - // g.FillRectangle(additionalBrush, _startPosX + 90, - // _startPosY + 10, 20, 40); - // g.FillRectangle(additionalBrush, _startPosX + 90, - //_startPosY + 1, 15, 15); - // g.FillRectangle(additionalBrush, _startPosX + 90, - // _startPosY + 45, 15, 15); - // g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20); - // g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20); - // g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, - // 40); - // g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, - // 15); - // g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, - // 14, 15); - // g.FillEllipse(additionalBrush, _startPosX, _startPosY, - // 20, 20); - // g.FillEllipse(additionalBrush, _startPosX, _startPosY + - // 40, 20, 20); - // g.FillRectangle(additionalBrush, _startPosX + 1, - // _startPosY + 10, 25, 40); - // g.FillRectangle(additionalBrush, _startPosX + 5, - // _startPosY + 1, 15, 15); - // g.FillRectangle(additionalBrush, _startPosX + 5, - // _startPosY + 45, 15, 15); - // g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, - // 15); - // g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, - // 39, 15); - // g.FillRectangle(additionalBrush, _startPosX + 35, - // _startPosY + 1, 40, 15); - // g.FillRectangle(additionalBrush, _startPosX + 35, - // _startPosY + 45, 40, 15); - // } - // //границы автомобиля - // g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20); - // g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20); - // g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20); - // g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20); - // g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30); - // g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10, - // 30); - // g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52); - // //задние фары - // Brush brRed = new SolidBrush(Color.Red); - // g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20); - // g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20, - // 20); - // //передние фары - // Brush brYellow = new SolidBrush(Color.Yellow); - // g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20, - // 20); - // g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20, - // 20); - // //кузов - // Brush br = new SolidBrush(EntityBattleship.BodyColor); - // g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30); - // g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30); - // g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50); - // //стекла - // Brush brBlue = new SolidBrush(Color.LightBlue); - // g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5, - // 40); - // g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5, - // 40); - // g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35, - // 2); - // g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35, - // 2); - // //выделяем рамкой крышу - // g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35, - // 40); - // g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25, - // 30); - // g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15, - // 30); - // // спортивная линия - // if (EntityBattleship.SportLine) - // { - // g.FillRectangle(additionalBrush, _startPosX + 75, - // _startPosY + 23, 25, 15); - // g.FillRectangle(additionalBrush, _startPosX + 35, - // _startPosY + 23, 35, 15); - // g.FillRectangle(additionalBrush, _startPosX + 10, - // _startPosY + 23, 20, 15); - // } - // // крыло - // if (EntityBattleship.Wing) - // { - // g.FillRectangle(additionalBrush, _startPosX, _startPosY - // + 5, 10, 50); - // g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, - // 50); - // } + if (EntityBattleship.Section) + { + Brush sectionBrush = new + SolidBrush(Color.Gray); + g.FillRectangle(sectionBrush, _startPosX + 20, _startPosY + 70, 40, 10); + g.DrawRectangle(pen, _startPosX + 20, _startPosY + 70, 40, 10); + g.FillRectangle(sectionBrush, _startPosX + 75, _startPosY + 70, 40, 10); + g.DrawRectangle(pen, _startPosX + 75, _startPosY + 70, 40, 10); + } } } } diff --git a/Battleship/Battleship/EntityBattleship.cs b/Battleship/Battleship/EntityBattleship.cs index 352c48f..e3ce06a 100644 --- a/Battleship/Battleship/EntityBattleship.cs +++ b/Battleship/Battleship/EntityBattleship.cs @@ -27,15 +27,15 @@ namespace Battleship /// /// Признак (опция) наличия обвеса /// - public bool BodyKit { get; private set; } + //public bool BodyKit { get; private set; } + // /// + // /// Признак (опция) наличия башни + // /// + public bool Tower { get; private set; } /// - /// Признак (опция) наличия антикрыла + /// Признак (опция) наличия секции под ракеты /// - public bool Wing { get; private set; } - /// - /// Признак (опция) наличия гоночной полосы - /// - public bool SportLine { get; private set; } + public bool Section { get; private set; } /// /// Шаг перемещения автомобиля /// @@ -48,18 +48,17 @@ namespace Battleship /// Основной цвет /// Дополнительный цвет /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool bodyKit, bool wing, bool sportLine) + additionalColor, bool tower, bool section) { Speed = speed; Weight = weight; BodyColor = bodyColor; - AdditionalColor = additionalColor; - BodyKit = bodyKit; - Wing = wing; - SportLine = sportLine; + AdditionalColor = additionalColor; + Tower = tower; + Section = section; } } }