Правки в лабораторной 2
This commit is contained in:
parent
e0874c2924
commit
21ce7abbe3
@ -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);
|
||||
|
@ -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);
|
||||
// Орудие
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
3
Tank/Tank/FormTank.Designer.cs
generated
3
Tank/Tank/FormTank.Designer.cs
generated
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -12,9 +12,5 @@ namespace Tank.MovementStrategy
|
||||
int GetStep { get; }
|
||||
bool CheckCanMove(Direction direction);
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
|
||||
// Доп задание
|
||||
bool CanStopObject(Direction direction);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user