From c5f197893fd11c3747766cf23aebb631ee7f2051 Mon Sep 17 00:00:00 2001
From: Sharosh322 <132645197+Sharosh322@users.noreply.github.com>
Date: Sat, 9 Dec 2023 22:27:17 +0400
Subject: [PATCH] Done
---
.../ProjStormtrooper/AbstractStrategy.cs | 2 +-
.../ProjStormtrooper/DrawingPlane.cs | 29 ++--
.../ProjStormtrooper/EntityPlane.cs | 2 -
.../ProjStormtrooper/EntityStormtrooper.cs | 1 -
.../ProjStormtrooper/ObjectParameters.cs | 1 -
.../PlaneCollection.Designer.cs | 128 ++++++++++++++++++
.../ProjStormtrooper/PlaneCollection.cs | 59 ++++++++
.../ProjStormtrooper/PlaneCollection.resx | 120 ++++++++++++++++
.../PlanesGenericCollection.cs | 91 +++++++++++++
ProjStormtrooper/ProjStormtrooper/Program.cs | 2 +-
.../ProjStormtrooper/SetGeneric.cs | 76 +++++++++++
.../ProjStormtrooper/Stormtrooper.Designer.cs | 15 +-
.../ProjStormtrooper/Stormtrooper.cs | 72 +++++++---
.../ProjStormtrooper/Stormtrooper.resx | 8 +-
14 files changed, 558 insertions(+), 48 deletions(-)
create mode 100644 ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
create mode 100644 ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
create mode 100644 ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx
create mode 100644 ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
create mode 100644 ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
diff --git a/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs b/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs
index 4283478..c2cfd00 100644
--- a/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs
+++ b/ProjStormtrooper/ProjStormtrooper/AbstractStrategy.cs
@@ -13,6 +13,7 @@ namespace ProjStormtrooper
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
+
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
@@ -53,7 +54,6 @@ namespace ProjStormtrooper
}
return _moveableObject?.GetStep;
}
-
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(Direction directionType)
diff --git a/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs b/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs
index 4e3d4ac..be86612 100644
--- a/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs
+++ b/ProjStormtrooper/ProjStormtrooper/DrawingPlane.cs
@@ -6,7 +6,6 @@ using System.Threading.Tasks;
namespace ProjStormtrooper
{
-
public class DrawingPlane
{
public EntityPlane? EntityPlane { get; protected set; }
@@ -54,18 +53,18 @@ namespace ProjStormtrooper
}
return direction switch
{
-
+
Direction.Up => _startPosY - EntityPlane.Step > 0,
-
+
Direction.Down => _startPosY + _planeHeight + EntityPlane.Step < _pictureHeight,
-
+
Direction.Left => _startPosX - EntityPlane.Step > 0,
-
+
Direction.Right => _startPosX + _planeWidth + EntityPlane.Step < _pictureWidth,
_ => false,
};
}
-
+
public void SetPosition(int x, int y)
{
if (x < 0)
@@ -97,19 +96,19 @@ namespace ProjStormtrooper
}
switch (direction)
{
-
+
case Direction.Up:
_startPosY -= (int)EntityPlane.Step;
break;
-
+
case Direction.Down:
_startPosY += (int)EntityPlane.Step;
break;
-
+
case Direction.Left:
_startPosX -= (int)EntityPlane.Step;
break;
-
+
case Direction.Right:
_startPosX += (int)EntityPlane.Step;
break;
@@ -126,10 +125,11 @@ namespace ProjStormtrooper
Brush brushBlack = new SolidBrush(Color.Black);
Brush brushBodyColor = new SolidBrush(EntityPlane.BodyColor);
-
+
int bodyHeight = _planeHeight / 9;
+
Point[] pointsCockPit = {
new Point(_startPosX, _startPosY + _planeHeight / 2),
new Point(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2),
@@ -138,7 +138,7 @@ namespace ProjStormtrooper
g.FillPolygon(brushBlack, pointsCockPit);
-
+
Point[] pointsWings = {
new Point(_startPosX + _planeWidth / 2, _startPosY),
@@ -151,7 +151,6 @@ namespace ProjStormtrooper
g.FillPolygon(brushBodyColor, pointsWings);
g.DrawPolygon(penBlack, pointsWings);
-
Point[] pointsTail = {
new Point(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3),
@@ -162,12 +161,12 @@ namespace ProjStormtrooper
};
g.FillPolygon(brushBodyColor, pointsTail);
+
g.DrawPolygon(penBlack, pointsTail);
-
-
g.FillRectangle(brushBodyColor, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
g.DrawRectangle(penBlack, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
}
+ public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
}
}
diff --git a/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs b/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs
index 9e82403..b459567 100644
--- a/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs
+++ b/ProjStormtrooper/ProjStormtrooper/EntityPlane.cs
@@ -10,12 +10,10 @@ namespace ProjStormtrooper
{
public class EntityPlane
{
-
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 250 / Weight;
-
public EntityPlane(int speed, double weight, Color bodyColor)
{
Speed = speed;
diff --git a/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs b/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs
index 097c29e..8a1edd3 100644
--- a/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs
+++ b/ProjStormtrooper/ProjStormtrooper/EntityStormtrooper.cs
@@ -11,7 +11,6 @@ namespace ProjStormtrooper
public Color AdditionalColor { get; private set; }
public bool Rockets { get; private set; }
public bool Bombs { get; private set; }
-
public EntityStormtrooper(int speed, double weight, Color bodyColor,
Color additionalColor, bool rockets, bool bombs) : base(speed, weight, bodyColor)
{
diff --git a/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs b/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs
index 9f26abc..99a7340 100644
--- a/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs
+++ b/ProjStormtrooper/ProjStormtrooper/ObjectParameters.cs
@@ -18,7 +18,6 @@ namespace ProjStormtrooper
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
-
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
diff --git a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
new file mode 100644
index 0000000..2273a56
--- /dev/null
+++ b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
@@ -0,0 +1,128 @@
+namespace ProjStormtrooper
+{
+ partial class PlaneCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBoxTools = new GroupBox();
+ maskedTextBoxNumber = new MaskedTextBox();
+ buttonRefreshCollection = new Button();
+ buttonRemovePlane = new Button();
+ buttonAddPlane = new Button();
+ pictureBoxCollection = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(maskedTextBoxNumber);
+ groupBoxTools.Controls.Add(buttonRefreshCollection);
+ groupBoxTools.Controls.Add(buttonRemovePlane);
+ groupBoxTools.Controls.Add(buttonAddPlane);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(787, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(230, 538);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // maskedTextBoxNumber
+ //
+ maskedTextBoxNumber.Location = new Point(6, 87);
+ maskedTextBoxNumber.Mask = "00";
+ maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ maskedTextBoxNumber.Size = new Size(218, 27);
+ maskedTextBoxNumber.TabIndex = 4;
+ maskedTextBoxNumber.TextAlign = HorizontalAlignment.Center;
+ maskedTextBoxNumber.ValidatingType = typeof(int);
+ //
+ // buttonRefreshCollection
+ //
+ buttonRefreshCollection.Location = new Point(6, 180);
+ buttonRefreshCollection.Name = "buttonRefreshCollection";
+ buttonRefreshCollection.Size = new Size(218, 29);
+ buttonRefreshCollection.TabIndex = 3;
+ buttonRefreshCollection.Text = "Обновить коллекцию";
+ buttonRefreshCollection.UseVisualStyleBackColor = true;
+ buttonRefreshCollection.Click += buttonRefreshCollection_Click;
+ //
+ // buttonRemovePlane
+ //
+ buttonRemovePlane.Location = new Point(6, 120);
+ buttonRemovePlane.Name = "buttonRemovePlane";
+ buttonRemovePlane.Size = new Size(218, 29);
+ buttonRemovePlane.TabIndex = 2;
+ buttonRemovePlane.Text = "Удалить самолет";
+ buttonRemovePlane.UseVisualStyleBackColor = true;
+ buttonRemovePlane.Click += buttonRemovePlane_Click;
+ //
+ // buttonAddPlane
+ //
+ buttonAddPlane.Location = new Point(6, 26);
+ buttonAddPlane.Name = "buttonAddPlane";
+ buttonAddPlane.Size = new Size(218, 29);
+ buttonAddPlane.TabIndex = 0;
+ buttonAddPlane.Text = "Добавить самолет";
+ buttonAddPlane.UseVisualStyleBackColor = true;
+ buttonAddPlane.Click += buttonAddPlane_Click;
+ //
+ // pictureBoxCollection
+ //
+ pictureBoxCollection.Dock = DockStyle.Fill;
+ pictureBoxCollection.Location = new Point(0, 0);
+ pictureBoxCollection.Name = "pictureBoxCollection";
+ pictureBoxCollection.Size = new Size(787, 538);
+ pictureBoxCollection.TabIndex = 1;
+ pictureBoxCollection.TabStop = false;
+ //
+ // FormPlaneCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1017, 538);
+ Controls.Add(pictureBoxCollection);
+ Controls.Add(groupBoxTools);
+ Name = "FormPlaneCollection";
+ Text = "Набор самолетов";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private Button buttonRefreshCollection;
+ private Button buttonRemovePlane;
+ private Button buttonAddPlane;
+ private MaskedTextBox maskedTextBoxNumber;
+ private PictureBox pictureBoxCollection;
+ }
+}
\ No newline at end of file
diff --git a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
new file mode 100644
index 0000000..bc204c6
--- /dev/null
+++ b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ProjStormtrooper
+{
+ public partial class PlaneCollection : Form
+ {
+ private readonly PlanesGenericCollection _planes;
+ public PlaneCollection()
+ {
+ InitializeComponent();
+ _planes = new PlanesGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+ private void buttonAddPlane_Click(object sender, EventArgs e)
+ {
+ Stormtrooper form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_planes + form.SelectedPlane > -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _planes.ShowPlanes();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ private void buttonRemovePlane_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_planes - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _planes.ShowPlanes();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ private void buttonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _planes.ShowPlanes();
+ }
+ }
+}
diff --git a/ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx
new file mode 100644
index 0000000..a395bff
--- /dev/null
+++ b/ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs b/ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
new file mode 100644
index 0000000..11036c0
--- /dev/null
+++ b/ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjStormtrooper
+{
+ internal class PlanesGenericCollection
+ where T : DrawingPlane
+ where U : IMoveableObject
+ {
+ private readonly int _pictureWidth;
+ private readonly int _pictureHeight;
+ private readonly int _placeSizeWidth = 160;
+ private readonly int _placeSizeHeight = 120;
+ private readonly SetGeneric _collection;
+ public PlanesGenericCollection(int picWidth, int picHeight)
+ {
+ int horizontalObjectsCount = picWidth / _placeSizeWidth;
+ int verticalObjectsCount = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = new SetGeneric(horizontalObjectsCount * verticalObjectsCount);
+ }
+
+ public static int operator +(PlanesGenericCollection collect, T? obj)
+ {
+ if (obj == null)
+ {
+ return -1;
+ }
+ return collect?._collection.Insert(obj) ?? -1;
+ }
+
+ public static bool operator -(PlanesGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ collect._collection.Remove(pos);
+ }
+ return false;
+ }
+
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+
+ public Bitmap ShowPlanes()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight +
+ 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth, j *
+ _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
+ _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i *
+ _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+
+ private void DrawObjects(Graphics g)
+ {
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ DrawingPlane plane = _collection.Get(i);
+ if (plane != null)
+ {
+ int inRow = _pictureWidth / _placeSizeWidth;
+ plane.SetPosition((_pictureWidth - 30 - (i % inRow + 1) * _placeSizeWidth), (i / inRow) * _placeSizeHeight);
+ plane.DrawTransport(g);
+ }
+ }
+ }
+ }
+}
diff --git a/ProjStormtrooper/ProjStormtrooper/Program.cs b/ProjStormtrooper/ProjStormtrooper/Program.cs
index a1edc17..52a7c1f 100644
--- a/ProjStormtrooper/ProjStormtrooper/Program.cs
+++ b/ProjStormtrooper/ProjStormtrooper/Program.cs
@@ -8,7 +8,7 @@ namespace ProjStormtrooper
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Stormtrooper());
+ Application.Run(new PlaneCollection());
}
}
}
\ No newline at end of file
diff --git a/ProjStormtrooper/ProjStormtrooper/SetGeneric.cs b/ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
new file mode 100644
index 0000000..ea7a8f5
--- /dev/null
+++ b/ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjStormtrooper
+{
+ internal class SetGeneric where T : class
+ {
+ private readonly T?[] _places;
+ public int Count => _places.Length;
+ public SetGeneric(int count)
+ {
+ _places = new T?[count];
+ }
+ public int Insert(T plane)
+ {
+ return Insert(plane, 0);
+ }
+ public int Insert(T plane, int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+
+ if (_places[position] != null)
+ {
+ int nullIndex = -1;
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_places[i] == null)
+ {
+ nullIndex = i;
+ break;
+ }
+ }
+
+ if (nullIndex < 0)
+ {
+ return -1;
+ }
+
+ int j = nullIndex - 1;
+ while (j >= position)
+ {
+ _places[j + 1] = _places[j];
+ j--;
+ }
+ }
+ _places[position] = plane;
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ T? plane = _places[position];
+ _places[position] = null;
+ return plane;
+ }
+
+ public T? Get(int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ }
+}
diff --git a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.Designer.cs b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.Designer.cs
index e676222..eba2467 100644
--- a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.Designer.cs
+++ b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.Designer.cs
@@ -38,6 +38,7 @@
buttonCreatePlane = new Button();
buttonStep = new Button();
comboBoxStrategy = new ComboBox();
+ buttonSelectPlane = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
SuspendLayout();
//
@@ -122,7 +123,7 @@
buttonCreatePlane.TabIndex = 8;
buttonCreatePlane.Text = "Создать самолет";
buttonCreatePlane.UseVisualStyleBackColor = true;
- buttonCreatePlane.Click += buttonCreatePlane_Click_1;
+ buttonCreatePlane.Click += buttonCreatePlane_Click;
//
// buttonStep
//
@@ -146,11 +147,22 @@
comboBoxStrategy.Size = new Size(133, 23);
comboBoxStrategy.TabIndex = 10;
//
+ // buttonSelectPlane
+ //
+ buttonSelectPlane.Location = new Point(376, 428);
+ buttonSelectPlane.Name = "buttonSelectPlane";
+ buttonSelectPlane.Size = new Size(198, 23);
+ buttonSelectPlane.TabIndex = 11;
+ buttonSelectPlane.Text = "выбрать";
+ buttonSelectPlane.UseVisualStyleBackColor = true;
+ buttonSelectPlane.Click += buttonSelectPlane_Click;
+ //
// Stormtrooper
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461);
+ Controls.Add(buttonSelectPlane);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonStep);
Controls.Add(buttonCreatePlane);
@@ -179,5 +191,6 @@
private Button buttonCreatePlane;
private Button buttonStep;
private ComboBox comboBoxStrategy;
+ private Button buttonSelectPlane;
}
}
\ No newline at end of file
diff --git a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs
index 44b07db..27c7f3b 100644
--- a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs
+++ b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.cs
@@ -7,12 +7,16 @@ namespace ProjStormtrooper
public partial class Stormtrooper : Form
{
private DrawingPlane? _drawingPlane;
- private AbstractStrategy? _abstractStrategy;
+ private AbstractStrategy? _strategy;
+ public DrawingPlane? SelectedPlane { get; private set; }
public Stormtrooper()
{
InitializeComponent();
+ _strategy = null;
+ SelectedPlane = null;
}
+
private void Draw()
{
if (_drawingPlane == null)
@@ -28,11 +32,23 @@ namespace ProjStormtrooper
private void buttonCreateStormtrooper_Click(object sender, EventArgs e)
{
Random random = new();
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialog.Color;
+ }
_drawingPlane = new DrawingStormtrooper(
random.Next(100, 300),
random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ color,
+ dopColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxStormtrooper.Width,
@@ -42,6 +58,26 @@ namespace ProjStormtrooper
Draw();
}
+ private void buttonCreatePlane_Click(object sender, EventArgs e)
+ {
+ Random random = new();
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ _drawingPlane = new DrawingPlane(
+ random.Next(100, 300),
+ random.Next(1000, 3000),
+ color,
+ pictureBoxStormtrooper.Width,
+ pictureBoxStormtrooper.Height
+ );
+ _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingPlane == null)
@@ -75,44 +111,36 @@ namespace ProjStormtrooper
}
if (comboBoxStrategy.Enabled)
{
- _abstractStrategy = comboBoxStrategy.SelectedIndex switch
+ _strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToRightBottom(),
_ => null,
};
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
- comboBoxStrategy.Enabled = false;
+ _strategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
}
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.MakeStep();
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
Draw();
- if (_abstractStrategy.GetStatus() == Status.Finish)
+ if (_strategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
- _abstractStrategy = null;
+ _strategy = null;
}
}
- private void buttonCreatePlane_Click_1(object sender, EventArgs e)
+ private void buttonSelectPlane_Click(object sender, EventArgs e)
{
- Random random = new();
- _drawingPlane = new DrawingPlane(
- random.Next(100, 300),
- random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- pictureBoxStormtrooper.Width,
- pictureBoxStormtrooper.Height
- );
- _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
- Draw();
+ SelectedPlane = _drawingPlane;
+ DialogResult = DialogResult.OK;
}
}
}
\ No newline at end of file
diff --git a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.resx b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.resx
index 1bda3d9..bca8dd8 100644
--- a/ProjStormtrooper/ProjStormtrooper/Stormtrooper.resx
+++ b/ProjStormtrooper/ProjStormtrooper/Stormtrooper.resx
@@ -123,7 +123,7 @@
iVBORw0KGgoAAAANSUhEUgAAANQAAADuCAMAAAB24dnhAAAABGdBTUEAALGPC/xhBQAAAHtQTFRFAAAA
////7u7u7e3t9fX1+Pj48/Pz+/v79PT0fn5+UFBQ5+fnMzMzs7Oz19fXb29vjY2NtLS00tLSpaWlHh4e
vLy8U1NTOzs7CgoKTExMysrK4eHhLy8vFBQUNzc3a2trk5OTXV1denp6JycnnJycIyMjWlpaREREw8PD
- TPw7owAAAAlwSFlzAAAOvgAADr4B6kKxwAAACpZJREFUeF7tnel2ozgQhQNiceI4e2dzMr1MT3e//xNO
+ TPw7owAAAAlwSFlzAAAOvAAADrwBlbxySQAACpZJREFUeF7tnel2ozgQhQNiceI4e2dzMr1MT3e//xNO
lbgFRVo2SyQWH30/cuIbTOmmMCoJgc/SNDVJjaGXlgJCkpSimQxKkmS1lifJmWfObYhchwAbSKkpoSQJ
lJaLaApKNDWcaMqjqVZEtMUbMVMxU8vMVK11m0rxO+EyBSVNlSkoaRrOFALYEKDOVNqYKqC0TPEPI2h7
QmMvh2Ja/7wApjiEPiyEJmwBxSgrKRRjKlMwq3JWH3QqZ+7DPIQpCnHgWAeu/EAhPmsqC5KpmU3FTPUj
@@ -176,7 +176,7 @@
iVBORw0KGgoAAAANSUhEUgAAANQAAADuCAMAAAB24dnhAAAABGdBTUEAALGPC/xhBQAAAHtQTFRFAAAA
////7u7u7e3t9fX1+Pj48/Pz+/v79PT0fn5+UFBQ5+fnMzMzs7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