PIbd-22. Stroev V.M. Lab Work 02 #3

Closed
StroevVladimir wants to merge 3 commits from Lab02 into Lab1
24 changed files with 1321 additions and 0 deletions
Showing only changes of commit 3bd364d6ab - Show all commits

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33801.468
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonorailProject", "MonorailProject\MonorailProject.csproj", "{9FCA3318-633F-404A-B465-6DF510961ED2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9FCA3318-633F-404A-B465-6DF510961ED2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FCA3318-633F-404A-B465-6DF510961ED2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FCA3318-633F-404A-B465-6DF510961ED2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FCA3318-633F-404A-B465-6DF510961ED2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E490344E-18A5-4A0A-A607-857B4986CFC5}
EndGlobalSection
EndGlobal

View File

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

View File

@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MonorailProject.Entities;
namespace MonorailProject.DrawningObjects
{
public class DrawningMonorail
{
public EntityMonorail? EntityMonorail { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected int _relWidth = 150;
protected readonly int _relHeight = 46;
public DrawningMonorail(int speed, double weight, Color bodyColor, int width, int height)
{
if (0 + _relWidth >= width || 0 + _relHeight >= height)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityMonorail = new EntityMonorail(speed, weight, bodyColor);
}
protected DrawningMonorail(int speed, double weight, Color bodyColor, int width,
int height, int carWidth, int carHeight)
{
if (0 + _relWidth >= width || 0 + _relHeight >= height)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_relWidth = carWidth;
_relHeight = carHeight;
EntityMonorail = new EntityMonorail(speed, weight, bodyColor);
}
public void SetPosition(int x, int y)
{
if (x < 0 || x > _pictureWidth - _relWidth)
{
x = 0;
}
if (y < 0 || y > _pictureHeight - _relHeight)
{
y = 0;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityMonorail == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
_startPosX -= (int)EntityMonorail.Step;
break;
case DirectionType.Right:
_startPosX += (int)EntityMonorail.Step;
break;
case DirectionType.Up:
_startPosY -= (int)EntityMonorail.Step;
break;
case DirectionType.Down:
_startPosY += (int)EntityMonorail.Step;
break;
}
}
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _relWidth;
public int GetHeight => _relHeight;
public bool CanMove(DirectionType direction)
{
if (EntityMonorail == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityMonorail.Step > 0,
DirectionType.Up => _startPosY - EntityMonorail.Step > 0,
DirectionType.Right => _startPosX + EntityMonorail.Step < _pictureWidth - _relWidth,
DirectionType.Down => _startPosY + EntityMonorail.Step < _pictureHeight - _relHeight
};
}
public virtual void DrawTransport(Graphics g)
{
if (EntityMonorail == null)
{
return;
}
_relWidth = 150;
Pen pen = new(Color.Black, 2);
Brush bodyBrush = new SolidBrush(EntityMonorail.BodyColor);
//колёса
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 15, 15);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 15, 15);
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 15, 15);
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 35, 15, 15);
g.DrawRectangle(pen, _startPosX + 22, _startPosY + 36, 40, 8);
g.DrawRectangle(pen, _startPosX + 82, _startPosY + 36, 40, 8);
g.DrawEllipse(pen, _startPosX + 3, _startPosY + 37, 30, 8);
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 37, 29, 8);
Brush brBlack = new SolidBrush(Color.Black);
g.FillRectangle(brBlack, _startPosX + 22, _startPosY + 36, 40, 8);
g.FillRectangle(brBlack, _startPosX + 82, _startPosY + 36, 40, 8);
g.FillEllipse(brBlack, _startPosX + 3, _startPosY + 37, 30, 8);
g.FillEllipse(brBlack, _startPosX + 110, _startPosY + 37, 29, 8);
Brush brWhite = new SolidBrush(Color.White);
g.FillEllipse(brWhite, _startPosX + 20, _startPosY + 35, 15, 15);
g.FillEllipse(brWhite, _startPosX + 50, _startPosY + 35, 15, 15);
g.FillEllipse(brWhite, _startPosX + 80, _startPosY + 35, 15, 15);
g.FillEllipse(brWhite, _startPosX + 110, _startPosY + 35, 15, 15);
//Кабина
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 20, 120, 16);
g.FillRectangle(bodyBrush, _startPosX + 10, _startPosY + 20, 120, 16);
Point p1 = new Point(_startPosX + 10, _startPosY + 20);
Point p2 = new Point(_startPosX + 130, _startPosY + 20);
Point p3 = new Point(_startPosX + 130, _startPosY + 5);
Point p4 = new Point(_startPosX + 13, _startPosY + 5);
g.DrawPolygon(pen, new Point[] { p1, p2, p3, p4 });
g.FillPolygon(bodyBrush, new Point[] { p1, p2, p3, p4 });
//дверь
g.FillRectangle(brWhite, _startPosX + 49, _startPosY + 9, 12, 22);
g.DrawRectangle(pen, _startPosX + 49, _startPosY + 9, 12, 22);
//Окна и прочее
Pen penBlue = new Pen(Color.Cyan, 2);
g.DrawRectangle(penBlue, _startPosX + 20, _startPosY + 8, 10, 10);
g.DrawRectangle(penBlue, _startPosX + 35, _startPosY + 8, 10, 10);
g.DrawRectangle(penBlue, _startPosX + 117, _startPosY + 8, 10, 10);
g.DrawRectangle(pen, _startPosX + 132, _startPosY + 10, 2, 22);
}
}
}

View File

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MonorailProject.Entities;
namespace MonorailProject.DrawningObjects
{
public class DrawningSecondMonorail : DrawningMonorail
{
public DrawningSecondMonorail(int speed, double weight, Color bodyColor, Color
additionalColor, bool monorails, bool secondCabin, int width, int height) :
base(speed, weight, bodyColor, width, height, 110, 60)
{
if(EntityMonorail != null)
{
EntityMonorail = new EntitySecondMonorail(speed, weight, bodyColor, additionalColor, monorails, secondCabin);
}
}
public override void DrawTransport(Graphics g)
{
base.DrawTransport(g);
if (EntityMonorail is not EntitySecondMonorail secondMonorail)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(secondMonorail.AdditionalColor);
Brush brBlack = new SolidBrush(Color.Black);
Brush brWhite = new SolidBrush(Color.White);
Pen penBlue = new Pen(Color.Cyan, 2);
if (secondMonorail.Monorails)
{
g.DrawRectangle(pen, _startPosX, _startPosY + 50, 140, 10);
g.FillRectangle(brBlack, _startPosX, _startPosY + 50, 140, 10);
g.FillRectangle(brWhite, _startPosX + 5, _startPosY + 53, 130, 5);
}
if (secondMonorail.SecondCabin)
{
_relWidth = 290;
//низ
g.DrawEllipse(pen, _startPosX + 160, _startPosY + 35, 15, 15);
g.DrawEllipse(pen, _startPosX + 190, _startPosY + 35, 15, 15);
g.DrawEllipse(pen, _startPosX + 220, _startPosY + 35, 15, 15);
g.DrawEllipse(pen, _startPosX + 250, _startPosY + 35, 15, 15);
g.DrawRectangle(pen, _startPosX + 162, _startPosY + 36, 40, 8);
g.DrawRectangle(pen, _startPosX + 222, _startPosY + 36, 40, 8);
g.DrawEllipse(pen, _startPosX + 143, _startPosY + 37, 30, 8);
g.DrawEllipse(pen, _startPosX + 250, _startPosY + 37, 29, 8);
g.FillRectangle(brBlack, _startPosX + 162, _startPosY + 36, 40, 8);
g.FillRectangle(brBlack, _startPosX + 222, _startPosY + 36, 40, 8);
g.FillEllipse(brBlack, _startPosX + 143, _startPosY + 37, 30, 8);
g.FillEllipse(brBlack, _startPosX + 250, _startPosY + 37, 29, 8);
g.FillEllipse(brWhite, _startPosX + 160, _startPosY + 35, 15, 15);
g.FillEllipse(brWhite, _startPosX + 190, _startPosY + 35, 15, 15);
g.FillEllipse(brWhite, _startPosX + 220, _startPosY + 35, 15, 15);
g.FillEllipse(brWhite, _startPosX + 250, _startPosY + 35, 15, 15);
if (secondMonorail.Monorails)
{
g.DrawRectangle(pen, _startPosX + 140, _startPosY + 50, 145, 10);
g.FillRectangle(brBlack, _startPosX + 140, _startPosY + 50, 145, 10);
g.FillRectangle(brWhite, _startPosX + 135, _startPosY + 53, 145, 5);
}
//Кабина
g.DrawRectangle(pen, _startPosX + 150, _startPosY + 20, 120, 16);
g.FillRectangle(additionalBrush, _startPosX + 150, _startPosY + 20, 120, 16);
Point p5 = new Point(_startPosX + 150, _startPosY + 20);
Point p6 = new Point(_startPosX + 270, _startPosY + 20);
Point p7 = new Point(_startPosX + 267, _startPosY + 5);
Point p8 = new Point(_startPosX + 150, _startPosY + 5);
g.DrawPolygon(pen, new Point[] { p5, p6, p7, p8 });
g.FillPolygon(additionalBrush, new Point[] { p5, p6, p7, p8 });
//дверь
g.FillRectangle(brWhite, _startPosX + 189, _startPosY + 9, 12, 22);
g.DrawRectangle(pen, _startPosX + 189, _startPosY + 9, 12, 22);
//Окна и прочее
g.DrawRectangle(penBlue, _startPosX + 160, _startPosY + 8, 10, 10);
g.DrawRectangle(penBlue, _startPosX + 175, _startPosY + 8, 10, 10);
g.DrawRectangle(penBlue, _startPosX + 257, _startPosY + 8, 10, 10);
g.DrawRectangle(pen, _startPosX + 272, _startPosY + 10, 2, 22);
}
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MonorailProject.Entities
{
public class EntityMonorail
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public EntityMonorail(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace MonorailProject.Entities
{
public class EntitySecondMonorail : EntityMonorail
{
public Color AdditionalColor { get; private set; }
public bool Monorails { get; private set; }
public bool SecondCabin { get; private set; }
public EntitySecondMonorail(int speed, double weight, Color bodyColor,
Color additionalColor, bool monorails, bool secondCabin) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Monorails = monorails;
SecondCabin = secondCabin;
}
}
}

View File

@ -0,0 +1,183 @@
namespace MonorailProject
{
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()
{
pictureBoxMonorail = new PictureBox();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
ButtonCreateSecondMonorail = new Button();
ButtonCreateMonorail = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit();
SuspendLayout();
//
// pictureBoxMonorail
//
pictureBoxMonorail.Dock = DockStyle.Fill;
pictureBoxMonorail.Location = new Point(0, 0);
pictureBoxMonorail.Name = "pictureBoxMonorail";
pictureBoxMonorail.Size = new Size(800, 450);
pictureBoxMonorail.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxMonorail.TabIndex = 2;
pictureBoxMonorail.TabStop = false;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackColor = SystemColors.Info;
buttonLeft.BackgroundImage = Properties.Resources.left_arrow;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(656, 398);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(40, 40);
buttonLeft.TabIndex = 14;
buttonLeft.UseVisualStyleBackColor = false;
buttonLeft.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackColor = SystemColors.Info;
buttonDown.BackgroundImage = Properties.Resources.down_arrow;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(702, 398);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(40, 40);
buttonDown.TabIndex = 13;
buttonDown.UseVisualStyleBackColor = false;
buttonDown.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackColor = SystemColors.Info;
buttonRight.BackgroundImage = Properties.Resources.right_arrow;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(748, 398);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(40, 40);
buttonRight.TabIndex = 12;
buttonRight.UseVisualStyleBackColor = false;
buttonRight.Click += ButtonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackColor = SystemColors.Info;
buttonUp.BackgroundImage = Properties.Resources.upper_arrow;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(702, 352);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(40, 40);
buttonUp.TabIndex = 11;
buttonUp.UseVisualStyleBackColor = false;
buttonUp.Click += ButtonMove_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.BackColor = SystemColors.Info;
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
comboBoxStrategy.Location = new Point(637, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 15;
//
// buttonStep
//
buttonStep.BackColor = SystemColors.Info;
buttonStep.Location = new Point(694, 46);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(94, 29);
buttonStep.TabIndex = 16;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = false;
buttonStep.Click += ButtonStep_Click;
//
// ButtonCreateSecondMonorail
//
ButtonCreateSecondMonorail.BackColor = SystemColors.Info;
ButtonCreateSecondMonorail.Location = new Point(205, 397);
ButtonCreateSecondMonorail.Name = "ButtonCreateSecondMonorail";
ButtonCreateSecondMonorail.Size = new Size(239, 41);
ButtonCreateSecondMonorail.TabIndex = 17;
ButtonCreateSecondMonorail.Text = "Создать два Монорельса";
ButtonCreateSecondMonorail.UseVisualStyleBackColor = false;
ButtonCreateSecondMonorail.Click += ButtonCreateSecondMonorail_Click;
//
// ButtonCreateMonorail
//
ButtonCreateMonorail.BackColor = SystemColors.Info;
ButtonCreateMonorail.Location = new Point(12, 397);
ButtonCreateMonorail.Name = "ButtonCreateMonorail";
ButtonCreateMonorail.Size = new Size(175, 41);
ButtonCreateMonorail.TabIndex = 18;
ButtonCreateMonorail.Text = "Создать Монорельс";
ButtonCreateMonorail.UseVisualStyleBackColor = false;
ButtonCreateMonorail.Click += ButtonCreateMonorail_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = SystemColors.ControlDarkDark;
ClientSize = new Size(800, 450);
Controls.Add(ButtonCreateMonorail);
Controls.Add(ButtonCreateSecondMonorail);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(pictureBoxMonorail);
Name = "Form1";
Text = "Form1";
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox pictureBoxMonorail;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private ComboBox comboBoxStrategy;
private Button buttonStep;
private Button ButtonCreateSecondMonorail;
private Button ButtonCreateMonorail;
}
}

View File

@ -0,0 +1,113 @@
using MonorailProject.DrawningObjects;
using MonorailProject.MovementStrategy;
namespace MonorailProject
{
public partial class Form1 : Form
{
private DrawningMonorail? _drawningMonorail;
private AbstractStrategy? _abstractStrategy;
public Form1()
{
InitializeComponent();
}
private void Draw()
{
if (_drawningMonorail == null)
{
return;
}
Bitmap bmp = new(pictureBoxMonorail.Width,
pictureBoxMonorail.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningMonorail.DrawTransport(gr);
pictureBoxMonorail.Image = bmp;
}
private void ButtonCreateSecondMonorail_Click(object sender, EventArgs e)
{
Random random = new();
_drawningMonorail = new DrawningSecondMonorail(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)),
true, true,
pictureBoxMonorail.Width, pictureBoxMonorail.Height);
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void ButtonCreateMonorail_Click(object sender, EventArgs e)
{
Random random = new();
_drawningMonorail = new DrawningMonorail(random.Next(100, 300),
random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)), pictureBoxMonorail.Width, pictureBoxMonorail.Height);
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningMonorail == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningMonorail.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningMonorail.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningMonorail.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningMonorail.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningMonorail == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectMonorail(_drawningMonorail), pictureBoxMonorail.Width,
pictureBoxMonorail.Height);
//comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
}

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,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,73 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MonorailProject.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int
height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MonorailProject.DrawningObjects;
namespace MonorailProject.MovementStrategy
{
public class DrawningObjectMonorail : IMoveableObject
{
private readonly DrawningMonorail? _drawningMonorail = null;
public DrawningObjectMonorail(DrawningMonorail drawningMonorail)
{
_drawningMonorail = drawningMonorail;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningMonorail == null || _drawningMonorail.EntityMonorail ==
null)
{
return null;
}
return new ObjectParameters(_drawningMonorail.GetPosX,
_drawningMonorail.GetPosY, _drawningMonorail.GetWidth, _drawningMonorail.GetHeight);
}
}
public int GetStep => (int)(_drawningMonorail?.EntityMonorail?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningMonorail?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningMonorail?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,17 @@
using MonorailProject.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MonorailProject.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MonorailProject.MovementStrategy
{
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth&&
objParams.DownBorder <= FieldHeight&&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MonorailProject.MovementStrategy
{
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MonorailProject.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,133 @@
<?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="down-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="right-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="upper-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\upper-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="left-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left-arrow.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: 281 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B