From e81bd3dfa7a31fdc2f692d9efc6e80ebacc9e8d3 Mon Sep 17 00:00:00 2001 From: Zara28 Date: Thu, 8 Sep 2022 08:52:53 +0400 Subject: [PATCH 1/8] create constructor --- ArmoredVehicle/ArmoredVehicleEntity.cs | 16 +++++++++------- ArmoredVehicle/DrawingArmoredVehicle.cs | 5 ++--- ArmoredVehicle/MainForm.cs | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ArmoredVehicle/ArmoredVehicleEntity.cs b/ArmoredVehicle/ArmoredVehicleEntity.cs index de9cc39..b5beeec 100644 --- a/ArmoredVehicle/ArmoredVehicleEntity.cs +++ b/ArmoredVehicle/ArmoredVehicleEntity.cs @@ -8,6 +8,14 @@ namespace ArmoredVehicle { internal class ArmoredVehicleEntity { + public ArmoredVehicleEntity(int speed, float weight, Color bodyColor) + { + Random rnd = new(); + Speed = speed <= 0 ? rnd.Next(50, 150) : speed; + Weight = weight <= 0 ? rnd.Next(40, 70) : weight; + BodyColor = bodyColor; + } + /// /// Скорость /// @@ -31,12 +39,6 @@ namespace ArmoredVehicle /// /// /// - public void Init(int speed, float weight, Color bodyColor) - { - Random rnd = new(); - Speed = speed <= 0 ? rnd.Next(50, 150) : speed; - Weight = weight <= 0 ? rnd.Next(40, 70) : weight; - BodyColor = bodyColor; - } + } } diff --git a/ArmoredVehicle/DrawingArmoredVehicle.cs b/ArmoredVehicle/DrawingArmoredVehicle.cs index 634a0a5..796b86e 100644 --- a/ArmoredVehicle/DrawingArmoredVehicle.cs +++ b/ArmoredVehicle/DrawingArmoredVehicle.cs @@ -42,10 +42,9 @@ namespace ArmoredVehicle /// Скорость /// Вес /// Цвет - public void Init(int speed, float weight, Color bodyColor) + public DrawingArmoredVehicle(int speed, float weight, Color bodyColor) { - ArmoredVehicle = new ArmoredVehicleEntity(); - ArmoredVehicle.Init(speed, weight, bodyColor); + ArmoredVehicle = new ArmoredVehicleEntity(speed, weight, bodyColor); } /// /// Установка позиции diff --git a/ArmoredVehicle/MainForm.cs b/ArmoredVehicle/MainForm.cs index 5adb8ee..4b685bc 100644 --- a/ArmoredVehicle/MainForm.cs +++ b/ArmoredVehicle/MainForm.cs @@ -34,8 +34,8 @@ namespace ArmoredVehicle private void CreateButton_Click(object sender, EventArgs e) { Random rnd = new(); - _ArmoredVehicle = new DrawingArmoredVehicle(); - _ArmoredVehicle.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _ArmoredVehicle = new DrawingArmoredVehicle(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _ArmoredVehicle.SetPosition(/*rnd.Next(0, 100)*/ -10, rnd.Next(0, 100), DrawingPictureBox.Width, DrawingPictureBox.Height); toolStripStatusLabelSpeed.Text = $": {_ArmoredVehicle.ArmoredVehicle.Speed}"; toolStripStatusLabelWeight.Text = $": {_ArmoredVehicle.ArmoredVehicle.Weight}"; From a6c1dd7c6f1715be942f4e165e596cab78d84c2c Mon Sep 17 00:00:00 2001 From: Zara28 Date: Sun, 11 Sep 2022 18:00:27 +0400 Subject: [PATCH 2/8] Create Tank --- ArmoredVehicle/DrawingArmoredVehicle.cs | 19 ++++++--- ArmoredVehicle/DrawingTank.cs | 45 +++++++++++++++++++++ ArmoredVehicle/MainForm.Designer.cs | 13 ++++++ ArmoredVehicle/MainForm.cs | 22 +++++++++- ArmoredVehicle/MainForm.resx | 8 ++-- ArmoredVehicle/TankEnity.cs | 53 +++++++++++++++++++++++++ 6 files changed, 149 insertions(+), 11 deletions(-) create mode 100644 ArmoredVehicle/DrawingTank.cs create mode 100644 ArmoredVehicle/TankEnity.cs diff --git a/ArmoredVehicle/DrawingArmoredVehicle.cs b/ArmoredVehicle/DrawingArmoredVehicle.cs index 796b86e..aaf5e00 100644 --- a/ArmoredVehicle/DrawingArmoredVehicle.cs +++ b/ArmoredVehicle/DrawingArmoredVehicle.cs @@ -11,15 +11,15 @@ namespace ArmoredVehicle /// /// Класс-сущность /// - public ArmoredVehicleEntity ArmoredVehicle { get; private set; } + public ArmoredVehicleEntity ArmoredVehicle { get; protected set; } /// /// Левая координата отрисовки /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -31,11 +31,11 @@ namespace ArmoredVehicle /// /// Ширина отрисовки /// - private readonly int _ArmoredVehicleWidth = 210; + private readonly int _ArmoredVehicleWidth = 500; /// /// Высота отрисовки /// - private readonly int _ArmoredVehicleHeight = 50; + private readonly int _ArmoredVehicleHeight = 100; /// /// Инициализация свойств /// @@ -46,6 +46,13 @@ namespace ArmoredVehicle { ArmoredVehicle = new ArmoredVehicleEntity(speed, weight, bodyColor); } + protected DrawingArmoredVehicle(int speed, float weight, Color bodyColor, int ArmoredVehicleWidth, int ArmoredVehicleHeight): + this(speed, weight, bodyColor) + { + _ArmoredVehicleHeight = ArmoredVehicleHeight; + _ArmoredVehicleWidth = ArmoredVehicleWidth; + } + /// /// Установка позиции /// @@ -128,7 +135,7 @@ namespace ArmoredVehicle /// Отрисовка /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/ArmoredVehicle/DrawingTank.cs b/ArmoredVehicle/DrawingTank.cs new file mode 100644 index 0000000..142fbda --- /dev/null +++ b/ArmoredVehicle/DrawingTank.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ArmoredVehicle +{ + internal class DrawingTank : DrawingArmoredVehicle + { + public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower, bool gun) + : base(speed, weight, bodyColor) + { + ArmoredVehicle = new TankEnity(speed, weight, bodyColor, dopColor, machineGun, tower, gun); + } + + public override void DrawTransport(Graphics g) + { + if (ArmoredVehicle is not TankEnity machine) + { + return; + } + base.DrawTransport(g); + + Brush br = new SolidBrush(machine?.DopColor ?? Color.Black); + Pen p = new Pen(machine?.DopColor ?? Color.Black, 5); + + if (machine.Tower) + { + + g.FillRectangle(br, _startPosX + 60, _startPosY - 30, 80, 30); + g.DrawLine(p, _startPosX + 90, _startPosY - 20, _startPosX + 250, _startPosY - 20); + if (machine.MachineGun) + { + p = new Pen(machine?.DopColor ?? Color.Black, 3); + + g.DrawLine(p, _startPosX + 90, _startPosY - 45, _startPosX + 90, _startPosY - 30); + g.DrawLine(p, _startPosX + 85, _startPosY - 35, _startPosX + 120, _startPosY - 35); + } + + } + + } + } +} diff --git a/ArmoredVehicle/MainForm.Designer.cs b/ArmoredVehicle/MainForm.Designer.cs index 069fd0c..316b720 100644 --- a/ArmoredVehicle/MainForm.Designer.cs +++ b/ArmoredVehicle/MainForm.Designer.cs @@ -39,6 +39,7 @@ this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel(); this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.TankButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.DrawingPictureBox)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -144,11 +145,22 @@ this.statusStrip.TabIndex = 8; this.statusStrip.Text = "statusStrip1"; // + // TankButton + // + this.TankButton.Location = new System.Drawing.Point(139, 365); + this.TankButton.Name = "TankButton"; + this.TankButton.Size = new System.Drawing.Size(143, 34); + this.TankButton.TabIndex = 14; + this.TankButton.Text = "Модификация"; + this.TankButton.UseVisualStyleBackColor = true; + this.TankButton.Click += new System.EventHandler(this.TankButton_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.TankButton); this.Controls.Add(this.ButtonDown); this.Controls.Add(this.ButtonRight); this.Controls.Add(this.ButtonLeft); @@ -179,5 +191,6 @@ private ToolStripStatusLabel toolStripStatusLabelWeight; private ToolStripStatusLabel toolStripStatusLabelColor; private StatusStrip statusStrip; + private Button TankButton; } } \ No newline at end of file diff --git a/ArmoredVehicle/MainForm.cs b/ArmoredVehicle/MainForm.cs index 4b685bc..7145fbf 100644 --- a/ArmoredVehicle/MainForm.cs +++ b/ArmoredVehicle/MainForm.cs @@ -36,11 +36,17 @@ namespace ArmoredVehicle Random rnd = new(); _ArmoredVehicle = new DrawingArmoredVehicle(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); + Draw(); + } + + private void SetData() + { + Random rnd = new(); _ArmoredVehicle.SetPosition(/*rnd.Next(0, 100)*/ -10, rnd.Next(0, 100), DrawingPictureBox.Width, DrawingPictureBox.Height); toolStripStatusLabelSpeed.Text = $": {_ArmoredVehicle.ArmoredVehicle.Speed}"; toolStripStatusLabelWeight.Text = $": {_ArmoredVehicle.ArmoredVehicle.Weight}"; toolStripStatusLabelColor.Text = $": {_ArmoredVehicle.ArmoredVehicle.BodyColor.Name}"; - Draw(); } /// /// @@ -79,5 +85,19 @@ namespace ArmoredVehicle _ArmoredVehicle?.ChangeBorders(DrawingPictureBox.Width, DrawingPictureBox.Height); Draw(); } + + private void TankButton_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ArmoredVehicle = new DrawingTank(rnd.Next(100, 300), + rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); + Draw(); + } } } \ No newline at end of file diff --git a/ArmoredVehicle/MainForm.resx b/ArmoredVehicle/MainForm.resx index a70faf4..3af6ba0 100644 --- a/ArmoredVehicle/MainForm.resx +++ b/ArmoredVehicle/MainForm.resx @@ -61,7 +61,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vwAADr8BOAVTJAAAy5RJREFUeF7s/emTZGd54O/3L9eqbkkI1GKxkUHsCA8gsXhACBNsxoBsY2BYhIkY + vgAADr4B6kKxwAAAy5RJREFUeF7s/emTZGd54O/3L9eqbkkI1GKxkUHsCA8gsXhACBNsxoBsY2BYhIkY ApgAIeMxYRADg74QNjJbBMYwrIPD0oBZBHjAbGYkbGMW4wn+GI/VXZVL+XdX3tmHstDSLVU/dVfmdb04 8WTptfq583Oec/LIvwFAbV/+8pf/fwDU0+v1cnHkyJG4vu1tb1v+ww0A+03AAqA6AQugJgELgGYELACq E7AAahKwAGhGwAKgOgELoCYBC4BmBCwAqhOwAGoSsABoRsACoDoBC6AmAQuAZgQsAKoTsABqErAAaEbA @@ -936,7 +936,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vwAADr8BOAVTJAAAtnhJREFUeF7s3fmbZXdVL/7NHs6p6m4ydRIvQwgJiQgSCJDwRUaVYICAPqjhEmVw + vgAADr4B6kKxwAAAtnhJREFUeF7s3fmbZXdVL/7NHs6p6m4ydRIvQwgJiQgSCJDwRUaVYICAPqjhEmVw iAo3xAjKKBBl8MEQUO5FgSBwITIJ6FUMgyZBCSjivX9O0nXG+q7aq2p7aELS6VTX2afq9frh86z92QdI uqvO4367PmsXmwAAAADQYwIsAAAAAHpNgAUAAABArwmwAAAAAOg1ARYAAAAAvSbAAgAAAKDXBFgAAAAA 9JoACwAAAIBeE2ABAAAA0GsCLAAAAAB6TYAFAAAAQK8JsAAAAADoNQEWAAAAAL0mwAIAAACg1wRYAAAA @@ -1721,7 +1721,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vwAADr8BOAVTJAAAt0tJREFUeF7s3fmXbHdZL/7qGvucEwicDBgkEIYwKCEB4mJIIiKwkEEGXQHBCA5c + vgAADr4B6kKxwAAAt0tJREFUeF7s3fmXbHdZL/7qGvucEwicDBgkEIYwKCEB4mJIIiKwkEEGXQHBCA5c hst0EQ34lcGrQBACsq5BJhUvYYoQVCZRQlBALsa77h9z17rprtq7Nt+n9lO9LUJCzsnp7r2r6/X64bOe /al2mdNdVWvtN8/n2b0fAgAAAECHCbAAAAAA6DQBFgAAAACdJsACAAAAoNMEWAAAAAB0mgALAAAAgE4T YAEAAADQaQIsAAAAADpNgAUAAABApwmwAAAAAOg0ARYAAAAAnSbAAgAAAKDTBFgAAAAAdJoACwAAAIBO @@ -2509,7 +2509,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vwAADr8BOAVTJAAAy01JREFUeF7s3fm/ZFV5L/7TVbWr6nTTjM0QBUQhikMEgsQBiYYEoqJGo8YxJlGD + vgAADr4B6kKxwAAAy01JREFUeF7s3fm/ZFV5L/7TVbWr6nTTjM0QBUQhikMEgsQBiYYEoqJGo8YxJlGD XxViNIng1WBiDEQxwRgvDhiNosYB472KQyBgohLuNa/c1/1fbuxTs9/n7Kd6WSLQ0+lzani/f1ivtTcK 3edU7f2sz15r7bUfAwAAAMAcE2ABAAAAMNcEWAAAAADMNQEWAAAAAHNNgAUAAADAXBNgAQAAADDXBFgA AAAAzDUBFgAAAABzTYAFAAAAwFwTYAEAAAAw1wRYAAAAAMw1ARYAAAAAc02ABQAAAMBcE2ABAAAAMNcE diff --git a/ArmoredVehicle/TankEnity.cs b/ArmoredVehicle/TankEnity.cs new file mode 100644 index 0000000..348e602 --- /dev/null +++ b/ArmoredVehicle/TankEnity.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ArmoredVehicle +{ + internal class TankEnity : ArmoredVehicleEntity + { + + public TankEnity(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower, bool gun) : base(speed, weight, bodyColor) + { + DopColor = dopColor; + MachineGun = machineGun; + Tower = tower; + Gun = gun; + } + + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия пулемета + /// + public bool MachineGun { get; private set; } + /// + /// Признак наличия башни + /// + public bool Tower { get; private set; } + /// + /// Признак наличия орудия + /// + public bool Gun { get; private set; } + /// + /// Признак наличия полосы + /// + public bool Line { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия пулемета + /// Признак наличия башни + /// Признак наличия орудия + + + } +} From 55115cfb4095947afb0585a41c34ed5e7abe13eb Mon Sep 17 00:00:00 2001 From: Zara28 Date: Sun, 11 Sep 2022 18:05:41 +0400 Subject: [PATCH 3/8] add interface --- ArmoredVehicle/DrawingArmoredVehicle.cs | 8 ++++++ ArmoredVehicle/DrawningObject.cs | 34 +++++++++++++++++++++++ ArmoredVehicle/IDrawningObject.cs | 37 +++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 ArmoredVehicle/DrawningObject.cs create mode 100644 ArmoredVehicle/IDrawningObject.cs diff --git a/ArmoredVehicle/DrawingArmoredVehicle.cs b/ArmoredVehicle/DrawingArmoredVehicle.cs index aaf5e00..78c8b6a 100644 --- a/ArmoredVehicle/DrawingArmoredVehicle.cs +++ b/ArmoredVehicle/DrawingArmoredVehicle.cs @@ -189,5 +189,13 @@ namespace ArmoredVehicle _startPosY = _pictureHeight.Value - _ArmoredVehicleHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _carWidth, _startPosY + _carHeight); + } } } diff --git a/ArmoredVehicle/DrawningObject.cs b/ArmoredVehicle/DrawningObject.cs new file mode 100644 index 0000000..53fd5a9 --- /dev/null +++ b/ArmoredVehicle/DrawningObject.cs @@ -0,0 +1,34 @@ +namespace ArmoredVehicle +{ + internal class DrawningObject : IDrawningObject + { + private DrawingArmoredVehicle _machine = null; + + public DrawningObject(DrawingArmoredVehicle car) + { + _machine = car; + } + + public float Step => _machine?.ArmoredVehicle?.Step ?? 0; + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _machine?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _machine?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _machine.SetPosition(x, y, width, height); + } + + void IDrawningObject.DrawningObject(Graphics g) + { + _machine.DrawTransport(g); + } + } +} \ No newline at end of file diff --git a/ArmoredVehicle/IDrawningObject.cs b/ArmoredVehicle/IDrawningObject.cs new file mode 100644 index 0000000..1ec4dc2 --- /dev/null +++ b/ArmoredVehicle/IDrawningObject.cs @@ -0,0 +1,37 @@ +namespace ArmoredVehicle +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawningObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + /// + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawningObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +} \ No newline at end of file From 9120c6ecf958b1c3e38100c4123d4f605800aeb2 Mon Sep 17 00:00:00 2001 From: Zara28 Date: Mon, 12 Sep 2022 16:19:44 +0400 Subject: [PATCH 4/8] Add check moving --- ArmoredVehicle/AbstractMap.cs | 209 +++++++++++++++++ ArmoredVehicle/ArmoredVehicle.csproj | 15 ++ ArmoredVehicle/Direction.cs | 1 + ArmoredVehicle/DrawingArmoredVehicle.cs | 12 +- ArmoredVehicle/FormMap.Designer.cs | 210 ++++++++++++++++++ ArmoredVehicle/FormMap.cs | 90 ++++++++ ArmoredVehicle/FormMap.resx | 63 ++++++ ArmoredVehicle/MainForm.Designer.cs | 13 ++ ArmoredVehicle/MainForm.cs | 6 + ArmoredVehicle/MainForm.resx | 8 +- ArmoredVehicle/Program.cs | 2 +- .../Properties/Resources.Designer.cs | 103 +++++++++ ArmoredVehicle/Properties/Resources.resx | 133 +++++++++++ ArmoredVehicle/SimpleMap.cs | 52 +++++ 14 files changed, 906 insertions(+), 11 deletions(-) create mode 100644 ArmoredVehicle/AbstractMap.cs create mode 100644 ArmoredVehicle/FormMap.Designer.cs create mode 100644 ArmoredVehicle/FormMap.cs create mode 100644 ArmoredVehicle/FormMap.resx create mode 100644 ArmoredVehicle/Properties/Resources.Designer.cs create mode 100644 ArmoredVehicle/Properties/Resources.resx create mode 100644 ArmoredVehicle/SimpleMap.cs diff --git a/ArmoredVehicle/AbstractMap.cs b/ArmoredVehicle/AbstractMap.cs new file mode 100644 index 0000000..c32d066 --- /dev/null +++ b/ArmoredVehicle/AbstractMap.cs @@ -0,0 +1,209 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ArmoredVehicle +{ + internal abstract class AbstractMap + { + private IDrawningObject _drawningObject = null; + protected int[,] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected readonly Random _random = new(); + protected readonly int _freeRoad = 0; + protected readonly int _barrier = 1; + + public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public Bitmap MoveObject(Direction direction) + { + bool possibility = true; + (float XTop, float YTop, float XBottom, float YBottom) = _drawningObject.GetCurrentPosition(); + bool busy = false; + int i; + int j; + int jt; + int i1; + switch (direction) + { + // вправо + case Direction.Right: + busy = false; + i = Math.Abs((int)Math.Ceiling(XBottom / _size_x)); + j = Math.Abs((int)Math.Ceiling(YBottom / _size_y)); + jt = Math.Abs((int)Math.Ceiling(YTop / _size_y)); + i1 = Math.Abs((int)Math.Ceiling((XBottom + _drawningObject.Step)/ _size_x)); + for (int r = i; r < i1; ++r) + { + for (int b = jt; b < j; ++b) + { + if (_map[r, b] == _barrier) + { + busy = true; + break; + } + + } + if (busy) + { + break; + } + } + + break; + //влево + case Direction.Left: + busy = false; + i = (int)Math.Ceiling((XTop - _drawningObject.Step )/ _size_x); + j = (int)Math.Ceiling(YBottom / _size_y); + jt = (int)Math.Ceiling(YTop / _size_y); + i1 = (int)Math.Ceiling((XTop)/ _size_x); + for (int r = i; r < i1; ++r) + { + for (int b = jt; b < j; ++b) + { + if (_map[r, b] == _barrier) + { + busy = true; + break; + } + + } + if (busy) + { + break; + } + } + + break; + //вверх + case Direction.Up: + { + busy = false; + i = (int)Math.Ceiling((XTop) / _size_x); + j = (int)((YTop)/ _size_y); + jt = (int)((YTop - _drawningObject.Step )/ _size_y); + i1 = (int)Math.Ceiling(XBottom / _size_x); + for (int r = i; r < i1; ++r) + { + for (int b = jt; b < j; ++b) + { + if (_map[r, b] == _barrier) + { + busy = true; + break; + } + + } + if (busy) + { + break; + } + } + break; + } + //вниз + case Direction.Down: + { + busy = false; + i = (int)Math.Ceiling(XTop / _size_x); + j = (int)((YBottom + _drawningObject.Step) / _size_y); + jt = (int)(YBottom / _size_y); + i1 = (int)Math.Ceiling(XBottom / _size_x); + for (int r = i; r <= i1; r++) + { + for (int b = jt; b <= j; b++) + { + if (_map[r, b] == _barrier) + { + busy = true; + break; + } + + } + if (busy) + { + break; + } + } + break; + } + } + if (busy) + { + possibility = false; + } + if (possibility) + { + _drawningObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + private bool SetObjectOnMap() + { + if (_drawningObject == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawningObject.SetObject(x, y, _width, _height); + // TODO првоерка, что объект не "накладывается" на закрытые участки + return true; + } + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawningObject == null || _map == null) + { + return bmp; + } + Graphics gr = Graphics.FromImage(bmp); + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (_map[i, j] == _freeRoad) + { + DrawRoadPart(gr, i, j); + } + else if (_map[i, j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + DrawRec(gr, 50, 50); + _drawningObject.DrawningObject(gr); + return bmp; + } + public void DrawRec(Graphics g, int countI, int couJj) + { + Pen p = new Pen(Color.Black); + for (int i = 0; i < countI; i++) + { + g.DrawLine(p, i * _size_x, 0, i * _size_x, 1000); + g.DrawLine(p, 0, i * _size_y, 1000, i * _size_y); + } + } + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} \ No newline at end of file diff --git a/ArmoredVehicle/ArmoredVehicle.csproj b/ArmoredVehicle/ArmoredVehicle.csproj index b57c89e..13ee123 100644 --- a/ArmoredVehicle/ArmoredVehicle.csproj +++ b/ArmoredVehicle/ArmoredVehicle.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ArmoredVehicle/Direction.cs b/ArmoredVehicle/Direction.cs index bc4c39a..0fe8ad8 100644 --- a/ArmoredVehicle/Direction.cs +++ b/ArmoredVehicle/Direction.cs @@ -11,6 +11,7 @@ namespace ArmoredVehicle /// internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/ArmoredVehicle/DrawingArmoredVehicle.cs b/ArmoredVehicle/DrawingArmoredVehicle.cs index 78c8b6a..eeef4dc 100644 --- a/ArmoredVehicle/DrawingArmoredVehicle.cs +++ b/ArmoredVehicle/DrawingArmoredVehicle.cs @@ -31,11 +31,11 @@ namespace ArmoredVehicle /// /// Ширина отрисовки /// - private readonly int _ArmoredVehicleWidth = 500; + private readonly int _ArmoredVehicleWidth = 200; /// /// Высота отрисовки /// - private readonly int _ArmoredVehicleHeight = 100; + private readonly int _ArmoredVehicleHeight = 60; /// /// Инициализация свойств /// @@ -161,9 +161,9 @@ namespace ArmoredVehicle g.DrawRectangle(pen, _startPosX + 15, _startPosY+20, 200, 20); g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 200, 35); - - - + + pen = new(Color.Red); + g.DrawRectangle(pen, _startPosX + 15, _startPosY, _ArmoredVehicleWidth, _ArmoredVehicleHeight); } /// /// Смена границ формы отрисовки @@ -195,7 +195,7 @@ namespace ArmoredVehicle /// public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { - return (_startPosX, _startPosY, _startPosX + _carWidth, _startPosY + _carHeight); + return (_startPosX + 15, _startPosY, _startPosX + 15 + _ArmoredVehicleWidth, _startPosY + _ArmoredVehicleHeight); } } } diff --git a/ArmoredVehicle/FormMap.Designer.cs b/ArmoredVehicle/FormMap.Designer.cs new file mode 100644 index 0000000..2b28b8a --- /dev/null +++ b/ArmoredVehicle/FormMap.Designer.cs @@ -0,0 +1,210 @@ +namespace ArmoredVehicle +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ButtonDown = new System.Windows.Forms.Button(); + this.ButtonRight = new System.Windows.Forms.Button(); + this.ButtonLeft = new System.Windows.Forms.Button(); + this.ButtonUp = new System.Windows.Forms.Button(); + this.CreateButton = new System.Windows.Forms.Button(); + this.DrawingPictureBox = new System.Windows.Forms.PictureBox(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.TankButton = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.DrawingPictureBox)).BeginInit(); + this.statusStrip.SuspendLayout(); + this.SuspendLayout(); + // + // ButtonDown + // + this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonDown.BackgroundImage = global::ArmoredVehicle.Properties.Resources.arrowDown; + this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonDown.Location = new System.Drawing.Point(711, 373); + this.ButtonDown.Name = "ButtonDown"; + this.ButtonDown.Size = new System.Drawing.Size(30, 30); + this.ButtonDown.TabIndex = 13; + this.ButtonDown.UseVisualStyleBackColor = true; + this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonRight + // + this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRight.BackgroundImage = global::ArmoredVehicle.Properties.Resources.arrowRight; + this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonRight.Location = new System.Drawing.Point(754, 326); + this.ButtonRight.Name = "ButtonRight"; + this.ButtonRight.Size = new System.Drawing.Size(30, 30); + this.ButtonRight.TabIndex = 12; + this.ButtonRight.UseVisualStyleBackColor = true; + this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonLeft + // + this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonLeft.BackgroundImage = global::ArmoredVehicle.Properties.Resources.arrowLeft; + this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonLeft.Location = new System.Drawing.Point(671, 328); + this.ButtonLeft.Name = "ButtonLeft"; + this.ButtonLeft.Size = new System.Drawing.Size(30, 30); + this.ButtonLeft.TabIndex = 11; + this.ButtonLeft.UseVisualStyleBackColor = true; + this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonUp + // + this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonUp.BackgroundImage = global::ArmoredVehicle.Properties.Resources.arrowUp; + this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonUp.Location = new System.Drawing.Point(711, 278); + this.ButtonUp.Name = "ButtonUp"; + this.ButtonUp.Size = new System.Drawing.Size(30, 30); + this.ButtonUp.TabIndex = 10; + this.ButtonUp.UseVisualStyleBackColor = true; + this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // CreateButton + // + this.CreateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.CreateButton.Location = new System.Drawing.Point(12, 362); + this.CreateButton.Name = "CreateButton"; + this.CreateButton.Size = new System.Drawing.Size(112, 34); + this.CreateButton.TabIndex = 9; + this.CreateButton.Text = "Создать"; + this.CreateButton.UseVisualStyleBackColor = true; + this.CreateButton.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // DrawingPictureBox + // + this.DrawingPictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.DrawingPictureBox.Location = new System.Drawing.Point(0, 0); + this.DrawingPictureBox.Name = "DrawingPictureBox"; + this.DrawingPictureBox.Size = new System.Drawing.Size(800, 418); + this.DrawingPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.DrawingPictureBox.TabIndex = 7; + this.DrawingPictureBox.TabStop = false; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(89, 25); + this.toolStripStatusLabelSpeed.Text = "Скорость"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(39, 25); + this.toolStripStatusLabelWeight.Text = "Вес"; + // + // toolStripStatusLabelColor + // + this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor"; + this.toolStripStatusLabelColor.Size = new System.Drawing.Size(51, 25); + this.toolStripStatusLabelColor.Text = "Цвет"; + // + // statusStrip + // + this.statusStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelColor}); + this.statusStrip.Location = new System.Drawing.Point(0, 418); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(800, 32); + this.statusStrip.TabIndex = 8; + this.statusStrip.Text = "statusStrip1"; + // + // TankButton + // + this.TankButton.Location = new System.Drawing.Point(139, 365); + this.TankButton.Name = "TankButton"; + this.TankButton.Size = new System.Drawing.Size(143, 34); + this.TankButton.TabIndex = 14; + this.TankButton.Text = "Модификация"; + this.TankButton.UseVisualStyleBackColor = true; + this.TankButton.Click += new System.EventHandler(this.TankButton_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 321); + this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(171, 33); + this.comboBoxSelectorMap.TabIndex = 15; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged_1); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.TankButton); + this.Controls.Add(this.ButtonDown); + this.Controls.Add(this.ButtonRight); + this.Controls.Add(this.ButtonLeft); + this.Controls.Add(this.ButtonUp); + this.Controls.Add(this.CreateButton); + this.Controls.Add(this.DrawingPictureBox); + this.Controls.Add(this.statusStrip); + this.MinimumSize = new System.Drawing.Size(210, 50); + this.Name = "FormMap"; + this.Text = "Карта"; + ((System.ComponentModel.ISupportInitialize)(this.DrawingPictureBox)).EndInit(); + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button ButtonDown; + private Button ButtonRight; + private Button ButtonLeft; + private Button ButtonUp; + private Button CreateButton; + private PictureBox DrawingPictureBox; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelColor; + private StatusStrip statusStrip; + private Button TankButton; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/ArmoredVehicle/FormMap.cs b/ArmoredVehicle/FormMap.cs new file mode 100644 index 0000000..4319b78 --- /dev/null +++ b/ArmoredVehicle/FormMap.cs @@ -0,0 +1,90 @@ +namespace ArmoredVehicle +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + /// + /// Заполнение информации по объекту + /// + /// + private void SetData(DrawingArmoredVehicle armoredVehicle) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {armoredVehicle.ArmoredVehicle.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {armoredVehicle.ArmoredVehicle.Weight}"; + toolStripStatusLabelColor.Text = $"Цвет: {armoredVehicle.ArmoredVehicle.BodyColor.Name}"; + DrawingPictureBox.Image = _abstractMap.CreateMap(DrawingPictureBox.Width, DrawingPictureBox.Height, + new DrawningObject(armoredVehicle)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var machine = new DrawingArmoredVehicle(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(machine); + } + /// + /// Изменение размеров формы + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "ButtonUp": + dir = Direction.Up; + break; + case "ButtonDown": + dir = Direction.Down; + break; + case "ButtonLeft": + dir = Direction.Left; + break; + case "ButtonRight": + dir = Direction.Right; + break; + } + + DrawingPictureBox.Image = _abstractMap?.MoveObject(dir); + } + /// + /// Смена карты + /// + /// + /// + + private void comboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } + } + + private void TankButton_Click(object sender, EventArgs e) + { + + Random rnd = new(); + var tank = new DrawingTank(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(tank); + } + } +} diff --git a/ArmoredVehicle/FormMap.resx b/ArmoredVehicle/FormMap.resx new file mode 100644 index 0000000..2c0949d --- /dev/null +++ b/ArmoredVehicle/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ArmoredVehicle/MainForm.Designer.cs b/ArmoredVehicle/MainForm.Designer.cs index 316b720..373ea63 100644 --- a/ArmoredVehicle/MainForm.Designer.cs +++ b/ArmoredVehicle/MainForm.Designer.cs @@ -40,6 +40,7 @@ this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel(); this.statusStrip = new System.Windows.Forms.StatusStrip(); this.TankButton = new System.Windows.Forms.Button(); + this.Mapbutton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.DrawingPictureBox)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -155,11 +156,22 @@ this.TankButton.UseVisualStyleBackColor = true; this.TankButton.Click += new System.EventHandler(this.TankButton_Click); // + // Mapbutton + // + this.Mapbutton.Location = new System.Drawing.Point(304, 362); + this.Mapbutton.Name = "Mapbutton"; + this.Mapbutton.Size = new System.Drawing.Size(179, 34); + this.Mapbutton.TabIndex = 15; + this.Mapbutton.Text = "Перейти на карту"; + this.Mapbutton.UseVisualStyleBackColor = true; + this.Mapbutton.Click += new System.EventHandler(this.Mapbutton_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.Mapbutton); this.Controls.Add(this.TankButton); this.Controls.Add(this.ButtonDown); this.Controls.Add(this.ButtonRight); @@ -192,5 +204,6 @@ private ToolStripStatusLabel toolStripStatusLabelColor; private StatusStrip statusStrip; private Button TankButton; + private Button Mapbutton; } } \ No newline at end of file diff --git a/ArmoredVehicle/MainForm.cs b/ArmoredVehicle/MainForm.cs index 7145fbf..96f653e 100644 --- a/ArmoredVehicle/MainForm.cs +++ b/ArmoredVehicle/MainForm.cs @@ -99,5 +99,11 @@ namespace ArmoredVehicle SetData(); Draw(); } + + private void Mapbutton_Click(object sender, EventArgs e) + { + FormMap map = new FormMap(); + map.Show(); + } } } \ No newline at end of file diff --git a/ArmoredVehicle/MainForm.resx b/ArmoredVehicle/MainForm.resx index 3af6ba0..65a0a79 100644 --- a/ArmoredVehicle/MainForm.resx +++ b/ArmoredVehicle/MainForm.resx @@ -61,7 +61,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAy5RJREFUeF7s/emTZGd54O/3L9eqbkkI1GKxkUHsCA8gsXhACBNsxoBsY2BYhIkY + vAAADrwBlbxySQAAy5RJREFUeF7s/emTZGd54O/3L9eqbkkI1GKxkUHsCA8gsXhACBNsxoBsY2BYhIkY ApgAIeMxYRADg74QNjJbBMYwrIPD0oBZBHjAbGYkbGMW4wn+GI/VXZVL+XdX3tmHstDSLVU/dVfmdb04 8WTptfq583Oec/LIvwFAbV/+8pf/fwDU0+v1cnHkyJG4vu1tb1v+ww0A+03AAqA6AQugJgELgGYELACq E7AAahKwAGhGwAKgOgELoCYBC4BmBCwAqhOwAGoSsABoRsACoDoBC6AmAQuAZgQsAKoTsABqErAAaEbA @@ -936,7 +936,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAtnhJREFUeF7s3fmbZXdVL/7NHs6p6m4ydRIvQwgJiQgSCJDwRUaVYICAPqjhEmVw + vAAADrwBlbxySQAAtnhJREFUeF7s3fmbZXdVL/7NHs6p6m4ydRIvQwgJiQgSCJDwRUaVYICAPqjhEmVw iAo3xAjKKBBl8MEQUO5FgSBwITIJ6FUMgyZBCSjivX9O0nXG+q7aq2p7aELS6VTX2afq9frh86z92QdI uqvO4367PmsXmwAAAADQYwIsAAAAAHpNgAUAAABArwmwAAAAAOg1ARYAAAAAvSbAAgAAAKDXBFgAAAAA 9JoACwAAAIBeE2ABAAAA0GsCLAAAAAB6TYAFAAAAQK8JsAAAAADoNQEWAAAAAL0mwAIAAACg1wRYAAAA @@ -1721,7 +1721,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAt0tJREFUeF7s3fmXbHdZL/7qGvucEwicDBgkEIYwKCEB4mJIIiKwkEEGXQHBCA5c + vAAADrwBlbxySQAAt0tJREFUeF7s3fmXbHdZL/7qGvucEwicDBgkEIYwKCEB4mJIIiKwkEEGXQHBCA5c hst0EQ34lcGrQBACsq5BJhUvYYoQVCZRQlBALsa77h9z17rprtq7Nt+n9lO9LUJCzsnp7r2r6/X64bOe /al2mdNdVWvtN8/n2b0fAgAAAECHCbAAAAAA6DQBFgAAAACdJsACAAAAoNMEWAAAAAB0mgALAAAAgE4T YAEAAADQaQIsAAAAADpNgAUAAABApwmwAAAAAOg0ARYAAAAAnSbAAgAAAKDTBFgAAAAAdJoACwAAAIBO @@ -2509,7 +2509,7 @@ iVBORw0KGgoAAAANSUhEUgAABkAAAAZACAIAAACubhnwAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAy01JREFUeF7s3fm/ZFV5L/7TVbWr6nTTjM0QBUQhikMEgsQBiYYEoqJGo8YxJlGD + vAAADrwBlbxySQAAy01JREFUeF7s3fm/ZFV5L/7TVbWr6nTTjM0QBUQhikMEgsQBiYYEoqJGo8YxJlGD XxViNIng1WBiDEQxwRgvDhiNosYB472KQyBgohLuNa/c1/1fbuxTs9/n7Kd6WSLQ0+lzani/f1ivtTcK 3edU7f2sz15r7bUfAwAAAMAcE2ABAAAAMNcEWAAAAADMNQEWAAAAAHNNgAUAAADAXBNgAQAAADDXBFgA AAAAzDUBFgAAAABzTYAFAAAAwFwTYAEAAAAw1wRYAAAAAMw1ARYAAAAAc02ABQAAAMBcE2ABAAAAMNcE diff --git a/ArmoredVehicle/Program.cs b/ArmoredVehicle/Program.cs index 9c1e225..fb70217 100644 --- a/ArmoredVehicle/Program.cs +++ b/ArmoredVehicle/Program.cs @@ -11,7 +11,7 @@ namespace ArmoredVehicle // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new MainForm()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/ArmoredVehicle/Properties/Resources.Designer.cs b/ArmoredVehicle/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e997a61 --- /dev/null +++ b/ArmoredVehicle/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ArmoredVehicle.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ArmoredVehicle.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowDown { + get { + object obj = ResourceManager.GetObject("arrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowLeft { + get { + object obj = ResourceManager.GetObject("arrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowRight { + get { + object obj = ResourceManager.GetObject("arrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowUp { + get { + object obj = ResourceManager.GetObject("arrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ArmoredVehicle/Properties/Resources.resx b/ArmoredVehicle/Properties/Resources.resx new file mode 100644 index 0000000..293419e --- /dev/null +++ b/ArmoredVehicle/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ArmoredVehicle/SimpleMap.cs b/ArmoredVehicle/SimpleMap.cs new file mode 100644 index 0000000..2ed1657 --- /dev/null +++ b/ArmoredVehicle/SimpleMap.cs @@ -0,0 +1,52 @@ +namespace ArmoredVehicle +{ + /// + /// Простая реализация абсрактного класса AbstractMap + /// + internal class SimpleMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.Gray); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i+1) * (_size_x + 1), (j+1) * (_size_y + 1)); + + } + + protected override void GenerateMap() + { + _map = new int[50, 50]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 50) + { + int x = _random.Next(0, 50); + int y = _random.Next(0, 50); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} \ No newline at end of file From f7b53c804c2db9adf58e7bf75d2b5bcd9ef0fdf2 Mon Sep 17 00:00:00 2001 From: Zara28 Date: Mon, 12 Sep 2022 19:23:19 +0400 Subject: [PATCH 5/8] add check create --- ArmoredVehicle/AbstractMap.cs | 38 +++++++++++++++++++------ ArmoredVehicle/DrawingArmoredVehicle.cs | 3 -- ArmoredVehicle/DrawingTank.cs | 12 ++++++-- ArmoredVehicle/DrawningObject.cs | 4 +-- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/ArmoredVehicle/AbstractMap.cs b/ArmoredVehicle/AbstractMap.cs index c32d066..114defc 100644 --- a/ArmoredVehicle/AbstractMap.cs +++ b/ArmoredVehicle/AbstractMap.cs @@ -70,10 +70,10 @@ namespace ArmoredVehicle //влево case Direction.Left: busy = false; - i = (int)Math.Ceiling((XTop - _drawningObject.Step )/ _size_x); - j = (int)Math.Ceiling(YBottom / _size_y); - jt = (int)Math.Ceiling(YTop / _size_y); - i1 = (int)Math.Ceiling((XTop)/ _size_x); + i = Math.Abs((int)Math.Ceiling((XTop - _drawningObject.Step )/ _size_x)); + j = Math.Abs((int)Math.Ceiling(YBottom / _size_y)); + jt = Math.Abs((int)Math.Ceiling(YTop / _size_y)); + i1 = Math.Abs((int)Math.Ceiling((XTop)/ _size_x)); for (int r = i; r < i1; ++r) { for (int b = jt; b < j; ++b) @@ -96,10 +96,10 @@ namespace ArmoredVehicle case Direction.Up: { busy = false; - i = (int)Math.Ceiling((XTop) / _size_x); - j = (int)((YTop)/ _size_y); - jt = (int)((YTop - _drawningObject.Step )/ _size_y); - i1 = (int)Math.Ceiling(XBottom / _size_x); + i = Math.Abs((int)Math.Ceiling((XTop) / _size_x)); + j = Math.Abs((int)((YTop)/ _size_y)); + jt = Math.Abs((int)((YTop - _drawningObject.Step )/ _size_y)); + i1 = Math.Abs((int)Math.Ceiling(XBottom / _size_x)); for (int r = i; r < i1; ++r) { for (int b = jt; b < j; ++b) @@ -161,10 +161,30 @@ namespace ArmoredVehicle { return false; } + (float XTop, float YTop, float XBottom, float YBottom) = _drawningObject.GetCurrentPosition(); + int x = _random.Next(0, 10); int y = _random.Next(0, 10); + + int beginI = (int)(x / _size_x); + int endI = (int)(XBottom / _size_x); + + int beginJ = (int)(y / _size_y); + int endJ = (int)(YBottom / _size_y); + + for (int i = beginI; i <= endI; i++) + { + for(int j = beginJ; j <= endJ; j++) + { + if(_map[i, j] == _barrier) + { + return false; + } + } + + } + _drawningObject.SetObject(x, y, _width, _height); - // TODO првоерка, что объект не "накладывается" на закрытые участки return true; } private Bitmap DrawMapWithObject() diff --git a/ArmoredVehicle/DrawingArmoredVehicle.cs b/ArmoredVehicle/DrawingArmoredVehicle.cs index eeef4dc..458432a 100644 --- a/ArmoredVehicle/DrawingArmoredVehicle.cs +++ b/ArmoredVehicle/DrawingArmoredVehicle.cs @@ -161,9 +161,6 @@ namespace ArmoredVehicle g.DrawRectangle(pen, _startPosX + 15, _startPosY+20, 200, 20); g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 200, 35); - - pen = new(Color.Red); - g.DrawRectangle(pen, _startPosX + 15, _startPosY, _ArmoredVehicleWidth, _ArmoredVehicleHeight); } /// /// Смена границ формы отрисовки diff --git a/ArmoredVehicle/DrawingTank.cs b/ArmoredVehicle/DrawingTank.cs index 142fbda..5a58ba3 100644 --- a/ArmoredVehicle/DrawingTank.cs +++ b/ArmoredVehicle/DrawingTank.cs @@ -20,6 +20,7 @@ namespace ArmoredVehicle { return; } + base.DrawTransport(g); Brush br = new SolidBrush(machine?.DopColor ?? Color.Black); @@ -37,9 +38,16 @@ namespace ArmoredVehicle g.DrawLine(p, _startPosX + 90, _startPosY - 45, _startPosX + 90, _startPosY - 30); g.DrawLine(p, _startPosX + 85, _startPosY - 35, _startPosX + 120, _startPosY - 35); } - } } - } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX + 15, _startPosY - 45, _startPosX + 250, _startPosY + 60); + } + } } diff --git a/ArmoredVehicle/DrawningObject.cs b/ArmoredVehicle/DrawningObject.cs index 53fd5a9..56359d1 100644 --- a/ArmoredVehicle/DrawningObject.cs +++ b/ArmoredVehicle/DrawningObject.cs @@ -4,9 +4,9 @@ { private DrawingArmoredVehicle _machine = null; - public DrawningObject(DrawingArmoredVehicle car) + public DrawningObject(DrawingArmoredVehicle machine) { - _machine = car; + _machine = machine; } public float Step => _machine?.ArmoredVehicle?.Step ?? 0; From bf9e8b576787ee601e3a0cca0529f7c75e803571 Mon Sep 17 00:00:00 2001 From: Zara28 Date: Mon, 12 Sep 2022 19:42:24 +0400 Subject: [PATCH 6/8] Add two map --- ArmoredVehicle/FormMap.Designer.cs | 4 +- ArmoredVehicle/FormMap.cs | 6 +++ ArmoredVehicle/HorizontalMap.cs | 63 ++++++++++++++++++++++++++++++ ArmoredVehicle/VerticalMAp.cs | 62 +++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 ArmoredVehicle/HorizontalMap.cs create mode 100644 ArmoredVehicle/VerticalMAp.cs diff --git a/ArmoredVehicle/FormMap.Designer.cs b/ArmoredVehicle/FormMap.Designer.cs index 2b28b8a..4e626da 100644 --- a/ArmoredVehicle/FormMap.Designer.cs +++ b/ArmoredVehicle/FormMap.Designer.cs @@ -159,7 +159,9 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта"}); + "Простая карта", + "Горизонтальная карта", + "Вертикальная карта"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 321); this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; diff --git a/ArmoredVehicle/FormMap.cs b/ArmoredVehicle/FormMap.cs index 4319b78..86e2e8d 100644 --- a/ArmoredVehicle/FormMap.cs +++ b/ArmoredVehicle/FormMap.cs @@ -73,6 +73,12 @@ case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Горизонтальная карта": + _abstractMap = new HorizontalMap(); + break; + case "Вертикальная карта": + _abstractMap = new VerticalMap(); + break; } } diff --git a/ArmoredVehicle/HorizontalMap.cs b/ArmoredVehicle/HorizontalMap.cs new file mode 100644 index 0000000..63a3727 --- /dev/null +++ b/ArmoredVehicle/HorizontalMap.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ArmoredVehicle +{ + internal class HorizontalMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.BlueViolet); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.White); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1)); + + } + + protected override void GenerateMap() + { + _map = new int[50, 50]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 5) + { + + int x1 = _random.Next(0, 12); + int x2 = _random.Next(12, _map.GetLength(0)); + + int y1 = _random.Next(0, _map.GetLength(1)); + + for(int i = x1; i + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Brown); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.LightGray); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1)); + + } + + protected override void GenerateMap() + { + _map = new int[50, 50]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 7) + { + + int x1 = _random.Next(0, 12); + int x2 = _random.Next(12, _map.GetLength(0)); + + int y1 = _random.Next(0, _map.GetLength(1)); + + for (int i = x1; i < x2; i++) + { + if (_map[y1, i] == _freeRoad) + { + _map[y1, i] = _barrier; + } + } + + counter++; + } + } + } +} From 26955fb8c88828595c567f3f5d5f6fc13cdd9ce2 Mon Sep 17 00:00:00 2001 From: Zara28 Date: Wed, 21 Sep 2022 14:05:06 +0400 Subject: [PATCH 7/8] fix --- ArmoredVehicle/ArmoredVehicleEntity.cs | 2 ++ ArmoredVehicle/DrawingArmoredVehicle.cs | 10 +++++--- ArmoredVehicle/DrawingTank.cs | 33 +++++++++++-------------- ArmoredVehicle/DrawningObject.cs | 1 + ArmoredVehicle/HorizontalMap.cs | 1 + ArmoredVehicle/IDrawningObject.cs | 1 + ArmoredVehicle/TankEnity.cs | 24 ++++++++---------- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/ArmoredVehicle/ArmoredVehicleEntity.cs b/ArmoredVehicle/ArmoredVehicleEntity.cs index b5beeec..870666a 100644 --- a/ArmoredVehicle/ArmoredVehicleEntity.cs +++ b/ArmoredVehicle/ArmoredVehicleEntity.cs @@ -16,6 +16,8 @@ namespace ArmoredVehicle BodyColor = bodyColor; } + + /// /// Скорость /// diff --git a/ArmoredVehicle/DrawingArmoredVehicle.cs b/ArmoredVehicle/DrawingArmoredVehicle.cs index 458432a..4e2d913 100644 --- a/ArmoredVehicle/DrawingArmoredVehicle.cs +++ b/ArmoredVehicle/DrawingArmoredVehicle.cs @@ -46,12 +46,14 @@ namespace ArmoredVehicle { ArmoredVehicle = new ArmoredVehicleEntity(speed, weight, bodyColor); } - protected DrawingArmoredVehicle(int speed, float weight, Color bodyColor, int ArmoredVehicleWidth, int ArmoredVehicleHeight): - this(speed, weight, bodyColor) + + public DrawingArmoredVehicle(int speed, float weight, Color bodyColor, int ArmoredVehicleWidth, int ArmoredVehicleHeight) + :this(speed, weight, bodyColor) { - _ArmoredVehicleHeight = ArmoredVehicleHeight; - _ArmoredVehicleWidth = ArmoredVehicleWidth; + _ArmoredVehicleHeight = ArmoredVehicleHeight + 50; + _ArmoredVehicleWidth = ArmoredVehicleWidth + 150; } + /// /// Установка позиции diff --git a/ArmoredVehicle/DrawingTank.cs b/ArmoredVehicle/DrawingTank.cs index 5a58ba3..23c1ed6 100644 --- a/ArmoredVehicle/DrawingTank.cs +++ b/ArmoredVehicle/DrawingTank.cs @@ -9,10 +9,11 @@ namespace ArmoredVehicle internal class DrawingTank : DrawingArmoredVehicle { public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower, bool gun) - : base(speed, weight, bodyColor) + : base(speed, weight, bodyColor, 200, 60) { ArmoredVehicle = new TankEnity(speed, weight, bodyColor, dopColor, machineGun, tower, gun); } + public override void DrawTransport(Graphics g) { @@ -21,33 +22,29 @@ namespace ArmoredVehicle return; } - base.DrawTransport(g); - Brush br = new SolidBrush(machine?.DopColor ?? Color.Black); Pen p = new Pen(machine?.DopColor ?? Color.Black, 5); - + + _startPosY += 40; + + base.DrawTransport(g); + _startPosY -= 40; if (machine.Tower) { - - g.FillRectangle(br, _startPosX + 60, _startPosY - 30, 80, 30); - g.DrawLine(p, _startPosX + 90, _startPosY - 20, _startPosX + 250, _startPosY - 20); + g.FillRectangle(br, _startPosX + 60, _startPosY + 10, 80, 30); + g.DrawLine(p, _startPosX + 90, _startPosY +20, _startPosX + 250, _startPosY + 20); if (machine.MachineGun) { p = new Pen(machine?.DopColor ?? Color.Black, 3); - g.DrawLine(p, _startPosX + 90, _startPosY - 45, _startPosX + 90, _startPosY - 30); - g.DrawLine(p, _startPosX + 85, _startPosY - 35, _startPosX + 120, _startPosY - 35); + g.DrawLine(p, _startPosX + 90, _startPosY, _startPosX + 90, _startPosY + 10); + g.DrawLine(p, _startPosX + 85, _startPosY + 5, _startPosX + 120, _startPosY + 5); } } - - } - /// - /// Получение текущей позиции объекта - /// - /// - public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() - { - return (_startPosX + 15, _startPosY - 45, _startPosX + 250, _startPosY + 60); + + + } + } } diff --git a/ArmoredVehicle/DrawningObject.cs b/ArmoredVehicle/DrawningObject.cs index 56359d1..8792a37 100644 --- a/ArmoredVehicle/DrawningObject.cs +++ b/ArmoredVehicle/DrawningObject.cs @@ -30,5 +30,6 @@ { _machine.DrawTransport(g); } + } } \ No newline at end of file diff --git a/ArmoredVehicle/HorizontalMap.cs b/ArmoredVehicle/HorizontalMap.cs index 63a3727..20aa378 100644 --- a/ArmoredVehicle/HorizontalMap.cs +++ b/ArmoredVehicle/HorizontalMap.cs @@ -8,6 +8,7 @@ namespace ArmoredVehicle { internal class HorizontalMap : AbstractMap { + /// /// Цвет участка закрытого /// diff --git a/ArmoredVehicle/IDrawningObject.cs b/ArmoredVehicle/IDrawningObject.cs index 1ec4dc2..c0dd705 100644 --- a/ArmoredVehicle/IDrawningObject.cs +++ b/ArmoredVehicle/IDrawningObject.cs @@ -33,5 +33,6 @@ /// /// (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } } \ No newline at end of file diff --git a/ArmoredVehicle/TankEnity.cs b/ArmoredVehicle/TankEnity.cs index 348e602..5a3cd21 100644 --- a/ArmoredVehicle/TankEnity.cs +++ b/ArmoredVehicle/TankEnity.cs @@ -8,6 +8,16 @@ namespace ArmoredVehicle { internal class TankEnity : ArmoredVehicleEntity { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия пулемета + /// Признак наличия башни + /// Признак наличия орудия public TankEnity(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower, bool gun) : base(speed, weight, bodyColor) { @@ -33,20 +43,6 @@ namespace ArmoredVehicle /// Признак наличия орудия /// public bool Gun { get; private set; } - /// - /// Признак наличия полосы - /// - public bool Line { get; private set; } - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес автомобиля - /// Цвет кузова - /// Дополнительный цвет - /// Признак наличия пулемета - /// Признак наличия башни - /// Признак наличия орудия } From 3425a132d3b6e6ccc7f60392220d25189b3a7184 Mon Sep 17 00:00:00 2001 From: Zara28 Date: Sat, 24 Sep 2022 17:13:07 +0400 Subject: [PATCH 8/8] fix comment --- ArmoredVehicle/MainForm.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ArmoredVehicle/MainForm.cs b/ArmoredVehicle/MainForm.cs index 96f653e..56e26e6 100644 --- a/ArmoredVehicle/MainForm.cs +++ b/ArmoredVehicle/MainForm.cs @@ -6,7 +6,6 @@ namespace ArmoredVehicle public MainForm() { InitializeComponent(); - //this.MinimumSize = new System.Drawing.Size(300, 250); } /// /// @@ -43,7 +42,7 @@ namespace ArmoredVehicle private void SetData() { Random rnd = new(); - _ArmoredVehicle.SetPosition(/*rnd.Next(0, 100)*/ -10, rnd.Next(0, 100), DrawingPictureBox.Width, DrawingPictureBox.Height); + _ArmoredVehicle.SetPosition( -10, rnd.Next(0, 100), DrawingPictureBox.Width, DrawingPictureBox.Height); toolStripStatusLabelSpeed.Text = $": {_ArmoredVehicle.ArmoredVehicle.Speed}"; toolStripStatusLabelWeight.Text = $": {_ArmoredVehicle.ArmoredVehicle.Weight}"; toolStripStatusLabelColor.Text = $": {_ArmoredVehicle.ArmoredVehicle.BodyColor.Name}";