Merge pull request 'Zakharov V. V. LabWork 1' (#1) from LabWork01 into master

Reviewed-on: http://student.git.athene.tech/Viraremi/ISEbd-22_Zakharov_V.V._Traktor_Base/pulls/1
This commit is contained in:
Евгений Эгов 2022-09-30 11:47:05 +04:00
commit 883bfeaccb
17 changed files with 641 additions and 50 deletions

View File

@ -0,0 +1,11 @@
namespace Traktor
{
//Направление перемещения
internal enum Direction
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

181
Traktor/Traktor/DrawField.Designer.cs generated Normal file
View File

@ -0,0 +1,181 @@
namespace Traktor
{
partial class DrawField
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxTraktor = new System.Windows.Forms.PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonLEFT = new System.Windows.Forms.Button();
this.buttonRIGHT = new System.Windows.Forms.Button();
this.buttonDOWN = new System.Windows.Forms.Button();
this.buttonUP = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTraktor)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxTraktor
//
this.pictureBoxTraktor.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxTraktor.Location = new System.Drawing.Point(0, 0);
this.pictureBoxTraktor.Name = "pictureBoxTraktor";
this.pictureBoxTraktor.Size = new System.Drawing.Size(800, 425);
this.pictureBoxTraktor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxTraktor.TabIndex = 0;
this.pictureBoxTraktor.TabStop = false;
this.pictureBoxTraktor.Resize += new System.EventHandler(this.PictureBoxTraktor_Resize);
//
// statusStrip
//
this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 425);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 26);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(80, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(40, 20);
this.toolStripStatusLabelWeight.Text = "Вес: ";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(95, 20);
this.toolStripStatusLabelBodyColor.Text = "Цвет кузова:";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(29, 363);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonLEFT
//
this.buttonLEFT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLEFT.BackgroundImage = global::Traktor.Properties.Resources.arrowLeft;
this.buttonLEFT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLEFT.Location = new System.Drawing.Point(673, 361);
this.buttonLEFT.Name = "buttonLEFT";
this.buttonLEFT.Size = new System.Drawing.Size(30, 29);
this.buttonLEFT.TabIndex = 3;
this.buttonLEFT.UseVisualStyleBackColor = true;
this.buttonLEFT.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRIGHT
//
this.buttonRIGHT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRIGHT.BackgroundImage = global::Traktor.Properties.Resources.arrowRight;
this.buttonRIGHT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRIGHT.Location = new System.Drawing.Point(745, 361);
this.buttonRIGHT.Name = "buttonRIGHT";
this.buttonRIGHT.Size = new System.Drawing.Size(30, 29);
this.buttonRIGHT.TabIndex = 4;
this.buttonRIGHT.UseVisualStyleBackColor = true;
this.buttonRIGHT.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDOWN
//
this.buttonDOWN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDOWN.BackgroundImage = global::Traktor.Properties.Resources.arrowDown;
this.buttonDOWN.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDOWN.Location = new System.Drawing.Point(709, 379);
this.buttonDOWN.Name = "buttonDOWN";
this.buttonDOWN.Size = new System.Drawing.Size(30, 29);
this.buttonDOWN.TabIndex = 5;
this.buttonDOWN.UseVisualStyleBackColor = true;
this.buttonDOWN.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUP
//
this.buttonUP.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUP.BackgroundImage = global::Traktor.Properties.Resources.arrowUp;
this.buttonUP.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUP.Location = new System.Drawing.Point(709, 343);
this.buttonUP.Name = "buttonUP";
this.buttonUP.Size = new System.Drawing.Size(30, 29);
this.buttonUP.TabIndex = 6;
this.buttonUP.UseVisualStyleBackColor = true;
this.buttonUP.Click += new System.EventHandler(this.ButtonMove_Click);
//
// DrawField
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 451);
this.Controls.Add(this.buttonUP);
this.Controls.Add(this.buttonDOWN);
this.Controls.Add(this.buttonRIGHT);
this.Controls.Add(this.buttonLEFT);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxTraktor);
this.Controls.Add(this.statusStrip);
this.Name = "DrawField";
this.Text = "Трактор";
this.Click += new System.EventHandler(this.ButtonMove_Click);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTraktor)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxTraktor;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonLEFT;
private Button buttonRIGHT;
private Button buttonDOWN;
private Button buttonUP;
}
}

View File

@ -0,0 +1,62 @@
namespace Traktor
{
public partial class DrawField : Form
{
private TraktorDraw _Traktor;
public DrawField()
{
InitializeComponent();
}
//Ïðîðèñîâêà ìàøèíû
private void Draw()
{
Bitmap bmp = new(pictureBoxTraktor.Width, pictureBoxTraktor.Height);
Graphics gr = Graphics.FromImage(bmp);
_Traktor?.DrawEntity(gr);
pictureBoxTraktor.Image = bmp;
}
//Ëîãèêà êíîïêè Ñîçäàòü
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
_Traktor = new TraktorDraw();
_Traktor.Init(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
_Traktor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTraktor.Width, pictureBoxTraktor.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_Traktor.Traktor.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_Traktor.Traktor.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò êóçîâà: {_Traktor.Traktor.BodyColor.Name}";
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
//ïîëó÷àåì èìÿ êíîïêè
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUP":
_Traktor?.MoveTransport(Direction.Up);
break;
case "buttonDOWN":
_Traktor?.MoveTransport(Direction.Down);
break;
case "buttonLEFT":
_Traktor?.MoveTransport(Direction.Left);
break;
case "buttonRIGHT":
_Traktor?.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void PictureBoxTraktor_Resize(object sender, EventArgs e)
{
_Traktor?.ChangeBorders(pictureBoxTraktor.Width, pictureBoxTraktor.Height);
Draw();
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Traktor
{
//Класс-сущности "Трактор"
internal class EntityTraktor
{
//Скорость
public int Speed { get; private set; }
//Вес
public float Weight { get; private set; }
//Цвет кузова
public Color BodyColor { get; private set; }
//Шаг перемещения трактора
public float Step => Speed * 100 / Weight;
public void Init(int speed, float weight, Color bodycolor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodycolor;
}
}
}

View File

@ -1,39 +0,0 @@
namespace Traktor
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace Traktor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -11,7 +11,7 @@ namespace Traktor
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(new DrawField());
}
}
}

View File

@ -0,0 +1,114 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Traktor.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Traktor.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowDown {
get {
object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowLeft {
get {
object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowRight {
get {
object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap arrowUp {
get {
object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap kisspng_computer_icons_arrow_encapsulated_postscript_left_arrow_5ac00b2487fba8_612718301522535204557 {
get {
object obj = ResourceManager.GetObject("kisspng-computer-icons-arrow-encapsulated-postscript-left-arrow-5ac00b2487fba8.61" +
"2718301522535204557", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -117,4 +117,20 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="kisspng-computer-icons-arrow-encapsulated-postscript-left-arrow-5ac00b2487fba8.612718301522535204557" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\kisspng-computer-icons-arrow-encapsulated-postscript-left-arrow-5ac00b2487fba8.612718301522535204557.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//test
namespace Traktor
{
// Класс, отвечающий за прорисовку и перемещение объекта-сущности
internal class TraktorDraw
{
//Сущность
public EntityTraktor Traktor { get; private set; }
/// Левая координата отрисовки сущности
private float startPosX;
/// Верхняя кооридната отрисовки сущности
private float startPosY;
/// Ширина окна отрисовки
private int? pictureWidth = null;
/// Высота окна отрисовки
private int? pictureHeight = null;
/// Ширина отрисовки сущности
private readonly int entWidth = 130;
/// Высота отрисовки сущности
private readonly int entHeight = 100;
public void Init(int speed, float weight, Color bodycolor)
{
Traktor = new EntityTraktor();
Traktor.Init(speed, weight, bodycolor);
}
//Установка позиции сущности
public void SetPosition(int x, int y, int width, int height)
{
if (x < 0 || y < 0 || width < x + entWidth || height < y + entHeight)
{
pictureHeight = null;
pictureWidth = null;
return;
}
startPosX = x;
startPosY = y;
pictureHeight = height;
pictureWidth = width;
}
//Изменение направления перемещения
public void MoveTransport(Direction direction)
{
if (!pictureWidth.HasValue || !pictureHeight.HasValue)
{
return;
}
switch (direction)
{
case Direction.Right:
if (startPosX + entWidth + Traktor.Step < pictureWidth)
{
startPosX += Traktor.Step;
}
break;
case Direction.Left:
if (startPosX-10 - Traktor.Step > 0)
{
startPosX -= Traktor.Step;
}
break;
case Direction.Down:
if (startPosY + entHeight + Traktor.Step < pictureHeight)
{
startPosY += Traktor.Step;
}
break;
case Direction.Up:
if (startPosY - Traktor.Step > 0)
{
startPosY -= Traktor.Step;
}
break;
}
}
//Отрисовка сущности
public void DrawEntity(Graphics g)
{
if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
{
return;
}
Pen pen_Black_1pxl = new Pen(Color.Black, 1);
Pen pen_Black_2pxl = new Pen(Color.Black, 2);
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY, 40, 30);
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 30, 100, 35);
g.DrawRectangle(pen_Black_1pxl, startPosX+72, startPosY + 10, 5, 20);
g.DrawEllipse(pen_Black_1pxl, startPosX-15, startPosY+67, 30, 30);
g.DrawEllipse(pen_Black_1pxl, startPosX+85, startPosY + 67, 30, 30);
g.DrawEllipse(pen_Black_1pxl, startPosX + 20, startPosY + 82, 15, 15);
g.DrawEllipse(pen_Black_1pxl, startPosX + 40, startPosY + 82, 15, 15);
g.DrawEllipse(pen_Black_1pxl, startPosX + 60, startPosY + 82, 15, 15);
g.DrawEllipse(pen_Black_1pxl, startPosX + 35, startPosY + 68, 10, 10);
g.DrawEllipse(pen_Black_1pxl, startPosX + 55, startPosY + 68, 10, 10);
g.DrawLine(pen_Black_2pxl, startPosX, startPosY + 67, startPosX + 100, startPosY + 67);
g.DrawLine(pen_Black_2pxl, startPosX, startPosY + 97, startPosX + 100, startPosY + 97);
Brush br = new SolidBrush(Traktor?.BodyColor ?? Color.Black);
g.FillRectangle(br, startPosX, startPosY, 40, 30);
g.FillRectangle(br, startPosX, startPosY + 30, 100, 35);
Brush brBlack = new SolidBrush(Color.Black);
g.FillRectangle(brBlack, startPosX + 72, startPosY + 10, 5, 20);
g.FillEllipse(brBlack, startPosX - 15, startPosY + 67, 30, 30);
g.FillEllipse(brBlack, startPosX + 85, startPosY + 67, 30, 30);
g.FillEllipse(brBlack, startPosX + 20, startPosY + 82, 15, 15);
g.FillEllipse(brBlack, startPosX + 40, startPosY + 82, 15, 15);
g.FillEllipse(brBlack, startPosX + 60, startPosY + 82, 15, 15);
g.FillEllipse(brBlack, startPosX + 35, startPosY + 68, 10, 10);
g.FillEllipse(brBlack, startPosX + 55, startPosY + 68, 10, 10);
}
//Смена границ формы
public void ChangeBorders(int width, int height)
{
pictureWidth = width;
pictureHeight = height;
if (pictureWidth <= entWidth || pictureHeight <= entHeight)
{
pictureWidth = null;
pictureHeight = null;
return;
}
if (startPosX + entWidth > pictureWidth)
{
startPosX = pictureWidth.Value - entWidth;
}
if (startPosY + entHeight > pictureHeight)
{
startPosY = pictureHeight.Value - entHeight;
}
}
}
}