Compare commits

...

4 Commits
start ... Lab2

Author SHA1 Message Date
3e17af2218 Directions(Centre&Boarder) 2024-04-16 08:45:59 +04:00
0897fa70ef For2Tranports_remade_Incapsulation_1 2024-03-03 17:39:49 +04:00
90ce4321f0 Incapsulation_1 2024-03-03 17:36:01 +04:00
6a4009d6ba FirstLab_Incupsulation 2024-03-03 16:11:54 +04:00
26 changed files with 1471 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<ForceDesignerDPIUnaware>true</ForceDesignerDPIUnaware>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Simplify.Windows.Forms" Version="1.1.3" />
<PackageReference Include="System.Windows.Extensions" Version="8.0.0" />
<PackageReference Include="System.Windows.Forms.Pictograms" Version="1.3.22" />
<PackageReference Include="System.Windows.Forms.Ribbon35" Version="3.5.8" />
</ItemGroup>
<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,203 @@
using System.Drawing.Printing;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
using System.Xml.Linq;
namespace CruiserMech
{
partial class DrawingCanvas
{
/// <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()
{
pictureBox1 = new PictureBox();
CreateButton = new Button();
CreateButton2 = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
ButtonActivate = new Button();
comboBox = new ComboBox();
Activate = new Button();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
SuspendLayout();
//
// pictureBox1
//
pictureBox1.Dock = DockStyle.Fill;
pictureBox1.Location = new Point(0, 0);
pictureBox1.Margin = new Padding(6);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(1018, 604);
pictureBox1.TabIndex = 0;
pictureBox1.TabStop = false;
//
// CreateButton
//
CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
CreateButton.Location = new Point(22, 465);
CreateButton.Margin = new Padding(6);
CreateButton.Name = "CreateButton";
CreateButton.Size = new Size(139, 113);
CreateButton.TabIndex = 1;
CreateButton.Text = "Create object";
CreateButton.UseVisualStyleBackColor = true;
CreateButton.Click += buttonCr_Click;
//
// CreateButton2
//
CreateButton2.Location = new Point(22, 26);
CreateButton2.Margin = new Padding(6);
CreateButton2.Name = "CreateButton2";
CreateButton2.Size = new Size(139, 113);
CreateButton2.TabIndex = 2;
CreateButton2.Text = "Cr Updated Object";
CreateButton2.UseVisualStyleBackColor = true;
CreateButton2.Click += buttonCr2_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.up_arrow_res;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(817, 371);
buttonUp.Margin = new Padding(6);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(84, 96);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left_arrow_res;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(722, 480);
buttonLeft.Margin = new Padding(6);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(84, 96);
buttonLeft.TabIndex = 4;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down_arrow_res;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(817, 480);
buttonDown.Margin = new Padding(6);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(84, 96);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right_arrow_res;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(912, 480);
buttonRight.Margin = new Padding(6);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(84, 96);
buttonRight.TabIndex = 6;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// ListComboBox
//
//
// ButtonActivate
//
ButtonActivate.Anchor = AnchorStyles.Right;
ButtonActivate.Location = new Point(22, 149);
ButtonActivate.Margin = new Padding(6);
ButtonActivate.Name = "ButtonActivate";
ButtonActivate.Size = new Size(84, 96);
ButtonActivate.TabIndex = 8;
ButtonActivate.UseVisualStyleBackColor = true;
ButtonActivate.Click += comboBox_Activate;
//
// comboBox1
//
comboBox.FormattingEnabled = true;
comboBox.Items.AddRange(new object[] { "Center", "Boarder" });
comboBox.Location = new Point(188, 26);
comboBox.Name = "Directions";
comboBox.Size = new Size(203, 40);
comboBox.TabIndex = 9;
//
// Activate
//
Activate.Location = new Point(188, 93);
Activate.Name = "Activate";
Activate.Size = new Size(203, 46);
Activate.TabIndex = 10;
Activate.Text = "ActivateStep";
Activate.UseVisualStyleBackColor = true;
Activate.Click += comboBox_Activate;
//
// DrawingCanvas
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
AutoValidate = AutoValidate.EnableAllowFocusChange;
BackColor = Color.CornflowerBlue;
ClientSize = new Size(1018, 604);
Controls.Add(Activate);
Controls.Add(comboBox);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(CreateButton);
Controls.Add(CreateButton2);
Controls.Add(pictureBox1);
Controls.Add(ButtonActivate);
Margin = new Padding(4, 2, 4, 2);
Name = "DrawingCanvas";
StartPosition = FormStartPosition.Manual;
Text = "DrawingCanvas";
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBox1;
private Button CreateButton;
private Button CreateButton2;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button ButtonActivate;
private ComboBox comboBox;
private Button Activate;
}
}

View File

@ -0,0 +1,117 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CruiserMech.Drawing_tools;
using CruiserMech.Entity_Folder;
using CruiserMech.Move_Strategy;
namespace CruiserMech
{
public partial class DrawingCanvas : Form
{
private DrawingBase? _DrCruiser;
private AbstractStrategy _strategy;
public DrawingCanvas()
{
InitializeComponent();
_strategy = null;
}
//private DrawingCanvas_Load(object sender, EventArgs e);
private void Draw()
{
if (_DrCruiser == null)
{
return;
}
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp); _DrCruiser.DrawTransport(gr);
pictureBox1.Image = bmp;
}
private void CreateObj(string type)
{
Random rn = new Random();
switch (type)
{
case nameof(DrawingBase):
_DrCruiser = new DrawingBase(rn.Next(100, 300), rn.Next(1000, 3000), Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)));
break;
case nameof(DrawingCruiser):
Class_CruiserEntity Obj = new Class_CruiserEntity(rn.Next(100, 300), rn.Next(1000, 3000),
Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)), Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)),
Convert.ToBoolean(rn.Next(0, 2)), Convert.ToBoolean(rn.Next(0, 2)), rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
_DrCruiser = new DrawingCruiser(Obj);
break;
default:
return;
}
_DrCruiser.SetPicSize(pictureBox1.Width, pictureBox1.Height);
_DrCruiser.SetPos(rn.Next(pictureBox1.Width - 600, pictureBox1.Width - _DrCruiser._CruiserMaxW), rn.Next(0, 100)); _strategy = null;
comboBox.Enabled = true;
Draw();
}
private void comboBox_Activate(object sender, EventArgs e)
{
if (_DrCruiser == null) return;
if (comboBox.Enabled)
{
_strategy = comboBox.SelectedIndex switch
{
0 => new Center(),
1 => new Boarder()
};
if (_strategy == null) return;
_strategy.SetData(new MovableCruiser(_DrCruiser), pictureBox1.Width, pictureBox1.Height);
}
if (_strategy == null) return;
comboBox.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == Status.Finish)
{
comboBox.Enabled = true;
_strategy = null;
}
}
private void buttonCr2_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingCruiser));
private void buttonCr_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingBase));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_DrCruiser == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _DrCruiser.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _DrCruiser.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _DrCruiser.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _DrCruiser.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
}
}

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>

View File

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

View File

@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CruiserMech.Entity_Folder;
namespace CruiserMech.Drawing_tools
{
public class DrawingBase
{
/// Инициализация свойств (все параметры класса (сущности))
public Base_Class_Cruiser? BaseEntity { get; protected set; }
/// Передача размеров поля & объекта
private int? _pictureWidth;
private int? _pictureHeight;
public readonly int _CruiserMaxW = 302;
public readonly int _CruiserMaxH = 72;
/// Установка позиции
protected int? _startPosX;
protected int? _startPosY;
// for relationship with Moves*
public int? GetPosX => _startPosX;
public int? GetPosY => _startPosY;
public int GetWidth => _CruiserMaxW;
public int GetHeight => _CruiserMaxH;
private DrawingBase()
{
_pictureHeight = null;
_pictureWidth = null;
_startPosX = null;
_startPosY = null;
}
public DrawingBase(int speed, double weight, Color mainc) : this()
{
BaseEntity = new Base_Class_Cruiser(speed, weight, mainc);
}
protected DrawingBase(int MaxW, int MaxH) : this()
{
_CruiserMaxW = MaxW;
_CruiserMaxH = MaxH;
}
public bool SetPicSize(int w, int h)
{
if (w > _pictureWidth || h > _pictureHeight)
{
return false;
}
_pictureWidth = w;
_pictureHeight = h;
if (_startPosX != null || _startPosY != null)
{
SetPos(_startPosX.Value, _startPosY.Value);
}
return true;
}
public void SetPos(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x > _pictureWidth - _CruiserMaxW) _startPosX = _pictureWidth - _CruiserMaxW;
else if (x < 0) _startPosX = 0;
else _startPosX = x;
if (y > _pictureHeight - _CruiserMaxH) _startPosY = _pictureHeight.Value - _CruiserMaxH;
else if (y < 0) _startPosY = 0;
else _startPosY = y;
}
public bool MoveTransport(DirectionType direction) // public Direction (?)
{
if (BaseEntity == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - BaseEntity.Step > 0)
{
_startPosX -= (int)BaseEntity.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - BaseEntity.Step > 0)
{
_startPosY -= (int)BaseEntity.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + _CruiserMaxW + BaseEntity.Step < _pictureWidth.Value)
{
_startPosX += (int)BaseEntity.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + _CruiserMaxH + BaseEntity.Step < _pictureHeight.Value)
{
_startPosY += (int)BaseEntity.Step;
}
return true;
default:
return false;
}
}
public virtual void DrawTransport(Graphics g)
{
if (BaseEntity == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black, 2);
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
// Brush additionalBrush = new SolidBrush(BaseEntity.AdditionalC);
Brush mainBrush = new SolidBrush(BaseEntity.MainC);
Random random = new();
// границы cruiser
Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 7);
Point point1 = new Point(_startPosX.Value + 2, _startPosY.Value + 30);
Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 42);
Point point3 = new Point(_startPosX.Value + 260, _startPosY.Value + 34);
Point point4 = new Point(_startPosX.Value + 300, _startPosY.Value + 22);
Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 10);
Point point6 = new Point(_startPosX.Value + 184, _startPosY.Value + 2);
Point[] boarders = {
point0,
point1,
point2,
point3,
point4,
point5,
point6,
};
g.DrawPolygon(pen, boarders);
g.FillPolygon(mainBrush, boarders);
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 7, 38, 24);
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + 7, 20, 12);
g.FillRectangle(mainBrush, _startPosX.Value + 110, _startPosY.Value + 7, 20, 12);
g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + 18, 6, 20);
g.FillRectangle(mainBrush, _startPosX.Value + 117, _startPosY.Value + 18, 6, 20);
// салон на верхней палубе
//if (BaseEntity.Deckhouse)
//{
// // random location
// int y_h = BaseEntity.values[1];
// g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + y_h, 38, 24); // 40, 26
//
// g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
// g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
// g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
// g.FillRectangle(additionalBrush, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
//}
}
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CruiserMech.Entity_Folder;
namespace CruiserMech.Drawing_tools
{
internal class DrawingCruiser : DrawingBase
{
/// Инициализация свойств (все параметры класса (сущности))
// public Class_CruiserEntity? CE { get; private set; }
// CE = new Class_CruiserEntity( <...> );
// public DrawingCruiser(int speed, double weight,
// Color mainc, Color addtc, bool pad,
// bool hangar, int p, int d_coordinates, int h) : base(302, 72) // <...>
//{
// BaseEntity = new Class_CruiserEntity(speed, weight, mainc, addtc, pad, hangar, p, d_coordinates, h);
//}
public DrawingCruiser(Class_CruiserEntity Obj) : base(302, 72)
{
BaseEntity = Obj;
}
public override void DrawTransport(Graphics g)
{
if (BaseEntity is not Class_CruiserEntity cruiser || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return;
}
base.DrawTransport(g);
Pen pen = new(Color.Black, 2);
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
Brush additionalBrush = new SolidBrush(cruiser.AdditionalC);
Random random = new();
//границы cruiser <...>
if (cruiser.HelicopterPads)
{
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
}
// салон на верхней палубе - Deckhouse <...>
if (cruiser.Hangar)
{
int n = cruiser.values[2];
if (n == 1) g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
else
{
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
}
}
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Entity_Folder
{
public class Base_Class_Cruiser
{
/// MAIN свойства
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color MainC { get; private set; }
public double Step => Speed * 100 / Weight;
/// Конструктор
public Base_Class_Cruiser(int speed, double weight,
Color mainc)
{
Speed = speed;
Weight = weight;
MainC = mainc;
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Entity_Folder
{
internal class Class_CruiserEntity : Base_Class_Cruiser
{
/// ADDITIONAL свойства
public Color AdditionalC { get; private set; }
/// признаки (наличия)
public bool HelicopterPads { get; private set; } /// вертолетная площадка
public bool Hangar { get; private set; } /// ангар
public bool Deckhouse { get; private set; } /// салон на верхней палубе
public int[] values = { 0, 0, 0 };
public Class_CruiserEntity(int speed, double weight,
Color mainc, Color addtc, bool pad,
bool hangar, int p, int d_coordinates, int h) : base(speed, weight, mainc)
{
// NOT PUBLIC, so: -> impossible
//base.Speed = speed;
//base.Weight = weight;
//base.MainC = mainc;
AdditionalC = addtc;
HelicopterPads = pad;
Hangar = hangar;
values[0] = p;
values[1] = d_coordinates;
values[2] = h;
}
}
}

View File

@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
{
public abstract class AbstractStrategy
{
private IMO? _movableObj;
private Status _state = Status.NotInit;
protected int FieldHeight { get; private set; }
protected int FieldWidth { get; private set; }
public Status GetStatus() { return _state; } // => _state;
public void SetData(IMO movableObj, int width, int height)
{
if (movableObj == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_movableObj = movableObj;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDes())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(Moves.Left);
protected bool MoveRight() => MoveTo(Moves.Right);
protected bool MoveUp() => MoveTo(Moves.Up);
protected bool MoveDown() => MoveTo(Moves.Down);
protected ObjectParam? GetObjParam => _movableObj?.GetPos;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _movableObj?.GetStep;
}
protected virtual void MoveToTarget()
{
ObjectParam? objParams = GetObjParam;
if (objParams == null) { return; }
int diffx = objParams.MiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffx) > GetStep())
{
if (diffx > 0) MoveLeft();
else MoveRight();
}
int diffy = objParams.MiddleVertical - FieldHeight / 2;
if (Math.Abs(diffy) > GetStep())
{
if (diffy > 0) MoveUp();
else MoveDown();
}
}
protected virtual bool IsTargetDes()
{
ObjectParam? objParams = GetObjParam;
if (objParams == null) { return false; }
return objParams.MiddleHorizontal - GetStep() <= FieldWidth / 2 &&
objParams.MiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.MiddleVertical - GetStep() <= FieldHeight / 2 &&
objParams.MiddleVertical + GetStep() >= FieldHeight / 2;
}
private bool MoveTo(Moves moves)
{
if (_state != Status.InProgress)
{
return false;
}
return _movableObj?.TryMoveObj(moves) ?? false;
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy;
public class Boarder : AbstractStrategy
{
protected override bool IsTargetDes()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return false;
}
return FieldWidth - GetStep() < objP.SecondCoordX
&& FieldHeight - GetStep() < objP.SecondCoordY;
}
protected override void MoveToTarget()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return;
}
int s = (int)GetStep();
int diffx = objP.SecondCoordX - (FieldWidth - s);
if (Math.Abs(diffx) > GetStep())
{
if (diffx > 0)
{
MoveLeft();
// MoveRight();
}
else { MoveRight(); }
}
int diffy = objP.SecondCoordY - (FieldHeight - s);
if (Math.Abs(diffy) > GetStep())
{
if (diffy > 0)
{
MoveUp();
// MoveDown();
}
else { MoveDown(); }
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy;
public class Center : AbstractStrategy
{
protected override bool IsTargetDes()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return false;
}
return objP.MiddleHorizontal - GetStep() <= FieldWidth / 2 && objP.MiddleHorizontal + GetStep() >= FieldWidth / 2
&& objP.MiddleVertical - GetStep() <= FieldHeight / 2 && objP.MiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return;
}
int diffx = objP.MiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffx) > GetStep())
{
if (diffx > 0)
{
MoveLeft();
}
else { MoveRight(); }
}
int diffy = objP.MiddleVertical - FieldHeight / 2;
if (Math.Abs(diffy) > GetStep())
{
if (diffy > 0)
{
MoveUp();
}
else { MoveDown(); }
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
{
public interface IMO
{
// methods ! only
ObjectParam? GetPos { get; }
int GetStep { get; }
bool TryMoveObj(Moves direction);
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CruiserMech.Drawing_tools;
namespace CruiserMech.Move_Strategy
{
public class MovableCruiser : IMO
{
private readonly DrawingBase? _DrBase = null;
public MovableCruiser(DrawingBase drBase)
{
_DrBase = drBase;
}
public ObjectParam? GetPos
{
get
{
if (_DrBase == null || _DrBase.BaseEntity == null || !_DrBase.GetPosX.HasValue || !_DrBase.GetPosY.HasValue)
{
return null;
}
return new ObjectParam(_DrBase.GetPosX.Value, _DrBase.GetPosY.Value, _DrBase.GetWidth, _DrBase.GetHeight);
}
}
public int GetStep => (int)(_DrBase?.BaseEntity?.Step ?? 0);
public bool TryMoveObj(Moves direction)
{
if (_DrBase == null || _DrBase.BaseEntity == null)
{
return false;
}
return _DrBase.MoveTransport(GetDirectionType(direction));
}
private static DirectionType GetDirectionType(Moves direction)
{
return direction switch
{
Moves.Left => DirectionType.Left,
Moves.Right => DirectionType.Right,
Moves.Up => DirectionType.Up,
Moves.Down => DirectionType.Down,
_ => DirectionType.Unknown
};
}
}
}

View File

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

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
{
public class ObjectParam
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int RightBorder => _x + _width;
public int TopBorder => _y;
public int BottomBorder => _y + _height;
public int MiddleHorizontal => _x + _width / 2;
public int MiddleVertical => _y + _height / 2;
public int SecondCoordY => _y + _height;
public int SecondCoordX => _x + _width;
public ObjectParam(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CruiserMech.Move_Strategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}

View File

@ -0,0 +1,17 @@
namespace CruiserMech
{
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 DrawingCanvas());
}
}
}

View File

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

View File

@ -0,0 +1,136 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="right_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up_arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up_arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="left_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="down_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down_arrow_res.png;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: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 877 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CruiserMech", "CruiserMech\CruiserMech.csproj", "{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4BB26A0-B2DE-4C25-99FA-C84AC5FAD361}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7A9FCCBC-7DB9-4CE7-AA8B-6C609F3E0FB0}
EndGlobalSection
EndGlobal