доделать форму

This commit is contained in:
spacyboy 2023-11-22 03:19:35 +04:00
parent e66fcaaf6a
commit 36e2fba235
16 changed files with 501 additions and 270 deletions

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.DrawingObjects;
namespace RoadTrain.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,33 @@
using RoadTrain.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.DrawingObjects;
namespace RoadTrain.MovementStrategy
{
public class DrawingObjectTrain : IMoveableObject
{
private readonly DrawingRoadTrain? _drawingRoadTrain = null;
public DrawingObjectTrain(DrawingRoadTrain drawingRoadTrain)
{
_drawingRoadTrain = drawingRoadTrain;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawingRoadTrain == null || _drawingRoadTrain.EntityRoadTrain == null)
{
return null;
}
return new ObjectParameters(_drawingRoadTrain.GetPosX, _drawingRoadTrain.GetPosY, _drawingRoadTrain.GetWidth, _drawingRoadTrain.GetHeight);
}
}
public int GetStep => (int)(_drawingRoadTrain?.EntityRoadTrain?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawingRoadTrain?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawingRoadTrain?.MoveTransport(direction);
}
}

View File

@ -1,28 +1,48 @@
using System.Net.NetworkInformation; using System;
using System.Net.Sockets; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.Entities;
namespace RoadTrain
namespace RoadTrain.DrawingObjects
{ {
internal class DrawingRoadTrain public class DrawingRoadTrain
{ {
public EntityRoadTrain? EntityRoadTrain { get; private set; } public EntityRoadTrain? EntityRoadTrain { get; protected set; }
private int _pictureWidth; private int _pictureWidth;
private int _pictureHeight; private int _pictureHeight;
private int _startPosX; protected int _startPosX;
private int _startPosY; protected int _startPosY;
private readonly int _roadTrainWidth = 200; protected readonly int _roadTrainWidth = 200;
private readonly int _roadTrainHeight = 100; protected readonly int _roadTrainHeight = 100;
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheel, bool door, bool light, int width, int height) public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _roadTrainWidth;
public int GetHeight => _roadTrainHeight;
public DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height)
{ {
if (_roadTrainWidth < width || _roadTrainHeight < height) if (width < _roadTrainWidth || height < _roadTrainHeight)
{ {
EntityRoadTrain = new EntityRoadTrain(); return;
EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor, wheel, door, light);
_pictureWidth = width;
_pictureHeight = height;
return true;
} }
return false; _pictureWidth = width;
_pictureHeight = height;
EntityRoadTrain = new EntityRoadTrain(speed, weight, bodyColor);
}
protected DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height, int roadTrainWidth, int roadTrainHeight)
{
if (width < _roadTrainWidth || height < _roadTrainHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_roadTrainWidth = roadTrainWidth;
_roadTrainHeight = roadTrainHeight;
EntityRoadTrain = new EntityRoadTrain(speed, weight, bodyColor);
} }
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
@ -37,74 +57,68 @@ namespace RoadTrain
} }
public void MoveTransport(DirectionType direction) public void MoveTransport(DirectionType direction)
{ {
if (EntityRoadTrain == null) if (!CanMove(direction) || EntityRoadTrain == null)
{ {
return; return;
} }
switch (direction) switch (direction)
{ {
//влево
case DirectionType.Left: case DirectionType.Left:
if (_startPosX - EntityRoadTrain.Step > 0) _startPosX -= (int)EntityRoadTrain.Step;
{
_startPosX -= (int)EntityRoadTrain.Step;
}
break; break;
//вверх
case DirectionType.Up: case DirectionType.Up:
if (_startPosY - EntityRoadTrain.Step > 0) _startPosY -= (int)EntityRoadTrain.Step;
{
_startPosY -= (int)EntityRoadTrain.Step;
}
break; break;
// вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX + EntityRoadTrain.Step < _pictureWidth - _roadTrainWidth) _startPosX += (int)EntityRoadTrain.Step;
{
_startPosX += (int)EntityRoadTrain.Step;
}
break; break;
//вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY + EntityRoadTrain.Step < _pictureHeight - _roadTrainHeight) _startPosY += (int)EntityRoadTrain.Step;
{
_startPosY += (int)EntityRoadTrain.Step;
}
break; break;
} }
} }
public void DrawTransport(Graphics g) public bool CanMove(DirectionType direction)
{
if (EntityRoadTrain == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityRoadTrain.Step > 0,
DirectionType.Up => _startPosY - EntityRoadTrain.Step > 0,
DirectionType.Right => _startPosX + _roadTrainWidth + EntityRoadTrain.Step < _pictureWidth,
DirectionType.Down => _startPosY + _roadTrainHeight + EntityRoadTrain.Step < _pictureHeight,
_ => false,
};
}
public virtual void DrawTransport(Graphics g)
{ {
if (EntityRoadTrain == null) if (EntityRoadTrain == null)
{ {
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black, 2);
Brush additionalBrush = new Pen anchor = new(Color.Black, 4);
SolidBrush(EntityRoadTrain.AdditionalColor); Brush bodyBrush = new SolidBrush(EntityRoadTrain.BodyColor);
Brush whiteBrush = new SolidBrush(Color.White);
//машина //машина
g.DrawRectangle(pen, _startPosX, _startPosY + 50, 160, 20); //кузов g.DrawRectangle(pen, _startPosX - 20, _startPosY + 50 + 80, 160, 20);
g.DrawEllipse(pen, _startPosX + 5, _startPosY + 70, 30, 30); //колесо g.FillRectangle(bodyBrush, _startPosX - 20, _startPosY + 50 + 80, 160, 20);
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 70, 30, 30); //колесо g.DrawEllipse(pen, _startPosX + 5 - 20, _startPosY + 70 + 80, 30, 30); //колесо
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 30, 30); //колесо g.FillEllipse(bodyBrush, _startPosX + 5 - 20, _startPosY + 70 + 80, 30, 30);
g.DrawRectangle(pen, _startPosX + 120, _startPosY + 10, 40, 40); //кабина g.DrawEllipse(pen, _startPosX + 40 - 20, _startPosY + 70 + 80, 30, 30); //колесо
g.DrawRectangle(pen, _startPosX + 10, _startPosY, 90, 50); //бак с водой g.FillEllipse(bodyBrush, _startPosX + 40 - 20, _startPosY + 70 + 80, 30, 30);
g.DrawRectangle(pen, _startPosX + 130, _startPosY + 20, 30, 20); //окно g.DrawEllipse(pen, _startPosX + 120 - 20, _startPosY + 70 + 80, 30, 30); //колесо
g.DrawLine(pen, _startPosX + 160, _startPosY + 70, _startPosX + 180, _startPosY + 80); //держатель для щетки g.FillEllipse(bodyBrush, _startPosX + 120 - 20, _startPosY + 70 + 80, 30, 30);
g.DrawRectangle(pen, _startPosX + 170, _startPosY + 80, 40, 10); //щетка g.DrawRectangle(pen, _startPosX + 120 - 20, _startPosY + 10 + 80, 40, 40); //кабина
//обвесы g.FillRectangle(bodyBrush, _startPosX + 120 - 20, _startPosY + 10 + 80, 40, 40);
if (EntityRoadTrain.Wheel) g.DrawRectangle(pen, _startPosX + 130 - 20, _startPosY + 20 + 80, 30, 20); //окно
{ g.FillRectangle(whiteBrush, _startPosX + 130 - 20, _startPosY + 20 + 80, 30, 20);
g.FillEllipse(additionalBrush, _startPosX + 75, _startPosY + 70, 30, 30); //колесо
}
if (EntityRoadTrain.Door)
{
g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 20, 20, 30); //дверь
}
if (EntityRoadTrain.Light)
{
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY, 10, 10); //мигалка
}
} }
} }
} }

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.Entities;
namespace RoadTrain.DrawingObjects
{
public class DrawingRoadTrainWithTank : DrawingRoadTrain
{
public DrawingRoadTrainWithTank(int speed, double weight, Color bodyColor, Color
additionalColor, bool pipes, bool section, int width, int height)
: base(speed, weight, bodyColor, width, height, 185, 180)
{
if (EntityRoadTrain != null)
{
EntityRoadTrain = new EntityRoadTrainWithTank(speed, weight, bodyColor, additionalColor, pipes, section);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityRoadTrain is not EntityRoadTrainWithTank roadTrain)
{
return;
}
Pen pen = new(Color.Black, 2);
Brush additionalBrush = new SolidBrush(roadTrain.AdditionalColor);
base.DrawTransport(g);
//щетка
Brush brGray = new SolidBrush(Color.Gray);
if (roadTrain.Brush)
{
g.DrawLine(pen, _startPosX + 160-20, _startPosY + 70 + 80, _startPosX + 180, _startPosY + 80 + 80);
g.DrawRectangle(pen, _startPosX + 170-20, _startPosY + 80 + 80, 40, 10); //щетка
g.FillRectangle(additionalBrush, _startPosX + 170-20, _startPosY + 80 + 80, 40, 10);
}
//бак
if (roadTrain.Tank)
{
g.DrawRectangle(pen, _startPosX + 10 - 20, _startPosY + 80, 90, 50); //бак с водой
g.FillRectangle(additionalBrush, _startPosX + 10-20, _startPosY + 80, 90, 50);
}
}
}
}

View File

@ -1,25 +1,22 @@
namespace RoadTrain using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RoadTrain.Entities
{ {
public class EntityRoadTrain public class EntityRoadTrain
{ {
public int Speed { get; private set; } public int Speed { get; private set; }
public double Weight { get; private set; } public double Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
public Color AdditionalColor { get; private set; }
public bool Wheel { get; private set; }
public bool Door { get; private set; }
public bool Light { get; private set; }
public double Step => (double)Speed * 100 / Weight; public double Step => (double)Speed * 100 / Weight;
public void Init(int speed, double weight, Color bodyColor, Color public EntityRoadTrain(int speed, double weight, Color bodyColor)
additionalColor, bool wheel, bool door, bool light)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor;
Wheel = wheel;
Door = door;
Light = light;
} }
} }
} }

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RoadTrain.Entities
{
public class EntityRoadTrainWithTank : EntityRoadTrain
{
public Color AdditionalColor { get; private set; }
public bool Tank { get; private set; }
public bool Brush { get; private set; }
public EntityRoadTrainWithTank(int speed, double weight, Color bodyColor, Color
additionalColor, bool tank, bool brush)
: base (speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Tank = tank;
Brush = brush;
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RoadTrain.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 RoadTrain.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,4 @@
namespace RoadTrain.A_RoadTrain_Basic namespace RoadTrain
{ {
internal static class Program internal static class Program
{ {

View File

@ -59,8 +59,15 @@
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : 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:schema id="root" xmlns="" xmlns:xsd="http:
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
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:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>
<xsd:choice maxOccurs="unbounded"> <xsd:choice maxOccurs="unbounded">

View File

@ -1,8 +1,16 @@
namespace RoadTrain.A_RoadTrain_Basic namespace RoadTrain
{ {
partial class RoadTrain partial class RoadTrain
{ {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; 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) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
@ -14,122 +22,18 @@
#region Windows Form Designer generated code #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() private void InitializeComponent()
{ {
pictureBoxRoadTrain = new PictureBox(); this.components = new System.ComponentModel.Container();
buttonCreate = new Button(); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
buttonRight = new Button(); this.ClientSize = new System.Drawing.Size(800, 450);
buttonUp = new Button(); this.Text = "RoadTrain";
buttonLeft = new Button();
buttonDown = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit();
SuspendLayout();
//
// pictureBoxRoadTrain
//
pictureBoxRoadTrain.Dock = DockStyle.Fill;
pictureBoxRoadTrain.Location = new Point(0, 0);
pictureBoxRoadTrain.Margin = new Padding(3, 2, 3, 2);
pictureBoxRoadTrain.Name = "pictureBoxRoadTrain";
pictureBoxRoadTrain.Size = new Size(700, 338);
pictureBoxRoadTrain.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxRoadTrain.TabIndex = 0;
pictureBoxRoadTrain.TabStop = false;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(10, 307);
buttonCreate.Margin = new Padding(3, 2, 3, 2);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(82, 22);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.ForeColor = SystemColors.ControlText;
buttonRight.Location = new Point(663, 306);
buttonRight.Margin = new Padding(3, 2, 3, 2);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(26, 22);
buttonRight.TabIndex = 2;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.up;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.ForeColor = SystemColors.ControlText;
buttonUp.Location = new Point(632, 280);
buttonUp.Margin = new Padding(3, 2, 3, 2);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(26, 22);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.ForeColor = SystemColors.ControlText;
buttonLeft.Location = new Point(600, 307);
buttonLeft.Margin = new Padding(3, 2, 3, 2);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(26, 22);
buttonLeft.TabIndex = 5;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.ForeColor = SystemColors.ControlText;
buttonDown.Location = new Point(632, 307);
buttonDown.Margin = new Padding(3, 2, 3, 2);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(26, 22);
buttonDown.TabIndex = 6;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// RoadTrain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(700, 338);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxRoadTrain);
Margin = new Padding(3, 2, 3, 2);
Name = "RoadTrain";
Text = "RoadTrainForm";
((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).EndInit();
ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
public PictureBox pictureBoxRoadTrain;
private Button buttonCreate;
private Button buttonRight;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
} }
} }

View File

@ -1,62 +1,20 @@
namespace RoadTrain.A_RoadTrain_Basic 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 RoadTrain
{ {
public partial class RoadTrain : Form public partial class RoadTrain : Form
{ {
private DrawingRoadTrain? _drawingRoadTrain;
public RoadTrain() public RoadTrain()
{ {
InitializeComponent(); InitializeComponent();
} }
private void Draw()
{
if (_drawingRoadTrain == null)
{
return;
}
Bitmap bmp = new(pictureBoxRoadTrain.Width,
pictureBoxRoadTrain.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingRoadTrain.DrawTransport(gr);
pictureBoxRoadTrain.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawingRoadTrain = new DrawingRoadTrain();
_drawingRoadTrain.Init(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)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
_drawingRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingRoadTrain == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingRoadTrain.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingRoadTrain.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingRoadTrain.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingRoadTrain.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
} }
} }

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
The primary goals of this format is to allow a simple XML format The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes various data types are done through the TypeConverter classes
associated with the data types. associated with the data types.
Example: Example:
... ado.net/XML headers & schema ... ... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader> <resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment> <comment>This is a comment</comment>
</data> </data>
There are any number of "resheader" rows that contain simple There are any number of "resheader" rows that contain simple
name/value pairs. name/value pairs.
Each data row contains a name, and value. The row also contains a Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture. text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the Classes that don't support this are serialized and stored with the
mimetype set. mimetype set.
The mimetype is used for serialized objects, and tells the The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly: extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below. read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64 mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64 mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->

View File

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