Compare commits

...

12 Commits

30 changed files with 1751 additions and 51 deletions

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectElectricLocomotive.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,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectricLocomotive
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4,
}
}

View File

@ -0,0 +1,50 @@
using ProjectElectricLocomotive.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.DrawingObjects
{
public class DrawingElectricLocomotive : DrawingLocomotive
{
public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor,
bool horns, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 85, 50)
{
if (EntityLocomotive != null)
{
EntityLocomotive = new EntityElectricLocomotive(speed, width, bodyColor, additionalColor, horns, seifBatteries);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityLocomotive is not EntityElectricLocomotive electricLocomotive)
{
return;
}
Pen pen = new(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
Brush windows = new SolidBrush(Color.LightBlue);
Brush bodyColor = new SolidBrush(electricLocomotive.BodyColor);
Brush additionalBrush = new SolidBrush(electricLocomotive.AdditionalColor);
if (electricLocomotive.Horns)
{
//horns
g.FillRectangle(additionalBrush, _startPosX + 30, _startPosY + 15, 20, 5);
g.DrawLine(pen, _startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 10);
g.DrawLine(pen, _startPosX + 50, _startPosY + 10, _startPosX + 45, _startPosY);
g.DrawLine(pen, _startPosX + 45, _startPosY + 15, _startPosX + 50, _startPosY + 10);
g.DrawLine(pen, _startPosX + 50, _startPosY + 10, _startPosX + 40, _startPosY);
}
if (electricLocomotive.SeifBatteries)
{
g.FillRectangle(blackBrush, _startPosX + 80, _startPosY + 30, 5, 10);
}
base.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,200 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.Entities;
using ProjectElectricLocomotive.MovementStrategy;
using ProjectElectricLocomotive.Properties;
namespace ProjectElectricLocomotive.DrawingObjects
{
public class DrawingLocomotive
{
public EntityLocomotive? EntityLocomotive { get; protected set; }
protected int _pictureWidth;
protected int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _locoWidth = 85;
protected readonly int _locoHeight = 50;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _locoWidth;
public int GetHeight => _locoHeight;
public IMoveableObject GetMoveableObject => new DrawingObjectLocomotive(this);
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
{
if (width < _locoWidth || heigth < _locoHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = heigth;
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
protected DrawingLocomotive(int speed, double weight, Color bodyColor, int width,
int height, int locoWidth, int locoHeight)
{
if (width < _locoWidth || height < _locoHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_locoWidth = locoWidth;
_locoHeight = locoHeight;
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
}
//Установка позиции
public void SetPosition(int x, int y)
{
if (x < 0 || x + _locoWidth > _pictureWidth)
{
x = _pictureWidth - _locoWidth;
}
if (y < 0 || y + _locoHeight > _pictureHeight)
{
y = _pictureHeight - _locoHeight;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (EntityLocomotive == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityLocomotive.Step > 0)
{
_startPosX -= (int)EntityLocomotive.Step;
}
break;
case DirectionType.Up:
if (_startPosY - EntityLocomotive.Step > 0)
{
_startPosY -= (int)EntityLocomotive.Step;
}
break;
case DirectionType.Right:
if (_startPosX + EntityLocomotive.Step + _locoWidth < _pictureWidth)
{
_startPosX += (int)EntityLocomotive.Step;
}
break;
case DirectionType.Down:
if (_startPosY + EntityLocomotive.Step + _locoHeight < _pictureHeight)
{
_startPosY += (int)EntityLocomotive.Step;
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
{
if (EntityLocomotive == null) return;
}
Pen pen = new(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
Brush windows = new SolidBrush(Color.LightBlue);
Brush bodyColor = new SolidBrush(EntityLocomotive.BodyColor);
//локомотив
g.FillPolygon(bodyColor, new Point[]
{
new Point(_startPosX, _startPosY + 40),
new Point(_startPosX, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 20),
new Point(_startPosX + 70, _startPosY + 20),
new Point(_startPosX +80, _startPosY + 30),
new Point(_startPosX +80, _startPosY + 40),
new Point(_startPosX +75, _startPosY + 45),
new Point(_startPosX +5, _startPosY + 45),
new Point(_startPosX, _startPosY + 40),
}
);
g.DrawPolygon(pen, new Point[]
{
new Point(_startPosX, _startPosY + 40),
new Point(_startPosX, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 20),
new Point(_startPosX + 70, _startPosY + 20),
new Point(_startPosX +80, _startPosY + 30),
new Point(_startPosX +80, _startPosY + 40),
new Point(_startPosX +75, _startPosY + 45),
new Point(_startPosX +5, _startPosY + 45),
new Point(_startPosX, _startPosY + 40),
}
);
//окошки
g.FillPolygon(windows, new Point[]
{
new Point(_startPosX + 10, _startPosY + 30),
new Point(_startPosX +15, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 30),
new Point(_startPosX +10, _startPosY + 30),
}
);
g.DrawPolygon(pen, new Point[]
{
new Point(_startPosX + 10, _startPosY + 30),
new Point(_startPosX +15, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 25),
new Point(_startPosX + 20, _startPosY + 30),
new Point(_startPosX +10, _startPosY + 30),
}
);
g.FillRectangle(windows, _startPosX + 25, _startPosY + 25, 10, 5);
g.DrawRectangle(pen, _startPosX + 25, _startPosY + 25, 10, 5);
//обязательные колеса
//loco
g.FillEllipse(blackBrush, _startPosX + 10, _startPosY + 45, 5, 5);
g.FillEllipse(blackBrush, _startPosX + 25, _startPosY + 45, 5, 5);
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 45, 5, 5);
g.FillEllipse(blackBrush, _startPosX + 65, _startPosY + 45, 5, 5);
}
public bool CanMove(DirectionType direction)
{
if (EntityLocomotive == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityLocomotive.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityLocomotive.Step > 0,
// вправо
DirectionType.Right => _startPosX + EntityLocomotive.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + EntityLocomotive.Step < _pictureHeight,
};
}
}
}

View File

@ -0,0 +1,35 @@
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.MovementStrategy
{
public class DrawingObjectLocomotive : IMoveableObject
{
private readonly DrawingLocomotive? _drawningLocomotive = null;
public DrawingObjectLocomotive(DrawingLocomotive drawningLocomotive)
{
_drawningLocomotive = drawningLocomotive;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningLocomotive == null || _drawningLocomotive.EntityLocomotive == null)
{
return null;
}
return new ObjectParameters(_drawningLocomotive.GetPosX,
_drawningLocomotive.GetPosY, _drawningLocomotive.GetWidth, _drawningLocomotive.GetHeight);
}
}
public int GetStep => (int)(_drawningLocomotive?.EntityLocomotive?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawningLocomotive?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawningLocomotive?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,23 @@
using ProjectElectricLocomotive.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.Entities
{
public class EntityElectricLocomotive : EntityLocomotive
{
public Color AdditionalColor { get; private set; }
public bool Horns { get; private set; }
public bool SeifBatteries { get; private set; }
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool horns,
bool seifBatteries) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Horns = horns;
SeifBatteries = seifBatteries;
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.Entities
{
public class EntityLocomotive
{
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 EntityLocomotive(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -1,39 +0,0 @@
namespace ProjectElectricLocomotive
{
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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace ProjectElectricLocomotive
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,211 @@
namespace ElectricLocomotive
{
partial class FormElectricLocomotive
{
/// <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.pictureBoxElectricLocomotive = new System.Windows.Forms.PictureBox();
this.buttonCreateElectricLocomotive = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonCreateLocomotive = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
this.ButtonSelect_Locomotive = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxElectricLocomotive)).BeginInit();
this.SuspendLayout();
//
// pictureBoxElectricLocomotive
//
this.pictureBoxElectricLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxElectricLocomotive.Location = new System.Drawing.Point(0, 0);
this.pictureBoxElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive";
this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(994, 520);
this.pictureBoxElectricLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxElectricLocomotive.TabIndex = 0;
this.pictureBoxElectricLocomotive.TabStop = false;
//
// buttonCreateElectricLocomotive
//
this.buttonCreateElectricLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateElectricLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateElectricLocomotive.Location = new System.Drawing.Point(13, 442);
this.buttonCreateElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateElectricLocomotive.TabIndex = 1;
this.buttonCreateElectricLocomotive.Text = "Создать электролокомотив";
this.buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
this.buttonCreateElectricLocomotive.Click += new System.EventHandler(this.buttonCreateElectricLocomotive_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(878, 481);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(2);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(24, 24);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.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::ProjectElectricLocomotive.Properties.Resources.arrowUP;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(915, 442);
this.buttonUp.Margin = new System.Windows.Forms.Padding(2);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(24, 24);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.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::ProjectElectricLocomotive.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(950, 481);
this.buttonRight.Margin = new System.Windows.Forms.Padding(2);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(24, 24);
this.buttonRight.TabIndex = 4;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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::ProjectElectricLocomotive.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(915, 481);
this.buttonDown.Margin = new System.Windows.Forms.Padding(2);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(24, 24);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// comboBoxStrategy
//
this.comboBoxStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"MoveToCenter",
"MoveToRightCorner"});
this.comboBoxStrategy.Location = new System.Drawing.Point(846, 10);
this.comboBoxStrategy.Margin = new System.Windows.Forms.Padding(2);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(129, 28);
this.comboBoxStrategy.TabIndex = 6;
//
// buttonCreateLocomotive
//
this.buttonCreateLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateLocomotive.Location = new System.Drawing.Point(266, 442);
this.buttonCreateLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateLocomotive.Name = "buttonCreateLocomotive";
this.buttonCreateLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateLocomotive.TabIndex = 7;
this.buttonCreateLocomotive.Text = "Создать локомотив";
this.buttonCreateLocomotive.UseVisualStyleBackColor = true;
this.buttonCreateLocomotive.Click += new System.EventHandler(this.buttonCreateLocomotive_Click);
//
// buttonStep
//
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonStep.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonStep.Location = new System.Drawing.Point(863, 52);
this.buttonStep.Margin = new System.Windows.Forms.Padding(2);
this.buttonStep.Name = "buttonStep";
this.buttonStep.Size = new System.Drawing.Size(100, 45);
this.buttonStep.TabIndex = 8;
this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true;
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
//
// ButtonSelect_Locomotive
//
this.ButtonSelect_Locomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonSelect_Locomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonSelect_Locomotive.Location = new System.Drawing.Point(863, 113);
this.ButtonSelect_Locomotive.Margin = new System.Windows.Forms.Padding(2);
this.ButtonSelect_Locomotive.Name = "ButtonSelect_Locomotive";
this.ButtonSelect_Locomotive.Size = new System.Drawing.Size(100, 61);
this.ButtonSelect_Locomotive.TabIndex = 9;
this.ButtonSelect_Locomotive.Text = "Выбор локо";
this.ButtonSelect_Locomotive.UseVisualStyleBackColor = true;
this.ButtonSelect_Locomotive.Click += new System.EventHandler(this.ButtonSelect_Locomotive_Click);
//
// FormElectricLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(994, 520);
this.Controls.Add(this.ButtonSelect_Locomotive);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateLocomotive);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonCreateElectricLocomotive);
this.Controls.Add(this.pictureBoxElectricLocomotive);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "FormElectricLocomotive";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ElectricLocomotive";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxElectricLocomotive)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxElectricLocomotive;
private Button buttonCreateElectricLocomotive;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
private ComboBox comboBoxStrategy;
private Button buttonCreateLocomotive;
private Button buttonStep;
private Button ButtonSelect_Locomotive;
}
}

View File

@ -0,0 +1,143 @@
using ProjectElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
using System;
using System.Windows.Forms;
namespace ElectricLocomotive
{
public partial class FormElectricLocomotive : Form
{
private DrawingLocomotive? _drawingLocomotive;
private AbstractStrategy? _abstractStrategy;
public DrawingLocomotive? SelectedLocomotive { get; private set; }
public FormElectricLocomotive()
{
InitializeComponent();
_abstractStrategy = null;
SelectedLocomotive = null;
}
private void Draw()
{
if (_drawingLocomotive == null)
{
return;
}
Bitmap bmp = new(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingLocomotive.DrawTransport(gr);
pictureBoxElectricLocomotive.Image = bmp;
}
private void buttonCreateElectricLocomotive_Click(object sender, EventArgs e)
{
Random random = new Random();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog colorDialog = new ColorDialog();
if(colorDialog.ShowDialog() == DialogResult.OK){
color = colorDialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
if (colorDialog.ShowDialog() == DialogResult.OK)
{
dopColor = colorDialog.Color;
}
_drawingLocomotive = new DrawingElectricLocomotive(random.Next(100, 300),random.Next(1000, 3000),color, dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonCreateLocomotive_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog colorDialog = new ColorDialog();
if (colorDialog.ShowDialog() == DialogResult.OK)
{
color = colorDialog.Color;
}
_drawingLocomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), color,
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawingLocomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingLocomotive == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingLocomotive.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingLocomotive.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingLocomotive.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingLocomotive.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingLocomotive == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToRightCorner(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(_drawingLocomotive.GetMoveableObject, pictureBoxElectricLocomotive.Width,
pictureBoxElectricLocomotive.Height);
}
if (_abstractStrategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
private void ButtonSelect_Locomotive_Click(object sender, EventArgs e)
{
SelectedLocomotive = _drawingLocomotive;
DialogResult = DialogResult.OK;
}
}
}

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,133 @@
namespace ProjectElectricLocomotive
{
partial class FormLocomotiveCollections
{
/// <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.Instruments = new System.Windows.Forms.Panel();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveLocomotive = new System.Windows.Forms.Button();
this.ButtonAddLocomotive = new System.Windows.Forms.Button();
this.pictureBoxCollections = new System.Windows.Forms.PictureBox();
this.Instruments.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).BeginInit();
this.SuspendLayout();
//
// Instruments
//
this.Instruments.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.Instruments.AutoSize = true;
this.Instruments.Controls.Add(this.maskedTextBoxNumber);
this.Instruments.Controls.Add(this.ButtonRefreshCollection);
this.Instruments.Controls.Add(this.ButtonRemoveLocomotive);
this.Instruments.Controls.Add(this.ButtonAddLocomotive);
this.Instruments.Location = new System.Drawing.Point(435, -40);
this.Instruments.Name = "Instruments";
this.Instruments.Size = new System.Drawing.Size(191, 451);
this.Instruments.TabIndex = 0;
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(42, 123);
this.maskedTextBoxNumber.Mask = "0";
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
this.maskedTextBoxNumber.TabIndex = 4;
//
// ButtonRefreshCollection
//
this.ButtonRefreshCollection.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ButtonRefreshCollection.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonRefreshCollection.Location = new System.Drawing.Point(29, 249);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 36);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить все";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveLocomotive
//
this.ButtonRemoveLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ButtonRemoveLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(29, 179);
this.ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 36);
this.ButtonRemoveLocomotive.TabIndex = 1;
this.ButtonRemoveLocomotive.Text = "Удалить локо";
this.ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
this.ButtonRemoveLocomotive.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
//
// ButtonAddLocomotive
//
this.ButtonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonAddLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonAddLocomotive.Location = new System.Drawing.Point(29, 52);
this.ButtonAddLocomotive.Name = "ButtonAddLocomotive";
this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 36);
this.ButtonAddLocomotive.TabIndex = 0;
this.ButtonAddLocomotive.Text = "Добавить локо";
this.ButtonAddLocomotive.UseVisualStyleBackColor = true;
this.ButtonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
//
// pictureBoxCollections
//
this.pictureBoxCollections.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.pictureBoxCollections.Location = new System.Drawing.Point(-3, -2);
this.pictureBoxCollections.Name = "pictureBoxCollections";
this.pictureBoxCollections.Size = new System.Drawing.Size(458, 373);
this.pictureBoxCollections.TabIndex = 1;
this.pictureBoxCollections.TabStop = false;
//
// FormLocomotiveCollections
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(626, 370);
this.Controls.Add(this.pictureBoxCollections);
this.Controls.Add(this.Instruments);
this.Name = "FormLocomotiveCollections";
this.Text = "Набор локомотивов";
this.Instruments.ResumeLayout(false);
this.Instruments.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Panel Instruments;
private Button ButtonRefreshCollection;
private Button ButtonRemoveLocomotive;
private Button ButtonAddLocomotive;
private PictureBox pictureBoxCollections;
private MaskedTextBox maskedTextBoxNumber;
}
}

View File

@ -0,0 +1,70 @@
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.Generics;
using ProjectElectricLocomotive.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 ProjectElectricLocomotive
{
public partial class FormLocomotiveCollections : Form
{
private readonly LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
public FormLocomotiveCollections()
{
InitializeComponent();
_locomotives = new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(pictureBoxCollections.Width,
pictureBoxCollections.Height);
}
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
{
if (_locomotives == null) return;
FormElectricLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK)
{
//проверяем, удалось ли нам загрузить объект
if (_locomotives + form.SelectedLocomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_locomotives - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
}
}
}

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,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
namespace ProjectElectricLocomotive.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
namespace ProjectElectricLocomotive.Generics
{
internal class LocomotiveGenericCollection<T, U> where T : DrawingLocomotive where U : IMoveableObject
{
//ширина/высота окна
private readonly int _pictureWidth;
private readonly int _pictureHeight;
//ширина/высота занимаемого места
private readonly int _placeSizeWidth = 85;
private readonly int _placeSizeHeight = 50;
/// Набор объектов
private readonly SetGeneric<T> _collection;
public LocomotiveGenericCollection(int picWidth, int picHeight)
{
// немного странная логика, что-то я пока ее не особо понимаю, зачем нам ААААА дошло...
// высчитываем размер массива для setgeneric
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// Перегрузка оператора сложения
public static int operator +(LocomotiveGenericCollection<T, U> collect, T loco)
{
if (loco == null)
{
return -1;
}
return collect._collection.Insert(loco);
}
/// Перегрузка оператора вычитания
public static T operator -(LocomotiveGenericCollection<T, U> collect, int pos)
{
return collect._collection.Remove(pos);
}
// получение объекта imoveableObj
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
/// Вывод всего набора объектов
public Bitmap ShowLocomotives()
{
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 HeightObjCount = _pictureHeight / _placeSizeHeight;
int WidthObjCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
{
T? type = _collection.Get(i);
if (type != null)
{
type.SetPosition(
(int)(i / HeightObjCount * _placeSizeWidth),
(HeightObjCount - 1) * _placeSizeHeight - (int)(i % HeightObjCount * _placeSizeHeight)
);
type?.DrawTransport(g);
}
}
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.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,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.MovementStrategy
{
public class MoveToRightCorner : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null) return false;
return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null) return;
if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
}
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.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

@ -1,4 +1,6 @@
namespace ProjectElectricLocomotive using ProjectElectricLocomotive;
namespace ElectricLocomotive
{ {
internal static class Program internal static class Program
{ {
@ -11,7 +13,7 @@ namespace ProjectElectricLocomotive
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new FormLocomotiveCollections());
} }
} }
} }

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </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> </Project>

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.Generics
{
internal class SetGeneric<T> where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
public SetGeneric(int count)
{
_places = new T[count];
}
/// Добавление объекта в набор
public int Insert(T loco)
{
return Insert(loco, 0);
}
public int Insert(T loco, int position)
{
int NoEmpty = 0, temp = 0;
for (int i = position; i < Count; i++)
{
if (_places[i] != null) NoEmpty++;
}
if (NoEmpty == Count - position - 1) return -1;
if (position < Count && position >= 0)
{
for (int j = position; j < Count; j++)
{
if (_places[j] == null)
{
temp = j;
break;
}
}
// shift right
for (int i = temp; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = loco;
return position;
}
return -1;
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент //
}
public T Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= Count || position < 0)
return null;
T tmp = _places[position];
_places[position] = null;
return tmp;
}
//Получение объекта из набора по позиции
public T Get(int position)
{
// TODO проверка позиции
if (position < 0 || position >= Count) return null;
return _places[position];
}
}
}

View File

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