diff --git a/Tank/Tank/DrawArmoVehicle.cs b/Tank/Tank/DrawArmoVehicle.cs index ed247f8..9996ee2 100644 --- a/Tank/Tank/DrawArmoVehicle.cs +++ b/Tank/Tank/DrawArmoVehicle.cs @@ -10,7 +10,7 @@ namespace Tank { public class DrawArmoVehicle { - public Base? Tank { get; protected set; } + public EntityBase? Tank { get; protected set; } protected int _pictureWidth; protected int _pictureHeight; protected int _startPosX; @@ -22,13 +22,6 @@ namespace Tank public int GetWidth => _Width; public int GetHeight => _Height; - //==========ДОРАБОТКА================// - public bool CanStopObject(Direction direction) - { - return false; - } - //==================================// - public bool CanMove(Direction direction) { if (Tank == null) @@ -48,16 +41,20 @@ namespace Tank { _pictureHeight = height; _pictureWidth = width; - Tank = new Base(speed, weight, bodyColor); + if (_pictureHeight < _Height || _pictureWidth < _Width) + return; + Tank = new EntityBase(speed, weight, bodyColor); } - public DrawArmoVehicle(int speed, double weight, Color bodyColor, int width, int height, int tankWidth, int tankHeight) + protected DrawArmoVehicle(int speed, double weight, Color bodyColor, int width, int height, int tankWidth, int tankHeight) { _pictureHeight = height; _pictureWidth = width; _Height = tankHeight; _Width = tankWidth; - Tank = new Base(speed, weight, bodyColor); + if (_pictureHeight < _Height || _pictureWidth < _Width) + return; + Tank = new EntityBase(speed, weight, bodyColor); } public void SetPosition(int x, int y) @@ -107,13 +104,12 @@ namespace Tank } } - public virtual void DrawTransport(Graphics g) // ПЕРЕПИСАТЬ В НОРМАЛЬНОЕ СОСТОЯНИЕ + public virtual void DrawTransport(Graphics g) { if (Tank == null) return; Brush BrushRandom = new SolidBrush(Tank?.BodyColor ?? Color.Black); - //Корпус Brush WhiteColor = new SolidBrush(Color.White); g.FillRectangle(WhiteColor, _startPosX, _startPosY, 155, 30); diff --git a/Tank/Tank/DrawTank.cs b/Tank/Tank/DrawTank.cs index 2c3fb17..8e94d83 100644 --- a/Tank/Tank/DrawTank.cs +++ b/Tank/Tank/DrawTank.cs @@ -10,17 +10,17 @@ namespace Tank.DrawningObjects { public class DrawTank : DrawArmoVehicle { - - public DrawTank(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) : base(speed, weight, bodyColor, width, height) + public DrawTank(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool tower, int width, int height) : base(speed, weight, bodyColor, width, height) { if (Tank != null) { - Tank = new AddBase(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine); + Tank = new EntityAddBase(speed, weight, bodyColor, additionalColor, bodyKit, caterpillar, tower); } } + public override void DrawTransport(Graphics g) { - if (Tank is not AddBase ArmoVehicle) + if (Tank is not EntityAddBase ArmoVehicle) return; base.DrawTransport(g); if (ArmoVehicle.BodyKit) @@ -28,32 +28,25 @@ namespace Tank.DrawningObjects Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor); // Корпус танка - Point[] pointsbody = { new Point(_startPosX + 5, _startPosY + 30), new Point(_startPosX + 140, _startPosY + 30), - new Point(_startPosX + 130, _startPosY + 42), new Point(_startPosX + 12, _startPosY + 42) }; - g.FillPolygon(bodyBrush, pointsbody); - Point[] pointtower = { new Point(_startPosX + 52, _startPosY + 30), new Point(_startPosX + 52, _startPosY + 27), new Point(_startPosX + 40, _startPosY + 23), new Point(_startPosX + 15, _startPosY + 18), new Point(_startPosX + 15,_startPosY + 15), new Point(_startPosX + 60, _startPosY + 11), new Point(_startPosX + 90, _startPosY + 11), new Point(_startPosX + 120, _startPosY + 20), new Point(_startPosX + 100,_startPosY + 25), new Point(_startPosX + 95, _startPosY + 27), new Point(_startPosX + 90, _startPosY + 30)}; g.FillPolygon(bodyBrush, pointtower); - } - if (ArmoVehicle.Rinks) + if (ArmoVehicle.Caterpillar) { Pen pen = new(Color.Black); Brush lineBrush = new SolidBrush(Color.Gray); // Гусеница - Brush BrushGray = new SolidBrush(Color.DarkGray); - //g.DrawEllipse(BrushGray, _startPosX + 10, _startPosY + 30, 120, 30); // Отрисовка танковых катков Brush BrushBlack = new SolidBrush(Color.Black); g.FillEllipse(BrushBlack, _startPosX + 113, _startPosY + 41, 11, 11); g.FillEllipse(BrushBlack, _startPosX + 13, _startPosY + 40, 11, 11); } - if (ArmoVehicle.Caterpillar) + if (ArmoVehicle.Tower) { Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor); // Орудие diff --git a/Tank/Tank/DrawingObjectTank.cs b/Tank/Tank/DrawingObjectTank.cs index 70eb9c4..149bcfa 100644 --- a/Tank/Tank/DrawingObjectTank.cs +++ b/Tank/Tank/DrawingObjectTank.cs @@ -27,8 +27,5 @@ namespace Tank.MovementStrategy public int GetStep => (int)(_drawTank?.Tank?.Step ?? 0); public bool CheckCanMove(Direction direction) => _drawTank?.CanMove(direction) ?? false; public void MoveObject(Direction direction) => _drawTank?.MoveTransport(direction); - - // Доработка - public bool CanStopObject(Direction direction) => _drawTank?.CanStopObject(direction) ?? false; } } diff --git a/Tank/Tank/AddBase.cs b/Tank/Tank/EntityAddBase.cs similarity index 61% rename from Tank/Tank/AddBase.cs rename to Tank/Tank/EntityAddBase.cs index d94b7d0..1527343 100644 --- a/Tank/Tank/AddBase.cs +++ b/Tank/Tank/EntityAddBase.cs @@ -6,18 +6,18 @@ using System.Threading.Tasks; namespace Tank.Entities { - public class AddBase : Base + public class EntityAddBase : EntityBase { public Color AdditionalColor { get; private set; } public bool BodyKit { get; private set; } public bool Caterpillar { get; private set; } - public bool Rinks { get; private set; } - public AddBase(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool rinks) : base(speed, weight, bodyColor) + public bool Tower { get; private set; } + public EntityAddBase(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool tower) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; BodyKit = bodyKit; Caterpillar = caterpillar; - Rinks = rinks; + Tower = tower; } } } diff --git a/Tank/Tank/Base.cs b/Tank/Tank/EntityBase.cs similarity index 83% rename from Tank/Tank/Base.cs rename to Tank/Tank/EntityBase.cs index 3e2bb80..2c23395 100644 --- a/Tank/Tank/Base.cs +++ b/Tank/Tank/EntityBase.cs @@ -6,13 +6,13 @@ using System.Threading.Tasks; namespace Tank.Entities { - public class Base + public class EntityBase { public int Speed { get; private set; } public double Weight { get; private set; } public Color BodyColor { get; private set; } public double Step => (double)Speed * 100 / Weight; - public Base(int speed, double weight, Color bodyColor) + public EntityBase(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; diff --git a/Tank/Tank/FormTank.Designer.cs b/Tank/Tank/FormTank.Designer.cs index 9f229b2..70578cb 100644 --- a/Tank/Tank/FormTank.Designer.cs +++ b/Tank/Tank/FormTank.Designer.cs @@ -58,7 +58,7 @@ ButtonCreate.TabIndex = 1; ButtonCreate.Text = "Создание танка"; ButtonCreate.UseVisualStyleBackColor = true; - ButtonCreate.Click += ButtonCreate_Click; + ButtonCreate.Click += ButtonCreateTank_Click; // // keyDown // @@ -161,7 +161,6 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormTank"; Text = "FormTank"; - Load += FormTank_Load; ((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit(); ResumeLayout(false); } diff --git a/Tank/Tank/FormTank.cs b/Tank/Tank/FormTank.cs index f2984c4..d43d757 100644 --- a/Tank/Tank/FormTank.cs +++ b/Tank/Tank/FormTank.cs @@ -25,13 +25,13 @@ namespace Tank } - private void ButtonCreate_Click(object sender, EventArgs e) + private void ButtonCreateTank_Click(object sender, EventArgs e) { Random rnd = new(); _Tank = new DrawTank(rnd.Next(100, 200), rnd.Next(2000, 4000), 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(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)), pictureBoxTank.Width, pictureBoxTank.Height); _Tank.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100)); Draw(); @@ -102,10 +102,5 @@ namespace Tank _abstractStrategy = null; } } - - private void FormTank_Load(object sender, EventArgs e) - { - - } } } \ No newline at end of file diff --git a/Tank/Tank/IMoveableObject.cs b/Tank/Tank/IMoveableObject.cs index 17673b4..6c0ba64 100644 --- a/Tank/Tank/IMoveableObject.cs +++ b/Tank/Tank/IMoveableObject.cs @@ -12,9 +12,5 @@ namespace Tank.MovementStrategy int GetStep { get; } bool CheckCanMove(Direction direction); void MoveObject(Direction direction); - - - // Доп задание - bool CanStopObject(Direction direction); } }