Правки в лабораторной 2

This commit is contained in:
nikbel2004@outlook.com 2023-10-08 00:14:56 +04:00
parent e0874c2924
commit 21ce7abbe3
8 changed files with 24 additions and 48 deletions

View File

@ -10,7 +10,7 @@ namespace Tank
{ {
public class DrawArmoVehicle public class DrawArmoVehicle
{ {
public Base? Tank { get; protected set; } public EntityBase? Tank { get; protected set; }
protected int _pictureWidth; protected int _pictureWidth;
protected int _pictureHeight; protected int _pictureHeight;
protected int _startPosX; protected int _startPosX;
@ -22,13 +22,6 @@ namespace Tank
public int GetWidth => _Width; public int GetWidth => _Width;
public int GetHeight => _Height; public int GetHeight => _Height;
//==========ДОРАБОТКА================//
public bool CanStopObject(Direction direction)
{
return false;
}
//==================================//
public bool CanMove(Direction direction) public bool CanMove(Direction direction)
{ {
if (Tank == null) if (Tank == null)
@ -48,16 +41,20 @@ namespace Tank
{ {
_pictureHeight = height; _pictureHeight = height;
_pictureWidth = width; _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; _pictureHeight = height;
_pictureWidth = width; _pictureWidth = width;
_Height = tankHeight; _Height = tankHeight;
_Width = tankWidth; _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) 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) if (Tank == null)
return; return;
Brush BrushRandom = new SolidBrush(Tank?.BodyColor ?? Color.Black); Brush BrushRandom = new SolidBrush(Tank?.BodyColor ?? Color.Black);
//Корпус //Корпус
Brush WhiteColor = new SolidBrush(Color.White); Brush WhiteColor = new SolidBrush(Color.White);
g.FillRectangle(WhiteColor, _startPosX, _startPosY, 155, 30); g.FillRectangle(WhiteColor, _startPosX, _startPosY, 155, 30);

View File

@ -10,17 +10,17 @@ namespace Tank.DrawningObjects
{ {
public class DrawTank : DrawArmoVehicle public class DrawTank : DrawArmoVehicle
{ {
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)
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)
{ {
if (Tank != null) 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) public override void DrawTransport(Graphics g)
{ {
if (Tank is not AddBase ArmoVehicle) if (Tank is not EntityAddBase ArmoVehicle)
return; return;
base.DrawTransport(g); base.DrawTransport(g);
if (ArmoVehicle.BodyKit) if (ArmoVehicle.BodyKit)
@ -28,32 +28,25 @@ namespace Tank.DrawningObjects
Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor); 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), 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 + 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)}; 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); g.FillPolygon(bodyBrush, pointtower);
} }
if (ArmoVehicle.Rinks) if (ArmoVehicle.Caterpillar)
{ {
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush lineBrush = new SolidBrush(Color.Gray); 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); Brush BrushBlack = new SolidBrush(Color.Black);
g.FillEllipse(BrushBlack, _startPosX + 113, _startPosY + 41, 11, 11); g.FillEllipse(BrushBlack, _startPosX + 113, _startPosY + 41, 11, 11);
g.FillEllipse(BrushBlack, _startPosX + 13, _startPosY + 40, 11, 11); g.FillEllipse(BrushBlack, _startPosX + 13, _startPosY + 40, 11, 11);
} }
if (ArmoVehicle.Caterpillar) if (ArmoVehicle.Tower)
{ {
Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor); Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor);
// Орудие // Орудие

View File

@ -27,8 +27,5 @@ namespace Tank.MovementStrategy
public int GetStep => (int)(_drawTank?.Tank?.Step ?? 0); public int GetStep => (int)(_drawTank?.Tank?.Step ?? 0);
public bool CheckCanMove(Direction direction) => _drawTank?.CanMove(direction) ?? false; public bool CheckCanMove(Direction direction) => _drawTank?.CanMove(direction) ?? false;
public void MoveObject(Direction direction) => _drawTank?.MoveTransport(direction); public void MoveObject(Direction direction) => _drawTank?.MoveTransport(direction);
// Доработка
public bool CanStopObject(Direction direction) => _drawTank?.CanStopObject(direction) ?? false;
} }
} }

View File

@ -6,18 +6,18 @@ using System.Threading.Tasks;
namespace Tank.Entities namespace Tank.Entities
{ {
public class AddBase : Base public class EntityAddBase : EntityBase
{ {
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public bool BodyKit { get; private set; } public bool BodyKit { get; private set; }
public bool Caterpillar { get; private set; } public bool Caterpillar { get; private set; }
public bool Rinks { get; private set; } public bool Tower { get; private set; }
public AddBase(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool rinks) : base(speed, weight, bodyColor) public EntityAddBase(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool tower) : base(speed, weight, bodyColor)
{ {
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
BodyKit = bodyKit; BodyKit = bodyKit;
Caterpillar = caterpillar; Caterpillar = caterpillar;
Rinks = rinks; Tower = tower;
} }
} }
} }

View File

@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace Tank.Entities namespace Tank.Entities
{ {
public class Base public class EntityBase
{ {
public int Speed { get; private set; } public int Speed { get; private set; }
public double Weight { get; private set; } public double Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight; 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; Speed = speed;
Weight = weight; Weight = weight;

View File

@ -58,7 +58,7 @@
ButtonCreate.TabIndex = 1; ButtonCreate.TabIndex = 1;
ButtonCreate.Text = "Создание танка"; ButtonCreate.Text = "Создание танка";
ButtonCreate.UseVisualStyleBackColor = true; ButtonCreate.UseVisualStyleBackColor = true;
ButtonCreate.Click += ButtonCreate_Click; ButtonCreate.Click += ButtonCreateTank_Click;
// //
// keyDown // keyDown
// //
@ -161,7 +161,6 @@
Margin = new Padding(3, 4, 3, 4); Margin = new Padding(3, 4, 3, 4);
Name = "FormTank"; Name = "FormTank";
Text = "FormTank"; Text = "FormTank";
Load += FormTank_Load;
((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }

View File

@ -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(); Random rnd = new();
_Tank = new DrawTank(rnd.Next(100, 200), rnd.Next(2000, 4000), _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)),
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); pictureBoxTank.Width, pictureBoxTank.Height);
_Tank.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100)); _Tank.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
Draw(); Draw();
@ -102,10 +102,5 @@ namespace Tank
_abstractStrategy = null; _abstractStrategy = null;
} }
} }
private void FormTank_Load(object sender, EventArgs e)
{
}
} }
} }

View File

@ -12,9 +12,5 @@ namespace Tank.MovementStrategy
int GetStep { get; } int GetStep { get; }
bool CheckCanMove(Direction direction); bool CheckCanMove(Direction direction);
void MoveObject(Direction direction); void MoveObject(Direction direction);
// Доп задание
bool CanStopObject(Direction direction);
} }
} }