This commit is contained in:
Honor 2025-02-14 16:34:27 +04:00
parent 4707153231
commit b43ada09a7
4 changed files with 106 additions and 131 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35303.130
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectMonorail", "ProjectMonorail\ProjectMonorail.csproj", "{FFFB69FA-2DD3-4887-B6FC-9BA8B6F356A2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectMonorail", "ProjectMonorail\ProjectMonorail.csproj", "{FFFB69FA-2DD3-4887-B6FC-9BA8B6F356A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,4 +1,6 @@
namespace ProjectMonorail;
using static System.Windows.Forms.AxHost;
namespace ProjectMonorail;
public class DrawningMonorail
{
@ -25,11 +27,20 @@ public class DrawningMonorail
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _drawningWidth = 140;
private readonly int _drawningWidth = 110;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _drawningHeight = 60;
private readonly int _drawningHeight = 56;
/// <summary>
/// Минимальный отступ слева
/// </summary>
private readonly int minLeftMargin = 0;
/// <summary>
/// Минимальный отступ сверху
/// </summary>
private readonly int minTopMargin = 0;
/// <summary>
/// Инициализация свойств
/// </summary>
@ -48,6 +59,7 @@ public class DrawningMonorail
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Установка границ поля
/// </summary>
@ -56,8 +68,6 @@ public class DrawningMonorail
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
// проверка, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
if (width >= _drawningWidth && height >= _drawningHeight)
{
_pictureWidth = width;
@ -66,6 +76,7 @@ public class DrawningMonorail
}
return false;
}
/// <summary>
/// Установка позиции
/// </summary>
@ -77,8 +88,10 @@ public class DrawningMonorail
{
return;
}
// если при установке объекта в эти координаты, он будет "выходить" за границы формы
// то надо изменить координаты, чтобы он оставался в этих границах
// Проверка на минимальные отступы
x = Math.Max(x, minLeftMargin);
y = Math.Max(y, minTopMargin);
if (x + 140 > _pictureWidth.Value)
{
@ -92,6 +105,7 @@ public class DrawningMonorail
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
@ -103,31 +117,27 @@ public class DrawningMonorail
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityMonorail.Step > 0)
if (_startPosX.Value - EntityMonorail.Step > minLeftMargin)
{
_startPosX -= (int)EntityMonorail.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityMonorail.Step > 0)
if (_startPosY.Value - EntityMonorail.Step > minTopMargin)
{
_startPosY -= (int)EntityMonorail.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + EntityMonorail.Step + _drawningWidth < _pictureWidth)
{
_startPosX += (int)EntityMonorail.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityMonorail.Step + _drawningHeight < _pictureHeight)
{
@ -138,6 +148,7 @@ public class DrawningMonorail
return false;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
@ -149,109 +160,72 @@ public class DrawningMonorail
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new
SolidBrush(EntityMonorail.AdditionalColor);
Brush additionalBrush = new SolidBrush(EntityMonorail.AdditionalColor);
Brush BodyBrush = new SolidBrush(EntityMonorail.BodyColor);
Brush CraneBrush = new SolidBrush(Color.Black);
//магнитная рельса
if (EntityMonorail.MagneticRail)
{
g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 48, 130, 5);
}
//вторая кабина
//корпус
g.FillRectangle(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.FillRectangle(BodyBrush, _startPosX.Value + 22, _startPosY.Value + 16, 4, 15);
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 16, 4, 14);
g.FillRectangle(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 8, 5, 23);
g.DrawRectangle(pen, _startPosX.Value + 37, _startPosY.Value + 8, 5, 22);
if (EntityMonorail.SecondCabin)
{
Point[] second_cabin = {
new Point(_startPosX.Value + 125, _startPosY.Value),
new Point(_startPosX.Value + 132, _startPosY.Value + 20),
new Point(_startPosX.Value + 132, _startPosY.Value + 40),
new Point(_startPosX.Value + 125, _startPosY.Value + 40),
new Point(_startPosX.Value + 125, _startPosY.Value + 20),
new Point(_startPosX.Value + 132, _startPosY.Value + 20)
};
g.DrawPolygon(pen, second_cabin);
g.FillPolygon(additionalBrush, second_cabin);
}
// Границы
Brush brush = new SolidBrush(EntityMonorail.BodyColor);
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20, 120, 20);
Point[] p1 = {
new Point(_startPosX.Value + 12, _startPosY.Value),
new Point(_startPosX.Value + 125, _startPosY.Value),
new Point(_startPosX.Value + 125, _startPosY.Value + 20),
new Point(_startPosX.Value + 5, _startPosY.Value + 20)
};
g.DrawPolygon(pen, p1);
// Окрас
g.FillRectangle(brush, _startPosX.Value + 6, _startPosY.Value + 21, 119, 19);
Point[] p2 = {
new Point(_startPosX.Value + 12, _startPosY.Value + 1),
new Point(_startPosX.Value + 125, _startPosY.Value + 1),
new Point(_startPosX.Value + 125, _startPosY.Value + 20),
new Point(_startPosX.Value + 5, _startPosY.Value + 20)
};
g.FillPolygon(brush, p2);
//дверь
Brush brWhite = new SolidBrush(Color.White);
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 8, 10, 25);
g.FillRectangle(brWhite, _startPosX.Value + 41, _startPosY.Value + 9, 9, 24);
//окна
Pen pen1 = new(Color.Blue);
g.DrawRectangle(pen1, _startPosX.Value + 13, _startPosY.Value + 4, 10, 11);
g.DrawRectangle(pen1, _startPosX.Value + 27, _startPosY.Value + 4, 10, 11);
g.DrawRectangle(pen1, _startPosX.Value + 110, _startPosY.Value + 4, 10, 11);
// держатели
Brush brBlack = new SolidBrush(Color.Black);
//1
Point[] point1 = {
new Point(_startPosX.Value + 7, _startPosY.Value + 40),
new Point(_startPosX.Value + 45, _startPosY.Value + 40),
new Point(_startPosX.Value + 38, _startPosY.Value + 46),
new Point(_startPosX.Value, _startPosY.Value + 46)
};
g.DrawPolygon(pen, point1);
g.FillPolygon(brBlack, point1);
//2
Point[] point3 = {
new Point(_startPosX.Value + 123, _startPosY.Value + 40),
new Point(_startPosX.Value + 130, _startPosY.Value + 46),
new Point(_startPosX.Value + 92, _startPosY.Value + 46),
new Point(_startPosX.Value + 85, _startPosY.Value + 40)
};
g.DrawPolygon(pen, point3);
g.FillPolygon(brBlack, point3);
//стекло
g.FillRectangle(additionalBrush, _startPosX.Value + 52, _startPosY.Value + 14, 21, 16);
g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 14, 20, 16);
//гусеницы
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 42, _startPosX.Value + 10, _startPosY.Value + 42);
g.DrawLine(pen, _startPosX.Value + 7, _startPosY.Value + 43, _startPosX.Value + 7, _startPosY.Value + 53);
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 54, _startPosX.Value + 12, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 13, _startPosY.Value + 55, _startPosX.Value + 69, _startPosY.Value + 55);
g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 54, _startPosX.Value + 73, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 74, _startPosY.Value + 53, _startPosX.Value + 74, _startPosY.Value + 43);
g.DrawLine(pen, _startPosX.Value + 71, _startPosY.Value + 42, _startPosX.Value + 73, _startPosY.Value + 42);
//колеса
g.FillEllipse(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
//1-ое колеса
g.DrawEllipse(pen, _startPosX.Value + 13, _startPosY.Value + 40, 11, 11);
g.FillEllipse(brWhite, _startPosX.Value + 13, _startPosY.Value + 40, 11, 11);
g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
//2-ое колесо
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 40, 11, 11);
g.FillEllipse(brWhite, _startPosX.Value + 35, _startPosY.Value + 40, 11, 11);
g.FillEllipse(BodyBrush, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.FillEllipse(BodyBrush, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
//3-ее колесо
g.DrawEllipse(pen, _startPosX.Value + 85, _startPosY.Value + 40, 11, 11);
g.FillEllipse(brWhite, _startPosX.Value + 85, _startPosY.Value + 40, 11, 11);
//кран
if (EntityMonorail.Crane)
{
//балка
g.FillRectangle(BodyBrush, _startPosX.Value, _startPosY.Value, 110, 9);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 109, 8);
//4-ое колесо
g.DrawEllipse(pen, _startPosX.Value + 107, _startPosY.Value + 40, 11, 11);
g.FillEllipse(brWhite, _startPosX.Value + 107, _startPosY.Value + 40, 11, 11);
//крюк
g.FillRectangle(CraneBrush, _startPosX.Value + 107, _startPosY.Value + 8, 3, 13);
g.FillRectangle(CraneBrush, _startPosX.Value + 102, _startPosY.Value + 18, 8, 3);
g.FillRectangle(CraneBrush, _startPosX.Value + 102, _startPosY.Value + 16, 3, 5);
}
//противовес
if (EntityMonorail.Сounterweight)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value, 10, 9);
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 9, 8);
g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 2, _startPosX.Value + 44, _startPosY.Value + 2);
g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 4, _startPosX.Value + 44, _startPosY.Value + 4);
g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 6, _startPosX.Value + 44, _startPosY.Value + 6);
}
}
}
}

View File

@ -1,4 +1,11 @@
namespace ProjectMonorail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMonorail;
public class EntityMonorail
{
/// <summary>
@ -18,15 +25,15 @@ public class EntityMonorail
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия обвеса
/// Признак (опция) наличия противовеса
/// </summary>
public bool MagneticRail { get; private set; }
public bool Сounterweight { get; private set; }
/// <summary>
/// /// Признак (опция) наличия антикрыла
/// /// </summary>
public bool SecondCabin { get; private set; }
/// Признак (опция) наличия крана
/// </summary>
public bool Crane { get; private set; }
/// <summary>
/// Признак (опция) наличия гоночной полосы
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
@ -36,17 +43,15 @@ public class EntityMonorail
/// <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 magneticRail, bool secondCabin)
/// <param name="counterweight">Признак наличия обвеса</param>
/// <param name="crane">Признак наличия крана</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool crane)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
MagneticRail = magneticRail;
SecondCabin = secondCabin;
Сounterweight = counterweight;
Crane = crane;
}
}

View File

@ -10,9 +10,8 @@
namespace ProjectMonorail.Properties {
using System;
using System.Drawing;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
@ -24,10 +23,7 @@ namespace ProjectMonorail.Properties {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
internal static Image free_icon_right;
internal static Image free_icon_left;
internal static Image free_icon_up;
internal static Image free_icon_down;
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;