Sdano
This commit is contained in:
parent
025bd88523
commit
d1f9a5eead
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms.VisualStyles;
|
using System.Windows.Forms.VisualStyles;
|
||||||
@ -10,35 +11,38 @@ namespace ElectricLocomotive
|
|||||||
{
|
{
|
||||||
public class DrawningElectricLocomotive
|
public class DrawningElectricLocomotive
|
||||||
{
|
{
|
||||||
private EntityElectricLocomotive enitity_electric_locomotive = new EntityElectricLocomotive();
|
public EntityElectricLocomotive? _ElectricLocomotive { get; private set; }
|
||||||
|
|
||||||
|
private int _pictureWidth;
|
||||||
|
|
||||||
|
private int _pictureHeight;
|
||||||
|
|
||||||
|
|
||||||
private int _startPosX;
|
private int _startPosX;
|
||||||
|
|
||||||
private int _startPosY;
|
private int _startPosY;
|
||||||
|
|
||||||
private const int _LengthLocomotive = 120;
|
private readonly int _LocomotiveWidth = 100;
|
||||||
|
|
||||||
private const int _HeightLocomorive=90;
|
private readonly int _LocomoriveHeight =50;
|
||||||
|
|
||||||
|
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor)
|
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns, int width, int height)
|
||||||
{
|
{
|
||||||
if (speed < 0 || bodyColor == additionalColor)
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
if ((_pictureHeight < _LocomoriveHeight) || (_pictureWidth < _LocomotiveWidth))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
_ElectricLocomotive = new EntityElectricLocomotive();
|
||||||
{
|
_ElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, horns);
|
||||||
enitity_electric_locomotive.Init(speed, weight, bodyColor, additionalColor);
|
return true;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
if (x < 0 || y < 0 || x + _LengthLocomotive > ElectricLocomotive.ActiveForm.Size.Width || y + _HeightLocomorive > ElectricLocomotive.ActiveForm.Size.Height)
|
if (x < 0 || y < 0 || x + _LocomotiveWidth > _pictureWidth || y + _LocomoriveHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
@ -52,7 +56,7 @@ namespace ElectricLocomotive
|
|||||||
|
|
||||||
public void MoveTransport(DirectionType direction)
|
public void MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (enitity_electric_locomotive == null)
|
if (_ElectricLocomotive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -61,33 +65,33 @@ namespace ElectricLocomotive
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX - enitity_electric_locomotive.Step > 0)
|
if (_startPosX - _ElectricLocomotive.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)enitity_electric_locomotive.Step;
|
_startPosX -= (int)_ElectricLocomotive.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY - enitity_electric_locomotive.Step > 0)
|
if (_startPosY - _ElectricLocomotive.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)enitity_electric_locomotive.Step;
|
_startPosY -= (int)_ElectricLocomotive.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right: // TODO: Продумать логику
|
case DirectionType.Right: // TODO: Продумать логику
|
||||||
if (_startPosX+_LengthLocomotive+(int)enitity_electric_locomotive.Step < ElectricLocomotive.ActiveForm.Size.Width)
|
if (_startPosX+ _LocomotiveWidth + (int)_ElectricLocomotive.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)enitity_electric_locomotive.Step;
|
_startPosX += (int)_ElectricLocomotive.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down: // TODO: Продумать логику
|
case DirectionType.Down: // TODO: Продумать логику
|
||||||
if (_startPosY + _HeightLocomorive + (int)enitity_electric_locomotive.Step < ElectricLocomotive.ActiveForm.Size.Height)
|
if (_startPosY + _LocomoriveHeight + (int)_ElectricLocomotive.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)enitity_electric_locomotive.Step;
|
_startPosY += (int)_ElectricLocomotive.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -98,13 +102,13 @@ namespace ElectricLocomotive
|
|||||||
|
|
||||||
public void DrawTransport(Graphics g)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (enitity_electric_locomotive == null)
|
if (_ElectricLocomotive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(enitity_electric_locomotive.AdditionalColor);
|
Pen pen = new(_ElectricLocomotive.AdditionalColor);
|
||||||
Brush brush = new SolidBrush(enitity_electric_locomotive.BodyColor);
|
Brush brush = new SolidBrush(_ElectricLocomotive.BodyColor);
|
||||||
|
|
||||||
///ВЛ60к-1595
|
///ВЛ60к-1595
|
||||||
|
|
||||||
@ -165,33 +169,35 @@ namespace ElectricLocomotive
|
|||||||
g.FillRectangle(brush, _startPosX + 50, _startPosY + 15, 10, 25);
|
g.FillRectangle(brush, _startPosX + 50, _startPosY + 15, 10, 25);
|
||||||
|
|
||||||
///рога
|
///рога
|
||||||
g.FillRectangle(brush, _startPosX + 25, _startPosY + 5, 15, 5);
|
if (_ElectricLocomotive.Horns == true)
|
||||||
|
|
||||||
Point[] horns =
|
|
||||||
{
|
{
|
||||||
new Point(_startPosX+25, _startPosY+10),
|
g.FillRectangle(brush, _startPosX + 25, _startPosY + 5, 15, 5);
|
||||||
new Point(_startPosX+25, _startPosY+5),
|
|
||||||
new Point(_startPosX+33,_startPosY+5),
|
|
||||||
new Point(_startPosX+50, _startPosY),
|
|
||||||
new Point(_startPosX+33,_startPosY+5),
|
|
||||||
new Point(_startPosX+40,_startPosY+5),
|
|
||||||
new Point(_startPosX+40,_startPosY+10)
|
|
||||||
};
|
|
||||||
g.DrawPolygon(pen, horns);
|
|
||||||
|
|
||||||
g.FillRectangle(brush, _startPosX + 65, _startPosY + 5, 15, 5);
|
Point[] horns =
|
||||||
Point[] horns2 =
|
{
|
||||||
{
|
new Point(_startPosX+25, _startPosY+10),
|
||||||
new Point(_startPosX+65, _startPosY+10),
|
new Point(_startPosX+25, _startPosY+5),
|
||||||
new Point(_startPosX+65, _startPosY+5),
|
new Point(_startPosX+33,_startPosY+5),
|
||||||
new Point(_startPosX+73,_startPosY+5),
|
new Point(_startPosX+50, _startPosY),
|
||||||
new Point(_startPosX+90, _startPosY),
|
new Point(_startPosX+33,_startPosY+5),
|
||||||
new Point(_startPosX+73,_startPosY+5),
|
new Point(_startPosX+40,_startPosY+5),
|
||||||
new Point(_startPosX+80,_startPosY+5),
|
new Point(_startPosX+40,_startPosY+10)
|
||||||
new Point(_startPosX+80,_startPosY+10)
|
};
|
||||||
};
|
g.DrawPolygon(pen, horns);
|
||||||
g.DrawPolygon(pen, horns2);
|
|
||||||
|
|
||||||
|
g.FillRectangle(brush, _startPosX + 65, _startPosY + 5, 15, 5);
|
||||||
|
Point[] horns2 =
|
||||||
|
{
|
||||||
|
new Point(_startPosX+65, _startPosY+10),
|
||||||
|
new Point(_startPosX+65, _startPosY+5),
|
||||||
|
new Point(_startPosX+73,_startPosY+5),
|
||||||
|
new Point(_startPosX+90, _startPosY),
|
||||||
|
new Point(_startPosX+73,_startPosY+5),
|
||||||
|
new Point(_startPosX+80,_startPosY+5),
|
||||||
|
new Point(_startPosX+80,_startPosY+10)
|
||||||
|
};
|
||||||
|
g.DrawPolygon(pen, horns2);
|
||||||
|
}
|
||||||
///Батарея
|
///Батарея
|
||||||
g.FillRectangle(brush, _startPosX + 45, _startPosY + 5, 15, 5);
|
g.FillRectangle(brush, _startPosX + 45, _startPosY + 5, 15, 5);
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ namespace ElectricLocomotive
|
|||||||
_drawningElectricLocomotive = new DrawningElectricLocomotive();
|
_drawningElectricLocomotive = new DrawningElectricLocomotive();
|
||||||
_drawningElectricLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000),
|
_drawningElectricLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height);
|
||||||
|
|
||||||
_drawningElectricLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningElectricLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
|
||||||
Draw();
|
Draw();
|
||||||
|
@ -8,28 +8,49 @@ namespace ElectricLocomotive
|
|||||||
{
|
{
|
||||||
public class EntityElectricLocomotive
|
public class EntityElectricLocomotive
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
public double Weight { get; private set; }
|
public double Weight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
|
/// </summary>
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия обвеса
|
||||||
|
/// </summary>
|
||||||
|
public bool Horns { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) roga
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight; ///свойство с лямбда выражением
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей объекта-класса электролокоматива
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="Horns">Признак наличия рогов</param>
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor)
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns)
|
||||||
{
|
{
|
||||||
|
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
|
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
|
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
|
Horns = horns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user