Update
This commit is contained in:
parent
ff66c04cfb
commit
3713f5cb1e
@ -1,8 +1,74 @@
|
|||||||
|
namespace ProjectBus;
|
||||||
namespace ProjectMain
|
/// <summary>
|
||||||
|
/// Êëàññ-ñóùíîñòü "Ñïîðòèâíûé àâòîìîáèëü"
|
||||||
|
/// </summary>
|
||||||
|
private void ShowPropertiesOfSlateBlue(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
public class Class1
|
Color slateBlue = Color.FromName("SlateBlue");
|
||||||
{
|
byte g = slateBlue.G;
|
||||||
}
|
byte b = slateBlue.B;
|
||||||
|
byte r = slateBlue.R;
|
||||||
|
byte a = slateBlue.A;
|
||||||
|
string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " +
|
||||||
|
"red:{1}, green: {2}, blue {3}", new object[] { a, r, g, b });
|
||||||
|
e.Graphics.DrawString(text,
|
||||||
|
new Font(this.Font, FontStyle.Italic),
|
||||||
|
new SolidBrush(slateBlue),
|
||||||
|
new RectangleF(new PointF(0.0F, 0.0F), this.Size));
|
||||||
|
}
|
||||||
|
public class EntityBus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ñêîðîñòü
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Âåñ
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Îñíîâíîé öâåò
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Äîïîëíèòåëüíûé öâåò (äëÿ îïöèîíàëüíûõ ýëåìåíòîâ)
|
||||||
|
/// </summary>
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Ïðèçíàê (îïöèÿ) íàëè÷èÿ îáâåñà
|
||||||
|
/// </summary>
|
||||||
|
public bool BodyKit { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Ïðèçíàê (îïöèÿ) íàëè÷èÿ àíòèêðûëà
|
||||||
|
/// </summary>
|
||||||
|
public bool Wing { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Ïðèçíàê (îïöèÿ) íàëè÷èÿ ãîíî÷íîé ïîëîñû
|
||||||
|
/// </summary>
|
||||||
|
public bool SportLine { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Øàã ïåðåìåùåíèÿ àâòîìîáèëÿ
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 100 / Weight;
|
||||||
|
/// <summary>
|
||||||
|
/// Èíèöèàëèçàöèÿ ïîëåé îáúåêòà-êëàññà ñïîðòèâíîãî àâòîìîáèëÿ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Ñêîðîñòü</param>
|
||||||
|
/// <param name="weight">Âåñ àâòîìîáèëÿ</param>
|
||||||
|
/// <param name="bodyColor">Îñíîâíîé öâåò</param>
|
||||||
|
/// <param name="additionalColor">Äîïîëíèòåëüíûé öâåò</param>
|
||||||
|
/// <param name="bodyKit">Ïðèçíàê íàëè÷èÿ îáâåñà</param>
|
||||||
|
/// <param name="wing">Ïðèçíàê íàëè÷èÿ àíòèêðûëà</param>
|
||||||
|
/// <param name="sportLine">Ïðèçíàê íàëè÷èÿ ãîíî÷íîé ïîëîñû</param>
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
BodyKit = bodyKit;
|
||||||
|
Wing = wing;
|
||||||
|
SportLine = sportLine;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
29
ProjectMain/ProjectMain/DirectionType.cs
Normal file
29
ProjectMain/ProjectMain/DirectionType.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectMain;
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
277
ProjectMain/ProjectMain/DrawningBus.cs
Normal file
277
ProjectMain/ProjectMain/DrawningBus.cs
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using ProjectBus;
|
||||||
|
|
||||||
|
namespace ProjectMain;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningSportCar
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityBus? EntityBus { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
private int? _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
private int? _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Левая координата прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private int? _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя кооридната прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private int? _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _drawningCarWidth = 110;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота прорисовки автомобиля
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _drawningCarHeight = 60;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||||
|
/// <param name="wing">Признак наличия антикрыла</param>
|
||||||
|
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||||
|
{
|
||||||
|
EntityBus = new EntityBus();
|
||||||
|
EntityBus.Init(speed, weight, bodyColor, additionalColor,
|
||||||
|
bodyKit, wing, sportLine);
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
_startPosX = null;
|
||||||
|
_startPosY = null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка границ поля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||||
|
public bool SetPictureSize(int width, int height)
|
||||||
|
{
|
||||||
|
// TODO проверка, что объект "влезает" в размеры поля
|
||||||
|
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||||
|
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
|
public bool MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityBus == null || !_startPosX.HasValue ||
|
||||||
|
!_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX.Value - EntityBus.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
//вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY.Value - EntityBus.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPosX.Value - EntityBus.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
//вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY.Value - EntityBus.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityBus.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityBus == null || !_startPosX.HasValue ||
|
||||||
|
!_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new
|
||||||
|
SolidBrush(EntityBus.AdditionalColor);
|
||||||
|
// обвесы
|
||||||
|
if (EntityBus.BodyKit)
|
||||||
|
{
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value,
|
||||||
|
20, 20);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value +
|
||||||
|
40, 20, 20);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value +
|
||||||
|
10, 20, 40);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value,
|
||||||
|
15, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value +
|
||||||
|
45, 15, 15);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 90,
|
||||||
|
_startPosY.Value, 20, 20);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 90,
|
||||||
|
_startPosY.Value + 40, 20, 20);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 90,
|
||||||
|
_startPosY.Value + 10, 20, 40);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 90,
|
||||||
|
_startPosY.Value + 1, 15, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 90,
|
||||||
|
_startPosY.Value + 45, 15, 15);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value, 20,
|
||||||
|
20);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 40,
|
||||||
|
20, 20);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 10,
|
||||||
|
20, 40);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value,
|
||||||
|
14, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value +
|
||||||
|
45, 14, 15);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value,
|
||||||
|
_startPosY.Value, 20, 20);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value,
|
||||||
|
_startPosY.Value + 40, 20, 20);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 1,
|
||||||
|
_startPosY.Value + 10, 25, 40);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 5,
|
||||||
|
_startPosY.Value + 1, 15, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 5,
|
||||||
|
_startPosY.Value + 45, 15, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value,
|
||||||
|
39, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value +
|
||||||
|
45, 39, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
|
||||||
|
_startPosY.Value + 1, 40, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
|
||||||
|
_startPosY.Value + 45, 40, 15);
|
||||||
|
}
|
||||||
|
//границы автомобиля
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20,
|
||||||
|
20);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20,
|
||||||
|
20);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20,
|
||||||
|
20);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20,
|
||||||
|
20);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10,
|
||||||
|
30);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15,
|
||||||
|
10, 30);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70,
|
||||||
|
52);
|
||||||
|
//задние фары
|
||||||
|
Brush brRed = new SolidBrush(Color.Red);
|
||||||
|
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 5, 20,
|
||||||
|
20);
|
||||||
|
g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 35,
|
||||||
|
20, 20);
|
||||||
|
//передние фары
|
||||||
|
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||||
|
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 5,
|
||||||
|
20, 20);
|
||||||
|
g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 35,
|
||||||
|
20, 20);
|
||||||
|
//кузов
|
||||||
|
Brush br = new SolidBrush(EntitySportCar.BodyColor);
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10,
|
||||||
|
30);
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10,
|
||||||
|
30);
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70,
|
||||||
|
50);
|
||||||
|
//стекла
|
||||||
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
|
g.FillRectangle(brBlue, _startPosX.Value + 70, _startPosY.Value + 10,
|
||||||
|
5, 40);
|
||||||
|
g.FillRectangle(brBlue, _startPosX.Value + 30, _startPosY.Value + 10,
|
||||||
|
5, 40);
|
||||||
|
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 8,
|
||||||
|
35, 2);
|
||||||
|
g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 51,
|
||||||
|
35, 2);
|
||||||
|
//выделяем рамкой крышу
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 10,
|
||||||
|
35, 40);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 15,
|
||||||
|
25, 30);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15,
|
||||||
|
15, 30);
|
||||||
|
// спортивная линия
|
||||||
|
if (EntityBus.SportLine)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 75,
|
||||||
|
_startPosY.Value + 23, 25, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 35,
|
||||||
|
_startPosY.Value + 23, 35, 15);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 10,
|
||||||
|
_startPosY.Value + 23, 20, 15);
|
||||||
|
}
|
||||||
|
// крыло
|
||||||
|
if (EntityBus.Wing)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value,
|
||||||
|
_startPosY.Value + 5, 10, 50);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5,
|
||||||
|
10, 50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user