Изменение init функций на конструкторы
This commit is contained in:
parent
7a1e35c6a4
commit
6d5e7b10c0
@ -18,7 +18,7 @@ namespace DoubleDeckerBus
|
|||||||
private readonly int _busWidth = 100;
|
private readonly int _busWidth = 100;
|
||||||
private readonly int _busHeight = 50;
|
private readonly int _busHeight = 50;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor) {
|
public DrawningBus(int speed, float weight, Color bodyColor) {
|
||||||
Bus = new EntityBus();
|
Bus = new EntityBus();
|
||||||
Bus.Init(speed, weight, bodyColor);
|
Bus.Init(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
@ -74,23 +74,20 @@ namespace DoubleDeckerBus
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
//границы автобсуса
|
|
||||||
g.DrawRectangle(pen, _startPosX - 1, _startPosY + 11, 100, 30);
|
g.DrawRectangle(pen, _startPosX - 1, _startPosY + 11, 100, 30);
|
||||||
Brush brBodyColor = new SolidBrush(Bus.BodyColor);
|
Brush brBodyColor = new SolidBrush(Bus.BodyColor);
|
||||||
g.FillRectangle(brBodyColor, _startPosX, _startPosY + 10, 100, 30);
|
g.FillRectangle(brBodyColor, _startPosX, _startPosY + 10, 100, 30);
|
||||||
|
|
||||||
//Дверь
|
|
||||||
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20);
|
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20);
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20);
|
g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20);
|
||||||
|
|
||||||
//Колеса
|
|
||||||
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 35, 10, 10);
|
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 35, 10, 10);
|
||||||
g.DrawEllipse(pen, _startPosX + 77, _startPosY + 35, 10, 10);
|
g.DrawEllipse(pen, _startPosX + 77, _startPosY + 35, 10, 10);
|
||||||
g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 35, 10, 10);
|
g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 35, 10, 10);
|
||||||
g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 35, 10, 10);
|
g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 35, 10, 10);
|
||||||
|
|
||||||
//окна
|
|
||||||
Brush brBlue = new SolidBrush(Color.Blue);
|
Brush brBlue = new SolidBrush(Color.Blue);
|
||||||
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15);
|
g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15);
|
||||||
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15);
|
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15);
|
||||||
|
@ -12,7 +12,7 @@ namespace DoubleDeckerBus
|
|||||||
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 float Step => Speed * 100 / Weight;
|
public float Step => Speed * 100 / Weight;
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityBus(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = (speed <= 0) ? rnd.Next(50, 150) : speed;
|
Speed = (speed <= 0) ? rnd.Next(50, 150) : speed;
|
||||||
|
@ -19,8 +19,7 @@ namespace DoubleDeckerBus
|
|||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_bus = new DrawningBus();
|
_bus = new DrawningBus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
_bus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
_bus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBus.Width, pictureBoxBus.Height);
|
_bus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBus.Width, pictureBoxBus.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_bus.Bus.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_bus.Bus.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_bus.Bus.Weight}";
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_bus.Bus.Weight}";
|
||||||
@ -30,7 +29,6 @@ namespace DoubleDeckerBus
|
|||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//ïîëó÷àåì èìÿ êíîïêè
|
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user