Compare commits
No commits in common. "35d382d5867259128b8a1d7f7f30adf3e5f5f1a1" and "698646124819a6b533d4a0fa323170171ecd355e" have entirely different histories.
35d382d586
...
6986461248
@ -10,34 +10,22 @@ namespace DumpTruck
|
|||||||
internal class DrawingTruck
|
internal class DrawingTruck
|
||||||
{
|
{
|
||||||
public EntityTruck? EntityTruck { get; private set; }
|
public EntityTruck? EntityTruck { get; private set; }
|
||||||
private int _startPosX;
|
private float _startPosX;
|
||||||
private int _startPosY;
|
private float _startPosY;
|
||||||
private int _pictureWidth;
|
private int? _pictureWidth;
|
||||||
private int _pictureHeight;
|
private int? _pictureHeight;
|
||||||
protected readonly int _truckWidth = 100;
|
protected readonly int _truckWidth = 110;
|
||||||
protected readonly int _truckHeight = 50;
|
protected readonly int _truckHeight = 60;
|
||||||
public bool Init(int speed, float weight, Color bodyColor, Color additionalColor, int width, int height, bool threeWheels, bool dump)
|
public bool Init(int speed, float weight, Color bodyColor, int width, int height)
|
||||||
{
|
{
|
||||||
if (width < _truckWidth || height < _truckHeight)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
EntityTruck = new EntityTruck();
|
EntityTruck = new EntityTruck();
|
||||||
EntityTruck.Init(speed, weight, bodyColor, additionalColor, threeWheels, dump);
|
EntityTruck.Init(speed, weight, bodyColor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public void SetPosition(int x, int y)
|
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;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
@ -81,9 +69,9 @@ namespace DumpTruck
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void DrawTransport(Graphics g, Color bodyColor, Color additionalColor)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityTruck == null)
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -92,7 +80,7 @@ namespace DumpTruck
|
|||||||
Brush br = new SolidBrush(EntityTruck?.BodyColor ?? Color.Black);
|
Brush br = new SolidBrush(EntityTruck?.BodyColor ?? Color.Black);
|
||||||
g.FillRectangle(br, _startPosX + 80, _startPosY, 20, 30);
|
g.FillRectangle(br, _startPosX + 80, _startPosY, 20, 30);
|
||||||
|
|
||||||
Brush brBodyRandom = new SolidBrush(bodyColor);
|
Brush brBodyRandom = new SolidBrush(Color.FromArgb(0, 255, 128));
|
||||||
g.FillRectangle(brBodyRandom, _startPosX, _startPosY + 30, 100, 5);
|
g.FillRectangle(brBodyRandom, _startPosX, _startPosY + 30, 100, 5);
|
||||||
|
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
@ -113,10 +101,8 @@ namespace DumpTruck
|
|||||||
g.DrawEllipse(pen, _startPosX + 22, _startPosY + 35, 20, 20);
|
g.DrawEllipse(pen, _startPosX + 22, _startPosY + 35, 20, 20);
|
||||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
|
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
|
||||||
|
|
||||||
|
Brush brBody = new SolidBrush(Color.FromArgb(255, 0, 0));
|
||||||
//Brush brBody = new SolidBrush(EntityTruck?.AdditionalColor ?? Color.Red);
|
g.FillRectangle(brBody, _startPosX + 0, _startPosY, 70, 30);
|
||||||
Brush brBodyAdditional = new SolidBrush(additionalColor);
|
|
||||||
g.FillRectangle(brBodyAdditional, _startPosX + 0, _startPosY, 70, 30);
|
|
||||||
Pen pen1 = new Pen(Color.Black);
|
Pen pen1 = new Pen(Color.Black);
|
||||||
g.DrawRectangle(pen1, _startPosX + 0, _startPosY, 70, 30);
|
g.DrawRectangle(pen1, _startPosX + 0, _startPosY, 70, 30);
|
||||||
|
|
||||||
|
@ -14,22 +14,14 @@ namespace DumpTruck
|
|||||||
public float Weight { get; private set; }
|
public float Weight { get; private set; }
|
||||||
|
|
||||||
public Color BodyColor { 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 float Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, bool threeWheels, bool dump)
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
ThreeWheels = threeWheels;
|
|
||||||
Dump = dump;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,11 +23,10 @@ namespace DumpTruck
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Random rnd = new Random();
|
|
||||||
Bitmap bmp = new(pictureBoxTruck.Width,
|
Bitmap bmp = new(pictureBoxTruck.Width,
|
||||||
pictureBoxTruck.Height);
|
pictureBoxTruck.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningTruck.DrawTransport(gr, Color.FromArgb(0,255,128),Color.FromArgb(255,0,0));
|
_drawningTruck.DrawTransport(gr);
|
||||||
pictureBoxTruck.Image = bmp;
|
pictureBoxTruck.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,8 +39,8 @@ namespace DumpTruck
|
|||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningTruck = new DrawingTruck();
|
_drawningTruck = new DrawingTruck();
|
||||||
_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.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256)), pictureBoxTruck.Width, pictureBoxTruck.Height);
|
||||||
_drawningTruck.SetPosition(random.Next(1, 100), random.Next(1, 100));
|
_drawningTruck.SetPosition(random.Next(1, pictureBoxTruck.Width), random.Next(1, pictureBoxTruck.Height));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user