PIbd-23. Radaev A.V. Lab work 01 #3

Closed
Arkadiy wants to merge 1 commits from Lab1 into main
9 changed files with 540 additions and 0 deletions
Showing only changes of commit c2010846bc - Show all commits

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

25
Catamaran/Catamaran.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Catamaran", "Catamaran.csproj", "{8734495B-CED4-4494-9044-77EA6895145A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8734495B-CED4-4494-9044-77EA6895145A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8734495B-CED4-4494-9044-77EA6895145A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8734495B-CED4-4494-9044-77EA6895145A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8734495B-CED4-4494-9044-77EA6895145A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4693C53A-17F9-49D1-B07F-0DF85BF650FB}
EndGlobalSection
EndGlobal

View File

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

View File

@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
internal class DrawningCatamaran
{
public EntityCatamaran? EntityCatamaran { get; private set; }
private int _pictureWidth = 800;
private int _pictureHeight = 450;
private int _startPosX = 0;
private int _startPosY = 0;
private readonly int _catamaranWidth = 120;
private readonly int _catamaranHeight = 80;
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, int width, int height)
{
if (_pictureHeight < _catamaranWidth && _pictureWidth < _catamaranHeight) return false;
_pictureWidth = width;
_pictureHeight = height;
EntityCatamaran = new EntityCatamaran();
EntityCatamaran.Init(speed, weight, bodyColor, additionalColor, bodyKit);
return true;
}
public void SetPosition(int x, int y)
{
if (EntityCatamaran == null) return;
while (x + _catamaranWidth > _pictureWidth)
{
x-= (int)EntityCatamaran.Step;
}
while (x < 0)
{
x+= (int)EntityCatamaran.Step;
}
while (y + _catamaranHeight > _pictureHeight)
{
y-= (int)EntityCatamaran.Step;
}
while (y < 0)
{
y+= (int)EntityCatamaran.Step;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (EntityCatamaran == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityCatamaran.Step > 0)
{
_startPosX -= (int)EntityCatamaran.Step;
}
break;
case DirectionType.Up:
if (_startPosY - EntityCatamaran.Step > 0)
{
_startPosY -= (int)EntityCatamaran.Step;
}
break;
case DirectionType.Right:
if (_startPosX + _catamaranWidth + EntityCatamaran.Step < _pictureWidth)
{
_startPosX += (int)EntityCatamaran.Step;
}
break;
case DirectionType.Down:
if (_startPosY + _catamaranHeight + EntityCatamaran.Step < _pictureHeight)
{
_startPosY += (int)EntityCatamaran.Step;
}
break;
}
}
public void DrawTransport(Graphics g)
{
if (EntityCatamaran == null)
{
return;
}
Pen pen = new(Color.Black);
Point[] pontf = { new Point(_startPosX + _catamaranWidth - 40, _startPosY+10), new Point(_startPosX + _catamaranWidth, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 40, _startPosY + 70) };
g.DrawRectangle(pen, _startPosX, _startPosY, _catamaranWidth - 20, 10);
g.DrawRectangle(pen, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
g.DrawRectangle(pen, _startPosX, _startPosY + 70, _catamaranWidth - 20, 10);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30);
g.DrawPolygon(pen, pontf);
Point[] trig1 = { new Point(_startPosX + _catamaranWidth -20, _startPosY), new Point(_startPosX + _catamaranWidth, _startPosY + 5), new Point(_startPosX+_catamaranWidth - 20, _startPosY+10) };
g.DrawPolygon(pen, trig1);
Point[] trig2 = { new Point(_startPosX + _catamaranWidth - 20, _startPosY + 70 ), new Point(_startPosX + _catamaranWidth, _startPosY + 75), new Point(_startPosX + _catamaranWidth - 20, _startPosY + 80) };
g.DrawPolygon(pen, trig2);
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
internal class EntityCatamaran
{
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 BodyKit { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
BodyKit = bodyKit;
}
}
}

126
Catamaran/FormCatamaran.Designer.cs generated Normal file
View File

@ -0,0 +1,126 @@
namespace Catamaran
{
partial class FormCatamaran
{
private System.ComponentModel.IContainer components = null;
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()
{
pictureBox=new PictureBox();
buttonCreate=new Button();
buttonUp=new Button();
buttonRight=new Button();
buttonDown=new Button();
buttonLeft=new Button();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// pictureBox
//
pictureBox.Dock=DockStyle.Fill;
pictureBox.Location=new Point(0, 0);
pictureBox.Name="pictureBox";
pictureBox.Size=new Size(800, 450);
pictureBox.TabIndex=5;
pictureBox.TabStop=false;
pictureBox.Click+=ButtonMove_Click;
//
// buttonCreate
//
buttonCreate.Anchor=AnchorStyles.Bottom|AnchorStyles.Left;
buttonCreate.Location=new Point(24, 383);
buttonCreate.Name="buttonCreate";
buttonCreate.Size=new Size(117, 44);
buttonCreate.TabIndex=6;
buttonCreate.Text="Создать";
buttonCreate.UseVisualStyleBackColor=true;
buttonCreate.Click+=buttonCreate_Click;
//
// buttonUp
//
buttonUp.Anchor=AnchorStyles.Bottom|AnchorStyles.Right;
buttonUp.Location=new Point(685, 358);
buttonUp.Name="buttonUp";
buttonUp.Size=new Size(30, 30);
buttonUp.TabIndex=10;
buttonUp.Text="⬆️";
buttonUp.UseVisualStyleBackColor=true;
buttonUp.Click+=ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor=AnchorStyles.Bottom|AnchorStyles.Right;
buttonRight.Location=new Point(721, 394);
buttonRight.Name="buttonRight";
buttonRight.Size=new Size(30, 30);
buttonRight.TabIndex=9;
buttonRight.Text="➞";
buttonRight.UseVisualStyleBackColor=true;
buttonRight.Click+=ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor=AnchorStyles.Bottom|AnchorStyles.Right;
buttonDown.Location=new Point(685, 394);
buttonDown.Name="buttonDown";
buttonDown.Size=new Size(30, 30);
buttonDown.TabIndex=8;
buttonDown.Text="⬇️";
buttonDown.UseVisualStyleBackColor=true;
buttonDown.Click+=ButtonMove_Click;
//
// buttonLeft
//
buttonLeft.Anchor=AnchorStyles.Bottom|AnchorStyles.Right;
buttonLeft.Location=new Point(649, 394);
buttonLeft.Name="buttonLeft";
buttonLeft.Size=new Size(30, 30);
buttonLeft.TabIndex=7;
buttonLeft.Text="⬅️";
buttonLeft.UseVisualStyleBackColor=true;
buttonLeft.Click+=ButtonMove_Click;
//
// FormCatamaran
//
AutoScaleDimensions=new SizeF(7F, 15F);
AutoScaleMode=AutoScaleMode.Font;
ClientSize=new Size(800, 450);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBox);
Name="FormCatamaran";
Text="FormCatamaran";
Load+=FormCatamaran_Load;
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private Button button1;
private Button UpBut;
private PictureBox pictureBox;
private Button buttonCreate;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
private Button buttonLeft;
}
}

View File

@ -0,0 +1,69 @@
namespace Catamaran
{
public partial class FormCatamaran : Form
{
public FormCatamaran()
{
InitializeComponent();
}
private DrawningCatamaran? _DrawningCatamaran;
private void Draw()
{
if (_DrawningCatamaran == null)
{
return;
}
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
Graphics gr = Graphics.FromImage(bmp);
_DrawningCatamaran.DrawTransport(gr);
pictureBox.Image = bmp;
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_DrawningCatamaran == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_DrawningCatamaran.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_DrawningCatamaran.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_DrawningCatamaran.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_DrawningCatamaran.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_DrawningCatamaran = new DrawningCatamaran();
_DrawningCatamaran.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)), false, pictureBox.Width, pictureBox.Height);
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void FormCatamaran_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -0,0 +1,120 @@
<?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>

14
Catamaran/Program.cs Normal file
View File

@ -0,0 +1,14 @@
namespace Catamaran
{
internal static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new FormCatamaran());
}
}
}