Directions(Centre&Boarder)
This commit is contained in:
parent
0897fa70ef
commit
3e17af2218
BIN
WinF_Lab1_Cruiser - Ярлык.lnk
Normal file
BIN
WinF_Lab1_Cruiser - Ярлык.lnk
Normal file
Binary file not shown.
@ -6,6 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<ForceDesignerDPIUnaware>true</ForceDesignerDPIUnaware>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
107
WinF_Lab1_Cruiser/CruiserMech/DrawingCanvas.Designer.cs
generated
107
WinF_Lab1_Cruiser/CruiserMech/DrawingCanvas.Designer.cs
generated
@ -1,4 +1,9 @@
|
||||
namespace CruiserMech
|
||||
using System.Drawing.Printing;
|
||||
using System.Windows.Forms;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CruiserMech
|
||||
{
|
||||
partial class DrawingCanvas
|
||||
{
|
||||
@ -30,10 +35,14 @@
|
||||
{
|
||||
pictureBox1 = new PictureBox();
|
||||
CreateButton = new Button();
|
||||
CreateButton2 = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
ButtonActivate = new Button();
|
||||
comboBox = new ComboBox();
|
||||
Activate = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -41,31 +50,45 @@
|
||||
//
|
||||
pictureBox1.Dock = DockStyle.Fill;
|
||||
pictureBox1.Location = new Point(0, 0);
|
||||
pictureBox1.Margin = new Padding(6);
|
||||
pictureBox1.Name = "pictureBox1";
|
||||
pictureBox1.Size = new Size(548, 283);
|
||||
pictureBox1.Size = new Size(1018, 604);
|
||||
pictureBox1.TabIndex = 0;
|
||||
pictureBox1.TabStop = false;
|
||||
//
|
||||
// CreateButton
|
||||
//
|
||||
CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
CreateButton.Location = new Point(12, 218);
|
||||
CreateButton.Location = new Point(22, 465);
|
||||
CreateButton.Margin = new Padding(6);
|
||||
CreateButton.Name = "CreateButton";
|
||||
CreateButton.Size = new Size(75, 53);
|
||||
CreateButton.Size = new Size(139, 113);
|
||||
CreateButton.TabIndex = 1;
|
||||
CreateButton.Text = "Create object";
|
||||
CreateButton.UseVisualStyleBackColor = true;
|
||||
CreateButton.Click += buttonCr_Click;
|
||||
//
|
||||
// CreateButton2
|
||||
//
|
||||
CreateButton2.Location = new Point(22, 26);
|
||||
CreateButton2.Margin = new Padding(6);
|
||||
CreateButton2.Name = "CreateButton2";
|
||||
CreateButton2.Size = new Size(139, 113);
|
||||
CreateButton2.TabIndex = 2;
|
||||
CreateButton2.Text = "Cr Updated Object";
|
||||
CreateButton2.UseVisualStyleBackColor = true;
|
||||
CreateButton2.Click += buttonCr2_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.up_arrow_res;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(440, 174);
|
||||
buttonUp.Location = new Point(817, 371);
|
||||
buttonUp.Margin = new Padding(6);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(45, 45);
|
||||
buttonUp.TabIndex = 2;
|
||||
buttonUp.Size = new Size(84, 96);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
@ -74,10 +97,11 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.left_arrow_res;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(389, 225);
|
||||
buttonLeft.Location = new Point(722, 480);
|
||||
buttonLeft.Margin = new Padding(6);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(45, 45);
|
||||
buttonLeft.TabIndex = 3;
|
||||
buttonLeft.Size = new Size(84, 96);
|
||||
buttonLeft.TabIndex = 4;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
@ -86,10 +110,11 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.down_arrow_res;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(440, 225);
|
||||
buttonDown.Location = new Point(817, 480);
|
||||
buttonDown.Margin = new Padding(6);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(45, 45);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.Size = new Size(84, 96);
|
||||
buttonDown.TabIndex = 5;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
@ -98,41 +123,81 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.right_arrow_res;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(491, 225);
|
||||
buttonRight.Location = new Point(912, 480);
|
||||
buttonRight.Margin = new Padding(6);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(45, 45);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.Size = new Size(84, 96);
|
||||
buttonRight.TabIndex = 6;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// ListComboBox
|
||||
//
|
||||
//
|
||||
// ButtonActivate
|
||||
//
|
||||
ButtonActivate.Anchor = AnchorStyles.Right;
|
||||
ButtonActivate.Location = new Point(22, 149);
|
||||
ButtonActivate.Margin = new Padding(6);
|
||||
ButtonActivate.Name = "ButtonActivate";
|
||||
ButtonActivate.Size = new Size(84, 96);
|
||||
ButtonActivate.TabIndex = 8;
|
||||
ButtonActivate.UseVisualStyleBackColor = true;
|
||||
ButtonActivate.Click += comboBox_Activate;
|
||||
//
|
||||
// comboBox1
|
||||
//
|
||||
comboBox.FormattingEnabled = true;
|
||||
comboBox.Items.AddRange(new object[] { "Center", "Boarder" });
|
||||
comboBox.Location = new Point(188, 26);
|
||||
comboBox.Name = "Directions";
|
||||
comboBox.Size = new Size(203, 40);
|
||||
comboBox.TabIndex = 9;
|
||||
//
|
||||
// Activate
|
||||
//
|
||||
Activate.Location = new Point(188, 93);
|
||||
Activate.Name = "Activate";
|
||||
Activate.Size = new Size(203, 46);
|
||||
Activate.TabIndex = 10;
|
||||
Activate.Text = "ActivateStep";
|
||||
Activate.UseVisualStyleBackColor = true;
|
||||
Activate.Click += comboBox_Activate;
|
||||
//
|
||||
// DrawingCanvas
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
AutoValidate = AutoValidate.EnableAllowFocusChange;
|
||||
BackColor = Color.CornflowerBlue;
|
||||
ClientSize = new Size(548, 283);
|
||||
ClientSize = new Size(1018, 604);
|
||||
Controls.Add(Activate);
|
||||
Controls.Add(comboBox);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(CreateButton);
|
||||
Controls.Add(CreateButton2);
|
||||
Controls.Add(pictureBox1);
|
||||
Margin = new Padding(2, 1, 2, 1);
|
||||
Controls.Add(ButtonActivate);
|
||||
Margin = new Padding(4, 2, 4, 2);
|
||||
Name = "DrawingCanvas";
|
||||
StartPosition = FormStartPosition.Manual;
|
||||
Text = "DrawingCanvas";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBox1;
|
||||
private Button CreateButton;
|
||||
private Button CreateButton2;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button ButtonActivate;
|
||||
private ComboBox comboBox;
|
||||
private Button Activate;
|
||||
}
|
||||
}
|
@ -1,27 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using CruiserMech.Drawing_tools;
|
||||
using CruiserMech.Entity_Folder;
|
||||
using CruiserMech.Move_Strategy;
|
||||
namespace CruiserMech
|
||||
{
|
||||
public partial class DrawingCanvas : Form
|
||||
{
|
||||
|
||||
private DrawingCruiser? _DrCruiser;
|
||||
|
||||
private DrawingBase? _DrCruiser;
|
||||
private AbstractStrategy _strategy;
|
||||
public DrawingCanvas()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
//private DrawingCanvas_Load(object sender, EventArgs e);
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_DrCruiser == null)
|
||||
@ -29,32 +27,64 @@ namespace CruiserMech
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_DrCruiser.DrawTransport(gr);
|
||||
Graphics gr = Graphics.FromImage(bmp); _DrCruiser.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
|
||||
}
|
||||
|
||||
private void buttonCr_Click(object sender, EventArgs e)
|
||||
private void CreateObj(string type)
|
||||
{
|
||||
Random rn = new();
|
||||
|
||||
Class_CruiserEntity CruiserEntity = new Class_CruiserEntity();
|
||||
CruiserEntity.Init(rn.Next(100, 300), rn.Next(1000, 3000),
|
||||
Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)),
|
||||
Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)),
|
||||
Convert.ToBoolean(rn.Next(0, 2)), Convert.ToBoolean(rn.Next(0, 2)),
|
||||
Convert.ToBoolean(rn.Next(0, 2)), rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
|
||||
|
||||
_DrCruiser = new DrawingCruiser();
|
||||
_DrCruiser.Init(CruiserEntity);
|
||||
// 32, 44
|
||||
Random rn = new Random();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawingBase):
|
||||
_DrCruiser = new DrawingBase(rn.Next(100, 300), rn.Next(1000, 3000), Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawingCruiser):
|
||||
Class_CruiserEntity Obj = new Class_CruiserEntity(rn.Next(100, 300), rn.Next(1000, 3000),
|
||||
Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)), Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)),
|
||||
Convert.ToBoolean(rn.Next(0, 2)), Convert.ToBoolean(rn.Next(0, 2)), rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
|
||||
_DrCruiser = new DrawingCruiser(Obj);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_DrCruiser.SetPicSize(pictureBox1.Width, pictureBox1.Height);
|
||||
_DrCruiser.SetPos(rn.Next(pictureBox1.Width - 600, pictureBox1.Width - _DrCruiser._CruiserMaxW), rn.Next(0, 100));
|
||||
|
||||
_DrCruiser.SetPos(rn.Next(pictureBox1.Width - 600, pictureBox1.Width - _DrCruiser._CruiserMaxW), rn.Next(0, 100)); _strategy = null;
|
||||
comboBox.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void comboBox_Activate(object sender, EventArgs e)
|
||||
{
|
||||
if (_DrCruiser == null) return;
|
||||
|
||||
if (comboBox.Enabled)
|
||||
{
|
||||
_strategy = comboBox.SelectedIndex switch
|
||||
{
|
||||
0 => new Center(),
|
||||
1 => new Boarder()
|
||||
};
|
||||
|
||||
if (_strategy == null) return;
|
||||
_strategy.SetData(new MovableCruiser(_DrCruiser), pictureBox1.Width, pictureBox1.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null) return;
|
||||
comboBox.Enabled = false;
|
||||
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBox.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCr2_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingCruiser));
|
||||
private void buttonCr_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingBase));
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_DrCruiser == null)
|
||||
|
@ -1,237 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech
|
||||
{
|
||||
internal class DrawingCruiser
|
||||
{
|
||||
/// Инициализация свойств (все параметры класса (сущности))
|
||||
public Class_CruiserEntity? CruiserEntity { get; private set; }
|
||||
|
||||
|
||||
/// Передача размеров поля для прорисовки (размеры поля - 2 параметра)
|
||||
private int? _pictureWidth;
|
||||
private int? _pictureHeight;
|
||||
|
||||
|
||||
public readonly int _CruiserMaxW = 302; // 262
|
||||
public readonly int _CruiserMaxH = 72; // 92
|
||||
|
||||
|
||||
/// Установка начальной позиции (координаты - 2 параметра:
|
||||
/// левая верхняя точка, от которой рисуется объект)
|
||||
private int? _startPosX;
|
||||
private int? _startPosY;
|
||||
|
||||
|
||||
public void Init(Class_CruiserEntity CruiserEntity)
|
||||
{
|
||||
CruiserEntity = new Class_CruiserEntity();
|
||||
}
|
||||
|
||||
|
||||
public bool SetPicSize(int w, int h)
|
||||
{
|
||||
if (w > _pictureWidth || h > _pictureHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_pictureWidth = w;
|
||||
_pictureHeight = h;
|
||||
|
||||
if (_startPosX != null || _startPosY != null)
|
||||
{
|
||||
SetPos(_startPosX.Value, _startPosY.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPos(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x > _pictureWidth - _CruiserMaxW) _startPosX = _pictureWidth - _CruiserMaxW;
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
|
||||
if (y > _pictureHeight - _CruiserMaxH) _startPosY = _pictureHeight.Value - _CruiserMaxH;
|
||||
else if (y < 0) _startPosY = 0;
|
||||
else _startPosY = y;
|
||||
}
|
||||
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (CruiserEntity == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - CruiserEntity.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)CruiserEntity.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - CruiserEntity.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)CruiserEntity.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _CruiserMaxW + CruiserEntity.Step < _pictureWidth.Value)
|
||||
{
|
||||
_startPosX += (int)CruiserEntity.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _CruiserMaxH + CruiserEntity.Step < _pictureHeight.Value)
|
||||
{
|
||||
_startPosY += (int)CruiserEntity.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Перемещение объекта (удалось перемещение - true \ false)
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (CruiserEntity == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(CruiserEntity.AdditionalC);
|
||||
Brush mainBrush = new SolidBrush(CruiserEntity.MainC);
|
||||
|
||||
Random random = new();
|
||||
|
||||
//границы cruiser
|
||||
|
||||
//Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 22);
|
||||
//Point point1 = new Point(_startPosX.Value + 5, _startPosY.Value + 66);
|
||||
//Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 90); // max y : 92
|
||||
//Point point3 = new Point(_startPosX.Value + 184, _startPosY.Value + 70); // max x : 262
|
||||
//Point point4 = new Point(_startPosX.Value + 260, _startPosY.Value + 62);
|
||||
//Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 32);
|
||||
//Point point6 = new Point(_startPosX.Value + 172, _startPosY.Value + 18);
|
||||
//Point point7 = new Point(_startPosX.Value + 160, _startPosY.Value + 2);
|
||||
//Point point8 = new Point(_startPosX.Value + 2, _startPosY.Value + 22);
|
||||
|
||||
Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 7);
|
||||
Point point1 = new Point(_startPosX.Value + 2, _startPosY.Value + 30);
|
||||
Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 42);
|
||||
Point point3 = new Point(_startPosX.Value + 260, _startPosY.Value + 34);
|
||||
Point point4 = new Point(_startPosX.Value + 300, _startPosY.Value + 22);
|
||||
Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 10);
|
||||
Point point6 = new Point(_startPosX.Value + 184, _startPosY.Value + 2);
|
||||
//Point point7 = new Point(_startPosX.Value + 2, _startPosY.Value + 36);
|
||||
|
||||
Point[] boarders = {
|
||||
point0,
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
point4,
|
||||
point5,
|
||||
point6,
|
||||
//point7,
|
||||
//point8
|
||||
};
|
||||
|
||||
g.DrawPolygon(pen, boarders);
|
||||
g.FillPolygon(mainBrush, boarders);
|
||||
|
||||
// вертолетная площадка (3)
|
||||
//if (CruiserEntity.HelicopterPads)
|
||||
//{
|
||||
// random number of pads : from 1 to 3
|
||||
// int n = CruiserEntity.values[0];
|
||||
// int w = 15;
|
||||
// int h = 41;
|
||||
|
||||
// for (int i = 1; i <= n; i++)
|
||||
// {
|
||||
// g.DrawEllipse(pen, _startPosX.Value + w, _startPosY.Value + h, 20, 20);
|
||||
// g.FillEllipse(PadBrush, _startPosX.Value + w, _startPosY.Value + h, 20, 20);
|
||||
// w += 28;
|
||||
// h += 3;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
if (CruiserEntity.HelicopterPads)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||
}
|
||||
|
||||
|
||||
// салон на верхней палубе
|
||||
if (CruiserEntity.Deckhouse)
|
||||
{
|
||||
// random location
|
||||
int y_h = CruiserEntity.values[1];
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + y_h, 38, 24); // 40, 26
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
||||
}
|
||||
|
||||
// ангар (2)
|
||||
//if (CruiserEntity.Hangar)
|
||||
//{
|
||||
// int n = CruiserEntity.values[2];
|
||||
|
||||
// if (n == 1)
|
||||
// {
|
||||
// g.FillRectangle(additionalBrush, _startPosX.Value + 105, _startPosY.Value + 18, 14, 7);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// g.FillRectangle(additionalBrush, _startPosX.Value + 146, _startPosY.Value + 52, 10, 26);
|
||||
// g.FillRectangle(additionalBrush, _startPosX.Value + 160, _startPosY.Value + 58, 8, 12);
|
||||
// }
|
||||
//}
|
||||
|
||||
if (CruiserEntity.Hangar)
|
||||
{
|
||||
int n = CruiserEntity.values[2];
|
||||
if (n == 1) g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
|
||||
|
||||
else
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
17
WinF_Lab1_Cruiser/CruiserMech/Drawing_tools/DirectionType.cs
Normal file
17
WinF_Lab1_Cruiser/CruiserMech/Drawing_tools/DirectionType.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Drawing_tools
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
Unknown = -1,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
}
|
||||
}
|
191
WinF_Lab1_Cruiser/CruiserMech/Drawing_tools/DrawingBase.cs
Normal file
191
WinF_Lab1_Cruiser/CruiserMech/Drawing_tools/DrawingBase.cs
Normal file
@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CruiserMech.Entity_Folder;
|
||||
|
||||
namespace CruiserMech.Drawing_tools
|
||||
{
|
||||
public class DrawingBase
|
||||
{
|
||||
/// Инициализация свойств (все параметры класса (сущности))
|
||||
public Base_Class_Cruiser? BaseEntity { get; protected set; }
|
||||
|
||||
/// Передача размеров поля & объекта
|
||||
private int? _pictureWidth;
|
||||
private int? _pictureHeight;
|
||||
|
||||
public readonly int _CruiserMaxW = 302;
|
||||
public readonly int _CruiserMaxH = 72;
|
||||
|
||||
/// Установка позиции
|
||||
protected int? _startPosX;
|
||||
protected int? _startPosY;
|
||||
|
||||
// for relationship with Moves*
|
||||
|
||||
public int? GetPosX => _startPosX;
|
||||
public int? GetPosY => _startPosY;
|
||||
public int GetWidth => _CruiserMaxW;
|
||||
public int GetHeight => _CruiserMaxH;
|
||||
|
||||
private DrawingBase()
|
||||
{
|
||||
_pictureHeight = null;
|
||||
_pictureWidth = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
public DrawingBase(int speed, double weight, Color mainc) : this()
|
||||
{
|
||||
BaseEntity = new Base_Class_Cruiser(speed, weight, mainc);
|
||||
}
|
||||
|
||||
protected DrawingBase(int MaxW, int MaxH) : this()
|
||||
{
|
||||
_CruiserMaxW = MaxW;
|
||||
_CruiserMaxH = MaxH;
|
||||
}
|
||||
|
||||
|
||||
public bool SetPicSize(int w, int h)
|
||||
{
|
||||
if (w > _pictureWidth || h > _pictureHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_pictureWidth = w;
|
||||
_pictureHeight = h;
|
||||
|
||||
if (_startPosX != null || _startPosY != null)
|
||||
{
|
||||
SetPos(_startPosX.Value, _startPosY.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPos(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x > _pictureWidth - _CruiserMaxW) _startPosX = _pictureWidth - _CruiserMaxW;
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
|
||||
if (y > _pictureHeight - _CruiserMaxH) _startPosY = _pictureHeight.Value - _CruiserMaxH;
|
||||
else if (y < 0) _startPosY = 0;
|
||||
else _startPosY = y;
|
||||
}
|
||||
|
||||
public bool MoveTransport(DirectionType direction) // public Direction (?)
|
||||
{
|
||||
if (BaseEntity == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - BaseEntity.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)BaseEntity.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - BaseEntity.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)BaseEntity.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _CruiserMaxW + BaseEntity.Step < _pictureWidth.Value)
|
||||
{
|
||||
_startPosX += (int)BaseEntity.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _CruiserMaxH + BaseEntity.Step < _pictureHeight.Value)
|
||||
{
|
||||
_startPosY += (int)BaseEntity.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (BaseEntity == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
|
||||
// Brush additionalBrush = new SolidBrush(BaseEntity.AdditionalC);
|
||||
Brush mainBrush = new SolidBrush(BaseEntity.MainC);
|
||||
|
||||
Random random = new();
|
||||
|
||||
// границы cruiser
|
||||
|
||||
Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 7);
|
||||
Point point1 = new Point(_startPosX.Value + 2, _startPosY.Value + 30);
|
||||
Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 42);
|
||||
Point point3 = new Point(_startPosX.Value + 260, _startPosY.Value + 34);
|
||||
Point point4 = new Point(_startPosX.Value + 300, _startPosY.Value + 22);
|
||||
Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 10);
|
||||
Point point6 = new Point(_startPosX.Value + 184, _startPosY.Value + 2);
|
||||
|
||||
Point[] boarders = {
|
||||
point0,
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
point4,
|
||||
point5,
|
||||
point6,
|
||||
};
|
||||
|
||||
g.DrawPolygon(pen, boarders);
|
||||
g.FillPolygon(mainBrush, boarders);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 7, 38, 24);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + 7, 20, 12);
|
||||
g.FillRectangle(mainBrush, _startPosX.Value + 110, _startPosY.Value + 7, 20, 12);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + 18, 6, 20);
|
||||
g.FillRectangle(mainBrush, _startPosX.Value + 117, _startPosY.Value + 18, 6, 20);
|
||||
|
||||
// салон на верхней палубе
|
||||
//if (BaseEntity.Deckhouse)
|
||||
//{
|
||||
// // random location
|
||||
// int y_h = BaseEntity.values[1];
|
||||
// g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + y_h, 38, 24); // 40, 26
|
||||
//
|
||||
// g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
||||
// g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
||||
// g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
||||
// g.FillRectangle(additionalBrush, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CruiserMech.Entity_Folder;
|
||||
|
||||
namespace CruiserMech.Drawing_tools
|
||||
{
|
||||
internal class DrawingCruiser : DrawingBase
|
||||
{
|
||||
/// Инициализация свойств (все параметры класса (сущности))
|
||||
// public Class_CruiserEntity? CE { get; private set; }
|
||||
// CE = new Class_CruiserEntity( <...> );
|
||||
|
||||
// public DrawingCruiser(int speed, double weight,
|
||||
// Color mainc, Color addtc, bool pad,
|
||||
// bool hangar, int p, int d_coordinates, int h) : base(302, 72) // <...>
|
||||
//{
|
||||
// BaseEntity = new Class_CruiserEntity(speed, weight, mainc, addtc, pad, hangar, p, d_coordinates, h);
|
||||
//}
|
||||
|
||||
public DrawingCruiser(Class_CruiserEntity Obj) : base(302, 72)
|
||||
{
|
||||
BaseEntity = Obj;
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (BaseEntity is not Class_CruiserEntity cruiser || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(cruiser.AdditionalC);
|
||||
Random random = new();
|
||||
|
||||
//границы cruiser <...>
|
||||
|
||||
if (cruiser.HelicopterPads)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||
}
|
||||
|
||||
// салон на верхней палубе - Deckhouse <...>
|
||||
if (cruiser.Hangar)
|
||||
{
|
||||
int n = cruiser.values[2];
|
||||
if (n == 1) g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
|
||||
|
||||
else
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Entity_Folder
|
||||
{
|
||||
public class Base_Class_Cruiser
|
||||
{
|
||||
/// MAIN свойства
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color MainC { get; private set; }
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// Конструктор
|
||||
public Base_Class_Cruiser(int speed, double weight,
|
||||
Color mainc)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
MainC = mainc;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,35 +5,32 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CruiserMech
|
||||
namespace CruiserMech.Entity_Folder
|
||||
{
|
||||
internal class Class_CruiserEntity
|
||||
internal class Class_CruiserEntity : Base_Class_Cruiser
|
||||
{
|
||||
/// свойства
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color MainC { get; private set; }
|
||||
/// ADDITIONAL свойства
|
||||
public Color AdditionalC { get; private set; }
|
||||
|
||||
/// признаки (наличия)
|
||||
public bool HelicopterPads { get; private set; } /// вертолетная площадка
|
||||
public bool Hangar { get; private set; } /// ангар
|
||||
public bool Hangar { get; private set; } /// ангар
|
||||
public bool Deckhouse { get; private set; } /// салон на верхней палубе
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
public int[] values = { 0, 0, 0 };
|
||||
|
||||
public void Init(int speed, double weight,
|
||||
Color mainc, Color addtc, bool pad,
|
||||
bool hangar, bool deckhouse, int p, int d_coordinates, int h)
|
||||
public Class_CruiserEntity(int speed, double weight,
|
||||
Color mainc, Color addtc, bool pad,
|
||||
bool hangar, int p, int d_coordinates, int h) : base(speed, weight, mainc)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
MainC = mainc;
|
||||
// NOT PUBLIC, so: -> impossible
|
||||
//base.Speed = speed;
|
||||
//base.Weight = weight;
|
||||
//base.MainC = mainc;
|
||||
|
||||
AdditionalC = addtc;
|
||||
HelicopterPads = pad;
|
||||
Hangar = hangar;
|
||||
Deckhouse = deckhouse;
|
||||
values[0] = p;
|
||||
values[1] = d_coordinates;
|
||||
values[2] = h;
|
111
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/AbstractStrategy.cs
Normal file
111
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Move_Strategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
private IMO? _movableObj;
|
||||
|
||||
private Status _state = Status.NotInit;
|
||||
|
||||
protected int FieldHeight { get; private set; }
|
||||
protected int FieldWidth { get; private set; }
|
||||
|
||||
public Status GetStatus() { return _state; } // => _state;
|
||||
|
||||
public void SetData(IMO movableObj, int width, int height)
|
||||
{
|
||||
if (movableObj == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
|
||||
_state = Status.InProgress;
|
||||
_movableObj = movableObj;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTargetDes())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected bool MoveLeft() => MoveTo(Moves.Left);
|
||||
protected bool MoveRight() => MoveTo(Moves.Right);
|
||||
protected bool MoveUp() => MoveTo(Moves.Up);
|
||||
protected bool MoveDown() => MoveTo(Moves.Down);
|
||||
|
||||
protected ObjectParam? GetObjParam => _movableObj?.GetPos;
|
||||
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _movableObj?.GetStep;
|
||||
}
|
||||
|
||||
protected virtual void MoveToTarget()
|
||||
{
|
||||
ObjectParam? objParams = GetObjParam;
|
||||
|
||||
if (objParams == null) { return; }
|
||||
|
||||
int diffx = objParams.MiddleHorizontal - FieldWidth / 2;
|
||||
|
||||
if (Math.Abs(diffx) > GetStep())
|
||||
{
|
||||
if (diffx > 0) MoveLeft();
|
||||
else MoveRight();
|
||||
}
|
||||
|
||||
int diffy = objParams.MiddleVertical - FieldHeight / 2;
|
||||
|
||||
if (Math.Abs(diffy) > GetStep())
|
||||
{
|
||||
if (diffy > 0) MoveUp();
|
||||
else MoveDown();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool IsTargetDes()
|
||||
{
|
||||
ObjectParam? objParams = GetObjParam;
|
||||
if (objParams == null) { return false; }
|
||||
|
||||
return objParams.MiddleHorizontal - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.MiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.MiddleVertical - GetStep() <= FieldHeight / 2 &&
|
||||
objParams.MiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
private bool MoveTo(Moves moves)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _movableObj?.TryMoveObj(moves) ?? false;
|
||||
}
|
||||
}
|
||||
}
|
56
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/Boarder.cs
Normal file
56
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/Boarder.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Move_Strategy;
|
||||
|
||||
public class Boarder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDes()
|
||||
{
|
||||
ObjectParam? objP = GetObjParam;
|
||||
if (objP == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return FieldWidth - GetStep() < objP.SecondCoordX
|
||||
&& FieldHeight - GetStep() < objP.SecondCoordY;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParam? objP = GetObjParam;
|
||||
if (objP == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int s = (int)GetStep();
|
||||
|
||||
int diffx = objP.SecondCoordX - (FieldWidth - s);
|
||||
if (Math.Abs(diffx) > GetStep())
|
||||
{
|
||||
if (diffx > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
|
||||
// MoveRight();
|
||||
}
|
||||
else { MoveRight(); }
|
||||
}
|
||||
|
||||
int diffy = objP.SecondCoordY - (FieldHeight - s);
|
||||
if (Math.Abs(diffy) > GetStep())
|
||||
{
|
||||
if (diffy > 0)
|
||||
{
|
||||
MoveUp();
|
||||
// MoveDown();
|
||||
}
|
||||
else { MoveDown(); }
|
||||
}
|
||||
}
|
||||
}
|
51
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/Center.cs
Normal file
51
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/Center.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Move_Strategy;
|
||||
|
||||
public class Center : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDes()
|
||||
{
|
||||
ObjectParam? objP = GetObjParam;
|
||||
if (objP == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objP.MiddleHorizontal - GetStep() <= FieldWidth / 2 && objP.MiddleHorizontal + GetStep() >= FieldWidth / 2
|
||||
&& objP.MiddleVertical - GetStep() <= FieldHeight / 2 && objP.MiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParam? objP = GetObjParam;
|
||||
if (objP == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffx = objP.MiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffx) > GetStep())
|
||||
{
|
||||
if (diffx > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else { MoveRight(); }
|
||||
}
|
||||
|
||||
int diffy = objP.MiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffy) > GetStep())
|
||||
{
|
||||
if (diffy > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else { MoveDown(); }
|
||||
}
|
||||
}
|
||||
}
|
19
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/IMO.cs
Normal file
19
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/IMO.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Move_Strategy
|
||||
{
|
||||
public interface IMO
|
||||
{
|
||||
// methods ! only
|
||||
|
||||
ObjectParam? GetPos { get; }
|
||||
|
||||
int GetStep { get; }
|
||||
|
||||
bool TryMoveObj(Moves direction);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CruiserMech.Drawing_tools;
|
||||
|
||||
namespace CruiserMech.Move_Strategy
|
||||
{
|
||||
public class MovableCruiser : IMO
|
||||
{
|
||||
private readonly DrawingBase? _DrBase = null;
|
||||
|
||||
public MovableCruiser(DrawingBase drBase)
|
||||
{
|
||||
_DrBase = drBase;
|
||||
}
|
||||
|
||||
public ObjectParam? GetPos
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DrBase == null || _DrBase.BaseEntity == null || !_DrBase.GetPosX.HasValue || !_DrBase.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ObjectParam(_DrBase.GetPosX.Value, _DrBase.GetPosY.Value, _DrBase.GetWidth, _DrBase.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_DrBase?.BaseEntity?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObj(Moves direction)
|
||||
{
|
||||
if (_DrBase == null || _DrBase.BaseEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _DrBase.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
private static DirectionType GetDirectionType(Moves direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
Moves.Left => DirectionType.Left,
|
||||
Moves.Right => DirectionType.Right,
|
||||
Moves.Up => DirectionType.Up,
|
||||
Moves.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknown
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -4,10 +4,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech
|
||||
namespace CruiserMech.Move_Strategy
|
||||
{
|
||||
internal enum DirectionType
|
||||
public enum Moves
|
||||
{
|
||||
Unknown = -1,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
39
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/ObjectParam.cs
Normal file
39
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/ObjectParam.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Move_Strategy
|
||||
{
|
||||
public class ObjectParam
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
|
||||
public int LeftBorder => _x;
|
||||
public int RightBorder => _x + _width;
|
||||
|
||||
public int TopBorder => _y;
|
||||
public int BottomBorder => _y + _height;
|
||||
|
||||
|
||||
public int MiddleHorizontal => _x + _width / 2;
|
||||
public int MiddleVertical => _y + _height / 2;
|
||||
|
||||
|
||||
public int SecondCoordY => _y + _height;
|
||||
public int SecondCoordX => _x + _width;
|
||||
|
||||
public ObjectParam(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
15
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/Status.cs
Normal file
15
WinF_Lab1_Cruiser/CruiserMech/Move_Strategy/Status.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CruiserMech.Move_Strategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 24 KiB |
Loading…
Reference in New Issue
Block a user