PIbd-22.Kurbanova A.A. Lab work 02 #2 #2
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
@ -83,8 +77,7 @@ namespace WarmlyLocomotive.MovementStrategy
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
protected ObjectParameters? GetObjectParameters =>_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
@ -27,6 +21,5 @@ namespace WarmlyLocomotive
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
|
||||
}
|
||||
}
|
@ -1,37 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
using WarmlyLocomotive.MovementStrategy;
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
{
|
||||
internal class DrawningObjectCar : IMoveableObject
|
||||
{
|
||||
private readonly DrawningWarmlyLocomotive? _drawningCar = null;
|
||||
private readonly DrawningWarmlyLocomotive? _drawningWarmlyLocomotive = null;
|
||||
public DrawningObjectCar(DrawningWarmlyLocomotive drawningCar)
|
||||
{
|
||||
_drawningCar = drawningCar;
|
||||
_drawningWarmlyLocomotive = drawningCar;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningCar == null || _drawningCar.EntityWarmlyLocomotive ==
|
||||
if (_drawningWarmlyLocomotive == null || _drawningWarmlyLocomotive.EntityWarmlyLocomotive ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningCar.GetPosX,
|
||||
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
|
||||
return new ObjectParameters(_drawningWarmlyLocomotive.GetPosX,
|
||||
_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) =>
|
||||
_drawningCar?.CanMove(direction) ?? false;
|
||||
_drawningWarmlyLocomotive?.CanMove(direction) ?? false;
|
||||
public void MoveObject(Direction direction) =>
|
||||
_drawningCar?.MoveTransport(direction);
|
||||
_drawningWarmlyLocomotive?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,4 @@
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.Entities;
|
||||
using WarmlyLocomotive;
|
||||
using WarmlyLocomotive.Entities;
|
||||
|
||||
namespace WarmlyLocomotive.DrawningObjects
|
||||
{
|
||||
@ -28,8 +21,6 @@ namespace WarmlyLocomotive.DrawningObjects
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush bodyBrush = new SolidBrush(warmlylocomotive.BodyColor);
|
||||
Brush addBrush = new SolidBrush(warmlylocomotive.AdditionalColor);
|
||||
Brush wheelBrush = new SolidBrush(Color.Black);
|
||||
base.DrawTransport(g);
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.Entities;
|
||||
|
||||
using WarmlyLocomotive.Entities;
|
||||
namespace WarmlyLocomotive.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
@ -65,7 +59,6 @@ namespace WarmlyLocomotive.DrawningObjects
|
||||
|
||||
EntityWarmlyLocomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawningWarmlyLocomotive(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int carWidth, int carHeight)
|
||||
{
|
||||
@ -95,7 +88,6 @@ namespace WarmlyLocomotive.DrawningObjects
|
||||
_startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
public bool CanMove(Direction direction)
|
||||
{
|
||||
if (EntityWarmlyLocomotive == null)
|
||||
@ -115,7 +107,6 @@ namespace WarmlyLocomotive.DrawningObjects
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <param name="direction">Направление</param>
|
||||
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 + 145, _startPosY + 50, 20, 20);
|
||||
g.FillEllipse(wheelBrush, _startPosX + 170, _startPosY + 50, 20, 20);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive.Entities
|
||||
namespace WarmlyLocomotive.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Автомобиль"
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
|
@ -1,11 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.MovementStrategy;
|
||||
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
{
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
@ -21,7 +14,6 @@ namespace WarmlyLocomotive.MovementStrategy
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
@ -32,19 +24,13 @@ namespace WarmlyLocomotive.MovementStrategy
|
||||
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
|
||||
MoveRight();
|
||||
|
||||
}
|
||||
var diffY = FieldHeight - objParams.ObjectMiddleVertical;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
|
||||
MoveDown();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.MovementStrategy;
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
{
|
||||
internal class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
@ -20,7 +13,6 @@ namespace WarmlyLocomotive.MovementStrategy
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2);
|
||||
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
|
@ -1,11 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace WarmlyLocomotive.Entities
|
||||
namespace WarmlyLocomotive.Entities
|
||||
{
|
||||
public class Pro : EntityWarmlyLocomotive
|
||||
|
||||
{
|
||||
eegov
commented
Нет префикса Entity Нет префикса Entity
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
namespace WarmlyLocomotive.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
|
||||
@ -10,16 +11,15 @@ namespace WarmlyLocomotive
|
||||
/// </summary>
|
||||
public partial class WarmlyLocomotiveForm : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
public DrawningWarmlyLocomotive? SelectedCar { get; private set; }
|
||||
public WarmlyLocomotiveForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
/// </summary>
|
||||
@ -29,11 +29,11 @@ namespace WarmlyLocomotive
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width,
|
||||
pictureBoxWarmlyLocomotive.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningWarmlyLocomotive.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
pictureBoxWarmlyLocomotive.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü òåïëîâîç"
|
||||
@ -47,12 +47,11 @@ namespace WarmlyLocomotive
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(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,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@ -78,16 +77,6 @@ namespace WarmlyLocomotive
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// </summary>
|
||||
@ -99,9 +88,9 @@ namespace WarmlyLocomotive
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBox1.Enabled)
|
||||
if (comboBoxWarmlyLocomotive.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBox1.SelectedIndex
|
||||
_abstractStrategy = comboBoxWarmlyLocomotive.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
@ -113,9 +102,9 @@ namespace WarmlyLocomotive
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectCar(_drawningWarmlyLocomotive), pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
comboBox1.Enabled = false;
|
||||
DrawningObjectCar(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width,
|
||||
pictureBoxWarmlyLocomotive.Height);
|
||||
comboBoxWarmlyLocomotive.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
@ -125,7 +114,7 @@ namespace WarmlyLocomotive
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBox1.Enabled = true;
|
||||
comboBoxWarmlyLocomotive.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
@ -145,7 +134,7 @@ namespace WarmlyLocomotive
|
||||
random.Next(0, 256)),
|
||||
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,
|
||||
100));
|
||||
Draw();
|
||||
|
51
WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs
generated
51
WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs
generated
@ -29,28 +29,27 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WarmlyLocomotiveForm));
|
||||
pictureBox1 = new PictureBox();
|
||||
pictureBoxWarmlyLocomotive = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
comboBox1 = new ComboBox();
|
||||
comboBoxWarmlyLocomotive = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonCreate_Pro = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBox1
|
||||
// pictureBoxWarmlyLocomotive
|
||||
//
|
||||
pictureBox1.Dock = DockStyle.Fill;
|
||||
pictureBox1.Location = new Point(0, 0);
|
||||
pictureBox1.Name = "pictureBox1";
|
||||
pictureBox1.Size = new Size(884, 461);
|
||||
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBox1.TabIndex = 0;
|
||||
pictureBox1.TabStop = false;
|
||||
pictureBox1.Click += pictureBox1_Click;
|
||||
pictureBoxWarmlyLocomotive.Dock = DockStyle.Fill;
|
||||
pictureBoxWarmlyLocomotive.Location = new Point(0, 0);
|
||||
pictureBoxWarmlyLocomotive.Name = "pictureBoxWarmlyLocomotive";
|
||||
pictureBoxWarmlyLocomotive.Size = new Size(884, 461);
|
||||
pictureBoxWarmlyLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxWarmlyLocomotive.TabIndex = 0;
|
||||
pictureBoxWarmlyLocomotive.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
@ -111,16 +110,15 @@
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// comboBox1
|
||||
// comboBoxWarmlyLocomotive
|
||||
//
|
||||
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBox1.FormattingEnabled = true;
|
||||
comboBox1.Items.AddRange(new object[] { "Центр", "Угол" });
|
||||
comboBox1.Location = new Point(717, 21);
|
||||
comboBox1.Name = "comboBox1";
|
||||
comboBox1.Size = new Size(121, 23);
|
||||
comboBox1.TabIndex = 7;
|
||||
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
|
||||
comboBoxWarmlyLocomotive.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxWarmlyLocomotive.FormattingEnabled = true;
|
||||
comboBoxWarmlyLocomotive.Items.AddRange(new object[] { "Центр", "Угол" });
|
||||
comboBoxWarmlyLocomotive.Location = new Point(717, 21);
|
||||
comboBoxWarmlyLocomotive.Name = "comboBoxWarmlyLocomotive";
|
||||
comboBoxWarmlyLocomotive.Size = new Size(121, 23);
|
||||
comboBoxWarmlyLocomotive.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
@ -147,16 +145,17 @@
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(buttonCreate_Pro);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBox1);
|
||||
Controls.Add(comboBoxWarmlyLocomotive);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBox1);
|
||||
Controls.Add(pictureBoxWarmlyLocomotive);
|
||||
Name = "WarmlyLocomotiveForm";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||
Text = "WarmlyLocomotiveForm";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -165,13 +164,13 @@
|
||||
|
||||
|
||||
|
||||
private PictureBox pictureBox1;
|
||||
private PictureBox pictureBoxWarmlyLocomotive;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private ComboBox comboBox1;
|
||||
private ComboBox comboBoxWarmlyLocomotive;
|
||||
private Button buttonStep;
|
||||
private Button buttonCreate_Pro;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Класс-сущность из первой части должен стать дочерним классом, а не родительским