ISEbd-12_Mukhamadieva_S.S._Simple_LabWork03 #3
@ -0,0 +1,106 @@
|
||||
using ProjectBattleship.DrawingObject;
|
||||
|
||||
namespace ProjectBattleship.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 80;
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Коллекция кораблей
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawingWarship>? _collection = null;
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно
|
||||
/// разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight /
|
||||
(_placeSizeWidth * _placeSizeHeight);
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth">Ширина окна</param>
|
||||
/// <param name="picHeight">Высота окна</param>
|
||||
/// <param name="collection">Коллекция автомобилей</param>
|
||||
public AbstractCompany(int picWidth, int picHeight,
|
||||
ICollectionGenericObjects<DrawingWarship> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="warship">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company,
|
||||
DrawingWarship warship)
|
||||
{
|
||||
return company._collection?.Insert(warship) ?? 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawingWarship? operator -(AbstractCompany company,
|
||||
int position)
|
||||
{
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawingWarship? GetRandomObject()
|
||||
{
|
||||
Random rnd = new();
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackgound(graphics);
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawingWarship? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
protected abstract void DrawBackgound(Graphics g);
|
||||
/// <summary>
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using ProjectBattleship.DrawingObject;
|
||||
|
||||
namespace ProjectBattleship.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Реализация абстрактной компании - доки
|
||||
/// </summary>
|
||||
public class Docks : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public Docks(int picWidth, int picHeight,
|
||||
ICollectionGenericObjects<DrawingWarship> collection) :
|
||||
base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
Brush brush = new SolidBrush(Color.Black);
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
for (int j = 0; j < height; ++j)
|
||||
{
|
||||
g.FillRectangle(brush, i * _placeSizeWidth,
|
||||
j * _placeSizeHeight, 200, 5);
|
||||
g.FillRectangle(brush, i * _placeSizeWidth,
|
||||
j * _placeSizeHeight, 5, 80);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < height - 4; ++j)
|
||||
{
|
||||
g.FillRectangle(brush, j * _placeSizeWidth,
|
||||
height * _placeSizeHeight, 200, 5);
|
||||
}
|
||||
}
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
if (_collection == null) return;
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int curWidth = width - 1;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawingWarship? _warship = _collection.Get(i);
|
||||
if (_warship != null)
|
||||
{
|
||||
if (_warship.SetPictureSize(_pictureWidth, _pictureHeight))
|
||||
{
|
||||
_warship.SetPosition(_placeSizeWidth * curWidth + 20,
|
||||
curHeight * _placeSizeHeight + 15);
|
||||
}
|
||||
}
|
||||
curWidth--;
|
||||
if (curWidth < 0)
|
||||
{
|
||||
curHeight++;
|
||||
curWidth = width - 1;
|
||||
}
|
||||
if (curHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
namespace ProjectBattleship.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Количество объектов в коллекции
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int position);
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
namespace ProjectBattleship.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T?[] _collection;
|
||||
public int Count => _collection.Length;
|
||||
public int SetMaxCount
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
if (_collection.Length > 0)
|
||||
{
|
||||
Array.Resize(ref _collection, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_collection = new T?[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
public int Insert(T obj)
|
||||
{
|
||||
return Insert(obj, 0);
|
||||
}
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = position - 1; i >= 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > Count || _collection[position] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
T? obj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace ProjectBattleship;
|
||||
namespace ProjectBattleship.DrawingObject;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
@ -29,14 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxBattleship = new PictureBox();
|
||||
buttonCreateBattleship = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
button1 = new Button();
|
||||
buttonCreateWarship = new Button();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBattleship).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -50,18 +48,6 @@
|
||||
pictureBoxBattleship.TabIndex = 0;
|
||||
pictureBoxBattleship.TabStop = false;
|
||||
//
|
||||
// buttonCreateBattleship
|
||||
//
|
||||
buttonCreateBattleship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBattleship.Location = new Point(11, 384);
|
||||
buttonCreateBattleship.Margin = new Padding(2);
|
||||
buttonCreateBattleship.Name = "buttonCreateBattleship";
|
||||
buttonCreateBattleship.Size = new Size(201, 40);
|
||||
buttonCreateBattleship.TabIndex = 1;
|
||||
buttonCreateBattleship.Text = "Создать линкор";
|
||||
buttonCreateBattleship.UseVisualStyleBackColor = true;
|
||||
buttonCreateBattleship.Click += ButtonCreateBattleship_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -126,38 +112,26 @@
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Location = new Point(752, 72);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(104, 43);
|
||||
button1.TabIndex = 7;
|
||||
button1.Text = "шаг";
|
||||
button1.TextAlign = ContentAlignment.TopCenter;
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// buttonCreateWarship
|
||||
//
|
||||
buttonCreateWarship.Location = new Point(217, 384);
|
||||
buttonCreateWarship.Name = "buttonCreateWarship";
|
||||
buttonCreateWarship.Size = new Size(200, 40);
|
||||
buttonCreateWarship.TabIndex = 8;
|
||||
buttonCreateWarship.Text = "Создать корабль";
|
||||
buttonCreateWarship.UseVisualStyleBackColor = true;
|
||||
buttonCreateWarship.Click += ButtonCreateWarship_Click;
|
||||
buttonStrategyStep.Location = new Point(752, 72);
|
||||
buttonStrategyStep.Name = "button1";
|
||||
buttonStrategyStep.Size = new Size(104, 43);
|
||||
buttonStrategyStep.TabIndex = 7;
|
||||
buttonStrategyStep.Text = "шаг";
|
||||
buttonStrategyStep.TextAlign = ContentAlignment.TopCenter;
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormBattleship
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(12F, 30F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(876, 436);
|
||||
Controls.Add(buttonCreateWarship);
|
||||
Controls.Add(button1);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateBattleship);
|
||||
Controls.Add(pictureBoxBattleship);
|
||||
Margin = new Padding(2);
|
||||
Name = "FormBattleship";
|
||||
@ -171,13 +145,11 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxBattleship;
|
||||
private Button buttonCreateBattleship;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button button1;
|
||||
private Button buttonCreateWarship;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
@ -15,6 +15,21 @@ public partial class FormBattleship : Form
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// Ïîëó÷åíèå îáúåêòà
|
||||
/// </summary>
|
||||
public DrawingWarship SetWarship
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawingWarship = value;
|
||||
_drawingWarship.SetPictureSize(pictureBoxBattleship.Width,
|
||||
pictureBoxBattleship.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Êîíñòðóêòîð ôîðìû
|
||||
/// </summary>
|
||||
public FormBattleship()
|
||||
@ -23,7 +38,7 @@ public partial class FormBattleship : Form
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
/// Ìåòîä ïðîðèñîâêè âîåííîãî êîðàáëÿ
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
@ -31,62 +46,13 @@ public partial class FormBattleship : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxBattleship.Width,
|
||||
pictureBoxBattleship.Height);
|
||||
Bitmap bmp = new(pictureBoxBattleship.Width,
|
||||
pictureBoxBattleship.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingWarship.DrawTransport(gr);
|
||||
pictureBoxBattleship.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ñîçäàíèå îáúåêòà êëàññà-ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
/// <param name="type">Òèï ñîçäàâàåìîãî îáúåêòà</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawingWarship):
|
||||
_drawingWarship = new DrawingWarship(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(DrawingBattleship):
|
||||
_drawingWarship = new DrawingBattleship(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;
|
||||
}
|
||||
_drawingWarship.SetPictureSize(pictureBoxBattleship.Width,
|
||||
pictureBoxBattleship.Height);
|
||||
_drawingWarship.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü ñïîðòèâíûé àâòîìîáèëü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBattleship_Click(object sender, EventArgs e) =>
|
||||
CreateObject(nameof(DrawingBattleship));
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü àâòîìîáèëü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateWarship_Click(object sender, EventArgs e) =>
|
||||
CreateObject(nameof(DrawingWarship));
|
||||
/// <summary>
|
||||
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -111,8 +77,7 @@ public partial class FormBattleship : Form
|
||||
result = _drawingWarship.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawingWarship.MoveTransport(DirectionType.Right);
|
||||
result = _drawingWarship.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -143,8 +108,8 @@ public partial class FormBattleship : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableWarship(_drawingWarship),
|
||||
pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
||||
_strategy.SetData(new MoveableWarship(_drawingWarship),
|
||||
pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
{
|
||||
@ -159,6 +124,4 @@ public partial class FormBattleship : Form
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
168
ProjectBattleship/ProjectBattleship/FormWarshipCollection.Designer.cs
generated
Normal file
168
ProjectBattleship/ProjectBattleship/FormWarshipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,168 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectBattleship
|
||||
{
|
||||
partial class FormWarshipCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxCollectionTools = new GroupBox();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveWarship = new Button();
|
||||
buttonAddBattleship = new Button();
|
||||
buttonAddWarship = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxCollectionTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxCollectionTools
|
||||
//
|
||||
groupBoxCollectionTools.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
groupBoxCollectionTools.Controls.Add(maskedTextBoxPosition);
|
||||
groupBoxCollectionTools.Controls.Add(buttonRefresh);
|
||||
groupBoxCollectionTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxCollectionTools.Controls.Add(buttonRemoveWarship);
|
||||
groupBoxCollectionTools.Controls.Add(buttonAddBattleship);
|
||||
groupBoxCollectionTools.Controls.Add(buttonAddWarship);
|
||||
groupBoxCollectionTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxCollectionTools.Location = new Point(777, 0);
|
||||
groupBoxCollectionTools.Name = "groupBoxCollectionTools";
|
||||
groupBoxCollectionTools.Size = new Size(196, 594);
|
||||
groupBoxCollectionTools.TabIndex = 1;
|
||||
groupBoxCollectionTools.TabStop = false;
|
||||
groupBoxCollectionTools.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(6, 271);
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Size = new Size(183, 31);
|
||||
maskedTextBoxPosition.TabIndex = 8;
|
||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Location = new Point(6, 514);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(183, 68);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Location = new Point(6, 410);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(183, 68);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// buttonRemoveWarship
|
||||
//
|
||||
buttonRemoveWarship.Location = new Point(6, 308);
|
||||
buttonRemoveWarship.Name = "buttonRemoveWarship";
|
||||
buttonRemoveWarship.Size = new Size(183, 68);
|
||||
buttonRemoveWarship.TabIndex = 5;
|
||||
buttonRemoveWarship.Text = "Удалить военный корабль";
|
||||
buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||
buttonRemoveWarship.Click += ButtonRemoveWarship_Click;
|
||||
//
|
||||
// buttonAddBattleship
|
||||
//
|
||||
buttonAddBattleship.Location = new Point(6, 172);
|
||||
buttonAddBattleship.Name = "buttonAddBattleship";
|
||||
buttonAddBattleship.Size = new Size(183, 68);
|
||||
buttonAddBattleship.TabIndex = 3;
|
||||
buttonAddBattleship.Text = "Добавление линкора";
|
||||
buttonAddBattleship.UseVisualStyleBackColor = true;
|
||||
buttonAddBattleship.Click += ButtonAddBattleship_Click;
|
||||
//
|
||||
// buttonAddWarship
|
||||
//
|
||||
buttonAddWarship.Location = new Point(6, 98);
|
||||
buttonAddWarship.Name = "buttonAddWarship";
|
||||
buttonAddWarship.Size = new Size(183, 68);
|
||||
buttonAddWarship.TabIndex = 2;
|
||||
buttonAddWarship.Text = "Добавление военного корабля";
|
||||
buttonAddWarship.UseVisualStyleBackColor = true;
|
||||
buttonAddWarship.Click += ButtonAddWarship_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.Location = new Point(6, 30);
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(183, 33);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(771, 594);
|
||||
pictureBox.TabIndex = 2;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormWarshipCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(978, 594);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxCollectionTools);
|
||||
Name = "FormWarshipCollection";
|
||||
Text = "Коллекция военных кораблей";
|
||||
groupBoxCollectionTools.ResumeLayout(false);
|
||||
groupBoxCollectionTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
private GroupBox groupBoxCollectionTools;
|
||||
private Button buttonAddBattleship;
|
||||
private Button buttonAddWarship;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonRemoveWarship;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private PictureBox pictureBox;
|
||||
}
|
||||
}
|
181
ProjectBattleship/ProjectBattleship/FormWarshipCollection.cs
Normal file
181
ProjectBattleship/ProjectBattleship/FormWarshipCollection.cs
Normal file
@ -0,0 +1,181 @@
|
||||
using ProjectBattleship.CollectionGenericObjects;
|
||||
using ProjectBattleship.DrawingObject;
|
||||
|
||||
namespace ProjectBattleship;
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormWarshipCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormWarshipCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new Docks(pictureBox.Width,
|
||||
pictureBox.Height,
|
||||
new MassiveGenericObjects<DrawingWarship>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление военного корабля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddWarship_Click(object sender, EventArgs e) =>
|
||||
CreateObject(nameof(DrawingWarship));
|
||||
/// <summary>
|
||||
/// Добавление линкора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBattleship_Click(object sender, EventArgs e) =>
|
||||
CreateObject(nameof(DrawingBattleship));
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Random random = new();
|
||||
DrawingWarship drawingWarship;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawingWarship):
|
||||
drawingWarship = new DrawingWarship(random.Next(100, 300),
|
||||
random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawingBattleship):
|
||||
drawingWarship = new DrawingBattleship(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 + drawingWarship != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение цвета
|
||||
/// </summary>
|
||||
/// <param name="random">Генератор случайных чисел</param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) ||
|
||||
_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
||||
!= DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Передача объекта в другую форму
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawingWarship? warship = null;
|
||||
int counter = 100;
|
||||
while (warship == null)
|
||||
{
|
||||
warship = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (warship == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormBattleship form = new()
|
||||
{
|
||||
SetWarship = warship
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перерисовка коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
120
ProjectBattleship/ProjectBattleship/FormWarshipCollection.resx
Normal file
120
ProjectBattleship/ProjectBattleship/FormWarshipCollection.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>
|
@ -9,7 +9,7 @@ namespace ProjectBattleship
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormBattleship());
|
||||
Application.Run(new FormWarshipCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user