Compare commits

..

16 Commits
main ... lab_4

Author SHA1 Message Date
Alenka
735492bfe2 Чуть пофиксила 2023-10-27 08:32:54 +04:00
Alenka
842e5a8ca4 почти done 2023-10-26 23:10:37 +04:00
Alenka
f5d9e89692 почти done 2023-10-26 16:46:27 +04:00
Alenka
1bacab8f18 start 2023-10-26 00:36:02 +04:00
Alenka
f08466a718 без доп 2023-10-13 11:21:23 +04:00
Alenka
065b937d2c no 2023-10-13 10:29:00 +04:00
Alenka
db85af0a99 Замена кнопок 2023-10-13 08:40:42 +04:00
Alenka
feeea2ef58 result 2023-10-12 22:22:08 +04:00
Alenka
5309de6c2f Почти готово 2023-10-12 19:01:51 +04:00
Alenka
5543d1951e 1 2023-10-12 18:50:26 +04:00
Alenka
929e314196 Лаба2 2023-10-12 18:30:16 +04:00
Alenka
4d583a149b Process 2023-10-12 00:51:50 +04:00
Alenka
3f9f29c8b8 Пробный класс 2023-10-12 00:40:22 +04:00
Alenka
ad1b457f40 1 лаба 2023-10-12 00:13:18 +04:00
Alenka
0ec2965ca6 Создание 2023-10-03 16:39:57 +04:00
Alenka
7a3c0eb6dd Создание проекта 2023-10-03 16:28:16 +04:00
31 changed files with 2016 additions and 0 deletions

25
Cruiser/Cruiser.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cruiser", "Cruiser\Cruiser.csproj", "{ED77B06B-3FF6-46B7-9C07-D85EADE42DBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED77B06B-3FF6-46B7-9C07-D85EADE42DBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED77B06B-3FF6-46B7-9C07-D85EADE42DBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED77B06B-3FF6-46B7-9C07-D85EADE42DBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED77B06B-3FF6-46B7-9C07-D85EADE42DBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {34B5A2AC-C740-4C58-BE0E-D0978BC3AFB6}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,84 @@
using Monorail.DrawningObjects;
namespace Monorail.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 @@


View File

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

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,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,177 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser;
using Monorail.Entities;
using Monorail.MovementStrategy;
namespace Monorail.DrawningObjects
{
public class DrawningMonorail
{
public EntityMonorail? EntityMonorail { get; protected set; }
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _monoRailWidth;
public int GetHeight => _monoRailHeight;
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX = 0;
protected int _startPosY = 0;
protected int _monoRailWidth = 110;
protected int _monoRailHeight = 60;
protected int wheelSz;
public DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int width, int height)
{
if (width <= _monoRailWidth || height <= _monoRailHeight)
return;
_pictureWidth = width;
_pictureHeight = height;
wheelSz = _monoRailHeight - _monoRailHeight * 7 / 10;
EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
}
protected DrawningMonorail(int speed, double weight, Color bodyColor, int width, int height, Color wheelColor, Color tireColor, int monoRailWidth, int monoRailHeight)
{
if (width <= _monoRailWidth || height <= _monoRailHeight)
return;
_pictureWidth = width;
_pictureHeight = height;
_monoRailHeight = monoRailHeight;
_monoRailWidth = monoRailWidth;
wheelSz = _monoRailHeight - _monoRailHeight * 7 / 10;
EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
}
public void SetPosition(int x, int y)
{
if (EntityMonorail == null)
return;
_startPosX = x;
_startPosY = y;
if (x + _monoRailWidth >= _pictureWidth || y + _monoRailHeight >= _pictureHeight)
{
_startPosX = 1;
_startPosY = 1;
}
}
public IMoveableObject GetMoveableObject => new
DrawningObjectMonorail(this);
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,
DirectionType.Down => _startPosY - +EntityMonorail.Step < _pictureHeight
};
}
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityMonorail == null)
return;
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityMonorail.Step >= 0)
_startPosX -= (int)EntityMonorail.Step;
break;
case DirectionType.Up:
if (_startPosY - EntityMonorail.Step >= 0)
_startPosY -= (int)EntityMonorail.Step;
break;
case DirectionType.Right:
if (_startPosX + EntityMonorail.Step + _monoRailWidth < _pictureWidth)
_startPosX += (int)EntityMonorail.Step;
break;
case DirectionType.Down:
if (_startPosY + EntityMonorail.Step + _monoRailHeight < _pictureHeight)
_startPosY += (int)EntityMonorail.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (EntityMonorail == null)
return;
int dif = _monoRailWidth / 10;
_monoRailWidth -= dif;
Pen pen = new(Color.Black);
Brush cartBrush = new SolidBrush(Color.Black);
Brush bodyBrush = new SolidBrush(EntityMonorail.BodyColor);
Pen windowPen = new(Color.Blue);
Brush wheelBrush = new SolidBrush(EntityMonorail.WheelColor);
Brush windowBrush = new SolidBrush(Color.White);
Pen tirePen = new Pen(EntityMonorail.TireColor);
if (_monoRailWidth - _monoRailWidth / 20 * 17 < wheelSz)
wheelSz = _monoRailWidth - _monoRailWidth / 20 * 17;
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
30);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
//если есть доп.фонари
/* if (Cruiser.Headlights)
{
Brush brYellow = new SolidBrush(Color.Yellow);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
20);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
20);
}*/
//основание лодки!!!
Brush br = new SolidBrush(EntityMonorail.BodyColor);
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
Point[] points = new Point[3];// нос лодки
points[0] = new Point(_startPosX + 100, _startPosY + 5);
points[1] = new Point(_startPosX + 100, _startPosY + 55);
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
g.FillPolygon(Brushes.Pink, points);
//границы носа лодки
Point[] points1 = new Point[3];// нос лодки
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
g.DrawPolygon(pen, points1);
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
//если есть ракетные шахты, добавить условие
g.DrawRectangle(Pens.Black, _startPosX + 35,
_startPosY + 23, 15, 15);
g.DrawRectangle(Pens.Black, _startPosX + 50,
_startPosY + 19, 30, 25);
// _monoRailWidth += dif;
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser;
using Monorail.DrawningObjects;
namespace Monorail.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,66 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Monorail.Entities;
namespace Monorail.DrawningObjects
{
public class DrawningLocomotive : DrawningMonorail
{
public DrawningLocomotive(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int width, int height, int addWheelsNumb,
Color additionalColor, bool secondCabine, bool magniteRail) : base(speed, weight, bodyColor, wheelColor, tireColor, width, height)
{
if (EntityMonorail != null)
{
EntityMonorail = new EntityLocomotive(speed, weight, bodyColor, wheelColor, tireColor,
addWheelsNumb, additionalColor, secondCabine, magniteRail);
}
}
public override void DrawTransport(Graphics g)
{
base.DrawTransport(g);
int dif = _monoRailWidth / 10;
_monoRailWidth -= dif;
Pen windowPen = new(Color.Blue);
Brush wheelBrush = new SolidBrush(EntityMonorail.WheelColor);
Brush windowBrush = new SolidBrush(Color.White);
if (EntityMonorail == null)
return;
if (EntityMonorail is not EntityLocomotive advancedMonorail)
{
return;
}
Pen additionalPen = new(advancedMonorail.AdditionalColor);
Brush additionalBrush = new SolidBrush(advancedMonorail.AdditionalColor);
//3 колеса
/* if (advancedMonorail.AddWheelsNumb >= 3)
{
g.FillEllipse(additionalBrush, _startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
g.DrawEllipse(additionalPen, _startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
}
g.DrawEllipse(additionalPen, _startPosX + _monoRailWidth / 10 * 3, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
}*/
if (advancedMonorail.SecondCabine)
{
Brush brYellow = new SolidBrush(Color.Yellow);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
20);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
20);
_monoRailWidth += dif;
//магнитная линия
if (advancedMonorail.MagniteRail)
{
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
}
}
}
}
}

196
Cruiser/Cruiser/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,196 @@
namespace Cruiser
{
partial class CruiserForm
{
/// <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>
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.ButtonStep = new System.Windows.Forms.Button();
this.SelectedCruiser = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(386, 68);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 34);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(667, 358);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Cruiser.Properties.Resources.вниз;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(543, 306);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 1;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Cruiser.Properties.Resources.влево;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(517, 306);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Cruiser.Properties.Resources.вправо;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(567, 306);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Cruiser.Properties.Resources.вверх;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(543, 284);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(0, 302);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(218, 34);
this.buttonCreate.TabIndex = 5;
this.buttonCreate.Text = "Создать простую";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button2.Location = new System.Drawing.Point(210, 301);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(251, 37);
this.button2.TabIndex = 6;
this.button2.Text = "Создать про версию";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"Центр",
"Угол"});
this.comboBox1.Location = new System.Drawing.Point(415, 22);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(182, 33);
this.comboBox1.TabIndex = 7;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// ButtonStep
//
this.ButtonStep.Location = new System.Drawing.Point(485, 70);
this.ButtonStep.Name = "ButtonStep";
this.ButtonStep.Size = new System.Drawing.Size(112, 34);
this.ButtonStep.TabIndex = 8;
this.ButtonStep.Text = "Шаг";
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// SelectedCruiser
//
this.SelectedCruiser.Location = new System.Drawing.Point(210, 261);
this.SelectedCruiser.Name = "SelectedCruiser";
this.SelectedCruiser.Size = new System.Drawing.Size(112, 34);
this.SelectedCruiser.TabIndex = 9;
this.SelectedCruiser.Text = "Выбрать";
this.SelectedCruiser.UseVisualStyleBackColor = true;
this.SelectedCruiser.Click += new System.EventHandler(this.SelectedCruiser_Click);
//
// CruiserForm
//
this.ClientSize = new System.Drawing.Size(667, 358);
this.Controls.Add(this.SelectedCruiser);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.pictureBox1);
this.Name = "CruiserForm";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
/// <param name="e"></param>
#endregion
private Button button1;
private PictureBox pictureBox1;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreate;
private Button button2;
private ComboBox comboBox1;
private Button ButtonStep;
private Button SelectedCruiser;
}
}

164
Cruiser/Cruiser/Form1.cs Normal file
View File

@ -0,0 +1,164 @@
using System;
using Cruiser;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Monorail.DrawningObjects;
using Monorail.MovementStrategy;
using Monorail;
namespace Cruiser
{
public partial class CruiserForm : Form
{
private DrawningMonorail? _drawningMonorail;
private AbstractStrategy? _abstractStrategy;
private AbstractStrategy? _strategy;
public DrawningMonorail? SelectedCar { get; private set; }
public CruiserForm()
{
InitializeComponent();
_strategy = null;
SelectedCar = null;
}
private void Draw()
{
if (_drawningMonorail == null)
{
return;
}
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningMonorail.DrawTransport(gr);
pictureBox1.Image = bmp;
}
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 button2_Click(object sender, EventArgs e)
{
Random random = new();
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
bodyColor = dialog.Color;
}
_drawningMonorail = new DrawningMonorail(random.Next(100, 300), random.Next(1000, 3000),
bodyColor, wheelColor, tireColor,
pictureBox1.Width, pictureBox1.Height);
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningMonorail == null)
{
return;
}
if (comboBox1.Enabled)
{
_abstractStrategy = comboBox1.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToEdge(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawningObjectMonorail(_drawningMonorail), pictureBox1.Width,
pictureBox1.Height);
comboBox1.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBox1.Enabled = true;
_abstractStrategy = null;
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
bodyColor = dialog.Color;
if (dialog.ShowDialog() == DialogResult.OK)
additionalColor = dialog.Color;
int addWheelNumb = random.Next(3, 5);
_drawningMonorail = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
bodyColor, wheelColor, tireColor,
pictureBox1.Width, pictureBox1.Height, addWheelNumb,
additionalColor, random.Next(0, 2) > 0, random.Next(0, 2) > 0);
Draw();
}
public void SelectedCruiser_Click(object sender, EventArgs e)
{
SelectedCar = _drawningMonorail;
DialogResult = DialogResult.OK;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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,176 @@
namespace Cruiser
{
partial class FormCruiserCollection
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel1 = new System.Windows.Forms.Panel();
this.textBox2 = new System.Windows.Forms.TextBox();
this.addStorageButton = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.button2 = new System.Windows.Forms.Button();
this.updateCollectionButton = new System.Windows.Forms.Button();
this.ButtonRemoveCar = new System.Windows.Forms.Button();
this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(971, 544);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// panel1
//
this.panel1.Controls.Add(this.textBox2);
this.panel1.Controls.Add(this.addStorageButton);
this.panel1.Controls.Add(this.listBoxStorages);
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.updateCollectionButton);
this.panel1.Controls.Add(this.ButtonRemoveCar);
this.panel1.Controls.Add(this.ButtonAddCruiser);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Location = new System.Drawing.Point(692, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(267, 520);
this.panel1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(60, 36);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(150, 31);
this.textBox2.TabIndex = 2;
//
// addStorageButton
//
this.addStorageButton.Location = new System.Drawing.Point(79, 88);
this.addStorageButton.Name = "addStorageButton";
this.addStorageButton.Size = new System.Drawing.Size(112, 34);
this.addStorageButton.TabIndex = 2;
this.addStorageButton.Text = "Добавить";
this.addStorageButton.UseVisualStyleBackColor = true;
this.addStorageButton.Click += new System.EventHandler(this.addStorageButton_Click);
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 25;
this.listBoxStorages.Location = new System.Drawing.Point(60, 128);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(152, 104);
this.listBoxStorages.TabIndex = 4;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(60, 264);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(159, 36);
this.button2.TabIndex = 2;
this.button2.Text = "Удалить набор";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.delStorageButton_Click);
//
// updateCollectionButton
//
this.updateCollectionButton.Location = new System.Drawing.Point(79, 469);
this.updateCollectionButton.Name = "updateCollectionButton";
this.updateCollectionButton.Size = new System.Drawing.Size(112, 34);
this.updateCollectionButton.TabIndex = 2;
this.updateCollectionButton.Text = "Обновить";
this.updateCollectionButton.UseVisualStyleBackColor = true;
this.updateCollectionButton.Click += new System.EventHandler(this.button1_Click);
//
// ButtonRemoveCar
//
this.ButtonRemoveCar.Location = new System.Drawing.Point(60, 429);
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
this.ButtonRemoveCar.Size = new System.Drawing.Size(150, 34);
this.ButtonRemoveCar.TabIndex = 2;
this.ButtonRemoveCar.Text = "Удалить";
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
//
// ButtonAddCruiser
//
this.ButtonAddCruiser.Location = new System.Drawing.Point(60, 317);
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(150, 34);
this.ButtonAddCruiser.TabIndex = 3;
this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(60, 381);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(150, 31);
this.textBox1.TabIndex = 2;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// FormCruiserCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(971, 544);
this.Controls.Add(this.panel1);
this.Controls.Add(this.pictureBox1);
this.Name = "FormCruiserCollection";
this.Text = "FormCruiserCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBox1;
private Panel panel1;
private Button ButtonRemoveCar;
private Button ButtonAddCruiser;
private TextBox textBox1;
private Button updateCollectionButton;
private TextBox textBox2;
private Button addStorageButton;
private ListBox listBoxStorages;
private Button button2;
}
}

View File

@ -0,0 +1,210 @@
using Monorail.DrawningObjects;
using Monorail.Generics;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Cruiser
{
public partial class FormCruiserCollection : Form
{
private readonly MonorailGenericStorage _storage;
public FormCruiserCollection()
{
InitializeComponent();
_storage = new MonorailGenericStorage(pictureBox1.Width, pictureBox1.Height);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void ButtonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
CruiserForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedCar != null)
{
MessageBox.Show("Объект добавлен");
pictureBox1.Image = obj.ShowMonorails();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
>= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
private void ButtonRemoveCar_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos;
if (textBox1.Text == null || !int.TryParse(textBox1.Text, out pos))
{
MessageBox.Show("Введите номер парковочного места");
return;
}
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox1.Image = obj.ShowMonorails();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
CruiserForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedCar != null)
{
MessageBox.Show("Объект добавлен");
pictureBox1.Image = obj.ShowMonorails();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void maskedTextBoxNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBox1.Image = obj.ShowMonorails();
}
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox1.Image =
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
}
private void delStorageButton_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void addStorageButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBox2.Text);
ReloadObjects();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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 Cruiser;
using Monorail.DrawningObjects;
namespace Monorail.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,102 @@
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Monorail.DrawningObjects;
using System.Drawing;
namespace Monorail.Generics
{
internal class MonorailGenericCollection<T, U>
where T : DrawningMonorail
where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 90;
private readonly SetGeneric<T> _collection;
public MonorailGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static bool operator +(MonorailGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
return false;
return collect?._collection.Insert(obj) ?? false;
}
public static T? operator -(MonorailGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection[pos];
if (obj != null)
collect._collection.Remove(pos);
return obj;
}
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowMonorails()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
int i = 0;
foreach (var monorail in _collection.GetMonorails())
{
if (monorail != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
// monorail.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight + 5);
monorail.SetPosition((i % inRow) * (_placeSizeWidth) + _placeSizeWidth / 20, _placeSizeHeight * (i / inRow) + _placeSizeHeight / 20);
monorail.DrawTransport(g);
}
i++;
}
}
}
}

View File

@ -0,0 +1,51 @@
using Monorail.DrawningObjects;
using Monorail.Generics;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.Generics
{
internal class MonorailGenericStorage
{
readonly Dictionary<string, MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> _monorailStorages;
public List<string> Keys => _monorailStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public MonorailGenericStorage(int pictureWidth, int pictureHeight)
{
_monorailStorages = new Dictionary<string,
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
_monorailStorages.Add(name, new MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (!_monorailStorages.ContainsKey(name))
return;
_monorailStorages.Remove(name);
}
public MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
{
get
{
if (_monorailStorages.ContainsKey(ind))
return _monorailStorages[ind];
return null;
}
}
}
}

View File

@ -0,0 +1,49 @@

using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.MovementStrategy
{
public class MoveToEdge : 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)
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY < 0)
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,59 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.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,32 @@
namespace Monorail.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;
}
}
}

28
Cruiser/Cruiser/Pro.cs Normal file
View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.Entities
{
public class EntityLocomotive : EntityMonorail
{
public Color AdditionalColor { get; private set; }
public int AddWheelsNumb { get; private set; }
public bool SecondCabine { get; private set; }
public bool MagniteRail { get; private set; }
public EntityLocomotive(int speed, double weight, Color bodyColor, Color wheelColor,
Color tireColor, int addWheelsNumb, Color secondCabineColor, bool secondCabine, bool magniteRail) : base(speed, weight, bodyColor, wheelColor, tireColor)
{
AdditionalColor = secondCabineColor;
AddWheelsNumb = addWheelsNumb;
SecondCabine = secondCabine;
MagniteRail = magniteRail;
}
}
}

View File

@ -0,0 +1,18 @@
namespace Cruiser
{
// ïîêà íå ìåíÿþ
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 FormCruiserCollection());
}
}
}

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Cruiser.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("Cruiser.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 вверх {
get {
object obj = ResourceManager.GetObject("вверх", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap влево {
get {
object obj = ResourceManager.GetObject("влево", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap вниз {
get {
object obj = ResourceManager.GetObject("вниз", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap вправо {
get {
object obj = ResourceManager.GetObject("вправо", 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="вниз" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\вниз.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="влево" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\влево.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="вверх" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\вверх.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="вправо" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\вправо.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: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.Generics
{
internal class SetGeneric<T>
where T : class
{
private readonly List<T?> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(count);
}
public bool Insert(T monorail)
{
if (_places.Count == _maxCount)
return false;
Insert(monorail, 0);
return true;
}
public bool Insert(T monorail, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
return false;
_places.Insert(position, monorail);
return true;
}
public bool Remove(int position)
{
if (!(position >= 0 && position < Count))
return false;
_places.RemoveAt(position);
return true;
}
public T? this[int position]
{
get
{
if (!(position >= 0 && position < Count))
return null;
return _places[position];
}
set
{
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
return;
_places.Insert(position, value);
return;
}
}
public IEnumerable<T?> GetMonorails(int? maxMonorails = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxMonorails.HasValue && i == maxMonorails.Value)
{
yield break;
}
}
}
}
}

15
Cruiser/Cruiser/Status.cs Normal file
View File

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