Compare commits

...

2 Commits

3 changed files with 40 additions and 17 deletions

View File

@ -10,22 +10,34 @@ namespace DumpTruck
internal class DrawingTruck
{
public EntityTruck? EntityTruck { get; private set; }
private float _startPosX;
private float _startPosY;
private int? _pictureWidth;
private int? _pictureHeight;
protected readonly int _truckWidth = 110;
protected readonly int _truckHeight = 60;
public bool Init(int speed, float weight, Color bodyColor, int width, int height)
private int _startPosX;
private int _startPosY;
private int _pictureWidth;
private int _pictureHeight;
protected readonly int _truckWidth = 100;
protected readonly int _truckHeight = 50;
public bool Init(int speed, float weight, Color bodyColor, Color additionalColor, int width, int height, bool threeWheels, bool dump)
{
if (width < _truckWidth || height < _truckHeight)
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
EntityTruck = new EntityTruck();
EntityTruck.Init(speed, weight, bodyColor);
EntityTruck.Init(speed, weight, bodyColor, additionalColor, threeWheels, dump);
return true;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x + _truckWidth > _pictureWidth)
{
x = _pictureWidth - _truckWidth;
}
if (y < 0 || y + _truckHeight > _pictureHeight)
{
y = _pictureHeight - _truckHeight;
}
_startPosX = x;
_startPosY = y;
}
@ -69,9 +81,9 @@ namespace DumpTruck
}
public void DrawTransport(Graphics g)
public void DrawTransport(Graphics g, Color bodyColor, Color additionalColor)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
if (EntityTruck == null)
{
return;
}
@ -80,7 +92,7 @@ namespace DumpTruck
Brush br = new SolidBrush(EntityTruck?.BodyColor ?? Color.Black);
g.FillRectangle(br, _startPosX + 80, _startPosY, 20, 30);
Brush brBodyRandom = new SolidBrush(Color.FromArgb(0, 255, 128));
Brush brBodyRandom = new SolidBrush(bodyColor);
g.FillRectangle(brBodyRandom, _startPosX, _startPosY + 30, 100, 5);
Brush brBlack = new SolidBrush(Color.Black);
@ -101,8 +113,10 @@ namespace DumpTruck
g.DrawEllipse(pen, _startPosX + 22, _startPosY + 35, 20, 20);
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
Brush brBody = new SolidBrush(Color.FromArgb(255, 0, 0));
g.FillRectangle(brBody, _startPosX + 0, _startPosY, 70, 30);
//Brush brBody = new SolidBrush(EntityTruck?.AdditionalColor ?? Color.Red);
Brush brBodyAdditional = new SolidBrush(additionalColor);
g.FillRectangle(brBodyAdditional, _startPosX + 0, _startPosY, 70, 30);
Pen pen1 = new Pen(Color.Black);
g.DrawRectangle(pen1, _startPosX + 0, _startPosY, 70, 30);

View File

@ -14,14 +14,22 @@ namespace DumpTruck
public float Weight { get; private set; }
public Color BodyColor { get; private set; }
public Color AdditionalColor { get; private set; }
public bool ThreeWheels { get; private set; }
public bool Dump { get; private set; }
public float Step => Speed * 100 / Weight;
public void Init(int speed, float weight, Color bodyColor)
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, bool threeWheels, bool dump)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
ThreeWheels = threeWheels;
Dump = dump;
}
}
}

View File

@ -23,10 +23,11 @@ namespace DumpTruck
{
return;
}
Random rnd = new Random();
Bitmap bmp = new(pictureBoxTruck.Width,
pictureBoxTruck.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningTruck.DrawTransport(gr);
_drawningTruck.DrawTransport(gr, Color.FromArgb(0,255,128),Color.FromArgb(255,0,0));
pictureBoxTruck.Image = bmp;
}
@ -39,8 +40,8 @@ namespace DumpTruck
{
Random random = new();
_drawningTruck = new DrawingTruck();
_drawningTruck.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256)), pictureBoxTruck.Width, pictureBoxTruck.Height);
_drawningTruck.SetPosition(random.Next(1, pictureBoxTruck.Width), random.Next(1, pictureBoxTruck.Height));
_drawningTruck.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256)), Color.FromArgb(random.Next(0,256)), pictureBoxTruck.Width, pictureBoxTruck.Height);
_drawningTruck.SetPosition(random.Next(1, 100), random.Next(1, 100));
Draw();
}