PI-12_Zaytsev_A.V_LabWork02_Base #5

Closed
tyxzo wants to merge 5 commits from lab2 into lab1
11 changed files with 270 additions and 30 deletions
Showing only changes of commit d5621e0d6d - Show all commits

View File

@ -23,6 +23,14 @@ public class DrawingBus
private readonly int _drawingBusHeight = 50;
public int? GetPosX => _startPosX;
public int? GetPosY => _startPosY;
public int? GetWidth => _drawingBusWidth;
public int? GetHeight => _drawingBusHeight;
private DrawingBus()
{
_pictureWidth = null;
@ -164,7 +172,7 @@ public class DrawingBus
//кузов 1го этажа
PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY),
PointF[] bus = { new PointF((float)_startPosX, (float)_startPosY),
new PointF((float)_startPosX, (float)_startPosY + 25),
new PointF((float)_startPosX + 100, (float)_startPosY + 25),
new PointF((float)_startPosX + 100, (float)_startPosY + 5),

View File

@ -6,7 +6,7 @@ namespace DoubleDeckerBus.Drawnings;
/// </summary>
public class DrawingDoubleDeckerBus : DrawingBus
{
public DrawingDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) : base (105,50)
public DrawingDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) : base (115,50)
{
EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor, additionalColor, secondFloor, stripes);
}

View File

@ -1,7 +1,9 @@
namespace DoubleDeckerBus.Entities;
public class EntityDoubleDeckerBus : EntityBus
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия второго этажа

View File

@ -34,6 +34,7 @@
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
CreateBus = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxDoubleDeckerBus).BeginInit();
SuspendLayout();
//
@ -42,9 +43,9 @@
buttonCreateDoubleDeckerBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateDoubleDeckerBus.Location = new Point(12, 415);
buttonCreateDoubleDeckerBus.Name = "buttonCreateDoubleDeckerBus";
buttonCreateDoubleDeckerBus.Size = new Size(75, 23);
buttonCreateDoubleDeckerBus.Size = new Size(159, 23);
buttonCreateDoubleDeckerBus.TabIndex = 1;
buttonCreateDoubleDeckerBus.Text = "Create";
buttonCreateDoubleDeckerBus.Text = "Create DoubleDeckerBus";
buttonCreateDoubleDeckerBus.UseVisualStyleBackColor = true;
buttonCreateDoubleDeckerBus.Click += buttonCreateDoubleDeckerBus_Click;
//
@ -105,11 +106,23 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// CreateBus
//
CreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
CreateBus.Location = new Point(188, 415);
CreateBus.Name = "CreateBus";
CreateBus.Size = new Size(159, 23);
CreateBus.TabIndex = 7;
CreateBus.Text = "Create Bus";
CreateBus.UseVisualStyleBackColor = true;
CreateBus.Click += buttonCreateBus_Click;
//
// FormDoubleDeckerBus
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(CreateBus);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
@ -130,5 +143,6 @@
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button CreateBus;
}
}

View File

@ -13,7 +13,7 @@ namespace DoubleDeckerBus
{
public partial class FormDoubleDeckerBus : Form
{
private DrawingDoubleDeckerBus? _drawingDoubleDeckerBus;
private DrawingBus? _drawingBus;
public FormDoubleDeckerBus()
{
InitializeComponent();
@ -21,37 +21,53 @@ namespace DoubleDeckerBus
private void Draw()
{
if (_drawingDoubleDeckerBus == null)
if (_drawingBus == null)
{
return;
}
Bitmap bmp = new(pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingDoubleDeckerBus.DrawTrasnport(gr);
_drawingBus.DrawTrasnport(gr);
pictureBoxDoubleDeckerBus.Image = bmp;
}
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawingBus):
_drawingBus = new DrawingBus(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0,256), random.Next(0,256)));
break;
case nameof(DrawingDoubleDeckerBus):
_drawingBus = new DrawingDoubleDeckerBus(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)));
break;
default:
return;
}
_drawingBus.SetPictureSize(pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonCreateDoubleDeckerBus_Click(object sender, EventArgs e)
{
Random random = new();
_drawingDoubleDeckerBus = new DrawingDoubleDeckerBus();
_drawingDoubleDeckerBus.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)));
_drawingDoubleDeckerBus.SetPictureSize(pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
_drawingDoubleDeckerBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
CreateObject(nameof(DrawingDoubleDeckerBus));
}
private void buttonCreateBus_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingBus));
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingDoubleDeckerBus == null)
if (_drawingBus == null)
{
return;
}
@ -61,19 +77,19 @@ namespace DoubleDeckerBus
switch (name)
{
case "buttonLeft":
result = _drawingDoubleDeckerBus.MoveTransport(DirectionType.Left);
result = _drawingBus.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawingDoubleDeckerBus.MoveTransport(DirectionType.Right);
result = _drawingBus.MoveTransport(DirectionType.Right);
break;
case "buttonUp":
result = _drawingDoubleDeckerBus.MoveTransport(DirectionType.Up);
result = _drawingBus.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawingDoubleDeckerBus.MoveTransport(DirectionType.Down);
result = _drawingBus.MoveTransport(DirectionType.Down);
break;
}
@ -82,5 +98,6 @@ namespace DoubleDeckerBus
Draw();
}
}
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus.MovementStrategy;
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private StrategyStatus _state = StrategyStatus.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public StrategyStatus GetStatus() { return _state; }
public void SetData(IMoveableObject movableObject, int width, int height)
{
if (movableObject == null)
{
_state = StrategyStatus.NotInit;
return;
}
_state = StrategyStatus.InProgress;
_moveableObject = movableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)
{
return;
}
if(IsTargetDestination())
{
_state = StrategyStatus.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
protected bool MoveRight() => MoveTo(MovementDirection.Right);
protected bool MoveUp() => MoveTo(MovementDirection.Up);
protected bool MoveDown() => MoveTo(MovementDirection.Down);
protected ObjectParametrs? GetObjectParaments => _moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != StrategyStatus.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestination();
private bool MoveTo(MovementDirection movementDirection)
{
if (_state != StrategyStatus.InProgress)
{
return false;
}
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
}
}

View File

@ -4,9 +4,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus.MovementStrategy
namespace DoubleDeckerBus.MovementStrategy;
public interface IMoveableObject
{
internal interface Interface1
{
}
ObjectParametrs? GetObjectPosition { get; }
int GetStep { get; }
bool TryMoveObject(MovementDirection direction);
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus.MovementStrategy;
private DrawningBus? _drawningBus;
public class MoveableBus : IMoveableObject
{
public ObjectParametrs? GetObjectPosition => throw new NotImplementedException();
public int GetStep => throw new NotImplementedException();
public bool TryMoveObject(MovementDirection direction)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus.MovementStrategy;
public enum MovementDirection
{
/// <summary>
/// вверх
/// </summary>
Up = 1,
/// <summary>
/// вниз
/// </summary>
Down = 2,
/// <summary>
/// влево
/// </summary>
Left = 3,
/// <summary>
/// вправо
/// </summary>
Right = 4
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus.MovementStrategy;
public class ObjectParametrs
{
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 ObjectParametrs(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus.MovementStrategy;
public enum StrategyStatus
{
/// <summary>
/// Все готово к началу
/// </summary>
NotInit,
/// <summary>
/// Выполняется
/// </summary>
InProgress,
/// <summary>
/// Завершено
/// </summary>
Finish
}