Осталось нарисовать трактор

This commit is contained in:
Владислав Захаров 2022-09-18 17:40:14 +04:00
parent dc3460c619
commit 39f71b684c
15 changed files with 434 additions and 52 deletions

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

@ -0,0 +1,176 @@
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, 450);
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, 424);
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, 362);
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, 30);
this.buttonLEFT.TabIndex = 3;
this.buttonLEFT.UseVisualStyleBackColor = true;
//
// 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, 30);
this.buttonRIGHT.TabIndex = 4;
this.buttonRIGHT.UseVisualStyleBackColor = true;
//
// 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, 30);
this.buttonDOWN.TabIndex = 5;
this.buttonDOWN.UseVisualStyleBackColor = true;
//
// 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, 30);
this.buttonUP.TabIndex = 6;
this.buttonUP.UseVisualStyleBackColor = true;
//
// DrawField
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.statusStrip);
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.Name = "DrawField";
this.Text = "Трактор";
((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,40 @@
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(10, 70), random.Next(2500, 7000), 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 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

@ -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, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); 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"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </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> </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> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </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> </Project>

View File

@ -34,7 +34,7 @@ namespace Traktor
//Установка позиции сущности //Установка позиции сущности
public void SetPosition(int x, int y, int widgh, int height) public void SetPosition(int x, int y, int widgh, int height)
{ {//сделать проверку!!!!!
startPosX = x; startPosX = x;
startPosY = y; startPosY = y;
pictureHeight = height; pictureHeight = height;
@ -80,6 +80,13 @@ namespace Traktor
//Отрисовка сущности //Отрисовка сущности
public void DrawEntity(Graphics g) public void DrawEntity(Graphics g)
{ {
if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
{
return;
}
Pen pen = new Pen(Color.Blue);
} }