1 лабораторная

This commit is contained in:
sardq 2023-10-20 21:54:03 +04:00
parent e26a4625f0
commit 05d5b82867
10 changed files with 2754 additions and 170 deletions

View File

@ -0,0 +1,136 @@
namespace HoistingCrane
{
partial class CraneVisual
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CraneVisual));
this.pictureBoxCrane = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).BeginInit();
this.SuspendLayout();
//
// pictureBoxCrane
//
this.pictureBoxCrane.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCrane.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCrane.Name = "pictureBoxCrane";
this.pictureBoxCrane.Size = new System.Drawing.Size(878, 444);
this.pictureBoxCrane.TabIndex = 0;
this.pictureBoxCrane.TabStop = false;
//
// buttonCreate
//
this.buttonCreate.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCreate.Location = new System.Drawing.Point(0, 385);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(170, 59);
this.buttonCreate.TabIndex = 24;
this.buttonCreate.Text = "создать кран";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonDown
//
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonDown.Location = new System.Drawing.Point(811, 414);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 23;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonRight.Location = new System.Drawing.Point(847, 414);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 22;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonLeft.Location = new System.Drawing.Point(775, 414);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 21;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonUp.Location = new System.Drawing.Point(811, 378);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 20;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// CraneVisual
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(878, 444);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.pictureBoxCrane);
this.Name = "CraneVisual";
this.Text = "HoistingCrane";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrane)).EndInit();
this.ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxCrane;
private Button buttonCreate;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
}
}

View File

@ -0,0 +1,48 @@
namespace HoistingCrane
{
public partial class CraneVisual : Form
{
private DrawingCrane? _drawingCrane;
public CraneVisual()
{
InitializeComponent();
}
private void Draw()
{
if (_drawingCrane == null) return;
Bitmap btm = new(pictureBoxCrane.Width, pictureBoxCrane.Height);
Graphics gr = Graphics.FromImage(btm);
_drawingCrane.DrawTransport(gr);
pictureBoxCrane.Image = btm;
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
_drawingCrane = new DrawingCrane();
_drawingCrane.Init(random.Next(100, 300), random.Next(1000, 3000), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), 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)), pictureBoxCrane.Width, pictureBoxCrane.Height);
_drawingCrane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingCrane == null) return;
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingCrane.MoveCrane(DirectionType.Up);
break;
case "buttonDown":
_drawingCrane.MoveCrane(DirectionType.Down);
break;
case "buttonRight":
_drawingCrane.MoveCrane(DirectionType.Right);
break;
case "buttonLeft":
_drawingCrane.MoveCrane(DirectionType.Left);
break;
}
Draw();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,121 @@
using HoistingCrane;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
internal class DrawingCrane
{
public EntityCrane? EntityCrane { get; private set; }
private int _pictureWidth;
private int _pictureHeight;
private int _startPositionX;
private int _startPositionY;
private readonly int _craneWidth = 200;
private readonly int _craneHeight = 150;
public bool Init(int speed, double weight, bool counterWeight, bool crane, Color bodyColor, Color additionalColor, int width, int height)
{
if ((_craneWidth > width) || (_craneHeight > height)) return false;
_pictureHeight = height;
_pictureWidth = width;
EntityCrane = new EntityCrane();
EntityCrane.Init(speed, weight, counterWeight, crane, bodyColor, additionalColor);
return true;
}
public void SetPosition(int x, int y)
{
while (x + _craneWidth > _pictureWidth)
{
x -= _pictureWidth;
}
_startPositionX = x;
while (y + _craneHeight > _pictureHeight)
{
y -= _pictureHeight;
}
_startPositionY = y;
}
public void MoveCrane(DirectionType direction)
{
if (EntityCrane == null) return;
switch (direction)
{
case DirectionType.Left:
if (_startPositionX - EntityCrane.Step > 0)
{
_startPositionX -= (int)EntityCrane.Step;
}
break;
case DirectionType.Right:
if (_startPositionX + EntityCrane.Step + _craneWidth < _pictureWidth)
{
_startPositionX += (int)EntityCrane.Step;
}
break;
case DirectionType.Up:
if (_startPositionY - EntityCrane.Step > 0)
{
_startPositionY -= (int)EntityCrane.Step;
}
break;
case DirectionType.Down:
if (_startPositionY + EntityCrane.Step + _craneHeight < _pictureHeight)
{
_startPositionY += (int)EntityCrane.Step;
}
break;
}
}
public void DrawTransport(Graphics g)
{
if (EntityCrane == null) return;
Pen pen = new Pen(Color.Black);
Brush additionalBrush = new SolidBrush(EntityCrane.AdditionalColor);
Brush bodybrush = new SolidBrush(EntityCrane.BodyColor);
// Гусеницы
g.DrawLine(pen, _startPositionX + 5, _startPositionY + 110, _startPositionX + 195, _startPositionY + 110);
g.DrawLine(pen, _startPositionX, _startPositionY + 115, _startPositionX, _startPositionY + 145);
g.DrawLine(pen, _startPositionX + 5, _startPositionY + 150, _startPositionX + 195, _startPositionY + 150);
g.DrawLine(pen, _startPositionX + 200, _startPositionY + 115, _startPositionX + 200, _startPositionY + 145);
g.DrawArc(pen, _startPositionX, _startPositionY + 110, _craneWidth / 20, _craneHeight / 15, 135, 180);
g.DrawArc(pen, _startPositionX, _startPositionY + 140, _craneWidth / 20, _craneHeight / 15, 45, 180);
g.DrawArc(pen, _startPositionX + 190, _startPositionY + 110, _craneWidth / 20, _craneHeight / 20, 225, 180);
g.DrawArc(pen, _startPositionX + 190, _startPositionY + 143, _craneWidth / 20, _craneHeight / 20, 315, 180);
// основное тело
g.DrawRectangle(pen, _startPositionX + 10, _startPositionY + 65, 180, 40);
g.FillRectangle(bodybrush, _startPositionX + 10, _startPositionY + 65, 180, 40);
//катки
g.DrawEllipse(pen, _startPositionX + 2, _startPositionY + 112, 36, 36);
g.DrawEllipse(pen, _startPositionX + 160, _startPositionY + 112, 36, 36);
g.DrawEllipse(pen, _startPositionX + 45, _startPositionY + 128, 20, 20);
g.DrawEllipse(pen, _startPositionX + 89, _startPositionY + 128, 20, 20);
g.DrawEllipse(pen, _startPositionX + 133, _startPositionY + 128, 20, 20);
g.DrawEllipse(pen, _startPositionX + 74, _startPositionY + 112, 10, 10);
g.DrawEllipse(pen, _startPositionX + 111, _startPositionY + 112, 10, 10);
//кабинка и выхлоп
g.DrawRectangle(pen, _startPositionX + 60, _startPositionY + 10, 20, 55);
g.DrawRectangle(pen, _startPositionX + 110, _startPositionY, 75, 65);
if (EntityCrane.CounterWeight)
{
g.DrawRectangle(pen, _startPositionX + 185, _startPositionY + 20, 15, 45);
}
if (EntityCrane.Crane)
{
g.DrawRectangle(pen, _startPositionX + 20, _startPositionY, 30, 65);
g.DrawRectangle(pen, _startPositionX, _startPositionY, 20, 30);
g.FillRectangle(additionalBrush, _startPositionX + 20, _startPositionY, 30, 65);
g.FillRectangle(additionalBrush, _startPositionX, _startPositionY, 20, 30);
}
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
internal class EntityCrane
{
//скорость
public int Speed { get; private set; }
//вес
public double Weight { get; private set; }
//основной цввет
public Color BodyColor { get; private set; }
//дополнительный
public Color AdditionalColor { get; private set; }
//противовес
public bool CounterWeight { get; private set; }
//Кран
public bool Crane { get; private set; }
//шаг перемещения
public double Step => (double)Speed * 100 / Weight;
public void Init(int speed, double weight, bool counterWeight, bool crane, Color bodyColor, Color additionalColor)
{
Speed = speed;
Weight = weight;
CounterWeight = counterWeight;
Crane = crane;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
}
}
}

View File

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

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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 HoistingCrane
// 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 CraneVisual());
} }
} }
} }