ПИбд-12, Шляпин Юрий Александрович, 3 простая #3
@ -0,0 +1,52 @@
|
||||
using AircraftCarrier.Drawing;
|
||||
|
||||
namespace AircraftCarrier.CollectionGenericObjects;
|
||||
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
protected const int _placeSizeWidth = 300;
|
||||
protected const int _placeSizeHeight = 150;
|
||||
protected readonly int _pictureWidth;
|
||||
protected readonly int _pictureHeight;
|
||||
private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
|
||||
protected ICollectionGenericObjects<DrawingSimpleAircraftCarrier>? _collection = null;
|
||||
public AbstractCompany(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingSimpleAircraftCarrier> collection) {
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
public static bool operator +(AbstractCompany company, DrawingSimpleAircraftCarrier aircraftCarrier)
|
||||
{
|
||||
return company._collection?.Insert(aircraftCarrier) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator -(AbstractCompany company, int pos)
|
||||
{
|
||||
return company._collection?.Remove(pos) ?? false;
|
||||
}
|
||||
|
||||
public DrawingSimpleAircraftCarrier? GetRandom()
|
||||
{
|
||||
Random random = new Random();
|
||||
return _collection?.Get(random.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackground(graphics);
|
||||
SetObjectPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
DrawingSimpleAircraftCarrier? obj = _collection?.Get(i);
|
||||
obj?.DrawAircraftCarrier(graphics);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
protected abstract void DrawBackground(Graphics g);
|
||||
protected abstract void SetObjectPosition();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
|
||||
using AircraftCarrier.Drawing;
|
||||
|
||||
namespace AircraftCarrier.CollectionGenericObjects;
|
||||
|
||||
public class DocksService : AbstractCompany
|
||||
{
|
||||
public DocksService(
|
||||
int pictureWidth,
|
||||
int pictureHeight,
|
||||
ICollectionGenericObjects<DrawingSimpleAircraftCarrier> collection
|
||||
) :
|
||||
base(pictureWidth, pictureHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||
{
|
||||
Point[] p = {
|
||||
new Point(i*_placeSizeWidth+250,j*_placeSizeHeight),
|
||||
new Point(i*_placeSizeWidth,j*_placeSizeHeight),
|
||||
new Point(i*_placeSizeWidth,j*_placeSizeHeight+_placeSizeHeight),
|
||||
new Point(i*_placeSizeWidth+250,j*_placeSizeHeight+_placeSizeHeight),
|
||||
};
|
||||
Pen pen = new Pen(Color.Black,5);
|
||||
g.DrawLines(pen, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition()
|
||||
{
|
||||
int maxXPositionCount = _pictureWidth / _placeSizeWidth;
|
||||
int maxYPositionCount = _pictureHeight / _placeSizeHeight;
|
||||
int xpos = 0;
|
||||
int ypos = maxYPositionCount;
|
||||
for (int i = 0; i < _collection?.Count; i++)
|
||||
{
|
||||
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i)?.SetPosition(xpos * _placeSizeWidth + 10, (ypos-1) * _placeSizeHeight + 10);
|
||||
xpos++;
|
||||
if (xpos >= maxXPositionCount)
|
||||
{
|
||||
xpos = 0;
|
||||
ypos--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
namespace AircraftCarrier.CollectionGenericObjects;
|
||||
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
int Count { get; }
|
||||
int SetMaxCount { set; }
|
||||
bool Insert(T obj);
|
||||
bool Insert(T obj, int position);
|
||||
bool Remove(int position);
|
||||
T? Get(int position);
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
namespace AircraftCarrier.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>();
|
||||
}
|
||||
|
||||
private bool _checkAndInsert(T obj, int pos)
|
||||
{
|
||||
if (_collection[pos] == null)
|
||||
{
|
||||
_collection[pos] = obj;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool _checkRange(int pos) => pos >= 0 && pos < Count;
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (!_checkRange(position)) return null;
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_checkAndInsert(obj,i)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (!_checkRange(position)) return false;
|
||||
if (_checkAndInsert(obj, position)) return true;
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_checkAndInsert(obj, i)) return true;
|
||||
}
|
||||
for (int i = 0; i < position; i++)
|
||||
{
|
||||
if (_checkAndInsert(obj, i)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!_checkRange(position) || _collection[position] == null) return false;
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -29,12 +29,10 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxAircraftCarrier = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateSimple = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategy = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit();
|
||||
@ -46,27 +44,16 @@
|
||||
pictureBoxAircraftCarrier.Dock = DockStyle.Fill;
|
||||
pictureBoxAircraftCarrier.Location = new Point(0, 0);
|
||||
pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier";
|
||||
pictureBoxAircraftCarrier.Size = new Size(800, 438);
|
||||
pictureBoxAircraftCarrier.Size = new Size(1128, 617);
|
||||
pictureBoxAircraftCarrier.TabIndex = 0;
|
||||
pictureBoxAircraftCarrier.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(20, 389);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.left_arrow;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(677, 386);
|
||||
buttonLeft.Location = new Point(1005, 565);
|
||||
buttonLeft.Margin = new Padding(0);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
@ -79,7 +66,7 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.down_arrow;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(710, 386);
|
||||
buttonDown.Location = new Point(1038, 565);
|
||||
buttonDown.Margin = new Padding(0);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
@ -92,7 +79,7 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.right_arrow;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(743, 386);
|
||||
buttonRight.Location = new Point(1071, 565);
|
||||
buttonRight.Margin = new Padding(0);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
@ -105,7 +92,7 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.up_arrow;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(710, 353);
|
||||
buttonUp.Location = new Point(1038, 532);
|
||||
buttonUp.Margin = new Padding(0);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
@ -113,24 +100,14 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateSimple
|
||||
//
|
||||
buttonCreateSimple.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateSimple.Location = new Point(120, 389);
|
||||
buttonCreateSimple.Name = "buttonCreateSimple";
|
||||
buttonCreateSimple.Size = new Size(128, 29);
|
||||
buttonCreateSimple.TabIndex = 6;
|
||||
buttonCreateSimple.Text = "Создать контур";
|
||||
buttonCreateSimple.UseVisualStyleBackColor = true;
|
||||
buttonCreateSimple.Click += buttonCreateSimple_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.Cursor = Cursors.SizeNESW;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к углу" });
|
||||
comboBoxStrategy.Location = new Point(637, 12);
|
||||
comboBoxStrategy.Location = new Point(965, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
@ -138,7 +115,7 @@
|
||||
// buttonStrategy
|
||||
//
|
||||
buttonStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStrategy.Location = new Point(694, 46);
|
||||
buttonStrategy.Location = new Point(1022, 46);
|
||||
buttonStrategy.Name = "buttonStrategy";
|
||||
buttonStrategy.Size = new Size(94, 29);
|
||||
buttonStrategy.TabIndex = 8;
|
||||
@ -150,15 +127,13 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 438);
|
||||
ClientSize = new Size(1128, 617);
|
||||
Controls.Add(buttonStrategy);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateSimple);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxAircraftCarrier);
|
||||
KeyPreview = true;
|
||||
Name = "FormAircraftCarrier";
|
||||
@ -171,12 +146,10 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAircraftCarrier;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateSimple;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategy;
|
||||
}
|
||||
|
@ -10,6 +10,21 @@ public partial class FormAircraftCarrier : Form
|
||||
private DrawingSimpleAircraftCarrier? _drawingAircraftCarrier;
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawingSimpleAircraftCarrier setCar
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawingAircraftCarrier = value;
|
||||
_drawingAircraftCarrier.SetPictureSize(
|
||||
pictureBoxAircraftCarrier.Width,
|
||||
pictureBoxAircraftCarrier.Height
|
||||
);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public FormAircraftCarrier()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -25,37 +40,6 @@ public partial class FormAircraftCarrier : Form
|
||||
pictureBoxAircraftCarrier.Image = bmp;
|
||||
}
|
||||
|
||||
private void CreateDrawingAircraftCarrier(string name)
|
||||
{
|
||||
Random random = new();
|
||||
switch (name)
|
||||
{
|
||||
case nameof(DrawingAircraftCarrier):
|
||||
_drawingAircraftCarrier = new DrawingAircraftCarrier(random.Next(100, 200), random.Next(1000, 2000),
|
||||
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;
|
||||
case nameof(DrawingSimpleAircraftCarrier):
|
||||
_drawingAircraftCarrier = new DrawingSimpleAircraftCarrier(random.Next(100, 200), random.Next(1000, 2000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawingAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
|
||||
_drawingAircraftCarrier.SetPosition(random.Next(10, 50), random.Next(10, 50));
|
||||
|
||||
Draw();
|
||||
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateDrawingAircraftCarrier(nameof(DrawingAircraftCarrier));
|
||||
|
||||
private void buttonCreateSimple_Click(object sender, EventArgs e) => CreateDrawingAircraftCarrier(nameof(DrawingSimpleAircraftCarrier));
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingAircraftCarrier == null) return;
|
||||
|
167
AircraftCarrier/AircraftCarrier/FormShipCollection.Designer.cs
generated
Normal file
167
AircraftCarrier/AircraftCarrier/FormShipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,167 @@
|
||||
namespace AircraftCarrier.CollectionGenericObjects
|
||||
{
|
||||
partial class FormShipCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBox1 = new GroupBox();
|
||||
TextBoxIdAircraft = new MaskedTextBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonTest = new Button();
|
||||
buttonDeleteAircraft = new Button();
|
||||
buttonCreateAircraft = new Button();
|
||||
buttonCreateSimpleAircraft = new Button();
|
||||
comboBoxStorage = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(TextBoxIdAircraft);
|
||||
groupBox1.Controls.Add(buttonRefresh);
|
||||
groupBox1.Controls.Add(buttonTest);
|
||||
groupBox1.Controls.Add(buttonDeleteAircraft);
|
||||
groupBox1.Controls.Add(buttonCreateAircraft);
|
||||
groupBox1.Controls.Add(buttonCreateSimpleAircraft);
|
||||
groupBox1.Controls.Add(comboBoxStorage);
|
||||
groupBox1.Dock = DockStyle.Right;
|
||||
groupBox1.Location = new Point(835, 0);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(250, 638);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// TextBoxIdAircraft
|
||||
//
|
||||
TextBoxIdAircraft.Location = new Point(15, 221);
|
||||
TextBoxIdAircraft.Mask = "00";
|
||||
TextBoxIdAircraft.Name = "TextBoxIdAircraft";
|
||||
TextBoxIdAircraft.Size = new Size(224, 27);
|
||||
TextBoxIdAircraft.TabIndex = 6;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Location = new Point(14, 397);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(224, 48);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += buttonRefresh_Click;
|
||||
//
|
||||
// buttonTest
|
||||
//
|
||||
buttonTest.Location = new Point(15, 343);
|
||||
buttonTest.Name = "buttonTest";
|
||||
buttonTest.Size = new Size(224, 48);
|
||||
buttonTest.TabIndex = 4;
|
||||
buttonTest.Text = "Тесты";
|
||||
buttonTest.UseVisualStyleBackColor = true;
|
||||
buttonTest.Click += buttonTest_Click;
|
||||
//
|
||||
// buttonDeleteAircraft
|
||||
//
|
||||
buttonDeleteAircraft.Location = new Point(15, 258);
|
||||
buttonDeleteAircraft.Name = "buttonDeleteAircraft";
|
||||
buttonDeleteAircraft.Size = new Size(224, 48);
|
||||
buttonDeleteAircraft.TabIndex = 3;
|
||||
buttonDeleteAircraft.Text = "Удалить Авианосец";
|
||||
buttonDeleteAircraft.UseVisualStyleBackColor = true;
|
||||
buttonDeleteAircraft.Click += buttonDeleteAircraft_Click;
|
||||
//
|
||||
// buttonCreateAircraft
|
||||
//
|
||||
buttonCreateAircraft.Location = new Point(14, 139);
|
||||
buttonCreateAircraft.Name = "buttonCreateAircraft";
|
||||
buttonCreateAircraft.Size = new Size(224, 48);
|
||||
buttonCreateAircraft.TabIndex = 2;
|
||||
buttonCreateAircraft.Text = "Создать супер Авианосец";
|
||||
buttonCreateAircraft.UseVisualStyleBackColor = true;
|
||||
buttonCreateAircraft.Click += buttonCreateAircraft_Click;
|
||||
//
|
||||
// buttonCreateSimpleAircraft
|
||||
//
|
||||
buttonCreateSimpleAircraft.Location = new Point(15, 85);
|
||||
buttonCreateSimpleAircraft.Name = "buttonCreateSimpleAircraft";
|
||||
buttonCreateSimpleAircraft.Size = new Size(224, 48);
|
||||
buttonCreateSimpleAircraft.TabIndex = 1;
|
||||
buttonCreateSimpleAircraft.Text = "Создать Авианосец";
|
||||
buttonCreateSimpleAircraft.UseVisualStyleBackColor = true;
|
||||
buttonCreateSimpleAircraft.Click += buttonCreateSimpleAircraft_Click;
|
||||
//
|
||||
// comboBoxStorage
|
||||
//
|
||||
comboBoxStorage.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxStorage.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStorage.FormattingEnabled = true;
|
||||
comboBoxStorage.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxStorage.Location = new Point(15, 30);
|
||||
comboBoxStorage.Name = "comboBoxStorage";
|
||||
comboBoxStorage.Size = new Size(224, 28);
|
||||
comboBoxStorage.TabIndex = 0;
|
||||
comboBoxStorage.SelectedIndexChanged += comboBoxStorage_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(835, 638);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormShipCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1085, 638);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormShipCollection";
|
||||
Text = "FormShipCollection";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxStorage;
|
||||
private MaskedTextBox TextBoxIdAircraft;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonTest;
|
||||
private Button buttonDeleteAircraft;
|
||||
private Button buttonCreateAircraft;
|
||||
private Button buttonCreateSimpleAircraft;
|
||||
}
|
||||
}
|
125
AircraftCarrier/AircraftCarrier/FormShipCollection.cs
Normal file
125
AircraftCarrier/AircraftCarrier/FormShipCollection.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using AircraftCarrier.Drawing;
|
||||
|
||||
namespace AircraftCarrier.CollectionGenericObjects;
|
||||
|
||||
public partial class FormShipCollection : Form
|
||||
{
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
public FormShipCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void comboBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxStorage.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new DocksService(
|
||||
pictureBox.Width,
|
||||
pictureBox.Height,
|
||||
new MassiveGenericObjects<DrawingSimpleAircraftCarrier>()
|
||||
);
|
||||
break;
|
||||
}
|
||||
_company.Show();
|
||||
}
|
||||
|
||||
private static Color GetColor(Random random)
|
||||
{
|
||||
Color c = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new ColorDialog();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
c = dialog.Color;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private void CreateAircraftCarrier(string name)
|
||||
{
|
||||
if (_company == null) return;
|
||||
Random random = new();
|
||||
DrawingSimpleAircraftCarrier _drawingAircraftCarrier;
|
||||
switch (name)
|
||||
{
|
||||
case nameof(DrawingAircraftCarrier):
|
||||
_drawingAircraftCarrier = new DrawingAircraftCarrier(random.Next(100, 200), random.Next(1000, 2000),
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
case nameof(DrawingSimpleAircraftCarrier):
|
||||
_drawingAircraftCarrier = new DrawingSimpleAircraftCarrier(
|
||||
random.Next(100, 200),
|
||||
random.Next(1000, 2000),
|
||||
GetColor(random));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company + _drawingAircraftCarrier)
|
||||
{
|
||||
MessageBox.Show("элемент добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("элемент не добавлен");
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreateSimpleAircraft_Click(object sender, EventArgs e) => CreateAircraftCarrier(nameof(DrawingSimpleAircraftCarrier));
|
||||
|
||||
private void buttonCreateAircraft_Click(object sender, EventArgs e) => CreateAircraftCarrier(nameof(DrawingAircraftCarrier));
|
||||
|
||||
private void buttonDeleteAircraft_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(TextBoxIdAircraft.Text) || _company == null) return;
|
||||
|
||||
if (
|
||||
MessageBox.Show(
|
||||
"Удалить объект " + TextBoxIdAircraft.Text,
|
||||
"Удаление",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.No
|
||||
) return;
|
||||
|
||||
int pos = Convert.ToInt32(TextBoxIdAircraft.Text);
|
||||
if (_company - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не был удален");
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null) return;
|
||||
DrawingSimpleAircraftCarrier? aircraft = null;
|
||||
int counter = 100;
|
||||
while (aircraft == null)
|
||||
{
|
||||
aircraft = _company.GetRandom();
|
||||
counter--;
|
||||
if (counter <= 0) break;
|
||||
}
|
||||
|
||||
if (aircraft == null) return;
|
||||
|
||||
FormAircraftCarrier form = new();
|
||||
form.setCar = aircraft;
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null) return;
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
120
AircraftCarrier/AircraftCarrier/FormShipCollection.resx
Normal file
120
AircraftCarrier/AircraftCarrier/FormShipCollection.resx
Normal file
@ -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>
|
@ -5,4 +5,4 @@ public interface IMoveableObject
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
int GetStep { get; }
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
}
|
@ -20,4 +20,4 @@ public class ObjectParameters
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using AircraftCarrier.CollectionGenericObjects;
|
||||
|
||||
namespace AircraftCarrier
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,7 +13,8 @@ namespace AircraftCarrier
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAircraftCarrier());
|
||||
//Application.Run(new FormAircraftCarrier());
|
||||
Application.Run(new FormShipCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user