LabWork2 #2
1
Lab_1/Data_Structure.cpp
Normal file
1
Lab_1/Data_Structure.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "Data_Structure.h"
|
42
Lab_1/Data_Structure.h
Normal file
42
Lab_1/Data_Structure.h
Normal file
@ -0,0 +1,42 @@
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//
|
||||
//#pragma once
|
||||
//
|
||||
//struct Node {
|
||||
// int data;
|
||||
// Node* next;
|
||||
//};
|
||||
//
|
||||
//class Data_Structure
|
||||
//{
|
||||
//private:
|
||||
// Node* head;
|
||||
// struct Node {
|
||||
// int data;
|
||||
// Node* next;
|
||||
// };
|
||||
//public:
|
||||
// Data_Structure(){
|
||||
// head = NULL;
|
||||
// }
|
||||
// void addNode(int val){
|
||||
// Node* newNode = new Node;
|
||||
// newNode->data = val;
|
||||
// newNode->next = head;
|
||||
// head = newNode;
|
||||
//
|
||||
//
|
||||
// }
|
||||
// void printList() {
|
||||
// Node* currentNode = head;
|
||||
// while (currentNode->next != NULL) {
|
||||
// printf("%d", currentNode->data);
|
||||
// currentNode = currentNode->next;
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//};
|
||||
//
|
31
Lab_1/Lab_1.sln
Normal file
31
Lab_1/Lab_1.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}") = "Lab_1", "Lab_1.vcxproj", "{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}"
|
||||
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
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Debug|x64.Build.0 = Debug|x64
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Debug|x86.Build.0 = Debug|Win32
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Release|x64.ActiveCfg = Release|x64
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Release|x64.Build.0 = Release|x64
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Release|x86.ActiveCfg = Release|Win32
|
||||
{B3B62C1B-E8D8-4038-8DFD-248406A48EE2}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FF15C0FB-D559-46A6-B4E8-E461B8F5C363}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
139
Lab_1/Lab_1.vcxproj
Normal file
139
Lab_1/Lab_1.vcxproj
Normal file
@ -0,0 +1,139 @@
|
||||
<?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>{b3b62c1b-e8d8-4038-8dfd-248406a48ee2}</ProjectGuid>
|
||||
<RootNamespace>Lab1</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="Data_Structure.cpp" />
|
||||
<ClCompile Include="Source.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Data_Structure.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
30
Lab_1/Lab_1.vcxproj.filters
Normal file
30
Lab_1/Lab_1.vcxproj.filters
Normal file
@ -0,0 +1,30 @@
|
||||
<?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="Source.cpp">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Data_Structure.cpp">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Data_Structure.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
199
Lab_1/Source.cpp
Normal file
199
Lab_1/Source.cpp
Normal file
@ -0,0 +1,199 @@
|
||||
/*
|
||||
Âàðèàíò 4
|
||||
ÀÒÄ - ÑÒÅÊ
|
||||
ÑÄ - Îäíîñâÿçàííûé ñïèñîê
|
||||
Îáúåêòíàÿ îáëàòü - Ñòóäåíòû, îáùèå äàííûå
|
||||
Ñîðòèðîâêà ñëèÿíèåì, øåéêåðîì
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "Data_Structure.h"
|
||||
|
||||
int unsorted_array[10] = { 2, 5, 1,8,3,4,7,6,9,0 };
|
||||
int arr[10] = { 2, 5, 1,8,3,4,7,6,9,0 };
|
||||
int n = 10;
|
||||
|
||||
void Buble_sort() {
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = n - 1; j > i; j--) {
|
||||
if (arr[j - 1] > arr[j]) {
|
||||
int temp = arr[j];
|
||||
arr[j] = arr[j - 1];
|
||||
arr[j - 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Merge(int arr[], int begin, int end) {
|
||||
int mid = begin + (end - begin) / 2;
|
||||
int i = begin;
|
||||
int j = mid + 1;
|
||||
int d[11] = { 0 };
|
||||
int k = 0;
|
||||
|
||||
while (i <= mid && j <= end) {
|
||||
if (arr[i] <= arr[j]) {
|
||||
d[k] = arr[i];
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
d[k] = arr[j];
|
||||
j++;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
while (i <= mid) {
|
||||
d[k] = arr[i];
|
||||
k++;
|
||||
i++;
|
||||
}
|
||||
while (j <= end) {
|
||||
d[k] = arr[j];
|
||||
k++;
|
||||
j++;
|
||||
}
|
||||
for (i = 0; i < k; i++) {
|
||||
arr[begin + i] = d[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Merge_sort(int* arr, int left, int right) {
|
||||
int temp = 0;
|
||||
if (left < right) {
|
||||
if (right - left == 1) {
|
||||
if (arr[left] > arr[right]) {
|
||||
temp = arr[left];
|
||||
arr[left] = arr[right];
|
||||
arr[right] = temp;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Merge_sort(arr, left, (right - left) / 2);
|
||||
Merge_sort(arr, left + (right - left) / 2 + 1, right);
|
||||
Merge(arr, left, right);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Shake_sort() {
|
||||
int direction = 0;
|
||||
int left = arr[0];
|
||||
int left_index = 0;
|
||||
int right = arr[n];
|
||||
int right_index = n;
|
||||
for (int _ = 0; _ < n - 1; _++) {
|
||||
if (direction == 0) {
|
||||
for (int i = left_index; i < right_index - 1; i++) {
|
||||
if (arr[i] > arr[i + 1]) {
|
||||
int temp = arr[i];
|
||||
arr[i] = arr[i + 1];
|
||||
arr[i + 1] = temp;
|
||||
}
|
||||
}
|
||||
if (right != arr[right_index]) {
|
||||
for (int i = n; i > 0; i--) {
|
||||
if (arr[i] == right) {
|
||||
right_index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
direction = 1;
|
||||
}
|
||||
else {
|
||||
for (int j = right_index; j > left_index; j--) {
|
||||
if (arr[j] < arr[j - 1]) {
|
||||
int temp1 = arr[j];
|
||||
arr[j] = arr[j - 1];
|
||||
arr[j - 1] = temp1;
|
||||
}
|
||||
}
|
||||
if (left != arr[left_index]) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (arr[i] == left) {
|
||||
left_index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
direction = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void print_list() {
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf("%d ", arr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Node {
|
||||
int student_year;
|
||||
int student_group;
|
||||
struct Node* next;
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct Node* first = NULL;
|
||||
|
||||
|
||||
|
||||
void s_addToHead(int year, int group) {
|
||||
struct Node* NewNode = (struct Node*)malloc(sizeof(NewNode));
|
||||
NewNode->student_year = year;
|
||||
NewNode->student_group = group;
|
||||
NewNode->next = first;
|
||||
|
||||
first = NewNode;
|
||||
|
||||
}
|
||||
|
||||
void s_deleteFromHead() {
|
||||
struct Node* DelNode = first;
|
||||
int val1 = DelNode->student_year;
|
||||
int val2 = DelNode->student_group;
|
||||
|
||||
first = first->next;
|
||||
printf("****|PI-%d, %d| - Deleted\n", val2, val1);
|
||||
|
||||
}
|
||||
|
||||
void s_print() {
|
||||
struct Node* i = first;
|
||||
while (i) {
|
||||
printf("|PI-%d, %d|\n", i->student_group, i->student_year);
|
||||
i = i->next;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
s_addToHead(2020, 12);
|
||||
s_addToHead(2021, 13);
|
||||
s_addToHead(2022, 14);
|
||||
s_addToHead(2024, 15);
|
||||
s_print();
|
||||
printf("------------------------\n");
|
||||
s_deleteFromHead();
|
||||
s_print();
|
||||
|
||||
print_list();
|
||||
Shake_sort();
|
||||
//Merge_sort(arr, 0, n - 1);
|
||||
print_list();
|
||||
//Data_structure newStructure;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за отрисовку и перемещение обьекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningElectricLocomotive
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityElectricLocomotive? EntityElectricLocomotive { 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 _drawningElectriLocomotiveWidth = 155;
|
||||
/// <summary>
|
||||
/// Высота прорисовки локомотива
|
||||
/// </summary>
|
||||
private readonly int _drawningElectricLocomotiveHeight = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="pantograph">Признак наличия обвеса</param>
|
||||
/// <param name="batterystorage">Признак наличия антикрыла</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool pantograph, bool batterystorage)
|
||||
{
|
||||
EntityElectricLocomotive = new EntityElectricLocomotive();
|
||||
EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor,
|
||||
pantograph, batterystorage);
|
||||
_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 проверка, что объект "влезает" в размеры поля
|
||||
if(_drawningElectriLocomotiveWidth > width || _drawningElectricLocomotiveHeight > height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if(_startPosX + _drawningElectriLocomotiveWidth > width)
|
||||
{
|
||||
_startPosX = width - _drawningElectriLocomotiveWidth;
|
||||
}
|
||||
if(_startPosY + _drawningElectricLocomotiveHeight > height)
|
||||
{
|
||||
_startPosY = height - _drawningElectricLocomotiveHeight;
|
||||
}
|
||||
}
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
if(x < 0 || x + _drawningElectriLocomotiveWidth > _pictureWidth.Value)
|
||||
{
|
||||
x = _pictureWidth.Value - _drawningElectriLocomotiveWidth;
|
||||
}
|
||||
if(y < 0 || y + _drawningElectricLocomotiveHeight > _pictureHeight.Value)
|
||||
{
|
||||
y = _pictureHeight.Value - _drawningElectricLocomotiveHeight;
|
||||
}
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityElectricLocomotive == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityElectricLocomotive.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if ((_startPosY.Value) - EntityElectricLocomotive.Step > 0)
|
||||
{
|
||||
|
||||
_startPosY -= (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityElectricLocomotive.Step < _pictureWidth - _drawningElectriLocomotiveWidth)
|
||||
{
|
||||
_startPosX += (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityElectricLocomotive.Step < _pictureHeight - _drawningElectricLocomotiveHeight)
|
||||
{
|
||||
_startPosY += (int)EntityElectricLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityElectricLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additonalBrush = new SolidBrush(EntityElectricLocomotive.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(EntityElectricLocomotive.BodyColor);
|
||||
//границы Электровоза
|
||||
//колеса
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 65, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 65, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 65, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 120, _startPosY.Value + 65, 20, 20);
|
||||
//кузов
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 155, 40);
|
||||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 50, _startPosX.Value + 20, _startPosY.Value + 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 30, 135,20 );
|
||||
//покраска кузова
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 10, _startPosY.Value + 85, 20, 20);
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 30, _startPosY.Value + 85, 20, 20);
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 100, _startPosY.Value + 85, 20, 20);
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 120, _startPosY.Value + 85, 20, 20);
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value+1, _startPosY.Value + 51, 154, 39);
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 21, _startPosY.Value + 31, 134, 19);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value , _startPosY.Value + 50, 155, 10);
|
||||
g.FillRectangle(additonalBrush, _startPosX.Value + 1, _startPosY.Value + 51, 154, 9);
|
||||
//g.FillPolygon(Brushes.AliceBlue, _startPosX.Value + 1, _startPosY.Value + 31, _startPosX.Value + 19, _startPosY.Value + 9, _startPosX.Value + 19, _startPosY.Value + 1);
|
||||
//Пантограф
|
||||
if (EntityElectricLocomotive.Pantograph)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 30, _startPosX.Value + 70, _startPosY.Value + 10);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 10, _startPosX.Value + 90, _startPosY.Value + 10);
|
||||
}
|
||||
//Отсек для батарей
|
||||
if (EntityElectricLocomotive.BatteryStorage)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 30, 30, 20);
|
||||
g.FillRectangle(additonalBrush, _startPosX.Value + 101, _startPosY.Value + 31, 29, 19);
|
||||
g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 40, _startPosX.Value + 115, _startPosY.Value + 50);
|
||||
g.DrawLine(pen, _startPosX.Value + 115, _startPosY.Value + 40, _startPosX.Value + 120, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 30, _startPosX.Value + 115, _startPosY.Value + 40);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive
|
||||
namespace ProjectElectricLocomotive.Drawnings
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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="pantograph">Признак наличия обвеса</param>
|
||||
/// <param name="batterystorage">Признак наличия антикрыла</param>
|
||||
/// --------------------------------------------------------------------------
|
||||
/// Требуется конструктор, вызывать надо будет у класса EntityElectricLocomotive
|
||||
/// ДОДЕЛАТЬ САМИМ!!!
|
||||
public DrawningElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool batterystorage) : base(155, 100)
|
||||
{
|
||||
EntityLocomotive = new EntityElectricLocomotive(speed, weight, bodyColor, additionalColor,
|
||||
pantograph, batterystorage);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityLocomotive == null || EntityLocomotive is not EntityElectricLocomotive electricLocomotive || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_startPosX += 0;
|
||||
_startPosY += 0;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 0;
|
||||
_startPosY -= 0;
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additonalBrush = new SolidBrush(electricLocomotive.AdditionalColor);
|
||||
Brush bodyBrush = new SolidBrush(electricLocomotive.BodyColor);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 155, 10);
|
||||
g.FillRectangle(additonalBrush, _startPosX.Value + 1, _startPosY.Value + 51, 154, 9);
|
||||
|
||||
//Пантограф
|
||||
if (electricLocomotive.Pantograph)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 30, _startPosX.Value + 70, _startPosY.Value + 10);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 10, _startPosX.Value + 90, _startPosY.Value + 10);
|
||||
}
|
||||
//Отсек для батарей
|
||||
if (electricLocomotive.BatteryStorage)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 30, 30, 20);
|
||||
g.FillRectangle(additonalBrush, _startPosX.Value + 101, _startPosY.Value + 31, 29, 19);
|
||||
g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 40, _startPosX.Value + 115, _startPosY.Value + 50);
|
||||
g.DrawLine(pen, _startPosX.Value + 115, _startPosY.Value + 40, _startPosX.Value + 120, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 30, _startPosX.Value + 115, _startPosY.Value + 40);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
204
ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs
Normal file
204
ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs
Normal file
@ -0,0 +1,204 @@
|
||||
using ProjectElectricLocomotive.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Drawnings;
|
||||
|
||||
public class DrawningLocomotive
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityLocomotive? EntityLocomotive { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки Электровоза
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки Электровоза
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки Локомотива
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveWidth = 155;
|
||||
/// <summary>
|
||||
/// Высота прорисовки локомотива
|
||||
/// </summary>
|
||||
private readonly int _drawningLocomotiveHeight = 90;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningLocomotive()
|
||||
{
|
||||
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = 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="drawningLocomotiveWidtе">Ширина прорисовки локомотива</param>
|
||||
/// <param name="drawningLocomotiveHeight">Высота прорисовки локомотива</param>
|
||||
protected DrawningLocomotive(int drawningLocomotiveWidtе, int drawningLocomotiveHeight) : this()
|
||||
{
|
||||
_drawningLocomotiveHeight = drawningLocomotiveHeight;
|
||||
_drawningLocomotiveWidth = drawningLocomotiveWidtе;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
if (_drawningLocomotiveWidth > width || _drawningLocomotiveHeight > height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawningLocomotiveWidth > width)
|
||||
{
|
||||
_startPosX = width - _drawningLocomotiveWidth;
|
||||
}
|
||||
if (_startPosY + _drawningLocomotiveHeight > height)
|
||||
{
|
||||
_startPosY = height - _drawningLocomotiveHeight;
|
||||
}
|
||||
}
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
if (x < 0 || x + _drawningLocomotiveWidth > _pictureWidth.Value)
|
||||
{
|
||||
x = _pictureWidth.Value - _drawningLocomotiveWidth;
|
||||
}
|
||||
if (y < 0 || y + _drawningLocomotiveHeight > _pictureHeight.Value)
|
||||
{
|
||||
y = _pictureHeight.Value - _drawningLocomotiveHeight;
|
||||
}
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityLocomotive == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityLocomotive.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityLocomotive.Step > 0)
|
||||
{
|
||||
|
||||
_startPosY -= (int)EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityLocomotive.Step < _pictureWidth - _drawningLocomotiveWidth)
|
||||
{
|
||||
_startPosX += (int)EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityLocomotive.Step < _pictureHeight - _drawningLocomotiveHeight)
|
||||
{
|
||||
_startPosY += (int)EntityLocomotive.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityLocomotive.BodyColor);
|
||||
//границы Электровоза
|
||||
//колеса
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 65, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 65, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 65, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 120, _startPosY.Value + 65, 20, 20);
|
||||
//кузов
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 155, 40);
|
||||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 50, _startPosX.Value + 20, _startPosY.Value + 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 30, 135, 20);
|
||||
//покраска кузова
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 10, _startPosY.Value + 85, 20, 20);
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 30, _startPosY.Value + 85, 20, 20);
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 100, _startPosY.Value + 85, 20, 20);
|
||||
g.FillEllipse(Brushes.Black, _startPosX.Value + 120, _startPosY.Value + 85, 20, 20);
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 1, _startPosY.Value + 51, 154, 39);
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 21, _startPosY.Value + 31, 134, 19);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 155, 10);
|
||||
g.FillRectangle(bodyBrush, _startPosX.Value + 1, _startPosY.Value + 51, 154, 9);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Entities
|
||||
{
|
||||
public class EntityElectricLocomotive : EntityLocomotive
|
||||
{
|
||||
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) "рогов"
|
||||
/// </summary>
|
||||
public bool Pantograph { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия отсека под батареи
|
||||
/// </summary>
|
||||
public bool BatteryStorage { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения Локомотива
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса ЭлектроЛокомотива
|
||||
/// </summary>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="pantograph">Признак "рогов"</param>
|
||||
/// <param name="batteryStorage">Признак наличия отсека под батареи</param>
|
||||
/// ------------------------------------------------------------------------------
|
||||
/// Переписать!!!!!!!!!
|
||||
/// САМИМ ТО ЧТО СНИЗУ!!!!!!!!!!!!!!!!!!
|
||||
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph
|
||||
, bool batteryStorage) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Pantograph = pantograph;
|
||||
BatteryStorage = batteryStorage;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
47
ProjectElectricLocomotive/Entities/EntityLocomotive.cs
Normal file
47
ProjectElectricLocomotive/Entities/EntityLocomotive.cs
Normal file
@ -0,0 +1,47 @@
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive
|
||||
{
|
||||
public class EntityElectricLocomotive
|
||||
{
|
||||
|
||||
/// <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 Pantograph{ get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия отсека под батареи
|
||||
/// </summary>
|
||||
public bool BatteryStorage { 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="pantograph">Признак "рогов"</param>
|
||||
/// <param name="batterystorage">Признак наличия отсека под батареи</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool pantograph, bool batterystorage)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Pantograph = pantograph;
|
||||
BatteryStorage = batterystorage;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@
|
||||
buttonLeft = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateLocomotive = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -46,16 +47,15 @@
|
||||
pictureBoxElectricLocomotive.Size = new Size(779, 411);
|
||||
pictureBoxElectricLocomotive.TabIndex = 0;
|
||||
pictureBoxElectricLocomotive.TabStop = false;
|
||||
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 353);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(112, 34);
|
||||
buttonCreate.Size = new Size(263, 34);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.Text = "Создать ЭлектроЛокомотив";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
@ -107,11 +107,23 @@
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateLocomotive
|
||||
//
|
||||
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateLocomotive.Location = new Point(281, 353);
|
||||
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
||||
buttonCreateLocomotive.Size = new Size(263, 34);
|
||||
buttonCreateLocomotive.TabIndex = 6;
|
||||
buttonCreateLocomotive.Text = "Создать Локомотив";
|
||||
buttonCreateLocomotive.UseVisualStyleBackColor = true;
|
||||
buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
|
||||
//
|
||||
// FormlectricLocomotive
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(788, 399);
|
||||
Controls.Add(buttonCreateLocomotive);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonLeft);
|
||||
@ -120,7 +132,6 @@
|
||||
Controls.Add(pictureBoxElectricLocomotive);
|
||||
Name = "FormlectricLocomotive";
|
||||
Text = "ЭлектроВоз";
|
||||
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -133,5 +144,6 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateLocomotive;
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectElectricLocomotive.Drawnings;
|
||||
|
||||
namespace ProjectElectricLocomotive
|
||||
{
|
||||
@ -15,41 +16,63 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawnningElectricLocomotive == null)
|
||||
if (_drawnningLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawnningElectricLocomotive.DrawTransport(gr);
|
||||
_drawnningLocomotive.DrawTransport(gr);
|
||||
pictureBoxElectricLocomotive.Image = bmp;
|
||||
}
|
||||
|
||||
private DrawningElectricLocomotive? _drawnningElectricLocomotive;
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningLocomotive):
|
||||
_drawnningLocomotive = 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):
|
||||
_drawnningLocomotive = 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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawnningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||
_drawnningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
private DrawningLocomotive? _drawnningLocomotive;
|
||||
public FormlectricLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawnningElectricLocomotive = new DrawningElectricLocomotive();
|
||||
_drawnningElectricLocomotive.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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawnningElectricLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
||||
_drawnningElectricLocomotive.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));
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawnningElectricLocomotive == null)
|
||||
if (_drawnningLocomotive == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -59,19 +82,19 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawnningElectricLocomotive.MoveTransport(DirectionType.Up);
|
||||
_drawnningLocomotive.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawnningElectricLocomotive.MoveTransport(DirectionType.Down);
|
||||
_drawnningLocomotive.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawnningElectricLocomotive.MoveTransport(DirectionType.Left);
|
||||
_drawnningLocomotive.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawnningElectricLocomotive.MoveTransport(DirectionType.Right);
|
||||
_drawnningLocomotive.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -80,5 +103,7 @@ namespace ProjectElectricLocomotive
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user