lab3
This commit is contained in:
parent
d82b23e1f4
commit
45e5eb57af
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||||||
using SelfPropelledArtilleryUnit.Entities;
|
using SelfPropelledArtilleryUnit.Entities;
|
||||||
using SelfPropelledArtilleryUnit.Drawnings;
|
using SelfPropelledArtilleryUnit.Drawnings;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
|
using SelfPropelledArtilleryUnit.MovementStrategy;
|
||||||
|
|
||||||
namespace SelfPropelledArtilleryUnit.DrawningObjects
|
namespace SelfPropelledArtilleryUnit.DrawningObjects
|
||||||
{
|
{
|
||||||
@ -102,15 +103,11 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int PictureWidth
|
/// <summary>
|
||||||
{
|
/// Получение объекта IMoveableObject из объекта DrawningUsta
|
||||||
get { return _pictureWidth; }
|
/// </summary>
|
||||||
}
|
public IMoveableObject GetMoveableObject => new DrawningObjectUsta(this);
|
||||||
|
|
||||||
protected int PictureHeight
|
|
||||||
{
|
|
||||||
get { return _pictureHeight; }
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Изменение направления перемещения
|
/// Изменение направления перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -201,7 +198,6 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
|
|||||||
Brush BodyColor = new SolidBrush(EntityUsta.BodyColor);
|
Brush BodyColor = new SolidBrush(EntityUsta.BodyColor);
|
||||||
|
|
||||||
//зеленый темнее
|
//зеленый темнее
|
||||||
int lineWidth = 10;
|
|
||||||
Color color1 = Color.FromArgb(65, 72, 51);
|
Color color1 = Color.FromArgb(65, 72, 51);
|
||||||
Brush pen1 = new SolidBrush(color1);
|
Brush pen1 = new SolidBrush(color1);
|
||||||
|
|
||||||
@ -229,7 +225,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
|
|||||||
path.CloseFigure(); // Замкнуть путь
|
path.CloseFigure(); // Замкнуть путь
|
||||||
|
|
||||||
// отрисовка прямоугольника с кругленными краями
|
// отрисовка прямоугольника с кругленными краями
|
||||||
g.FillPath(pen1, path);
|
g.FillPath(BodyColor, path);
|
||||||
g.DrawPath(pen, path);
|
g.DrawPath(pen, path);
|
||||||
|
|
||||||
|
|
||||||
@ -238,7 +234,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
|
|||||||
g.FillEllipse(pen3, _startPosX + 77, _startPosY + 44, 13, 13);
|
g.FillEllipse(pen3, _startPosX + 77, _startPosY + 44, 13, 13);
|
||||||
|
|
||||||
|
|
||||||
g.FillRectangle(pen2, _startPosX + 45, _startPosY + 20, 40, 20);
|
g.FillRectangle(BodyColor, _startPosX + 45, _startPosY + 20, 40, 20);
|
||||||
g.DrawRectangle(pen, _startPosX + 45, _startPosY + 20, 40, 20);
|
g.DrawRectangle(pen, _startPosX + 45, _startPosY + 20, 40, 20);
|
||||||
|
|
||||||
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 65, 13, 13);
|
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 65, 13, 13);
|
||||||
@ -246,7 +242,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects
|
|||||||
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 65, 13, 13);
|
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 65, 13, 13);
|
||||||
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 65, 13, 13);
|
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 65, 13, 13);
|
||||||
|
|
||||||
g.FillRectangle(pen2, _startPosX + 10, _startPosY + 40, 120, 10);
|
g.FillRectangle(BodyColor, _startPosX + 10, _startPosY + 40, 120, 10);
|
||||||
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 40, 120, 10);
|
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 40, 120, 10);
|
||||||
|
|
||||||
g.FillEllipse(pen3, _startPosX + 10, _startPosY + 52, 26, 26);
|
g.FillEllipse(pen3, _startPosX + 10, _startPosY + 52, 26, 26);
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
pictureBoxUsta = new PictureBox();
|
pictureBoxUsta = new PictureBox();
|
||||||
|
ButtonSelectUsta = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxUsta).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxUsta).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -83,8 +84,9 @@
|
|||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||||
buttonUp.Location = new Point(617, 314);
|
buttonUp.Location = new Point(622, 326);
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
buttonUp.Size = new Size(50, 50);
|
buttonUp.Size = new Size(50, 50);
|
||||||
buttonUp.TabIndex = 4;
|
buttonUp.TabIndex = 4;
|
||||||
@ -93,8 +95,9 @@
|
|||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||||
buttonDown.Location = new Point(617, 370);
|
buttonDown.Location = new Point(622, 382);
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
buttonDown.Size = new Size(50, 50);
|
buttonDown.Size = new Size(50, 50);
|
||||||
buttonDown.TabIndex = 5;
|
buttonDown.TabIndex = 5;
|
||||||
@ -103,8 +106,9 @@
|
|||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||||
buttonLeft.Location = new Point(561, 370);
|
buttonLeft.Location = new Point(566, 382);
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
buttonLeft.Size = new Size(50, 50);
|
buttonLeft.Size = new Size(50, 50);
|
||||||
buttonLeft.TabIndex = 6;
|
buttonLeft.TabIndex = 6;
|
||||||
@ -113,8 +117,9 @@
|
|||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||||
buttonRight.Location = new Point(673, 370);
|
buttonRight.Location = new Point(678, 382);
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
buttonRight.Size = new Size(50, 50);
|
buttonRight.Size = new Size(50, 50);
|
||||||
buttonRight.TabIndex = 7;
|
buttonRight.TabIndex = 7;
|
||||||
@ -131,11 +136,22 @@
|
|||||||
pictureBoxUsta.TabIndex = 8;
|
pictureBoxUsta.TabIndex = 8;
|
||||||
pictureBoxUsta.TabStop = false;
|
pictureBoxUsta.TabStop = false;
|
||||||
//
|
//
|
||||||
|
// ButtonSelectUsta
|
||||||
|
//
|
||||||
|
ButtonSelectUsta.Location = new Point(348, 393);
|
||||||
|
ButtonSelectUsta.Name = "ButtonSelectUsta";
|
||||||
|
ButtonSelectUsta.Size = new Size(157, 42);
|
||||||
|
ButtonSelectUsta.TabIndex = 9;
|
||||||
|
ButtonSelectUsta.Text = "Выбор";
|
||||||
|
ButtonSelectUsta.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSelectUsta.Click += ButtonSelectUsta_Click;
|
||||||
|
//
|
||||||
// FormSelfPropelledArtilleryUnit
|
// FormSelfPropelledArtilleryUnit
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(ButtonSelectUsta);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
@ -146,7 +162,7 @@
|
|||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(pictureBoxUsta);
|
Controls.Add(pictureBoxUsta);
|
||||||
Name = "FormSelfPropelledArtilleryUnit";
|
Name = "FormSelfPropelledArtilleryUnit";
|
||||||
Text = "SelfPropelledArtilleryUnit";
|
Text = "Создание арт. установки";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxUsta).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxUsta).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
@ -162,5 +178,6 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private PictureBox pictureBoxUsta;
|
private PictureBox pictureBoxUsta;
|
||||||
|
private Button ButtonSelectUsta;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,12 +16,21 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Âűáđŕííŕ˙ óńňŕíîâęŕ
|
||||||
|
/// </summary>
|
||||||
|
public DrawningUsta? SelectedUsta { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormSelfPropelledArtilleryUnit()
|
public FormSelfPropelledArtilleryUnit()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedUsta = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ìåòîä ïðîðèñîâêè óñòàíîâêè
|
/// Ìåòîä ïðîðèñîâêè óñòàíîâêè
|
||||||
@ -39,19 +48,33 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
pictureBoxUsta.Image = bmp;
|
pictureBoxUsta.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü óñòàíîâêó ñ âîîðóæåíèåì"
|
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Ńîçäŕňü ŕđň. óńňŕíîâęó ń âîîđóćĺíčĺě"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonCreateUstaBat_Click(object sender, EventArgs e)
|
private void ButtonCreateUstaBat_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
|
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
//TODO âűáîđ îńíîâíîăî öâĺňŕ
|
||||||
|
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));
|
||||||
|
//TODO âűáîđ äîďîëíčňĺëüíîăî öâĺňŕ
|
||||||
|
ColorDialog dialog_dop = new();
|
||||||
|
if (dialog_dop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialog_dop.Color;
|
||||||
|
}
|
||||||
|
|
||||||
_drawningUsta = new DrawningUstaBat(random.Next(100, 300),
|
_drawningUsta = new DrawningUstaBat(random.Next(100, 300),
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
color,
|
||||||
random.Next(0, 256)),
|
dopColor,
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
|
||||||
random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
pictureBoxUsta.Width, pictureBoxUsta.Height);
|
pictureBoxUsta.Width, pictureBoxUsta.Height);
|
||||||
_drawningUsta.SetPosition(random.Next(10, 100), random.Next(10,
|
_drawningUsta.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
@ -59,17 +82,24 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü óñòàíîâêó"
|
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Ńîçäŕňü ŕđň. óńňŕíîâęó"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonCreateUsta_Click(object sender, EventArgs e)
|
private void ButtonCreateUsta_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
_drawningUsta = new DrawningUsta(random.Next(100, 300),
|
_drawningUsta = new DrawningUsta(random.Next(100, 300),
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
color,
|
||||||
random.Next(0, 256)),
|
|
||||||
pictureBoxUsta.Width, pictureBoxUsta.Height);
|
pictureBoxUsta.Width, pictureBoxUsta.Height);
|
||||||
_drawningUsta.SetPosition(random.Next(10, 100), random.Next(10,
|
_drawningUsta.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
100));
|
100));
|
||||||
@ -147,5 +177,11 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectUsta_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedUsta = _drawningUsta;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,125 @@
|
|||||||
|
namespace SelfPropelledArtilleryUnit
|
||||||
|
{
|
||||||
|
partial class FormSelfPropelledArtilleryUnitCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
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>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#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()
|
||||||
|
{
|
||||||
|
ButtonAddUsta = new Button();
|
||||||
|
ButtonRemoveUsta = new Button();
|
||||||
|
ButtonRefreshCollection = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// ButtonAddUsta
|
||||||
|
//
|
||||||
|
ButtonAddUsta.Location = new Point(665, 45);
|
||||||
|
ButtonAddUsta.Name = "ButtonAddUsta";
|
||||||
|
ButtonAddUsta.Size = new Size(166, 31);
|
||||||
|
ButtonAddUsta.TabIndex = 0;
|
||||||
|
ButtonAddUsta.Text = "Добавить арт. установку";
|
||||||
|
ButtonAddUsta.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddUsta.Click += ButtonAddUsta_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveUsta
|
||||||
|
//
|
||||||
|
ButtonRemoveUsta.Location = new Point(665, 129);
|
||||||
|
ButtonRemoveUsta.Name = "ButtonRemoveUsta";
|
||||||
|
ButtonRemoveUsta.Size = new Size(166, 31);
|
||||||
|
ButtonRemoveUsta.TabIndex = 1;
|
||||||
|
ButtonRemoveUsta.Text = "Удалить арт. установку";
|
||||||
|
ButtonRemoveUsta.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveUsta.Click += ButtonRemoveUsta_Click;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(665, 215);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(166, 31);
|
||||||
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(643, 423);
|
||||||
|
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
|
||||||
|
pictureBoxCollection.TabIndex = 3;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
maskedTextBoxNumber.Location = new Point(695, 100);
|
||||||
|
maskedTextBoxNumber.Mask = "00";
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(100, 22);
|
||||||
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
|
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Location = new Point(643, 12);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(209, 411);
|
||||||
|
groupBox1.TabIndex = 5;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// FormSelfPropelledArtilleryUnitCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(859, 435);
|
||||||
|
Controls.Add(ButtonRefreshCollection);
|
||||||
|
Controls.Add(ButtonRemoveUsta);
|
||||||
|
Controls.Add(maskedTextBoxNumber);
|
||||||
|
Controls.Add(ButtonAddUsta);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormSelfPropelledArtilleryUnitCollection";
|
||||||
|
Text = "Набор арт. установок";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button ButtonAddUsta;
|
||||||
|
private Button ButtonRemoveUsta;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
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;
|
||||||
|
using SelfPropelledArtilleryUnit.DrawningObjects;
|
||||||
|
using SelfPropelledArtilleryUnit.Drawnings;
|
||||||
|
using SelfPropelledArtilleryUnit.Generics;
|
||||||
|
using SelfPropelledArtilleryUnit.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
namespace SelfPropelledArtilleryUnit
|
||||||
|
{
|
||||||
|
public partial class FormSelfPropelledArtilleryUnitCollection : Form
|
||||||
|
{
|
||||||
|
private readonly UstaGenericCollection<DrawningUsta, DrawningObjectUsta> _usta;
|
||||||
|
public FormSelfPropelledArtilleryUnitCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_usta = new UstaGenericCollection<DrawningUsta, DrawningObjectUsta>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddUsta_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormSelfPropelledArtilleryUnit form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_usta + form.SelectedUsta > -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _usta.ShowUsta();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRemoveUsta_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (_usta - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _usta.ShowUsta();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _usta.ShowUsta();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -31,6 +31,11 @@ namespace SelfPropelledArtilleryUnit.MovementStrategy
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="direction">Направление</param>
|
/// <param name="direction">Направление</param>
|
||||||
void MoveObject(DirectionType direction);
|
void MoveObject(DirectionType direction);
|
||||||
|
|
||||||
|
void SetPosition(int x, int y);
|
||||||
|
|
||||||
|
void Draw(Graphics g);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ using SelfPropelledArtilleryUnit.Drawnings;
|
|||||||
namespace SelfPropelledArtilleryUnit.MovementStrategy
|
namespace SelfPropelledArtilleryUnit.MovementStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningUsta (паттерн Adapter)
|
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DrawningObjectUsta : IMoveableObject
|
public class DrawningObjectUsta : IMoveableObject
|
||||||
{
|
{
|
||||||
@ -37,5 +37,20 @@ namespace SelfPropelledArtilleryUnit.MovementStrategy
|
|||||||
_drawningUsta?.CanMove(direction) ?? false;
|
_drawningUsta?.CanMove(direction) ?? false;
|
||||||
public void MoveObject(DirectionType direction) =>
|
public void MoveObject(DirectionType direction) =>
|
||||||
_drawningUsta?.MoveTransport(direction);
|
_drawningUsta?.MoveTransport(direction);
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (_drawningUsta != null)
|
||||||
|
{
|
||||||
|
_drawningUsta.SetPosition(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(Graphics g)
|
||||||
|
{
|
||||||
|
if (_drawningUsta != null)
|
||||||
|
{
|
||||||
|
_drawningUsta.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace SelfPropelledArtilleryUnit
|
using SelfPropelledArtilleryUnit;
|
||||||
|
|
||||||
|
namespace ProjectUsta
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
@ -11,7 +13,7 @@ namespace SelfPropelledArtilleryUnit
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormSelfPropelledArtilleryUnit());
|
Application.Run(new FormSelfPropelledArtilleryUnitCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
namespace SelfPropelledArtilleryUnit.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly T?[] _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Length;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="usta">Добавляемая установка</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T usta)
|
||||||
|
{
|
||||||
|
return Insert(usta, 0);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="usta">Добавляемая установка</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T usta, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0 && position > Count)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
int d = 0;
|
||||||
|
for (int j = 1; j < Count - position; j++)
|
||||||
|
{
|
||||||
|
if (_places[position + j] == null)
|
||||||
|
{
|
||||||
|
d = position + j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d == 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (int j = d; j > position; j--)
|
||||||
|
{
|
||||||
|
_places[j] = _places[j - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||||
|
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
|
// TODO вставка по позиции
|
||||||
|
_places[position] = usta;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// Проверка позиции
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
{
|
||||||
|
// Позиция недопустима
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
{
|
||||||
|
// Позиция недопустима
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,154 @@
|
|||||||
|
using SelfPropelledArtilleryUnit.Drawnings;
|
||||||
|
using SelfPropelledArtilleryUnit.MovementStrategy;
|
||||||
|
using SelfPropelledArtilleryUnit.DrawningObjects;
|
||||||
|
|
||||||
|
namespace SelfPropelledArtilleryUnit.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов DrawningUsta
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
internal class UstaGenericCollection<T, U>
|
||||||
|
where T : DrawningUsta
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 100;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public UstaGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int? operator +(UstaGenericCollection<T, U> collect, T?
|
||||||
|
obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect?._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(UstaGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowUsta()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
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 + 2, j *
|
||||||
|
_placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||||
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int c = 11;
|
||||||
|
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
if (i % 3 == 0 && i != 0)
|
||||||
|
{
|
||||||
|
c = c - 3;
|
||||||
|
|
||||||
|
}
|
||||||
|
T? obj = _collection.Get(i);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
// Получение объекта
|
||||||
|
IMoveableObject moveableObject = obj.GetMoveableObject;
|
||||||
|
// Установка позиции
|
||||||
|
|
||||||
|
int x = i % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth + 3;
|
||||||
|
int y = c / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight + 10;
|
||||||
|
moveableObject.SetPosition(x, y);
|
||||||
|
|
||||||
|
// Прорисовка объекта
|
||||||
|
moveableObject.Draw(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user