Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
cf3945209c | |||
17cb3342de | |||
0497411365 | |||
9f2f1b0686 | |||
9bd4a33db6 | |||
abc845461b | |||
9965a02c98 | |||
1c87d04014 | |||
925981ec50 | |||
8a9112530c | |||
a8e887e77d |
@ -0,0 +1,88 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Абстрактный класс стратегии
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
@ -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(blackBrush, _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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,198 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ElectricLocomotive;
|
||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
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 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace ProjectElectricLocomotive
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
185
ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
generated
Normal file
185
ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
generated
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
namespace ElectricLocomotive
|
||||||
|
{
|
||||||
|
partial class ElectricLocomotive
|
||||||
|
{
|
||||||
|
/// <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();
|
||||||
|
((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.Name = "pictureBoxElectricLocomotive";
|
||||||
|
this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(1242, 512);
|
||||||
|
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(16, 442);
|
||||||
|
this.buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
|
||||||
|
this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(272, 52);
|
||||||
|
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(1098, 464);
|
||||||
|
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);
|
||||||
|
//
|
||||||
|
// 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(1144, 415);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
|
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(1188, 464);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
|
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(1144, 464);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
|
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(1058, 12);
|
||||||
|
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
this.comboBoxStrategy.Size = new System.Drawing.Size(160, 33);
|
||||||
|
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(333, 442);
|
||||||
|
this.buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
||||||
|
this.buttonCreateLocomotive.Size = new System.Drawing.Size(272, 52);
|
||||||
|
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(1079, 65);
|
||||||
|
this.buttonStep.Name = "buttonStep";
|
||||||
|
this.buttonStep.Size = new System.Drawing.Size(125, 56);
|
||||||
|
this.buttonStep.TabIndex = 8;
|
||||||
|
this.buttonStep.Text = "Шаг";
|
||||||
|
this.buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||||
|
//
|
||||||
|
// ElectricLocomotive
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1242, 512);
|
||||||
|
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.Name = "ElectricLocomotive";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
using ProjectElectricLocomotive;
|
||||||
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
|
using ProjectElectricLocomotive.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ElectricLocomotive
|
||||||
|
{
|
||||||
|
public partial class ElectricLocomotive : Form
|
||||||
|
{
|
||||||
|
|
||||||
|
private DrawingLocomotive? _drawingLocomotive;
|
||||||
|
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
|
||||||
|
public ElectricLocomotive()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
_drawingLocomotive = new DrawingElectricLocomotive(random.Next(100, 300),random.Next(1000, 3000),
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
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();
|
||||||
|
_drawingLocomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||||
|
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(new
|
||||||
|
DrawingObjectLocomotive(_drawingLocomotive), pictureBoxElectricLocomotive.Width,
|
||||||
|
pictureBoxElectricLocomotive.Height);
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
@ -0,0 +1,20 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectElectricLocomotive
|
namespace ElectricLocomotive
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
@ -11,7 +11,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 ElectricLocomotive());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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>
|
103
ProjectElectricLocomotive/ProjectElectricLocomotive/Properties/Resources.Designer.cs
generated
Normal file
103
ProjectElectricLocomotive/ProjectElectricLocomotive/Properties/Resources.Designer.cs
generated
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 |
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user