завершение проекта

This commit is contained in:
ALINA_KURBANOVA 2023-11-03 21:51:37 +04:00
parent e88714da83
commit 1994f6ec4d
14 changed files with 61 additions and 165 deletions

View File

@ -1,10 +1,4 @@
using System; namespace WarmlyLocomotive.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive.MovementStrategy
{ {
public abstract class AbstractStrategy public abstract class AbstractStrategy
{ {
@ -83,8 +77,7 @@ namespace WarmlyLocomotive.MovementStrategy
/// <summary> /// <summary>
/// Параметры объекта /// Параметры объекта
/// </summary> /// </summary>
protected ObjectParameters? GetObjectParameters => protected ObjectParameters? GetObjectParameters =>_moveableObject?.GetObjectPosition;
_moveableObject?.GetObjectPosition;
/// <summary> /// <summary>
/// Шаг объекта /// Шаг объекта
/// </summary> /// </summary>

View File

@ -1,10 +1,4 @@
using System; namespace WarmlyLocomotive
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive
{ {
/// <summary> /// <summary>
/// Направление перемещения /// Направление перемещения
@ -27,6 +21,5 @@ namespace WarmlyLocomotive
/// Вправо /// Вправо
/// </summary> /// </summary>
Right = 4 Right = 4
} }
} }

View File

@ -1,37 +1,31 @@
using System; using WarmlyLocomotive.DrawningObjects;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarmlyLocomotive.DrawningObjects;
using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive.MovementStrategy namespace WarmlyLocomotive.MovementStrategy
{ {
internal class DrawningObjectCar : IMoveableObject internal class DrawningObjectCar : IMoveableObject
{ {
private readonly DrawningWarmlyLocomotive? _drawningCar = null; private readonly DrawningWarmlyLocomotive? _drawningWarmlyLocomotive = null;
public DrawningObjectCar(DrawningWarmlyLocomotive drawningCar) public DrawningObjectCar(DrawningWarmlyLocomotive drawningCar)
{ {
_drawningCar = drawningCar; _drawningWarmlyLocomotive = drawningCar;
} }
public ObjectParameters? GetObjectPosition public ObjectParameters? GetObjectPosition
{ {
get get
{ {
if (_drawningCar == null || _drawningCar.EntityWarmlyLocomotive == if (_drawningWarmlyLocomotive == null || _drawningWarmlyLocomotive.EntityWarmlyLocomotive ==
null) null)
{ {
return null; return null;
} }
return new ObjectParameters(_drawningCar.GetPosX, return new ObjectParameters(_drawningWarmlyLocomotive.GetPosX,
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight); _drawningWarmlyLocomotive.GetPosY, _drawningWarmlyLocomotive.GetWidth, _drawningWarmlyLocomotive.GetHeight);
} }
} }
public int GetStep => (int)(_drawningCar?.EntityWarmlyLocomotive?.Step ?? 0); public int GetStep => (int)(_drawningWarmlyLocomotive?.EntityWarmlyLocomotive?.Step ?? 0);
public bool CheckCanMove(Direction direction) => public bool CheckCanMove(Direction direction) =>
_drawningCar?.CanMove(direction) ?? false; _drawningWarmlyLocomotive?.CanMove(direction) ?? false;
public void MoveObject(Direction direction) => public void MoveObject(Direction direction) =>
_drawningCar?.MoveTransport(direction); _drawningWarmlyLocomotive?.MoveTransport(direction);
} }
} }

View File

@ -1,11 +1,4 @@
using WarmlyLocomotive.DrawningObjects; using WarmlyLocomotive.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarmlyLocomotive.Entities;
using WarmlyLocomotive;
namespace WarmlyLocomotive.DrawningObjects namespace WarmlyLocomotive.DrawningObjects
{ {
@ -28,8 +21,6 @@ namespace WarmlyLocomotive.DrawningObjects
{ {
return; return;
} }
Pen pen = new(Color.Black, 2);
Brush bodyBrush = new SolidBrush(warmlylocomotive.BodyColor);
Brush addBrush = new SolidBrush(warmlylocomotive.AdditionalColor); Brush addBrush = new SolidBrush(warmlylocomotive.AdditionalColor);
Brush wheelBrush = new SolidBrush(Color.Black); Brush wheelBrush = new SolidBrush(Color.Black);
base.DrawTransport(g); base.DrawTransport(g);

View File

@ -1,10 +1,4 @@
using System; using WarmlyLocomotive.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarmlyLocomotive.Entities;
namespace WarmlyLocomotive.DrawningObjects namespace WarmlyLocomotive.DrawningObjects
{ {
/// <summary> /// <summary>
@ -65,7 +59,6 @@ namespace WarmlyLocomotive.DrawningObjects
EntityWarmlyLocomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor); EntityWarmlyLocomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor);
} }
protected DrawningWarmlyLocomotive(int speed, double weight, Color bodyColor, int protected DrawningWarmlyLocomotive(int speed, double weight, Color bodyColor, int
width, int height, int carWidth, int carHeight) width, int height, int carWidth, int carHeight)
{ {
@ -95,7 +88,6 @@ namespace WarmlyLocomotive.DrawningObjects
_startPosY = y; _startPosY = y;
} }
public bool CanMove(Direction direction) public bool CanMove(Direction direction)
{ {
if (EntityWarmlyLocomotive == null) if (EntityWarmlyLocomotive == null)
@ -115,7 +107,6 @@ namespace WarmlyLocomotive.DrawningObjects
_ => false, _ => false,
}; };
} }
/// <param name="direction">Направление</param> /// <param name="direction">Направление</param>
public void MoveTransport(Direction direction) public void MoveTransport(Direction direction)
{ {
@ -186,7 +177,6 @@ namespace WarmlyLocomotive.DrawningObjects
g.FillEllipse(wheelBrush, _startPosX + 85, _startPosY + 50, 20, 20); g.FillEllipse(wheelBrush, _startPosX + 85, _startPosY + 50, 20, 20);
g.FillEllipse(wheelBrush, _startPosX + 145, _startPosY + 50, 20, 20); g.FillEllipse(wheelBrush, _startPosX + 145, _startPosY + 50, 20, 20);
g.FillEllipse(wheelBrush, _startPosX + 170, _startPosY + 50, 20, 20); g.FillEllipse(wheelBrush, _startPosX + 170, _startPosY + 50, 20, 20);
} }
} }
} }

View File

@ -1,10 +1,4 @@
using System; namespace WarmlyLocomotive.Entities
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive.Entities
{ {
/// <summary> /// <summary>
/// Класс-сущность "Автомобиль" /// Класс-сущность "Автомобиль"

View File

@ -1,10 +1,4 @@
using System; namespace WarmlyLocomotive.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive.MovementStrategy
{ {
/// <summary> /// <summary>
/// Интерфейс для работы с перемещаемым объектом /// Интерфейс для работы с перемещаемым объектом

View File

@ -1,11 +1,4 @@
using System; namespace WarmlyLocomotive.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive.MovementStrategy
{ {
internal class MoveToBorder : AbstractStrategy internal class MoveToBorder : AbstractStrategy
{ {
@ -21,7 +14,6 @@ namespace WarmlyLocomotive.MovementStrategy
objParams.DownBorder <= FieldHeight && objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight; objParams.DownBorder + GetStep() >= FieldHeight;
} }
protected override void MoveToTarget() protected override void MoveToTarget()
{ {
var objParams = GetObjectParameters; var objParams = GetObjectParameters;
@ -32,19 +24,13 @@ namespace WarmlyLocomotive.MovementStrategy
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal; var diffX = FieldWidth - objParams.ObjectMiddleHorizontal;
if (Math.Abs(diffX) > GetStep()) if (Math.Abs(diffX) > GetStep())
{ {
MoveRight(); MoveRight();
} }
var diffY = FieldHeight - objParams.ObjectMiddleVertical; var diffY = FieldHeight - objParams.ObjectMiddleVertical;
if (Math.Abs(diffY) > GetStep()) if (Math.Abs(diffY) > GetStep())
{ {
MoveDown(); MoveDown();
} }
} }
} }
} }

View File

@ -1,11 +1,4 @@
using System; namespace WarmlyLocomotive.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive.MovementStrategy
{ {
internal class MoveToCenter : AbstractStrategy internal class MoveToCenter : AbstractStrategy
{ {
@ -20,7 +13,6 @@ namespace WarmlyLocomotive.MovementStrategy
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2); objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2);
} }
protected override void MoveToTarget() protected override void MoveToTarget()
{ {

View File

@ -1,10 +1,4 @@
using System; namespace WarmlyLocomotive.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive.MovementStrategy
{ {
/// <summary> /// <summary>
/// Параметры-координаты объекта /// Параметры-координаты объекта

View File

@ -1,11 +1,4 @@
using System; namespace WarmlyLocomotive.Entities
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace WarmlyLocomotive.Entities
{ {
public class Pro : EntityWarmlyLocomotive public class Pro : EntityWarmlyLocomotive
{ {

View File

@ -1,10 +1,4 @@
using System; namespace WarmlyLocomotive.MovementStrategy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyLocomotive.MovementStrategy
{ {
/// <summary> /// <summary>
/// Статус выполнения операции перемещения /// Статус выполнения операции перемещения

View File

@ -1,3 +1,4 @@
using System;
using System.Windows.Forms; using System.Windows.Forms;
using WarmlyLocomotive.DrawningObjects; using WarmlyLocomotive.DrawningObjects;
@ -10,16 +11,15 @@ namespace WarmlyLocomotive
/// </summary> /// </summary>
public partial class WarmlyLocomotiveForm : Form public partial class WarmlyLocomotiveForm : Form
{ {
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive; private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
private AbstractStrategy? _abstractStrategy; private AbstractStrategy? _abstractStrategy;
public DrawningWarmlyLocomotive? SelectedCar { get; private set; }
public WarmlyLocomotiveForm() public WarmlyLocomotiveForm()
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary> /// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû /// Ìåòîä ïðîðèñîâêè ìàøèíû
/// </summary> /// </summary>
@ -29,11 +29,11 @@ namespace WarmlyLocomotive
{ {
return; return;
} }
Bitmap bmp = new(pictureBox1.Width, Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width,
pictureBox1.Height); pictureBoxWarmlyLocomotive.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawningWarmlyLocomotive.DrawTransport(gr); _drawningWarmlyLocomotive.DrawTransport(gr);
pictureBox1.Image = bmp; pictureBoxWarmlyLocomotive.Image = bmp;
} }
/// <summary> /// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü òåïëîâîç" /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü òåïëîâîç"
@ -47,12 +47,11 @@ namespace WarmlyLocomotive
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)), random.Next(0, 256)),
pictureBox1.Width, pictureBox1.Height); pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, _drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
100)); 100));
Draw(); Draw();
} }
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
@ -78,16 +77,6 @@ namespace WarmlyLocomotive
} }
Draw(); Draw();
} }
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
/// <summary> /// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã" /// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
/// </summary> /// </summary>
@ -99,9 +88,9 @@ namespace WarmlyLocomotive
{ {
return; return;
} }
if (comboBox1.Enabled) if (comboBoxWarmlyLocomotive.Enabled)
{ {
_abstractStrategy = comboBox1.SelectedIndex _abstractStrategy = comboBoxWarmlyLocomotive.SelectedIndex
switch switch
{ {
0 => new MoveToCenter(), 0 => new MoveToCenter(),
@ -113,9 +102,9 @@ namespace WarmlyLocomotive
return; return;
} }
_abstractStrategy.SetData(new _abstractStrategy.SetData(new
DrawningObjectCar(_drawningWarmlyLocomotive), pictureBox1.Width, DrawningObjectCar(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width,
pictureBox1.Height); pictureBoxWarmlyLocomotive.Height);
comboBox1.Enabled = false; comboBoxWarmlyLocomotive.Enabled = false;
} }
if (_abstractStrategy == null) if (_abstractStrategy == null)
{ {
@ -125,7 +114,7 @@ namespace WarmlyLocomotive
Draw(); Draw();
if (_abstractStrategy.GetStatus() == Status.Finish) if (_abstractStrategy.GetStatus() == Status.Finish)
{ {
comboBox1.Enabled = true; comboBoxWarmlyLocomotive.Enabled = true;
_abstractStrategy = null; _abstractStrategy = null;
} }
} }
@ -145,7 +134,7 @@ namespace WarmlyLocomotive
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)), Convert.ToBoolean(random.Next(0, 2)),
pictureBox1.Width, pictureBox1.Height); pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, _drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
100)); 100));
Draw(); Draw();

View File

@ -29,28 +29,27 @@
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WarmlyLocomotiveForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WarmlyLocomotiveForm));
pictureBox1 = new PictureBox(); pictureBoxWarmlyLocomotive = new PictureBox();
buttonCreate = new Button(); buttonCreate = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonRight = new Button(); buttonRight = new Button();
comboBox1 = new ComboBox(); comboBoxWarmlyLocomotive = new ComboBox();
buttonStep = new Button(); buttonStep = new Button();
buttonCreate_Pro = new Button(); buttonCreate_Pro = new Button();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// pictureBox1 // pictureBoxWarmlyLocomotive
// //
pictureBox1.Dock = DockStyle.Fill; pictureBoxWarmlyLocomotive.Dock = DockStyle.Fill;
pictureBox1.Location = new Point(0, 0); pictureBoxWarmlyLocomotive.Location = new Point(0, 0);
pictureBox1.Name = "pictureBox1"; pictureBoxWarmlyLocomotive.Name = "pictureBoxWarmlyLocomotive";
pictureBox1.Size = new Size(884, 461); pictureBoxWarmlyLocomotive.Size = new Size(884, 461);
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxWarmlyLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.TabIndex = 0; pictureBoxWarmlyLocomotive.TabIndex = 0;
pictureBox1.TabStop = false; pictureBoxWarmlyLocomotive.TabStop = false;
pictureBox1.Click += pictureBox1_Click;
// //
// buttonCreate // buttonCreate
// //
@ -111,16 +110,15 @@
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click; buttonRight.Click += buttonMove_Click;
// //
// comboBox1 // comboBoxWarmlyLocomotive
// //
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxWarmlyLocomotive.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.FormattingEnabled = true; comboBoxWarmlyLocomotive.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "Центр", "Угол" }); comboBoxWarmlyLocomotive.Items.AddRange(new object[] { "Центр", "Угол" });
comboBox1.Location = new Point(717, 21); comboBoxWarmlyLocomotive.Location = new Point(717, 21);
comboBox1.Name = "comboBox1"; comboBoxWarmlyLocomotive.Name = "comboBoxWarmlyLocomotive";
comboBox1.Size = new Size(121, 23); comboBoxWarmlyLocomotive.Size = new Size(121, 23);
comboBox1.TabIndex = 7; comboBoxWarmlyLocomotive.TabIndex = 7;
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
// //
// buttonStep // buttonStep
// //
@ -147,16 +145,17 @@
ClientSize = new Size(884, 461); ClientSize = new Size(884, 461);
Controls.Add(buttonCreate_Pro); Controls.Add(buttonCreate_Pro);
Controls.Add(buttonStep); Controls.Add(buttonStep);
Controls.Add(comboBox1); Controls.Add(comboBoxWarmlyLocomotive);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
Controls.Add(pictureBox1); Controls.Add(pictureBoxWarmlyLocomotive);
Name = "WarmlyLocomotiveForm"; Name = "WarmlyLocomotiveForm";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); Text = "WarmlyLocomotiveForm";
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -165,13 +164,13 @@
private PictureBox pictureBox1; private PictureBox pictureBoxWarmlyLocomotive;
private Button buttonCreate; private Button buttonCreate;
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;
private Button buttonRight; private Button buttonRight;
private ComboBox comboBox1; private ComboBox comboBoxWarmlyLocomotive;
private Button buttonStep; private Button buttonStep;
private Button buttonCreate_Pro; private Button buttonCreate_Pro;
} }