ISEbd-22 Andrikhov A.S. Lab Work 01 #1

Closed
asoc1al wants to merge 6 commits from lab1 into main
16 changed files with 592 additions and 50 deletions

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck
{
internal enum DirectionType
Review

Имя файла не соответствует имени элемента проекта

Имя файла не соответствует имени элемента проекта
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck
{
internal class DrawingTruck
{
public EntityTruck? EntityTruck { get; private set; }
private int _startPosX;
private int _startPosY;
private int _pictureWidth;
private int _pictureHeight;
protected readonly int _truckWidth = 100;
protected readonly int _truckHeight = 50;
public bool Init(int speed, float weight, Color bodyColor, Color additionalColor, int width, int height, bool threeWheels, bool dump)
{
if (width < _truckWidth || height < _truckHeight)
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
EntityTruck = new EntityTruck();
EntityTruck.Init(speed, weight, bodyColor, additionalColor, threeWheels, dump);
return true;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x + _truckWidth > _pictureWidth)
{
x = _pictureWidth - _truckWidth;
}
if (y < 0 || y + _truckHeight > _pictureHeight)
{
y = _pictureHeight - _truckHeight;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (EntityTruck == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityTruck.Step > 0)
{
_startPosX -= (int)EntityTruck.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityTruck.Step > 0)
{
_startPosY -= (int)EntityTruck.Step;
}
break;
//вправо
case DirectionType.Right:
if (_startPosX + EntityTruck.Step + _truckWidth < _pictureWidth)
{
_startPosX += (int)EntityTruck.Step;
}
break;
case DirectionType.Down:
if (_startPosY + EntityTruck.Step + _truckHeight < _pictureHeight)
{
_startPosY += (int)EntityTruck.Step;
}
break;
}
}
public void DrawTransport(Graphics g, Color bodyColor, Color additionalColor, bool threeWheels, bool Dump)
Review

Color bodyColor, Color additionalColor, bool threeWheels, bool Dump не должны передаваться в метод, а должны браться из объекта EntityTruck

Color bodyColor, Color additionalColor, bool threeWheels, bool Dump не должны передаваться в метод, а должны браться из объекта EntityTruck
{
if (EntityTruck == null)
{
return;
}
Brush br = new SolidBrush(EntityTruck?.BodyColor ?? Color.Black);
g.FillRectangle(br, _startPosX + 80, _startPosY, 20, 30);
Brush brBodyRandom = new SolidBrush(bodyColor);
g.FillRectangle(brBodyRandom, _startPosX, _startPosY + 30, 100, 5);
Brush brBlack = new SolidBrush(Color.Black);
g.FillEllipse(brBlack, _startPosX, _startPosY + 35, 20, 20);
if (threeWheels)
g.FillEllipse(brBlack, _startPosX + 22, _startPosY + 35, 20, 20);
g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 35, 20, 20);
Brush brWhite = new SolidBrush(Color.White);
g.FillEllipse(brWhite, _startPosX + 5, _startPosY + 40, 10, 10);
if (threeWheels)
g.FillEllipse(brWhite, _startPosX + 27, _startPosY + 40, 10, 10);
g.FillEllipse(brWhite, _startPosX + 85, _startPosY + 40, 10, 10);
Pen pen = new Pen(Color.Black);
g.DrawRectangle(pen, _startPosX + 80, _startPosY, 20, 30);
g.DrawRectangle(pen, _startPosX, _startPosY + 30, 100, 5);
g.DrawEllipse(pen, _startPosX, _startPosY + 35, 20, 20);
if (threeWheels)
g.DrawEllipse(pen, _startPosX + 22, _startPosY + 35, 20, 20);
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20);
//Brush brBody = new SolidBrush(EntityTruck?.AdditionalColor ?? Color.Red);
Review

Закомментированного кода быть не должно

Закомментированного кода быть не должно
if (Dump)
{
Brush brBodyAdditional = new SolidBrush(additionalColor);
g.FillRectangle(brBodyAdditional, _startPosX + 0, _startPosY, 70, 30);
Pen pen1 = new Pen(Color.Black);
g.DrawRectangle(pen1, _startPosX + 0, _startPosY, 70, 30);
}
}
}
}

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,35 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck
{
internal class EntityTruck
{
public int Speed { get; private set; }
public float Weight { get; private set; }
public Color BodyColor { get; private set; }
public Color AdditionalColor { get; private set; }
public bool ThreeWheels { get; private set; }
public bool Dump { get; private set; }
public float Step => Speed * 100 / Weight;
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, bool threeWheels, bool dump)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
ThreeWheels = threeWheels;
Dump = dump;
}
}
}

View File

@ -1,39 +0,0 @@
namespace DumpTruck
{
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 DumpTruck
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

142
DumpTruck/DumpTruck/FormTruck.Designer.cs generated Normal file
View File

@ -0,0 +1,142 @@
namespace DumpTruck
{
partial class FormTruck
{
/// <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.btnCreate = new System.Windows.Forms.Button();
this.btnLeft = new System.Windows.Forms.Button();
this.btnDown = new System.Windows.Forms.Button();
this.btnRight = new System.Windows.Forms.Button();
this.btnUp = new System.Windows.Forms.Button();
this.pictureBoxTruck = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTruck)).BeginInit();
this.SuspendLayout();
//
// btnCreate
//
this.btnCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnCreate.Location = new System.Drawing.Point(12, 426);
this.btnCreate.Name = "btnCreate";
this.btnCreate.Size = new System.Drawing.Size(75, 23);
this.btnCreate.TabIndex = 0;
this.btnCreate.Text = "Создать";
this.btnCreate.UseVisualStyleBackColor = true;
this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
//
// btnLeft
//
this.btnLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnLeft.BackgroundImage = global::DumpTruck.Properties.Resources.left;
this.btnLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnLeft.Location = new System.Drawing.Point(766, 419);
this.btnLeft.Name = "btnLeft";
this.btnLeft.Size = new System.Drawing.Size(30, 30);
this.btnLeft.TabIndex = 1;
this.btnLeft.Text = " ";
this.btnLeft.UseVisualStyleBackColor = true;
this.btnLeft.Click += new System.EventHandler(this.btnMove_Click);
//
// btnDown
//
this.btnDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnDown.BackgroundImage = global::DumpTruck.Properties.Resources.down;
this.btnDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnDown.Location = new System.Drawing.Point(802, 419);
this.btnDown.Name = "btnDown";
this.btnDown.Size = new System.Drawing.Size(30, 30);
this.btnDown.TabIndex = 2;
this.btnDown.Text = " ";
this.btnDown.UseVisualStyleBackColor = true;
this.btnDown.Click += new System.EventHandler(this.btnMove_Click);
//
// btnRight
//
this.btnRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnRight.BackgroundImage = global::DumpTruck.Properties.Resources.right;
this.btnRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnRight.Location = new System.Drawing.Point(838, 419);
this.btnRight.Name = "btnRight";
this.btnRight.Size = new System.Drawing.Size(30, 30);
this.btnRight.TabIndex = 3;
this.btnRight.Text = " ";
this.btnRight.UseVisualStyleBackColor = true;
this.btnRight.Click += new System.EventHandler(this.btnMove_Click);
//
// btnUp
//
this.btnUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnUp.BackgroundImage = global::DumpTruck.Properties.Resources.up;
this.btnUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnUp.Location = new System.Drawing.Point(802, 383);
this.btnUp.Name = "btnUp";
this.btnUp.Size = new System.Drawing.Size(30, 30);
this.btnUp.TabIndex = 4;
this.btnUp.Text = " ";
this.btnUp.UseVisualStyleBackColor = true;
this.btnUp.Click += new System.EventHandler(this.btnMove_Click);
//
// pictureBoxTruck
//
this.pictureBoxTruck.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxTruck.Location = new System.Drawing.Point(0, 0);
this.pictureBoxTruck.Name = "pictureBoxTruck";
this.pictureBoxTruck.Size = new System.Drawing.Size(884, 461);
this.pictureBoxTruck.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxTruck.TabIndex = 5;
this.pictureBoxTruck.TabStop = false;
//
// FormTruck
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461);
this.Controls.Add(this.btnUp);
this.Controls.Add(this.btnRight);
this.Controls.Add(this.btnDown);
this.Controls.Add(this.btnLeft);
this.Controls.Add(this.btnCreate);
this.Controls.Add(this.pictureBoxTruck);
this.Name = "FormTruck";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FormTruck";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTruck)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button btnCreate;
private Button btnLeft;
private Button btnDown;
private Button btnRight;
private Button btnUp;
private PictureBox pictureBoxTruck;
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DumpTruck
{
public partial class FormTruck : Form
{
private DrawingTruck? _drawningTruck;
private void Draw()
{
if (_drawningTruck == null)
{
return;
}
Random rnd = new Random();
Bitmap bmp = new(pictureBoxTruck.Width,
pictureBoxTruck.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningTruck.DrawTransport(gr, Color.FromArgb(0,255,128),Color.FromArgb(255,0,0), false, true);
pictureBoxTruck.Image = bmp;
}
public FormTruck()
{
InitializeComponent();
}
private void btnCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningTruck = new DrawingTruck();
_drawningTruck.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256)), Color.FromArgb(random.Next(0,256)), pictureBoxTruck.Width, pictureBoxTruck.Height, Convert.ToBoolean(random.Next(2)), Convert.ToBoolean(random.Next(2)));
_drawningTruck.SetPosition(random.Next(1, 100), random.Next(1, 100));
Draw();
}
private void btnMove_Click(object sender, EventArgs e)
{
if (_drawningTruck == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "btnUp":
_drawningTruck.MoveTransport(DirectionType.Up);
break;
case "btnDown":
_drawningTruck.MoveTransport(DirectionType.Down);
break;
case "btnLeft":
_drawningTruck.MoveTransport(DirectionType.Left);
break;
case "btnRight":
_drawningTruck.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
}
}

View File

@ -0,0 +1,60 @@
<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>
</root>

View File

@ -11,7 +11,7 @@ namespace DumpTruck
// 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 FormTruck());
}
}
}

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DumpTruck.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("DumpTruck.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 down {
get {
object obj = ResourceManager.GetObject("down", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap left {
get {
object obj = ResourceManager.GetObject("left", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap right {
get {
object obj = ResourceManager.GetObject("right", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap up {
get {
object obj = ResourceManager.GetObject("up", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -117,4 +117,17 @@
<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="down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="left" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up.jpg;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: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB