LabWork3
This commit is contained in:
parent
9c41c8c23c
commit
ed5ff92d41
@ -0,0 +1,69 @@
|
|||||||
|
using Project_SelfPropelledArtilleryUnit.Drawings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
protected readonly int _placeSizeWidth = 300;
|
||||||
|
|
||||||
|
protected readonly int _placeSizeHeight = 110;
|
||||||
|
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
|
||||||
|
protected ICollectionGenericObjects<DrawingBase>? _collection = null;
|
||||||
|
|
||||||
|
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||||
|
|
||||||
|
public AbstractCompany(int picWidth, int picHeigth, ICollectionGenericObjects<DrawingBase> collection)
|
||||||
|
{
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeigth;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.SetMaxCount = GetMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int operator +(AbstractCompany company, DrawingBase sau)
|
||||||
|
{
|
||||||
|
return company._collection.Insert(sau);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DrawingBase operator -(AbstractCompany company, int position)
|
||||||
|
{
|
||||||
|
return company._collection.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingBase? GetRandomObject()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap? Show()
|
||||||
|
{
|
||||||
|
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
|
DrawBackground(graphics);
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||||
|
{
|
||||||
|
DrawingBase? obj = _collection?.Get(i);
|
||||||
|
SetObjectPosition(i, _collection?.Count ?? 0, obj);
|
||||||
|
obj?.DrawSAU(graphics);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void DrawBackground(Graphics g);
|
||||||
|
|
||||||
|
protected abstract void SetObjectPosition(int position, int MaxPos, DrawingBase? sau);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public interface ICollectionGenericObjects <T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
int Count { get; }
|
||||||
|
int SetMaxCount { set; }
|
||||||
|
int Insert(T obj);
|
||||||
|
int Insert(T obj, int position);
|
||||||
|
T? Remove(int position);
|
||||||
|
T? Get(int position);
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
using Project_SelfPropelledArtilleryUnit.Drawings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public class MassiveGenericObjects <T> : ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private T?[] _collection;
|
||||||
|
public int Count => _collection.Length;
|
||||||
|
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||||
|
|
||||||
|
|
||||||
|
public MassiveGenericObjects()
|
||||||
|
{
|
||||||
|
_collection = Array.Empty<T?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj)
|
||||||
|
{
|
||||||
|
// TODO вставка в свободное место набора
|
||||||
|
int index = 0;
|
||||||
|
while (index < _collection.Length)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
//проверка, что элемент массива по этой позиции пустой
|
||||||
|
if (_collection[position] != null)
|
||||||
|
{
|
||||||
|
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
int nullIndex = -1;
|
||||||
|
for (int i = position + 1; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
nullIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Если пустого элемента нет, то выходим
|
||||||
|
if (nullIndex < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
|
int j = nullIndex - 1;
|
||||||
|
while (j >= position)
|
||||||
|
{
|
||||||
|
_collection[j + 1] = _collection[j];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//вставка по позиции
|
||||||
|
_collection[position] = obj;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
//проверка позиции
|
||||||
|
//удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
T temp = _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
using Project_SelfPropelledArtilleryUnit.Drawings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public class SAUSharingService : AbstractCompany
|
||||||
|
{
|
||||||
|
public SAUSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawingBase> collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override 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; 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetObjectPosition(int position, int MaxPos, DrawingBase? sau)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
int m = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||||
|
{
|
||||||
|
if (_collection?.Get(i) != null)
|
||||||
|
{
|
||||||
|
int x = 5 + _placeSizeWidth * n;
|
||||||
|
int y = (10 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m;
|
||||||
|
|
||||||
|
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection?.Get(i)?.SetPosition(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n < _pictureWidth / _placeSizeWidth)
|
||||||
|
n++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n = 0;
|
||||||
|
m++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -150,7 +150,14 @@ namespace Project_SelfPropelledArtilleryUnit.Drawings
|
|||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush BaseBrush = new SolidBrush(BaseSAU.BodyColor);
|
Brush BaseBrush = new SolidBrush(BaseSAU.BodyColor);
|
||||||
|
Brush WheelBrush = new SolidBrush(Color.Brown);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//колеса
|
||||||
|
g.FillEllipse(WheelBrush, _startPosX.Value, _startPosY.Value + 45, 40, 40);
|
||||||
|
g.FillEllipse(WheelBrush, _startPosX.Value + 40, _startPosY.Value + 45, 40, 40);
|
||||||
|
g.FillEllipse(WheelBrush, _startPosX.Value + 80, _startPosY.Value + 45, 40, 40);
|
||||||
|
|
||||||
//Корпус
|
//Корпус
|
||||||
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 45);
|
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 45);
|
||||||
|
@ -27,21 +27,11 @@ public class DrawingSAU : DrawingBase
|
|||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new SolidBrush(SAU.AdditionalColor);
|
Brush additionalBrush = new SolidBrush(SAU.AdditionalColor);
|
||||||
|
|
||||||
|
|
||||||
if (SAU.Wheels)
|
|
||||||
{
|
|
||||||
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 45, 40, 40);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 45, 40, 40);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 45, 40, 40);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 55, 130, 40);
|
//гусеницы
|
||||||
}
|
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 55, 130, 40);
|
||||||
|
|
||||||
|
|
||||||
//пулеметы
|
//пулеметы
|
||||||
|
|
||||||
@ -54,6 +44,9 @@ public class DrawingSAU : DrawingBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
base.DrawSAU(g);
|
base.DrawSAU(g);
|
||||||
|
|
||||||
|
//гусеницы
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 55, 130, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ namespace Project_SelfPropelledArtilleryUnit.Entity
|
|||||||
public double Weight { get; private set; }
|
public double Weight { get; private set; }
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public double Step => Speed * 100 / Weight;
|
public double Step => Speed * 100 / Weight;
|
||||||
public BaseSAU(int speed, double weight, Color bodyColor)
|
public BaseSAU(int speed, double weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
|
@ -29,12 +29,10 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBox1 = new PictureBox();
|
pictureBox1 = new PictureBox();
|
||||||
create = new Button();
|
|
||||||
left = new Button();
|
left = new Button();
|
||||||
up = new Button();
|
up = new Button();
|
||||||
right = new Button();
|
right = new Button();
|
||||||
down = new Button();
|
down = new Button();
|
||||||
baseSAU = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
strategyStep = new Button();
|
strategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||||
@ -49,17 +47,6 @@
|
|||||||
pictureBox1.TabIndex = 0;
|
pictureBox1.TabIndex = 0;
|
||||||
pictureBox1.TabStop = false;
|
pictureBox1.TabStop = false;
|
||||||
//
|
//
|
||||||
// create
|
|
||||||
//
|
|
||||||
create.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
create.Location = new Point(12, 481);
|
|
||||||
create.Name = "create";
|
|
||||||
create.Size = new Size(94, 29);
|
|
||||||
create.TabIndex = 1;
|
|
||||||
create.Text = "create";
|
|
||||||
create.UseVisualStyleBackColor = true;
|
|
||||||
create.Click += Create_Click;
|
|
||||||
//
|
|
||||||
// left
|
// left
|
||||||
//
|
//
|
||||||
left.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
left.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
@ -108,17 +95,6 @@
|
|||||||
down.UseVisualStyleBackColor = true;
|
down.UseVisualStyleBackColor = true;
|
||||||
down.Click += Move_Click;
|
down.Click += Move_Click;
|
||||||
//
|
//
|
||||||
// baseSAU
|
|
||||||
//
|
|
||||||
baseSAU.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
baseSAU.Location = new Point(112, 481);
|
|
||||||
baseSAU.Name = "baseSAU";
|
|
||||||
baseSAU.Size = new Size(94, 29);
|
|
||||||
baseSAU.TabIndex = 6;
|
|
||||||
baseSAU.Text = "creat base sau";
|
|
||||||
baseSAU.UseVisualStyleBackColor = true;
|
|
||||||
baseSAU.Click += baseSAU_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
// comboBoxStrategy
|
||||||
//
|
//
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
@ -146,12 +122,10 @@
|
|||||||
ClientSize = new Size(1054, 522);
|
ClientSize = new Size(1054, 522);
|
||||||
Controls.Add(strategyStep);
|
Controls.Add(strategyStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(baseSAU);
|
|
||||||
Controls.Add(down);
|
Controls.Add(down);
|
||||||
Controls.Add(right);
|
Controls.Add(right);
|
||||||
Controls.Add(up);
|
Controls.Add(up);
|
||||||
Controls.Add(left);
|
Controls.Add(left);
|
||||||
Controls.Add(create);
|
|
||||||
Controls.Add(pictureBox1);
|
Controls.Add(pictureBox1);
|
||||||
Name = "FormSAU";
|
Name = "FormSAU";
|
||||||
Text = "Самоходная артиллерийская установка";
|
Text = "Самоходная артиллерийская установка";
|
||||||
@ -162,12 +136,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBox1;
|
private PictureBox pictureBox1;
|
||||||
private Button create;
|
|
||||||
private Button left;
|
private Button left;
|
||||||
private Button up;
|
private Button up;
|
||||||
private Button right;
|
private Button right;
|
||||||
private Button down;
|
private Button down;
|
||||||
private Button baseSAU;
|
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button strategyStep;
|
private Button strategyStep;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,17 @@ public partial class FormSAU : Form
|
|||||||
private DrawingBase? _drawingBase;
|
private DrawingBase? _drawingBase;
|
||||||
private AbstractStrategy? _strategy;
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
public DrawingBase SetSAU
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawingBase = value;
|
||||||
|
_drawingBase.SetPictureSize(pictureBox1.Width, pictureBox1.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public FormSAU()
|
public FormSAU()
|
||||||
{
|
{
|
||||||
@ -37,36 +48,7 @@ public partial class FormSAU : Form
|
|||||||
pictureBox1.Image = bmp;
|
pictureBox1.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawingBase):
|
|
||||||
_drawingBase = new DrawingBase(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
|
||||||
break;
|
|
||||||
case nameof(DrawingSAU):
|
|
||||||
_drawingBase = new DrawingSAU(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)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_drawingBase.SetPictureSize(pictureBox1.Width, pictureBox1.Height);
|
|
||||||
_drawingBase.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
private void Create_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingSAU));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Move_Click(object sender, EventArgs e)
|
private void Move_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -99,7 +81,7 @@ public partial class FormSAU : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void baseSAU_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBase));
|
|
||||||
|
|
||||||
private void strategyStep_Click(object sender, EventArgs e)
|
private void strategyStep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
172
Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs
generated
Normal file
172
Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs
generated
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
namespace Project_SelfPropelledArtilleryUnit
|
||||||
|
{
|
||||||
|
partial class FormSAUCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
groupBoxTools = new GroupBox();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
buttonGoToCheck = new Button();
|
||||||
|
buttonRemoveSAU = new Button();
|
||||||
|
maskedTextBox = new MaskedTextBox();
|
||||||
|
buttonAddSAU = new Button();
|
||||||
|
buttonAddBaseSAU = new Button();
|
||||||
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
groupBoxTools.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
groupBoxTools.Controls.Add(buttonUpdate);
|
||||||
|
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||||
|
groupBoxTools.Controls.Add(buttonRemoveSAU);
|
||||||
|
groupBoxTools.Controls.Add(maskedTextBox);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddSAU);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddBaseSAU);
|
||||||
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
|
groupBoxTools.Location = new Point(1113, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(218, 591);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonUpdate.Location = new Point(6, 544);
|
||||||
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
|
buttonUpdate.Size = new Size(206, 41);
|
||||||
|
buttonUpdate.TabIndex = 8;
|
||||||
|
buttonUpdate.Text = "Обновить";
|
||||||
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdate.Click += buttonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonGoToCheck
|
||||||
|
//
|
||||||
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonGoToCheck.Location = new Point(6, 497);
|
||||||
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
|
buttonGoToCheck.Size = new Size(206, 41);
|
||||||
|
buttonGoToCheck.TabIndex = 7;
|
||||||
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||||
|
//
|
||||||
|
// buttonRemoveSAU
|
||||||
|
//
|
||||||
|
buttonRemoveSAU.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRemoveSAU.Location = new Point(6, 259);
|
||||||
|
buttonRemoveSAU.Name = "buttonRemoveSAU";
|
||||||
|
buttonRemoveSAU.Size = new Size(206, 41);
|
||||||
|
buttonRemoveSAU.TabIndex = 6;
|
||||||
|
buttonRemoveSAU.Text = "Удаление САУ";
|
||||||
|
buttonRemoveSAU.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveSAU.Click += buttonRemoveSAU_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBox
|
||||||
|
//
|
||||||
|
maskedTextBox.Location = new Point(6, 226);
|
||||||
|
maskedTextBox.Mask = "00";
|
||||||
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
|
maskedTextBox.Size = new Size(206, 27);
|
||||||
|
maskedTextBox.TabIndex = 5;
|
||||||
|
maskedTextBox.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonAddSAU
|
||||||
|
//
|
||||||
|
buttonAddSAU.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddSAU.Location = new Point(6, 128);
|
||||||
|
buttonAddSAU.Name = "buttonAddSAU";
|
||||||
|
buttonAddSAU.Size = new Size(206, 41);
|
||||||
|
buttonAddSAU.TabIndex = 3;
|
||||||
|
buttonAddSAU.Text = "Добавление САУ";
|
||||||
|
buttonAddSAU.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddSAU.Click += buttonAddSAU_Click;
|
||||||
|
//
|
||||||
|
// buttonAddBaseSAU
|
||||||
|
//
|
||||||
|
buttonAddBaseSAU.Location = new Point(6, 81);
|
||||||
|
buttonAddBaseSAU.Name = "buttonAddBaseSAU";
|
||||||
|
buttonAddBaseSAU.Size = new Size(206, 41);
|
||||||
|
buttonAddBaseSAU.TabIndex = 2;
|
||||||
|
buttonAddBaseSAU.Text = "Добавление базовой САУ";
|
||||||
|
buttonAddBaseSAU.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddBaseSAU.Click += buttonAddBaseSAU_Click;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorCompany
|
||||||
|
//
|
||||||
|
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||||
|
comboBoxSelectorCompany.Location = new Point(6, 26);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(206, 28);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 1;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(1113, 591);
|
||||||
|
pictureBox.TabIndex = 4;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormSAUCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1331, 591);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Name = "FormSAUCollection";
|
||||||
|
Text = "FormSAUCollection";
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private ComboBox comboBoxSelectorCompany;
|
||||||
|
private Button buttonAddSAU;
|
||||||
|
private Button buttonAddBaseSAU;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonGoToCheck;
|
||||||
|
private Button buttonRemoveSAU;
|
||||||
|
private MaskedTextBox maskedTextBox;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,140 @@
|
|||||||
|
using Project_SelfPropelledArtilleryUnit.CollectionGenericObjects;
|
||||||
|
using Project_SelfPropelledArtilleryUnit.Drawings;
|
||||||
|
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 Project_SelfPropelledArtilleryUnit;
|
||||||
|
|
||||||
|
public partial class FormSAUCollection : Form
|
||||||
|
{
|
||||||
|
private AbstractCompany? _company;
|
||||||
|
public FormSAUCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new SAUSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingBase>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
if (_company == null) { return; }
|
||||||
|
DrawingBase drawingbase;
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawingBase):
|
||||||
|
drawingbase = new DrawingBase(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||||
|
break;
|
||||||
|
case nameof(DrawingSAU):
|
||||||
|
drawingbase = new DrawingSAU(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
GetColor(random), GetColor(random),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_company + drawingbase !=-1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color GetColor(Random random)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void buttonAddBaseSAU_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBase));
|
||||||
|
|
||||||
|
private void buttonAddSAU_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingSAU));
|
||||||
|
|
||||||
|
private void buttonRemoveSAU_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
|
if (_company - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawingBase? sau = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (sau == null)
|
||||||
|
{
|
||||||
|
sau = _company.GetRandomObject();
|
||||||
|
counter--;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (sau == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormSAU form = new()
|
||||||
|
{
|
||||||
|
SetSAU = sau
|
||||||
|
};
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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>
|
@ -12,7 +12,7 @@ public interface IMoveableObject
|
|||||||
|
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
|
||||||
int GetStep { get; }
|
int GetStep { get; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ public class MoveableSAU : IMoveableObject
|
|||||||
_SAU = sau;
|
_SAU = sau;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ObjectParameters? GetObjectPosition
|
public ObjectParameters? GetObjectPosition
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -32,6 +34,8 @@ public class MoveableSAU : IMoveableObject
|
|||||||
|
|
||||||
public int GetStep => (int)(_SAU?.BaseSAU.Step ?? 0);
|
public int GetStep => (int)(_SAU?.BaseSAU.Step ?? 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public bool TryMoveObject(MovementDirection direction)
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
{
|
{
|
||||||
if (_SAU == null || _SAU.BaseSAU == null)
|
if (_SAU == null || _SAU.BaseSAU == null)
|
||||||
|
@ -11,7 +11,7 @@ namespace Project_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 FormSAU());
|
Application.Run(new FormSAUCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user