Добавление родителей и ввод конструкторов
This commit is contained in:
parent
5e1d237096
commit
3348c036dd
31
Project1/Project1.sln
Normal file
31
Project1/Project1.sln
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.7.34024.191
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1\Project1.vcxproj", "{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x64.Build.0 = Release|x64
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{51322AFD-5D22-49A7-BC85-AC24DACBAEE8}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {188BD3AE-A59B-46F9-AEC9-A67BF38B0430}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
135
Project1/Project1/Project1.vcxproj
Normal file
135
Project1/Project1/Project1.vcxproj
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{51322afd-5d22-49a7-bc85-ac24dacbaee8}</ProjectGuid>
|
||||||
|
<RootNamespace>Project1</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="sove.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
22
Project1/Project1/Project1.vcxproj.filters
Normal file
22
Project1/Project1/Project1.vcxproj.filters
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Исходные файлы">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы заголовков">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы ресурсов">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="sove.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
56
Project1/Project1/sove.cpp
Normal file
56
Project1/Project1/sove.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <cassert>
|
||||||
|
#include <math.h>
|
||||||
|
#include <numeric>
|
||||||
|
#include <ctime>
|
||||||
|
#include <time.h>
|
||||||
|
#include <deque>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
typedef long long ll;
|
||||||
|
typedef unsigned long long ull;
|
||||||
|
typedef unsigned int uint;
|
||||||
|
typedef long double ld;
|
||||||
|
typedef pair<long long, long long> pll;
|
||||||
|
typedef pair<int, int> pii;
|
||||||
|
|
||||||
|
|
||||||
|
const ll LINF = 100090009990;
|
||||||
|
const int INF = 1009000999;
|
||||||
|
const int N = 1002;
|
||||||
|
const int M = 1002;
|
||||||
|
const ld PI = 3.1415926535;
|
||||||
|
const ld E = 2.7182818284;
|
||||||
|
const ll MOD = 1000000007;
|
||||||
|
const int MAX = 150010;
|
||||||
|
const ld EPS = 1e-10;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
vector<string> Buttons{ "A", "B","C", "D", "L1", "L2", "R1", "R2" };
|
||||||
|
vector<string> ButtonsAns{ "A", "B","C", "D", "L1", "L2", "R1", "R2" };
|
||||||
|
vector<string> used, unused;
|
||||||
|
int stick;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ProjectElectricLocomotive;
|
namespace ProjectElectricLocomotive.Drawnings;
|
||||||
|
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{
|
{
|
@ -0,0 +1,84 @@
|
|||||||
|
|
||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Drawnings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта - сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningElectricLocomotive : DrawningLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"></param>
|
||||||
|
/// <param name="weight"></param>
|
||||||
|
/// <param name="bodyColor"></param>
|
||||||
|
/// <param name="additionalColor"></param>
|
||||||
|
/// <param name="bodyKit"></param>
|
||||||
|
/// <param name="electricHorns"></param>
|
||||||
|
/// <param name="batteryPlacement"></param>
|
||||||
|
public DrawningElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement) : base(83,45)
|
||||||
|
{
|
||||||
|
EntityLocomotive = new EntityElectricLocomotive(speed, weight, bodyColor, additionalColor, electricHorns, batteryPlacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityLocomotive == null || EntityLocomotive is not EntityElectricLocomotive electricLocomotive || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Создание перьев и кистей для прорисовки электровоза
|
||||||
|
Brush blackBrush = new SolidBrush(Color.Black);
|
||||||
|
Pen penSolid = new(Color.Black, 2);
|
||||||
|
Pen penSolidYellow = new(Color.Yellow, 0.5f);
|
||||||
|
Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor);
|
||||||
|
|
||||||
|
//Прорисовка дополнительного элемента (рогов)
|
||||||
|
if (electricLocomotive.ElectricHorns)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//Инициализация опорных точек для прорисовки "рогов"
|
||||||
|
Point pointHorns1 = new Point(_startPosX.Value + 13, _startPosY.Value + 5);
|
||||||
|
Point pointHorns2 = new Point(_startPosX.Value + 16, _startPosY.Value + 2);
|
||||||
|
Point pointHorns3 = new Point(_startPosX.Value + 11, _startPosY.Value);
|
||||||
|
|
||||||
|
//Прорисовка "рогов" электровоза
|
||||||
|
g.DrawLine(penSolid, pointHorns1, pointHorns2);
|
||||||
|
g.DrawLine(penSolid, pointHorns2, pointHorns3);
|
||||||
|
}
|
||||||
|
//Прорисовка дополнительного элемента (места под батарею)
|
||||||
|
if (electricLocomotive.BatteryPlacement)
|
||||||
|
{
|
||||||
|
//Инициализация опорных точек для прорисовки молнии на хранилище батарей
|
||||||
|
Point pointLightning1 = new Point(_startPosX.Value + 39, _startPosY.Value + 37);
|
||||||
|
Point pointLightning2 = new Point(_startPosX.Value + 37, _startPosY.Value + 39);
|
||||||
|
Point pointLightning3 = new Point(_startPosX.Value + 39, _startPosY.Value + 40);
|
||||||
|
Point pointLightning4 = new Point(_startPosX.Value + 37, _startPosY.Value + 41);
|
||||||
|
|
||||||
|
//Прорисовка "хранилища батарей" электровоза
|
||||||
|
g.FillRectangle(blackBrush, _startPosX.Value + 36, _startPosY.Value + 37, 8, 4.5f);
|
||||||
|
g.DrawLine(penSolidYellow, pointLightning1, pointLightning2);
|
||||||
|
g.DrawLine(penSolidYellow, pointLightning2, pointLightning3);
|
||||||
|
g.DrawLine(penSolidYellow, pointLightning3, pointLightning4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosY += 5;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosY -= 5;
|
||||||
|
|
||||||
|
//Опциональная прорисовка цвета передних колёс
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8);
|
||||||
|
|
||||||
|
//Опциональная прорисовка цвета задних колёс
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 37, _startPosY.Value + 37, 8, 8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,18 @@
|
|||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
namespace ProjectElectricLocomotive;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
/// <summary>
|
namespace ProjectElectricLocomotive.Drawnings;
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта - сущности
|
|
||||||
/// </summary>
|
public class DrawningLocomotive
|
||||||
public class DrawningElectricLocomotive
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityElectricLocomotive? EntityElectricLocomotive { get; private set; }
|
public EntityLocomotive? EntityLocomotive { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -22,47 +25,59 @@ public class DrawningElectricLocomotive
|
|||||||
private int? _pictureHeight;
|
private int? _pictureHeight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки электровоза
|
/// Левая координата прорисовки локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя координата прорисовки электровоза
|
/// Верхняя координата прорисовки локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки электровоза
|
/// Ширина прорисовки локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningElectricLocomotiveWidth = 83;
|
private readonly int _drawningElectricLocomotiveWidth = 83;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки электровоза
|
/// Высота прорисовки локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningElectricLocomotiveHeight = 45;
|
private readonly int _drawningElectricLocomotiveHeight = 40;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Пустой конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed"></param>
|
private DrawningLocomotive()
|
||||||
/// <param name="weight"></param>
|
|
||||||
/// <param name="bodyColor"></param>
|
|
||||||
/// <param name="additionalColor"></param>
|
|
||||||
/// <param name="bodyKit"></param>
|
|
||||||
/// <param name="electricHorns"></param>
|
|
||||||
/// <param name="batteryPlacement"></param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement)
|
|
||||||
{
|
{
|
||||||
EntityElectricLocomotive = new EntityElectricLocomotive();
|
|
||||||
|
|
||||||
EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, electricHorns, batteryPlacement);
|
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"></param>
|
||||||
|
/// <param name="weight"></param>
|
||||||
|
/// <param name="bodyColor"></param>
|
||||||
|
public DrawningLocomotive(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningElectricLocomotiveWidth">Ширина прорисовки локомотива</param>
|
||||||
|
/// <param name="drawningElectricLocomotiveHeight">Высота прорисовки локомотива</param>
|
||||||
|
protected DrawningLocomotive(int drawningElectricLocomotiveWidth, int drawningElectricLocomotiveHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningElectricLocomotiveWidth = drawningElectricLocomotiveWidth;
|
||||||
|
_drawningElectricLocomotiveHeight = drawningElectricLocomotiveHeight;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -71,17 +86,17 @@ public class DrawningElectricLocomotive
|
|||||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||||
public bool SetPictureSize(int width, int height)
|
public bool SetPictureSize(int width, int height)
|
||||||
{
|
{
|
||||||
if(_drawningElectricLocomotiveHeight > height || _drawningElectricLocomotiveWidth > width)
|
if (_drawningElectricLocomotiveHeight > height || _drawningElectricLocomotiveWidth > width)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
if (_startPosY.HasValue && _startPosY + _drawningElectricLocomotiveHeight < _pictureHeight )
|
if (_startPosY.HasValue && _startPosY + _drawningElectricLocomotiveHeight < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY = _pictureHeight - _drawningElectricLocomotiveHeight;
|
_startPosY = _pictureHeight - _drawningElectricLocomotiveHeight;
|
||||||
}
|
}
|
||||||
if (_startPosX.HasValue && _startPosX + _drawningElectricLocomotiveWidth < _pictureWidth )
|
if (_startPosX.HasValue && _startPosX + _drawningElectricLocomotiveWidth < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX = _pictureWidth - _drawningElectricLocomotiveWidth;
|
_startPosX = _pictureWidth - _drawningElectricLocomotiveWidth;
|
||||||
}
|
}
|
||||||
@ -95,7 +110,8 @@ public class DrawningElectricLocomotive
|
|||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
if(!_pictureHeight.HasValue || !_pictureWidth.HasValue) {
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,11 +121,11 @@ public class DrawningElectricLocomotive
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( _drawningElectricLocomotiveHeight + y > _pictureHeight)
|
if (_drawningElectricLocomotiveHeight + y > _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY = _pictureHeight - _drawningElectricLocomotiveHeight;
|
_startPosY = _pictureHeight - _drawningElectricLocomotiveHeight;
|
||||||
}
|
}
|
||||||
if ( _drawningElectricLocomotiveWidth + x > _pictureWidth)
|
if (_drawningElectricLocomotiveWidth + x > _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX = _pictureWidth - _drawningElectricLocomotiveWidth;
|
_startPosX = _pictureWidth - _drawningElectricLocomotiveWidth;
|
||||||
}
|
}
|
||||||
@ -133,39 +149,39 @@ public class DrawningElectricLocomotive
|
|||||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if(EntityElectricLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if(_startPosX.Value - EntityElectricLocomotive.Step > 0)
|
if (_startPosX.Value - EntityLocomotive.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityElectricLocomotive.Step;
|
_startPosX -= (int)EntityLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if(_startPosY.Value - EntityElectricLocomotive.Step > 0)
|
if (_startPosY.Value - EntityLocomotive.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityElectricLocomotive.Step;
|
_startPosY -= (int)EntityLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вправо
|
//вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + _drawningElectricLocomotiveWidth + EntityElectricLocomotive.Step < _pictureWidth)
|
if (_startPosX.Value + _drawningElectricLocomotiveWidth + EntityLocomotive.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityElectricLocomotive.Step;
|
_startPosX += (int)EntityLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY.Value + _drawningElectricLocomotiveHeight + EntityElectricLocomotive.Step < _pictureHeight)
|
if (_startPosY.Value + _drawningElectricLocomotiveHeight + EntityLocomotive.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityElectricLocomotive.Step;
|
_startPosY += (int)EntityLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -177,9 +193,9 @@ public class DrawningElectricLocomotive
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityElectricLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -189,25 +205,24 @@ public class DrawningElectricLocomotive
|
|||||||
Pen penSolid = new(Color.Black, 2);
|
Pen penSolid = new(Color.Black, 2);
|
||||||
Pen penSolidYellow = new(Color.Yellow, 0.5f);
|
Pen penSolidYellow = new(Color.Yellow, 0.5f);
|
||||||
Pen windowPen = new(Color.DeepSkyBlue);
|
Pen windowPen = new(Color.DeepSkyBlue);
|
||||||
Brush additionalBrush = new SolidBrush(EntityElectricLocomotive.AdditionalColor);
|
|
||||||
Brush blackBrush = new SolidBrush(Color.Black);
|
Brush blackBrush = new SolidBrush(Color.Black);
|
||||||
Brush whiteBrush = new SolidBrush(Color.White);
|
Brush whiteBrush = new SolidBrush(Color.White);
|
||||||
|
|
||||||
//Инициализация опорных точек для прорисовки корпуса
|
//Инициализация опорных точек для прорисовки корпуса
|
||||||
Point pointStart = new Point(_startPosX.Value + 75, _startPosY.Value + 20);
|
Point pointStart = new Point(_startPosX.Value + 75, _startPosY.Value + 15);
|
||||||
Point point1 = new Point(_startPosX.Value + 75, _startPosY.Value + 5);
|
Point point1 = new Point(_startPosX.Value + 75, _startPosY.Value);
|
||||||
Point point2 = new Point(_startPosX.Value + 10, _startPosY.Value + 5);
|
Point point2 = new Point(_startPosX.Value + 10, _startPosY.Value);
|
||||||
Point pointFinish = new Point(_startPosX.Value + 5, _startPosY.Value + 20);
|
Point pointFinish = new Point(_startPosX.Value + 5, _startPosY.Value + 15);
|
||||||
|
|
||||||
//Инициализация опорных точек для прорисовки первой "юбки"
|
//Инициализация опорных точек для прорисовки первой "юбки"
|
||||||
Point point3 = new Point(_startPosX.Value + 7, _startPosY.Value + 37);
|
Point point3 = new Point(_startPosX.Value + 7, _startPosY.Value + 32);
|
||||||
Point point4 = new Point(_startPosX.Value + 0, _startPosY.Value + 37 +6 );
|
Point point4 = new Point(_startPosX.Value, _startPosY.Value + 32 + 6);
|
||||||
Point point5 = new Point(_startPosX.Value + 7, _startPosY.Value + 37 + 6 );
|
Point point5 = new Point(_startPosX.Value + 7, _startPosY.Value + 32 + 6);
|
||||||
|
|
||||||
//Инициализация опорных точек для прорисовки второй "юбки"
|
//Инициализация опорных точек для прорисовки второй "юбки"
|
||||||
Point point6 = new Point(_startPosX.Value + 69, _startPosY.Value + 37);
|
Point point6 = new Point(_startPosX.Value + 69, _startPosY.Value + 32);
|
||||||
Point point7 = new Point(_startPosX.Value + 75 + 7, _startPosY.Value + 37 + 6);
|
Point point7 = new Point(_startPosX.Value + 75 + 7, _startPosY.Value + 32 + 6);
|
||||||
Point point8 = new Point(_startPosX.Value + 69, _startPosY.Value + 37 + 6);
|
Point point8 = new Point(_startPosX.Value + 69, _startPosY.Value + 32 + 6);
|
||||||
|
|
||||||
//Совокупность точек полигона уголка первой "юбки"
|
//Совокупность точек полигона уголка первой "юбки"
|
||||||
Point[] firstTrianglePoints =
|
Point[] firstTrianglePoints =
|
||||||
@ -233,7 +248,7 @@ public class DrawningElectricLocomotive
|
|||||||
g.FillPolygon(blackBrush, secondTrianglePoints);
|
g.FillPolygon(blackBrush, secondTrianglePoints);
|
||||||
|
|
||||||
//Прорисовка корпуса
|
//Прорисовка корпуса
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20, 70, 17);
|
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 15, 70, 17);
|
||||||
g.DrawLine(pen, point3, point4);
|
g.DrawLine(pen, point3, point4);
|
||||||
|
|
||||||
g.DrawLine(pen, pointStart, point1);
|
g.DrawLine(pen, pointStart, point1);
|
||||||
@ -242,68 +257,41 @@ public class DrawningElectricLocomotive
|
|||||||
|
|
||||||
|
|
||||||
Brush brWhite = new SolidBrush(Color.White);
|
Brush brWhite = new SolidBrush(Color.White);
|
||||||
g.DrawRectangle(windowPen, _startPosX.Value + 24.3f, _startPosY.Value + 9, 8, 8);
|
g.DrawRectangle(windowPen, _startPosX.Value + 24.3f, _startPosY.Value + 4, 8, 8);
|
||||||
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 14, 8, 12);
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 9, 8, 12);
|
||||||
|
|
||||||
g.FillRectangle(brWhite, _startPosX.Value + 36, _startPosY.Value + 16, 7, 10);
|
g.FillRectangle(brWhite, _startPosX.Value + 36, _startPosY.Value + 11, 7, 10);
|
||||||
|
|
||||||
|
|
||||||
//Прорисовка передней и задней "юбки"
|
//Прорисовка передней и задней "юбки"
|
||||||
g.FillRectangle(blackBrush, _startPosX.Value + 7, _startPosY.Value + 37, 25, 5.3f);
|
g.FillRectangle(blackBrush, _startPosX.Value + 7, _startPosY.Value + 32, 25, 5.3f);
|
||||||
g.FillRectangle(blackBrush, _startPosX.Value + 47, _startPosY.Value + 37, 22, 5.3f);
|
g.FillRectangle(blackBrush, _startPosX.Value + 47, _startPosY.Value + 32, 22, 5.3f);
|
||||||
|
|
||||||
//Прорисовка двух передних колёс
|
//Прорисовка двух передних колёс
|
||||||
g.FillEllipse(whiteBrush, _startPosX.Value + 6.3f, _startPosY.Value + 37, 10, 10);
|
g.FillEllipse(whiteBrush, _startPosX.Value + 6.3f, _startPosY.Value + 32, 10, 10);
|
||||||
g.DrawEllipse(penSolid, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8);
|
g.DrawEllipse(penSolid, _startPosX.Value + 9, _startPosY.Value + 32, 8, 8);
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8);
|
g.DrawEllipse(penSolid, _startPosX.Value + 24, _startPosY.Value + 32, 8, 8);
|
||||||
g.DrawEllipse(penSolid, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8);
|
|
||||||
|
|
||||||
//Прорисовка двух задних колёс
|
//Прорисовка двух задних колёс
|
||||||
g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 38, _startPosY.Value + 37, 10, 10);
|
g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 38, _startPosY.Value + 32, 10, 10);
|
||||||
g.DrawEllipse(penSolid, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8);
|
g.DrawEllipse(penSolid, _startPosX.Value + 25 + 26, _startPosY.Value + 32, 8, 8);
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8);
|
g.DrawEllipse(penSolid, _startPosX.Value + 25 + 37, _startPosY.Value + 32, 8, 8);
|
||||||
g.DrawEllipse(penSolid, _startPosX.Value+ 25 + 37, _startPosY.Value + 37, 8, 8);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 37, _startPosY.Value + 37, 8, 8);
|
|
||||||
|
|
||||||
//Прорисовка заднего "шлюза"
|
//Прорисовка заднего "шлюза"
|
||||||
g.FillRectangle(blackBrush, _startPosX.Value + 75, _startPosY.Value + 9, 5.7f, 27.4f);
|
g.FillRectangle(blackBrush, _startPosX.Value + 75, _startPosY.Value + 4, 5.7f, 27.4f);
|
||||||
|
|
||||||
//Прорисовка первого и третьего окна
|
//Прорисовка первого и третьего окна
|
||||||
g.DrawRectangle(windowPen, _startPosX.Value + 12, _startPosY.Value + 9, 8, 8);
|
g.DrawRectangle(windowPen, _startPosX.Value + 12, _startPosY.Value + 4, 8, 8);
|
||||||
g.DrawRectangle(windowPen, _startPosX.Value + 63, _startPosY.Value + 9, 8, 8);
|
g.DrawRectangle(windowPen, _startPosX.Value + 63, _startPosY.Value + 4, 8, 8);
|
||||||
|
|
||||||
|
//Опциональная прорисовка цвета передних колёс
|
||||||
|
g.FillEllipse(whiteBrush, _startPosX.Value + 9, _startPosY.Value + 32, 8, 8);
|
||||||
|
g.FillEllipse(whiteBrush, _startPosX.Value + 24, _startPosY.Value + 32, 8, 8);
|
||||||
|
|
||||||
|
//Опциональная прорисовка цвета задних колёс
|
||||||
if (EntityElectricLocomotive.ElectricHorns)
|
g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 26, _startPosY.Value + 32, 8, 8);
|
||||||
{
|
g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 37, _startPosY.Value + 32, 8, 8);
|
||||||
|
|
||||||
|
|
||||||
//Инициализация опорных точек для прорисовки "рогов"
|
|
||||||
Point pointHorns1 = new Point(_startPosX.Value + 13, _startPosY.Value + 5);
|
|
||||||
Point pointHorns2 = new Point(_startPosX.Value + 16, _startPosY.Value + 2);
|
|
||||||
Point pointHorns3 = new Point(_startPosX.Value + 11, _startPosY.Value);
|
|
||||||
|
|
||||||
//Прорисовка "рогов" электровоза
|
|
||||||
g.DrawLine(penSolid, pointHorns1, pointHorns2);
|
|
||||||
g.DrawLine(penSolid, pointHorns2, pointHorns3);
|
|
||||||
}
|
|
||||||
if(EntityElectricLocomotive.BatteryPlacement)
|
|
||||||
{
|
|
||||||
//Инициализация опорных точек для прорисовки молнии на хранилище батарей
|
|
||||||
Point pointLightning1 = new Point(_startPosX.Value + 39, _startPosY.Value + 37);
|
|
||||||
Point pointLightning2 = new Point(_startPosX.Value + 37, _startPosY.Value + 39);
|
|
||||||
Point pointLightning3 = new Point(_startPosX.Value + 39, _startPosY.Value + 40);
|
|
||||||
Point pointLightning4 = new Point(_startPosX.Value + 37, _startPosY.Value + 41);
|
|
||||||
|
|
||||||
//Прорисовка "хранилища батарей" электровоза
|
|
||||||
g.FillRectangle(blackBrush, _startPosX.Value + 36, _startPosY.Value + 37, 8, 4.5f);
|
|
||||||
g.DrawLine(penSolidYellow, pointLightning1, pointLightning2);
|
|
||||||
g.DrawLine(penSolidYellow, pointLightning2, pointLightning3);
|
|
||||||
g.DrawLine(penSolidYellow, pointLightning3, pointLightning4);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,26 +1,11 @@
|
|||||||
|
|
||||||
namespace ProjectElectricLocomotive;
|
namespace ProjectElectricLocomotive.Entities;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Тепловоз"
|
/// Класс-сущность "Электровоз"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityElectricLocomotive
|
public class EntityElectricLocomotive : EntityLocomotive
|
||||||
{
|
{
|
||||||
/// <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>
|
||||||
/// Дополнительный цвет (для дополнительных элементов)
|
/// Дополнительный цвет (для дополнительных элементов)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -36,11 +21,6 @@ public class EntityElectricLocomotive
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool BatteryPlacement { get; private set; }
|
public bool BatteryPlacement { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения объекта
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса тепловоза
|
/// Инициализация полей объекта-класса тепловоза
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -51,14 +31,10 @@ public class EntityElectricLocomotive
|
|||||||
/// <param name="electrichorns"></param>
|
/// <param name="electrichorns"></param>
|
||||||
/// <param name="batteryplacement"></param>
|
/// <param name="batteryplacement"></param>
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement)
|
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool electricHorns, bool batteryPlacement) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
ElectricHorns = electricHorns;
|
ElectricHorns = electricHorns;
|
||||||
BatteryPlacement = batteryPlacement;
|
BatteryPlacement = batteryPlacement;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectElectricLocomotive.Entities;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Локомотив"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityLocomotive
|
||||||
|
{
|
||||||
|
/// <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 double Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор сущности
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"></param>
|
||||||
|
/// <param name="weight"></param>
|
||||||
|
/// <param name="bodyColor"></param>
|
||||||
|
public EntityLocomotive(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,7 @@
|
|||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
|
buttonCreateLocomotive = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -49,11 +50,11 @@
|
|||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
//
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Location = new Point(12, 430);
|
buttonCreate.Location = new Point(12, 436);
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreate.Name = "buttonCreate";
|
||||||
buttonCreate.Size = new Size(104, 37);
|
buttonCreate.Size = new Size(150, 31);
|
||||||
buttonCreate.TabIndex = 1;
|
buttonCreate.TabIndex = 1;
|
||||||
buttonCreate.Text = "Создать";
|
buttonCreate.Text = "Создать электровоз";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
buttonCreate.Click += ButtonCreate_Click;
|
buttonCreate.Click += ButtonCreate_Click;
|
||||||
//
|
//
|
||||||
@ -109,11 +110,23 @@
|
|||||||
buttonUp.UseVisualStyleBackColor = false;
|
buttonUp.UseVisualStyleBackColor = false;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateLocomotive
|
||||||
|
//
|
||||||
|
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateLocomotive.Location = new Point(187, 436);
|
||||||
|
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
||||||
|
buttonCreateLocomotive.Size = new Size(150, 31);
|
||||||
|
buttonCreateLocomotive.TabIndex = 6;
|
||||||
|
buttonCreateLocomotive.Text = "Создать локомотив";
|
||||||
|
buttonCreateLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
|
||||||
|
//
|
||||||
// FormElectricLocomotive
|
// FormElectricLocomotive
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(866, 479);
|
ClientSize = new Size(866, 479);
|
||||||
|
Controls.Add(buttonCreateLocomotive);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
@ -134,5 +147,6 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private Button buttonCreateLocomotive;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using ProjectElectricLocomotive.Drawnings;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -12,7 +13,7 @@ namespace ProjectElectricLocomotive;
|
|||||||
|
|
||||||
public partial class FormElectricLocomotive : Form
|
public partial class FormElectricLocomotive : Form
|
||||||
{
|
{
|
||||||
private DrawningElectricLocomotive? _drawningElectricLocomotive;
|
private DrawningLocomotive? _drawningLocomotive;
|
||||||
|
|
||||||
public FormElectricLocomotive()
|
public FormElectricLocomotive()
|
||||||
{
|
{
|
||||||
@ -24,33 +25,54 @@ public partial class FormElectricLocomotive : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningElectricLocomotive == null)
|
if (_drawningLocomotive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxElectricLocomotive.Width,
|
Bitmap bmp = new(pictureBoxElectricLocomotive.Width,
|
||||||
pictureBoxElectricLocomotive.Height);
|
pictureBoxElectricLocomotive.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningElectricLocomotive.DrawTransport(gr);
|
_drawningLocomotive.DrawTransport(gr);
|
||||||
pictureBoxElectricLocomotive.Image = bmp;
|
pictureBoxElectricLocomotive.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void CreateObject(string type)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningElectricLocomotive = new DrawningElectricLocomotive();
|
switch (type)
|
||||||
_drawningElectricLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000),
|
{
|
||||||
|
case nameof(DrawningLocomotive):
|
||||||
|
_drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||||
|
break;
|
||||||
|
case nameof(DrawningElectricLocomotive):
|
||||||
|
_drawningLocomotive = new DrawningElectricLocomotive(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)), Convert.ToBoolean(random.Next(0, 2)));
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
_drawningElectricLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
break;
|
||||||
_drawningElectricLocomotive.SetPosition(random.Next(0,pictureBoxElectricLocomotive.Width), random.Next(0,pictureBoxElectricLocomotive.Height));
|
default:
|
||||||
|
return;
|
||||||
Bitmap bmp = new(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
|
||||||
_drawningElectricLocomotive.DrawTransport(gr);
|
|
||||||
pictureBoxElectricLocomotive.Image = bmp;
|
|
||||||
}
|
}
|
||||||
|
_drawningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||||
|
_drawningLocomotive.SetPosition(random.Next(10,100), random.Next(10,100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать электровоз"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectricLocomotive));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать локомотив"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
@ -59,7 +81,7 @@ public partial class FormElectricLocomotive : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningElectricLocomotive == null)
|
if (_drawningLocomotive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -69,19 +91,19 @@ public partial class FormElectricLocomotive : Form
|
|||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result =
|
result =
|
||||||
_drawningElectricLocomotive.MoveTransport(DirectionType.Up);
|
_drawningLocomotive.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result =
|
result =
|
||||||
_drawningElectricLocomotive.MoveTransport(DirectionType.Down);
|
_drawningLocomotive.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result =
|
result =
|
||||||
_drawningElectricLocomotive.MoveTransport(DirectionType.Left);
|
_drawningLocomotive.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result =
|
result =
|
||||||
_drawningElectricLocomotive.MoveTransport(DirectionType.Right);
|
_drawningLocomotive.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
@ -89,6 +111,8 @@ public partial class FormElectricLocomotive : Form
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user