Compare commits

...

3 Commits
main ... laba1

Author SHA1 Message Date
6295e00999 зафиксировать 2023-12-25 00:13:20 +04:00
126cd2332b зафиксировать 2023-12-10 22:19:19 +04:00
93c5ba6742 зафиксировать 2023-12-10 22:18:33 +04:00
13 changed files with 2584 additions and 0 deletions

25
Boat_Hard/Boat_Hard.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Boat_Hard", "Boat_Hard\Boat_Hard.csproj", "{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6F3D5F9-6B0F-40E6-B0A1-4F6D3783D0CC}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<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,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
public class DrawningBoat
{
public EntityBoat? EntityBoat { get; private set; }
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private readonly int _boatWidth = 160;
private readonly int _boatHeight = 118;
private DrawningOars drawningOars;
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool motor, int oars, int width, int height)
{
if (width < _boatWidth || height < _boatHeight)
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
EntityBoat = new EntityBoat();
EntityBoat.Init(speed, weight, bodyColor, additionalColor, motor, oars);
drawningOars = new DrawningOars();
drawningOars.SetAmount(oars);
return true;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x + _boatWidth > _pictureWidth)
{
x = _pictureWidth - _boatWidth;
}
if (y < 0 || y + _boatWidth > _pictureHeight)
{
y = _pictureHeight - _boatHeight;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (EntityBoat == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityBoat.Step > 0)
{
_startPosX -= (int)EntityBoat.Step;
}
break;
case DirectionType.Up:
if (_startPosY - EntityBoat.Step > 0)
{
_startPosY -= (int)EntityBoat.Step;
}
break;
case DirectionType.Right:
if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
{
_startPosX += (int)EntityBoat.Step;
}
break;
case DirectionType.Down:
if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
{
_startPosY += (int)EntityBoat.Step;
}
break;
}
}
public void DrawBoat(Graphics g)
{
if (EntityBoat == null)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityBoat.BodyColor);
Brush mainBrush = new SolidBrush(EntityBoat.AdditionalColor);
drawningOars.DrawOars(g, _startPosX, _startPosY);
g.FillRectangle(mainBrush, _startPosX + 20, _startPosY + 20, 150, 90);
g.DrawEllipse(pen, _startPosX + 30, _startPosY + 30, 130, 70);
g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY + 30, 130, 70);
#region Координаты переда лодки
Point b1 = new Point(_startPosX + 170, _startPosY + 20);
Point b2 = new Point(_startPosX + 200, _startPosY + 70);
Point b3 = new Point(_startPosX + 170, _startPosY + 110);
Point[] pointsBoat = { b1, b2, b3 };
#endregion
g.DrawPolygon(pen, pointsBoat);
g.FillPolygon(mainBrush, pointsBoat);
}
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
public class DrawningOars
{
private Oars amount;
public void SetAmount(int a)
{
if (a <= 1)
{
amount = Oars.One;
}
else if (a == 2)
{
amount = Oars.Two;
}
else if (a >= 3)
{
amount = Oars.Three;
}
}
public void DrawOars(Graphics g, int _startPosX, int _startPosY)
{
Brush oarsColor = new SolidBrush(Color.Black);
g.FillPolygon(oarsColor, new Point[] // up
{
new Point(_startPosX + 31, _startPosY - 10),
new Point(_startPosX + 41, _startPosY - 10),
new Point(_startPosX + 41, _startPosY + 90),
new Point(_startPosX + 31, _startPosY + 90),
}
);
g.FillPolygon(oarsColor, new Point[] // down
{
new Point(_startPosX + 31, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 140),
new Point(_startPosX + 31, _startPosY + 140),
}
);
if (amount == Oars.Two || amount == Oars.Three)
{
g.FillPolygon(oarsColor, new Point[] // up
{
new Point(_startPosX + 61, _startPosY - 10),
new Point(_startPosX + 71, _startPosY - 10),
new Point(_startPosX + 71, _startPosY + 90),
new Point(_startPosX + 61, _startPosY + 90),
}
);
g.FillPolygon(oarsColor, new Point[] // down
{
new Point(_startPosX + 61, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 140),
new Point(_startPosX + 61, _startPosY + 140),
}
);
}
if (amount == Oars.Three)
{
g.FillPolygon(oarsColor, new Point[] // up
{
new Point(_startPosX + 91, _startPosY - 10),
new Point(_startPosX + 101, _startPosY - 10),
new Point(_startPosX + 101, _startPosY + 90),
new Point(_startPosX + 91, _startPosY + 90),
}
);
g.FillPolygon(oarsColor, new Point[] // down
{
new Point(_startPosX + 91, _startPosY + 30),
new Point(_startPosX + 101, _startPosY + 30),
new Point(_startPosX + 101, _startPosY + 140),
new Point(_startPosX + 91, _startPosY + 140),
}
);
}
}
}
}

View File

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

132
Boat_Hard/Boat_Hard/FormBoat.Designer.cs generated Normal file
View File

@ -0,0 +1,132 @@
namespace Boat_Hard
{
partial class FormBoat
{
/// <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(FormBoat));
buttonCreate = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonLeft = new Button();
pictureBoxBoat = new PictureBox();
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit();
SuspendLayout();
//
// buttonCreate
//
buttonCreate.Location = new Point(23, 573);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(112, 34);
buttonCreate.TabIndex = 0;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// buttonUp
//
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(936, 525);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 1;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
//
// buttonDown
//
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(936, 577);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 2;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
// buttonRight
//
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(972, 550);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// buttonLeft
//
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(900, 550);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 4;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
//
// pictureBoxBoat
//
pictureBoxBoat.Dock = DockStyle.Fill;
pictureBoxBoat.Location = new Point(0, 0);
pictureBoxBoat.Name = "pictureBoxBoat";
pictureBoxBoat.Size = new Size(1035, 619);
pictureBoxBoat.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxBoat.TabIndex = 5;
pictureBoxBoat.TabStop = false;
//
// FormBoat
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1035, 619);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxBoat);
Name = "FormBoat";
Text = "FormBoat";
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCreate;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private PictureBox pictureBoxBoat;
}
}

View File

@ -0,0 +1,61 @@
namespace Boat_Hard
{
public partial class FormBoat : Form
{
private DrawningBoat? _drawningBoat;
public FormBoat()
{
InitializeComponent();
}
private void Draw()
{
if (_drawningBoat == null)
{
return;
}
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningBoat.DrawBoat(gr);
pictureBoxBoat.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningBoat = new DrawningBoat();
_drawningBoat.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)), Convert.ToBoolean(random.Next(0, 2))
//, Convert.ToBoolean(random.Next(0, 2))
,random.Next(1, 4) * 2, pictureBoxBoat.Width, pictureBoxBoat.Height);
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningBoat == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningBoat.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningBoat.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningBoat.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningBoat.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
public enum Oars
{
One,
Two,
Three
}
}

View File

@ -0,0 +1,17 @@
namespace Boat_Hard
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormBoat());
}
}
}

View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Boat_Hard.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("Boat_Hard.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;
}
}
}
}

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>