Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8db23745a | ||
|
|
2dcb3f67e3 |
@@ -3,35 +3,16 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
namespace Cruiser.MovementStrategy
|
namespace Cruiser.MovementStrategy
|
||||||
{
|
{
|
||||||
public abstract class AbstractStrategy
|
public abstract class AbstractStrategy
|
||||||
{
|
{
|
||||||
private IMoveableObject? _moveableObject;
|
private IMoveableObject? _moveableObject;
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
private Status _state = Status.NotInit;
|
private Status _state = Status.NotInit;
|
||||||
/// <summary>
|
|
||||||
/// Ширина поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldWidth { get; private set; }
|
protected int FieldWidth { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Высота поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldHeight { get; private set; }
|
protected int FieldHeight { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
public Status GetStatus() { return _state; }
|
public Status GetStatus() { return _state; }
|
||||||
/// <summary>
|
|
||||||
/// Установка данных
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
|
||||||
/// <param name="width">Ширина поля</param>
|
|
||||||
/// <param name="height">Высота поля</param>
|
|
||||||
public void SetData(IMoveableObject moveableObject, int width, int
|
public void SetData(IMoveableObject moveableObject, int width, int
|
||||||
height)
|
height)
|
||||||
{
|
{
|
||||||
@@ -45,9 +26,6 @@ namespace Cruiser.MovementStrategy
|
|||||||
FieldWidth = width;
|
FieldWidth = width;
|
||||||
FieldHeight = height;
|
FieldHeight = height;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения
|
|
||||||
/// </summary>
|
|
||||||
public void MakeStep()
|
public void MakeStep()
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
@@ -61,35 +39,12 @@ namespace Cruiser.MovementStrategy
|
|||||||
}
|
}
|
||||||
MoveToTarget();
|
MoveToTarget();
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Перемещение влево
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveLeft() => MoveTo(Direction.Left);
|
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вправо
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveRight() => MoveTo(Direction.Right);
|
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вверх
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveUp() => MoveTo(Direction.Up);
|
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вниз
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
|
||||||
protected bool MoveDown() => MoveTo(Direction.Down);
|
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||||
/// <summary>
|
|
||||||
/// Параметры объекта
|
|
||||||
/// </summary>
|
|
||||||
protected ObjectParameters? GetObjectParameters =>
|
protected ObjectParameters? GetObjectParameters =>
|
||||||
_moveableObject?.GetObjectPosition;
|
_moveableObject?.GetObjectPosition;
|
||||||
/// <summary>
|
|
||||||
/// Шаг объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected int? GetStep()
|
protected int? GetStep()
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
@@ -98,33 +53,20 @@ namespace Cruiser.MovementStrategy
|
|||||||
}
|
}
|
||||||
return _moveableObject?.GetStep;
|
return _moveableObject?.GetStep;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Перемещение к цели
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void MoveToTarget();
|
protected abstract void MoveToTarget();
|
||||||
/// <summary>
|
|
||||||
/// Достигнута ли цель
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected abstract bool IsTargetDestinaion();
|
protected abstract bool IsTargetDestinaion();
|
||||||
/// <summary>
|
private bool MoveTo(Direction direction)
|
||||||
/// Попытка перемещения в требуемом направлении
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="directionType">Направление</param>
|
|
||||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
private bool MoveTo(Direction directionType)
|
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
if (_moveableObject?.CheckCanMove(direction) ?? false)
|
||||||
{
|
{
|
||||||
_moveableObject.MoveObject(directionType);
|
_moveableObject.MoveObject(direction);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2,60 +2,31 @@
|
|||||||
{
|
{
|
||||||
partial class CruiserForm
|
partial class CruiserForm
|
||||||
{
|
{
|
||||||
/// <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>
|
|
||||||
|
|
||||||
|
|
||||||
#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()
|
||||||
{
|
{
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
|
||||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdvancedCreate = new System.Windows.Forms.Button();
|
||||||
this.buttonCreate = new System.Windows.Forms.Button();
|
this.buttonCreate = new System.Windows.Forms.Button();
|
||||||
this.button2 = new System.Windows.Forms.Button();
|
this.comboBoxCruiser = new System.Windows.Forms.ComboBox();
|
||||||
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
|
||||||
this.ButtonStep = new System.Windows.Forms.Button();
|
this.ButtonStep = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
// pictureBoxCruiser
|
||||||
// button1
|
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
//
|
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
|
||||||
this.button1.Location = new System.Drawing.Point(386, 68);
|
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
|
||||||
this.button1.Name = "button1";
|
this.pictureBoxCruiser.Size = new System.Drawing.Size(667, 358);
|
||||||
this.button1.Size = new System.Drawing.Size(112, 34);
|
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.button1.TabIndex = 0;
|
this.pictureBoxCruiser.TabIndex = 0;
|
||||||
this.button1.Text = "button1";
|
this.pictureBoxCruiser.TabStop = false;
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
this.pictureBoxCruiser.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
|
||||||
// pictureBox1
|
|
||||||
//
|
|
||||||
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
|
|
||||||
this.pictureBox1.Name = "pictureBox1";
|
|
||||||
this.pictureBox1.Size = new System.Drawing.Size(667, 358);
|
|
||||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
|
||||||
this.pictureBox1.TabIndex = 0;
|
|
||||||
this.pictureBox1.TabStop = false;
|
|
||||||
this.pictureBox1.Click += new System.EventHandler(this.buttonMove_Click);
|
|
||||||
//
|
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
|
||||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonDown.BackgroundImage = global::Cruiser.Properties.Resources.вниз;
|
this.buttonDown.BackgroundImage = global::Cruiser.Properties.Resources.вниз;
|
||||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
@@ -65,9 +36,7 @@
|
|||||||
this.buttonDown.TabIndex = 1;
|
this.buttonDown.TabIndex = 1;
|
||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
|
||||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonLeft.BackgroundImage = global::Cruiser.Properties.Resources.влево;
|
this.buttonLeft.BackgroundImage = global::Cruiser.Properties.Resources.влево;
|
||||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
@@ -77,9 +46,7 @@
|
|||||||
this.buttonLeft.TabIndex = 2;
|
this.buttonLeft.TabIndex = 2;
|
||||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
|
||||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonRight.BackgroundImage = global::Cruiser.Properties.Resources.вправо;
|
this.buttonRight.BackgroundImage = global::Cruiser.Properties.Resources.вправо;
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
@@ -89,9 +56,7 @@
|
|||||||
this.buttonRight.TabIndex = 3;
|
this.buttonRight.TabIndex = 3;
|
||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
// buttonUp
|
||||||
// buttonUp
|
|
||||||
//
|
|
||||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonUp.BackgroundImage = global::Cruiser.Properties.Resources.вверх;
|
this.buttonUp.BackgroundImage = global::Cruiser.Properties.Resources.вверх;
|
||||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
@@ -101,43 +66,35 @@
|
|||||||
this.buttonUp.TabIndex = 4;
|
this.buttonUp.TabIndex = 4;
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
// buttonAdvancedCreate
|
||||||
|
this.buttonAdvancedCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonAdvancedCreate.Location = new System.Drawing.Point(12, 267);
|
||||||
|
this.buttonAdvancedCreate.Name = "buttonAdvancedCreate";
|
||||||
|
this.buttonAdvancedCreate.Size = new System.Drawing.Size(210, 69);
|
||||||
|
this.buttonAdvancedCreate.TabIndex = 5;
|
||||||
|
this.buttonAdvancedCreate.Text = "Создать продвинутую версию";
|
||||||
|
this.buttonAdvancedCreate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdvancedCreate.Click += new System.EventHandler(this.buttonAdvancedCreate_Click);
|
||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
|
||||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
this.buttonCreate.Location = new System.Drawing.Point(0, 302);
|
this.buttonCreate.Location = new System.Drawing.Point(240, 267);
|
||||||
this.buttonCreate.Name = "buttonCreate";
|
this.buttonCreate.Name = "buttonCreate";
|
||||||
this.buttonCreate.Size = new System.Drawing.Size(218, 34);
|
this.buttonCreate.Size = new System.Drawing.Size(242, 69);
|
||||||
this.buttonCreate.TabIndex = 5;
|
this.buttonCreate.TabIndex = 6;
|
||||||
this.buttonCreate.Text = "Создать Про версию";
|
this.buttonCreate.Text = "Создать простую версию";
|
||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||||
//
|
// comboBoxCruiser
|
||||||
// button2
|
this.comboBoxCruiser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
//
|
this.comboBoxCruiser.FormattingEnabled = true;
|
||||||
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.comboBoxCruiser.Items.AddRange(new object[] {
|
||||||
this.button2.Location = new System.Drawing.Point(210, 301);
|
|
||||||
this.button2.Name = "button2";
|
|
||||||
this.button2.Size = new System.Drawing.Size(251, 37);
|
|
||||||
this.button2.TabIndex = 6;
|
|
||||||
this.button2.Text = "Создать простую версию";
|
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
|
||||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
|
||||||
//
|
|
||||||
// comboBox1
|
|
||||||
//
|
|
||||||
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
|
||||||
this.comboBox1.FormattingEnabled = true;
|
|
||||||
this.comboBox1.Items.AddRange(new object[] {
|
|
||||||
"Центр",
|
"Центр",
|
||||||
"Угол"});
|
"Угол"});
|
||||||
this.comboBox1.Location = new System.Drawing.Point(415, 22);
|
this.comboBoxCruiser.Location = new System.Drawing.Point(415, 22);
|
||||||
this.comboBox1.Name = "comboBox1";
|
this.comboBoxCruiser.Name = "comboBoxCruiser";
|
||||||
this.comboBox1.Size = new System.Drawing.Size(182, 33);
|
this.comboBoxCruiser.Size = new System.Drawing.Size(182, 33);
|
||||||
this.comboBox1.TabIndex = 7;
|
this.comboBoxCruiser.TabIndex = 7;
|
||||||
//
|
|
||||||
// ButtonStep
|
// ButtonStep
|
||||||
//
|
|
||||||
this.ButtonStep.Location = new System.Drawing.Point(485, 70);
|
this.ButtonStep.Location = new System.Drawing.Point(485, 70);
|
||||||
this.ButtonStep.Name = "ButtonStep";
|
this.ButtonStep.Name = "ButtonStep";
|
||||||
this.ButtonStep.Size = new System.Drawing.Size(112, 34);
|
this.ButtonStep.Size = new System.Drawing.Size(112, 34);
|
||||||
@@ -145,38 +102,33 @@
|
|||||||
this.ButtonStep.Text = "Шаг";
|
this.ButtonStep.Text = "Шаг";
|
||||||
this.ButtonStep.UseVisualStyleBackColor = true;
|
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||||
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||||
//
|
|
||||||
// CruiserForm
|
// CruiserForm
|
||||||
//
|
|
||||||
this.ClientSize = new System.Drawing.Size(667, 358);
|
this.ClientSize = new System.Drawing.Size(667, 358);
|
||||||
this.Controls.Add(this.ButtonStep);
|
this.Controls.Add(this.ButtonStep);
|
||||||
this.Controls.Add(this.comboBox1);
|
this.Controls.Add(this.comboBoxCruiser);
|
||||||
this.Controls.Add(this.button2);
|
|
||||||
this.Controls.Add(this.buttonCreate);
|
this.Controls.Add(this.buttonCreate);
|
||||||
|
this.Controls.Add(this.buttonAdvancedCreate);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.pictureBox1);
|
this.Controls.Add(this.pictureBoxCruiser);
|
||||||
this.Name = "CruiserForm";
|
this.Name = "CruiserForm";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <param name="e"></param>
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Button button1;
|
#endregion
|
||||||
private PictureBox pictureBox1;
|
private PictureBox pictureBoxCruiser;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private Button buttonAdvancedCreate;
|
||||||
private Button buttonCreate;
|
private Button buttonCreate;
|
||||||
private Button button2;
|
private ComboBox comboBoxCruiser;
|
||||||
private ComboBox comboBox1;
|
|
||||||
private Button ButtonStep;
|
private Button ButtonStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Cruiser.DrawningObjects;
|
using Cruiser.DrawningObjects;
|
||||||
|
|
||||||
using Cruiser.MovementStrategy;
|
using Cruiser.MovementStrategy;
|
||||||
|
|
||||||
namespace Cruiser
|
namespace Cruiser
|
||||||
{
|
{
|
||||||
|
|
||||||
public partial class CruiserForm : Form
|
public partial class CruiserForm : Form
|
||||||
{
|
{
|
||||||
private DrawningCruiser? _drawningCruiser;
|
private DrawningCruiser? _drawningCruiser;
|
||||||
@@ -21,10 +19,10 @@ namespace Cruiser
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
|
Bitmap bmp = new Bitmap(pictureBoxCruiser.Width, pictureBoxCruiser.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningCruiser.DrawTransport(gr);
|
_drawningCruiser.DrawTransport(gr);
|
||||||
pictureBox1.Image = bmp;
|
pictureBoxCruiser.Image = bmp;
|
||||||
}
|
}
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@@ -50,33 +48,27 @@ namespace Cruiser
|
|||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
private void button2_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningCruiser = new DrawningCruiser(random.Next(100, 300),
|
_drawningCruiser = new DrawningCruiser(random.Next(100, 300),
|
||||||
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);
|
pictureBoxCruiser.Width, pictureBoxCruiser.Height);
|
||||||
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,
|
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
100));
|
100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void ButtonStep_Click(object sender, EventArgs e)
|
private void ButtonStep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningCruiser == null)
|
if (_drawningCruiser == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (comboBox1.Enabled)
|
if (comboBoxCruiser.Enabled)
|
||||||
{
|
{
|
||||||
_abstractStrategy = comboBox1.SelectedIndex
|
_abstractStrategy = comboBoxCruiser.SelectedIndex
|
||||||
switch
|
switch
|
||||||
{
|
{
|
||||||
0 => new MoveToCenter(),
|
0 => new MoveToCenter(),
|
||||||
@@ -87,9 +79,9 @@ namespace Cruiser
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(new DrawningObjectCar(_drawningCruiser), pictureBox1.Width,
|
_abstractStrategy.SetData(new DrawningObjectCruiser(_drawningCruiser), pictureBoxCruiser.Width,
|
||||||
pictureBox1.Height);
|
pictureBoxCruiser.Height);
|
||||||
comboBox1.Enabled = false;
|
comboBoxCruiser.Enabled = false;
|
||||||
}
|
}
|
||||||
if (_abstractStrategy == null)
|
if (_abstractStrategy == null)
|
||||||
{
|
{
|
||||||
@@ -99,15 +91,14 @@ namespace Cruiser
|
|||||||
Draw();
|
Draw();
|
||||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
{
|
{
|
||||||
comboBox1.Enabled = true;
|
comboBoxCruiser.Enabled = true;
|
||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void buttonAdvancedCreate_Click(object sender, EventArgs e)
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawningCruiser = new DrawningPro(random.Next(100, 300),
|
_drawningCruiser = new DrawningAdvancedCruiser(random.Next(100, 300),
|
||||||
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)),
|
||||||
@@ -117,16 +108,10 @@ namespace Cruiser
|
|||||||
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);
|
pictureBoxCruiser.Width, pictureBoxCruiser.Height);
|
||||||
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,
|
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
100));
|
100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3,28 +3,13 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Cruiser
|
namespace Cruiser
|
||||||
{
|
{
|
||||||
public enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
/// Вверх
|
|
||||||
|
|
||||||
/// </summary>
|
|
||||||
Up = 1,
|
Up = 1,
|
||||||
/// <summary>
|
|
||||||
/// Вниз
|
|
||||||
/// </summary>
|
|
||||||
Down = 2,
|
Down = 2,
|
||||||
/// <summary>
|
|
||||||
/// Влево
|
|
||||||
/// </summary>
|
|
||||||
Left = 3,
|
Left = 3,
|
||||||
/// <summary>
|
|
||||||
/// Вправо
|
|
||||||
/// </summary>
|
|
||||||
Right = 4
|
Right = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5,56 +5,44 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Cruiser.Entities;
|
using Cruiser.Entities;
|
||||||
using Cruiser;
|
|
||||||
|
|
||||||
namespace Cruiser.DrawningObjects
|
namespace Cruiser.DrawningObjects
|
||||||
{
|
{
|
||||||
|
public class DrawningAdvancedCruiser : DrawningCruiser
|
||||||
public class DrawningPro : DrawningCruiser
|
|
||||||
{
|
{
|
||||||
public DrawningPro(int speed, double weight, Color bodyColor, Color additionalColor, bool headlights, bool helicopterPad, bool coating, int width, int height) : base(speed, weight, bodyColor, width, height, 150, 50)
|
public DrawningAdvancedCruiser(int speed, double weight, Color bodyColor, Color additionalColor, bool headlights, bool helicopterPad, bool coating, int width, int height) : base(speed, weight, bodyColor, width, height, 150, 50)
|
||||||
{
|
{
|
||||||
if (EntityCruiser != null)
|
if (EntityCruiser != null)
|
||||||
{
|
{
|
||||||
EntityCruiser = new Pro(speed, weight, bodyColor, additionalColor, headlights, helicopterPad, coating);
|
EntityCruiser = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, headlights, helicopterPad, coating);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityCruiser is not Pro cruiser)
|
if (EntityCruiser is not EntityAdvancedCruiser cruiser)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new Pen(Color.Black);
|
Pen pen = new Pen(Color.Black);
|
||||||
Brush addBrush = new SolidBrush(cruiser.AdditionalColor);
|
Brush addBrush = new SolidBrush(cruiser.AdditionalColor);
|
||||||
Brush brush = new SolidBrush(cruiser.BodyColor);
|
Brush brush = new SolidBrush(cruiser.BodyColor);
|
||||||
|
|
||||||
base.DrawTransport(g);
|
base.DrawTransport(g);
|
||||||
if (cruiser.Headlights)
|
if (cruiser.Headlights)
|
||||||
{
|
{
|
||||||
|
|
||||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
|
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
|
||||||
20);
|
20);
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
||||||
20);
|
20);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cruiser.HelicopterPad)
|
if (cruiser.HelicopterPad)
|
||||||
{
|
{
|
||||||
//если есть площадка под вертолет
|
|
||||||
|
|
||||||
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
|
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (cruiser.Coating)
|
||||||
/* if (cruiser.Coating)
|
|
||||||
{
|
{
|
||||||
//если есть спец покрытие для площадки под вертолет
|
g.FillEllipse(Brushes.Red, _startPosX + 80, _startPosY + 20, 20, 20);
|
||||||
g.FillEllipse(Brushes.Red, _startPosX + 90, _startPosY + 20, 20, 20);
|
g.FillEllipse(Brushes.Red, _startPosX + 60, _startPosY + 20, 20, 20);
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,7 +11,6 @@ namespace Cruiser.DrawningObjects
|
|||||||
{
|
{
|
||||||
|
|
||||||
public EntityCruiser ? EntityCruiser { get; protected set; }
|
public EntityCruiser ? EntityCruiser { get; protected set; }
|
||||||
|
|
||||||
private int _pictureWidth;
|
private int _pictureWidth;
|
||||||
|
|
||||||
private int _pictureHeight;
|
private int _pictureHeight;
|
||||||
@@ -22,30 +21,11 @@ namespace Cruiser.DrawningObjects
|
|||||||
|
|
||||||
private readonly int _cruiserWidth = 150;
|
private readonly int _cruiserWidth = 150;
|
||||||
|
|
||||||
|
|
||||||
private readonly int _cruiserHeight = 50;
|
private readonly int _cruiserHeight = 50;
|
||||||
|
|
||||||
public int GetPosX => _startPosX;
|
public int GetPosX => _startPosX;
|
||||||
/// <summary>
|
|
||||||
/// Координата Y объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetPosY => _startPosY;
|
public int GetPosY => _startPosY;
|
||||||
/// <summary>
|
|
||||||
/// Ширина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetWidth => _cruiserWidth;
|
public int GetWidth => _cruiserWidth;
|
||||||
/// <summary>
|
|
||||||
/// Высота объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetHeight => _cruiserHeight;
|
public int GetHeight => _cruiserHeight;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
|
||||||
/// <param name="height">Высота картинки</param>
|
|
||||||
|
|
||||||
public DrawningCruiser(int speed, double weight, Color bodyColor, int width, int height)
|
public DrawningCruiser(int speed, double weight, Color bodyColor, int width, int height)
|
||||||
{
|
{
|
||||||
@@ -55,15 +35,10 @@ namespace Cruiser.DrawningObjects
|
|||||||
}
|
}
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
|
||||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawningCruiser(int speed, double weight, Color bodyColor, int
|
protected DrawningCruiser(int speed, double weight, Color bodyColor, int
|
||||||
width, int height, int carWidth, int carHeight)
|
width, int height, int cruiserWidth, int cruiserHeight)
|
||||||
{
|
{
|
||||||
if (width <= _cruiserWidth || height <= _cruiserHeight)
|
if (width <= _cruiserWidth || height <= _cruiserHeight)
|
||||||
{
|
{
|
||||||
@@ -71,33 +46,23 @@ width, int height, int carWidth, int carHeight)
|
|||||||
}
|
}
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
_cruiserWidth = carWidth;
|
_cruiserWidth = cruiserWidth;
|
||||||
_cruiserHeight = carHeight;
|
_cruiserHeight = cruiserHeight;
|
||||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <param name="x">Координата X</param>
|
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight)
|
if (x < 0 || x + _cruiserWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX = 0;
|
x = Math.Max(0, _pictureWidth - _cruiserWidth);
|
||||||
_startPosY = 0;
|
}
|
||||||
|
if (y < 0 || y + _cruiserHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y = Math.Max(0, _pictureHeight - _cruiserHeight);
|
||||||
}
|
}
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
public void MoveTransport(Direction direction)
|
public void MoveTransport(Direction direction)
|
||||||
{
|
{
|
||||||
if (!CanMove(direction) || EntityCruiser == null)
|
if (!CanMove(direction) || EntityCruiser == null)
|
||||||
@@ -106,25 +71,18 @@ width, int height, int carWidth, int carHeight)
|
|||||||
}
|
}
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
//влево
|
|
||||||
case Direction.Left:
|
case Direction.Left:
|
||||||
_startPosX -= (int)EntityCruiser.Step;
|
_startPosX -= (int)EntityCruiser.Step;
|
||||||
break;
|
break;
|
||||||
//вверх
|
|
||||||
case Direction.Up:
|
case Direction.Up:
|
||||||
_startPosY -= (int)EntityCruiser.Step;
|
_startPosY -= (int)EntityCruiser.Step;
|
||||||
break;
|
break;
|
||||||
// вправо
|
|
||||||
case Direction.Right:
|
case Direction.Right:
|
||||||
_startPosX += (int)EntityCruiser.Step;
|
_startPosX += (int)EntityCruiser.Step;
|
||||||
break;
|
break;
|
||||||
//вниз
|
|
||||||
case Direction.Down:
|
case Direction.Down:
|
||||||
_startPosY += (int)EntityCruiser.Step;
|
_startPosY += (int)EntityCruiser.Step;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool CanMove(Direction direction)
|
public bool CanMove(Direction direction)
|
||||||
@@ -135,19 +93,13 @@ width, int height, int carWidth, int carHeight)
|
|||||||
}
|
}
|
||||||
return direction switch
|
return direction switch
|
||||||
{
|
{
|
||||||
//влево
|
|
||||||
Direction.Left => _startPosX - EntityCruiser.Step > 0,
|
Direction.Left => _startPosX - EntityCruiser.Step > 0,
|
||||||
//вверх
|
|
||||||
Direction.Up => _startPosY - EntityCruiser.Step > 0,
|
Direction.Up => _startPosY - EntityCruiser.Step > 0,
|
||||||
// вправо
|
|
||||||
Direction.Right => _startPosX + EntityCruiser.Step + _cruiserWidth < _pictureWidth,
|
Direction.Right => _startPosX + EntityCruiser.Step + _cruiserWidth < _pictureWidth,
|
||||||
//вниз
|
|
||||||
Direction.Down => _startPosY + EntityCruiser.Step + _cruiserHeight < _pictureHeight,
|
Direction.Down => _startPosY + EntityCruiser.Step + _cruiserHeight < _pictureHeight,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="g"></param>
|
|
||||||
public virtual void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityCruiser == null)
|
if (EntityCruiser == null)
|
||||||
@@ -156,70 +108,34 @@ width, int height, int carWidth, int carHeight)
|
|||||||
}
|
}
|
||||||
Pen pen = new Pen(Color.Black);
|
Pen pen = new Pen(Color.Black);
|
||||||
Brush brush = new SolidBrush(EntityCruiser.BodyColor);
|
Brush brush = new SolidBrush(EntityCruiser.BodyColor);
|
||||||
//SolidBrush(Cruiser.AdditionalColor);
|
|
||||||
|
|
||||||
|
|
||||||
//границы автомобиля
|
|
||||||
|
|
||||||
|
|
||||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
|
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
|
||||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
|
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
|
||||||
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
|
||||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
|
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
|
||||||
30);
|
30);
|
||||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
||||||
|
|
||||||
//если есть доп.фонари
|
|
||||||
/* if (Cruiser.Headlights)
|
|
||||||
{
|
|
||||||
|
|
||||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
|
|
||||||
20);
|
|
||||||
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
|
|
||||||
20);
|
|
||||||
}*/
|
|
||||||
//основание лодки!!!
|
|
||||||
Brush br = new SolidBrush(EntityCruiser.BodyColor);
|
Brush br = new SolidBrush(EntityCruiser.BodyColor);
|
||||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
|
||||||
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
|
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
|
||||||
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
|
||||||
Point[] points = new Point[3];// нос лодки
|
Point[] points = new Point[3];
|
||||||
points[0] = new Point(_startPosX + 100, _startPosY + 5);
|
points[0] = new Point(_startPosX + 100, _startPosY + 5);
|
||||||
points[1] = new Point(_startPosX + 100, _startPosY + 55);
|
points[1] = new Point(_startPosX + 100, _startPosY + 55);
|
||||||
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
||||||
g.FillPolygon(Brushes.Pink, points);
|
g.FillPolygon(Brushes.Pink, points);
|
||||||
//границы носа лодки
|
|
||||||
Point[] points1 = new Point[3];// нос лодки
|
Point[] points1 = new Point[3];
|
||||||
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
|
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
|
||||||
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
|
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
|
||||||
points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
|
||||||
g.DrawPolygon(pen, points1);
|
g.DrawPolygon(pen, points1);
|
||||||
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
|
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
|
||||||
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
|
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
|
||||||
|
|
||||||
//если есть ракетные шахты, добавить условие
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + 35,
|
g.DrawRectangle(Pens.Black, _startPosX + 35,
|
||||||
_startPosY + 23, 15, 15);
|
_startPosY + 23, 15, 15);
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + 50,
|
g.DrawRectangle(Pens.Black, _startPosX + 50,
|
||||||
_startPosY + 19, 30, 25);
|
_startPosY + 19, 30, 25);
|
||||||
|
|
||||||
/* if (Cruiser.HelicopterPad)
|
|
||||||
{
|
|
||||||
//если есть площадка под вертолет
|
|
||||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 20, 20);
|
|
||||||
}
|
|
||||||
if (Cruiser.Coating)
|
|
||||||
{
|
|
||||||
//если есть спец покрытие для площадки под вертолет
|
|
||||||
g.FillEllipse(Brushes.Red, _startPosX + 90, _startPosY + 20, 20, 20);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Cruiser.DrawningObjects;
|
|
||||||
using Cruiser.MovementStrategy;
|
|
||||||
|
|
||||||
namespace Cruiser.MovementStrategy
|
|
||||||
{
|
|
||||||
internal class DrawningObjectCar : IMoveableObject
|
|
||||||
{
|
|
||||||
private readonly DrawningCruiser? _drawningCar = null;
|
|
||||||
public DrawningObjectCar(DrawningCruiser drawningCar)
|
|
||||||
{
|
|
||||||
_drawningCar = drawningCar;
|
|
||||||
}
|
|
||||||
public ObjectParameters? GetObjectPosition
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_drawningCar == null || _drawningCar.EntityCruiser ==
|
|
||||||
null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new ObjectParameters(_drawningCar.GetPosX,
|
|
||||||
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int GetStep => (int)(_drawningCar?.EntityCruiser?.Step ?? 0);
|
|
||||||
public bool CheckCanMove(Direction direction) =>
|
|
||||||
_drawningCar?.CanMove(direction) ?? false;
|
|
||||||
public void MoveObject(Direction direction) =>
|
|
||||||
_drawningCar?.MoveTransport(direction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
36
Cruiser/Cruiser/DrawningObjectCruiser.cs
Normal file
36
Cruiser/Cruiser/DrawningObjectCruiser.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Cruiser.DrawningObjects;
|
||||||
|
|
||||||
|
namespace Cruiser.MovementStrategy
|
||||||
|
{
|
||||||
|
internal class DrawningObjectCruiser : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawningCruiser? _drawningCruiser = null;
|
||||||
|
public DrawningObjectCruiser(DrawningCruiser drawningCruiser)
|
||||||
|
{
|
||||||
|
_drawningCruiser = drawningCruiser;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningCruiser == null || _drawningCruiser.EntityCruiser ==
|
||||||
|
null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningCruiser.GetPosX,
|
||||||
|
_drawningCruiser.GetPosY, _drawningCruiser.GetWidth, _drawningCruiser.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningCruiser?.EntityCruiser?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(Direction direction) =>
|
||||||
|
_drawningCruiser?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(Direction direction) =>
|
||||||
|
_drawningCruiser?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,30 +4,22 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
namespace Cruiser.Entities
|
namespace Cruiser.Entities
|
||||||
{
|
{
|
||||||
public class Pro : EntityCruiser
|
public class EntityAdvancedCruiser : EntityCruiser
|
||||||
{
|
{
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public bool Headlights { get; private set; }
|
public bool Headlights { get; private set; }
|
||||||
public bool HelicopterPad { get; private set; }
|
public bool HelicopterPad { get; private set; }
|
||||||
|
|
||||||
public bool Coating { get; private set; }
|
public bool Coating { get; private set; }
|
||||||
|
|
||||||
public Pro(int speed, double weight, Color bodyColor, Color
|
public EntityAdvancedCruiser(int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, bool headlights, bool helicopterPad, bool coating) : base(speed, weight, bodyColor)
|
additionalColor, bool headlights, bool helicopterPad, bool coating) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Headlights = headlights;
|
Headlights = headlights;
|
||||||
HelicopterPad = helicopterPad;
|
HelicopterPad = helicopterPad;
|
||||||
Coating = coating;
|
Coating = coating;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -8,28 +8,10 @@ namespace Cruiser.Entities
|
|||||||
{
|
{
|
||||||
public class EntityCruiser
|
public class EntityCruiser
|
||||||
{
|
{
|
||||||
|
|
||||||
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 Headlights { get; private set; }
|
|
||||||
// public bool HelicopterPad { get; private set; }
|
|
||||||
|
|
||||||
// public bool Coating { get; private set; }
|
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
|
|
||||||
public EntityCruiser(int speed, double weight, Color bodyColor)
|
public EntityCruiser(int speed, double weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
@@ -38,4 +20,4 @@ namespace Cruiser.Entities
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,28 +3,13 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Cruiser.MovementStrategy
|
namespace Cruiser.MovementStrategy
|
||||||
|
|
||||||
{
|
{
|
||||||
public interface IMoveableObject
|
public interface IMoveableObject
|
||||||
{
|
{
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
/// <summary>
|
|
||||||
/// Шаг объекта
|
|
||||||
/// </summary>
|
|
||||||
int GetStep { get; }
|
int GetStep { get; }
|
||||||
/// <summary>
|
|
||||||
/// Проверка, можно ли переместиться по нужному направлению
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
bool CheckCanMove(Direction direction);
|
bool CheckCanMove(Direction direction);
|
||||||
/// <summary>
|
|
||||||
/// Изменение направления пермещения объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
void MoveObject(Direction direction);
|
void MoveObject(Direction direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,23 +29,32 @@ namespace Cruiser.MovementStrategy
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal;
|
var diffX = objParams.RightBorder - FieldWidth;
|
||||||
if (Math.Abs(diffX) > GetStep())
|
if (Math.Abs(diffX) > GetStep())
|
||||||
{
|
{
|
||||||
|
if (diffX > 0)
|
||||||
MoveRight();
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var diffY = FieldHeight - objParams.ObjectMiddleVertical;
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
if (Math.Abs(diffY) > GetStep())
|
if (Math.Abs(diffY) > GetStep())
|
||||||
{
|
{
|
||||||
|
if (diffY > 0)
|
||||||
MoveDown();
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Cruiser.MovementStrategy;
|
|
||||||
namespace Cruiser.MovementStrategy
|
namespace Cruiser.MovementStrategy
|
||||||
{
|
{
|
||||||
internal class MoveToCenter : AbstractStrategy
|
internal class MoveToCenter : AbstractStrategy
|
||||||
@@ -54,5 +54,4 @@ namespace Cruiser.MovementStrategy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,37 +12,12 @@ namespace Cruiser.MovementStrategy
|
|||||||
private readonly int _y;
|
private readonly int _y;
|
||||||
private readonly int _width;
|
private readonly int _width;
|
||||||
private readonly int _height;
|
private readonly int _height;
|
||||||
/// <summary>
|
|
||||||
/// Левая граница
|
|
||||||
/// </summary>
|
|
||||||
public int LeftBorder => _x;
|
public int LeftBorder => _x;
|
||||||
/// <summary>
|
|
||||||
/// Верхняя граница
|
|
||||||
/// </summary>
|
|
||||||
public int TopBorder => _y;
|
public int TopBorder => _y;
|
||||||
/// <summary>
|
|
||||||
/// Правая граница
|
|
||||||
/// </summary>
|
|
||||||
public int RightBorder => _x + _width;
|
public int RightBorder => _x + _width;
|
||||||
/// <summary>
|
|
||||||
/// Нижняя граница
|
|
||||||
/// </summary>
|
|
||||||
public int DownBorder => _y + _height;
|
public int DownBorder => _y + _height;
|
||||||
/// <summary>
|
|
||||||
/// Середина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
/// <summary>
|
|
||||||
/// Середина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int ObjectMiddleVertical => _y + _height / 2;
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Координата X</param>
|
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
/// <param name="width">Ширина</param>
|
|
||||||
/// <param name="height">Высота</param>
|
|
||||||
public ObjectParameters(int x, int y, int width, int height)
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
_x = x;
|
_x = x;
|
||||||
@@ -51,5 +26,4 @@ namespace Cruiser.MovementStrategy
|
|||||||
_height = height;
|
_height = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2,9 +2,6 @@ namespace Cruiser
|
|||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ namespace Cruiser.MovementStrategy
|
|||||||
InProgress,
|
InProgress,
|
||||||
Finish
|
Finish
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user