Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
238312a1ad |
4
.gitignore
vendored
4
.gitignore
vendored
@ -412,3 +412,7 @@ FodyWeavers.xsd
|
|||||||
# Built Visual Studio Code Extensions
|
# Built Visual Studio Code Extensions
|
||||||
*.vsix
|
*.vsix
|
||||||
|
|
||||||
|
/DoubleDeckerBus/DoubleDeckerBus/Form1.Designer.cs
|
||||||
|
/DoubleDeckerBus/DoubleDeckerBus/Form1.cs
|
||||||
|
/DoubleDeckerBus/DoubleDeckerBus/Form1.Designer.cs
|
||||||
|
/DoubleDeckerBus/DoubleDeckerBus/Form1.resx
|
||||||
|
27
DoubleDeckerBus/DoubleDeckerBus/DirectionType.cs
Normal file
27
DoubleDeckerBus/DoubleDeckerBus/DirectionType.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
namespace DoubleDeckerBus;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
154
DoubleDeckerBus/DoubleDeckerBus/DrawingDDB.cs
Normal file
154
DoubleDeckerBus/DoubleDeckerBus/DrawingDDB.cs
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение Автобуса
|
||||||
|
/// </summary>
|
||||||
|
public class DrawingDDB
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityDDB? EntityDDB {get; private set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
public int? _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
public int? _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Левая координата прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private int? _startPosX;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя координата прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private int? _startPosY;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина прорисовки автобуса
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _drawingBusWidth = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота прорисовки автобуса
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _drawingBusHeight = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Осн.цвет</param>
|
||||||
|
/// <param name="additionalColor">Доп.цвет</param>
|
||||||
|
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||||
|
/// <param name="busLine">Признак наличия автобусной полосы</param>
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool busLine)
|
||||||
|
{
|
||||||
|
EntityDDB = new EntityDDB();
|
||||||
|
EntityDDB.Init(speed, weight, bodyColor, additionalColor, bodyKit, busLine);
|
||||||
|
_pictureHeight = null;
|
||||||
|
_pictureWidth = null;
|
||||||
|
_startPosX = null;
|
||||||
|
_startPosY = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка границ поля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool SetPictureSize(int width, int height)
|
||||||
|
{
|
||||||
|
if (_pictureWidth != null) { }
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x"></param>
|
||||||
|
/// <param name="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 (EntityDDB == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(direction)
|
||||||
|
{
|
||||||
|
// влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
if(_startPosX.Value - EntityDDB.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityDDB.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY.Value - EntityDDB.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityDDB.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
if(_startPosX.Value - EntityDDB.Step < 0)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityDDB.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
if(_startPosY.Value - EntityDDB.Step < 0)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityDDB.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if(EntityDDB == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
DoubleDeckerBus/DoubleDeckerBus/EntityDDB.cs
Normal file
56
DoubleDeckerBus/DoubleDeckerBus/EntityDDB.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
namespace DoubleDeckerBus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Двухэтажный автобус"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityDDB
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; 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 BusLine { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения автобуса
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 50 / 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="busLine">Признак наличия автобусной полосы</param>
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool busLine)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
BodyKit = bodyKit;
|
||||||
|
BusLine = busLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace DoubleDeckerBus
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
namespace DoubleDeckerBus
|
namespace DoubleDeckerBus
|
||||||
{
|
{
|
||||||
partial class Form1
|
partial class FormDDB
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -28,10 +28,16 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
SuspendLayout();
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
//
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
// FormDDB
|
||||||
this.Text = "Form1";
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 21F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Name = "FormDDB";
|
||||||
|
Text = "Двухэтажный автобус";
|
||||||
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
20
DoubleDeckerBus/DoubleDeckerBus/FormDDB.cs
Normal file
20
DoubleDeckerBus/DoubleDeckerBus/FormDDB.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace DoubleDeckerBus
|
||||||
|
{
|
||||||
|
public partial class FormDDB : Form
|
||||||
|
{
|
||||||
|
public FormDDB()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user