Compare commits
No commits in common. "3ac1dab1c97c86e9826854eccf30d044681809c2" and "3b0784dd0b27fa1e35fa4aad6aa43725bf022d54" have entirely different histories.
3ac1dab1c9
...
3b0784dd0b
@ -7,7 +7,7 @@ public abstract class AbstractCompany
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 238;
|
||||
protected readonly int _placeSizeWidth = 210;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
@ -29,7 +29,7 @@ public abstract class AbstractCompany
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight) + 2;
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _pictureHeight);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -52,19 +52,20 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="car">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawingWarship warship)
|
||||
public static bool operator +(AbstractCompany company, DrawingWarship car)
|
||||
{
|
||||
return company._collection.Insert(warship);
|
||||
return company._collection?.Insert(car) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезагрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawingWarship operator -(AbstractCompany company, int position)
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection.Remove(position);
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -88,7 +89,7 @@ public abstract class AbstractCompany
|
||||
DrawBackground(graphics);
|
||||
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
DrawingWarship? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
@ -106,4 +107,5 @@ public abstract class AbstractCompany
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public interface ICollectionGenericObjects<T>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// Установка минимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
|
||||
@ -23,7 +23,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
bool Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
@ -31,14 +31,14 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
bool Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int position);
|
||||
bool Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
@ -46,4 +46,4 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
using Battleship.CollectionGenericObjects;
|
||||
|
||||
//namespace Battleship.CollectionGenericObjects;
|
||||
namespace Battleship.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// Параметрированный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// Массив объектов, которые хранили
|
||||
/// </summary>
|
||||
private T?[] _collection;
|
||||
|
||||
@ -23,86 +21,76 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
_collection = Array.Empty<T>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= _collection.Length || position < 0)
|
||||
//TODO проверка позиции
|
||||
if(position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
//TODO вставка в свободное место набора
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
return true;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// TODO вставка
|
||||
if (position >= _collection.Length || position < 0)
|
||||
return -1;
|
||||
return false;
|
||||
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
if (_collection[position] != null)
|
||||
while (position + 1 < _collection.Length)
|
||||
{
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int nullIndex = -1;
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
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 true;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
// TODO вставка по позиции
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
|
||||
while (position - 1 >= 0)
|
||||
{
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return true;
|
||||
}
|
||||
position--;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
T temp = _collection[position];
|
||||
_collection[position] = null;
|
||||
return temp;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -2,24 +2,16 @@
|
||||
|
||||
namespace Battleship.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация абстрактной компании - доки
|
||||
/// </summary>
|
||||
public class WarshipSharingService : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
|
||||
public WarshipSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawingWarship> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.DarkSlateBlue, 4);
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j <= _pictureHeight / _placeSizeHeight; j++)
|
||||
@ -30,21 +22,20 @@ public class WarshipSharingService : AbstractCompany
|
||||
}
|
||||
}
|
||||
|
||||
//установка объектов
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int posWidth = 0;
|
||||
int posHeight = height - 1;
|
||||
int posHeight = height;
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection?.Get(i) != null)
|
||||
{
|
||||
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i)?.SetPosition(_placeSizeWidth * posWidth + 4, posHeight * _placeSizeHeight + 4);
|
||||
_collection?.Get(i)?.SetPosition(_placeSizeWidth * posWidth + 4, posHeight * _placeSizeHeight + 4, width, height);
|
||||
}
|
||||
|
||||
if (posWidth < width)
|
||||
@ -54,7 +45,7 @@ public class WarshipSharingService : AbstractCompany
|
||||
posWidth = 0;
|
||||
posHeight--;
|
||||
}
|
||||
if (posHeight > height)
|
||||
if (posHeight < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Battleship.Entities;
|
||||
//using System.Drawings;
|
||||
|
||||
namespace Battleship.Drawings;
|
||||
/// <summary>
|
||||
@ -16,7 +17,9 @@ public class DrawingBattleship : DrawingWarship
|
||||
/// <param name="bodyDeck">Признак наличия палубы</param>
|
||||
/// <param name="compartment">Признак наличия отсека для ракет</param>
|
||||
/// <param name="tower">Признак наличия башни</param>
|
||||
public DrawingBattleship(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyDeck, bool compartment, bool tower) : base(129, 80)
|
||||
///
|
||||
|
||||
public DrawingBattleship(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyDeck, bool compartment, bool tower) : base(129, 60)
|
||||
{
|
||||
EntityWarship = new EntityBattleship(speed, weight, bodyColor, compartment, tower, bodyDeck, additionalColor);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class DrawingWarship
|
||||
/// <summary>
|
||||
/// Высота прорисовки военного корабля
|
||||
/// </summary>
|
||||
private readonly int _drawingWarshipHeight = 80;
|
||||
private readonly int _drawingWarshipHeight = 40;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Х объекта
|
||||
@ -135,7 +135,7 @@ public class DrawingWarship
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
{
|
||||
@ -238,7 +238,7 @@ public class DrawingWarship
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 7, 5, 10); //верхний
|
||||
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 22, 5, 10); //нижний
|
||||
//границы двигателей
|
||||
//границы двигателей
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 7, 5, 10); //двигатель верхний
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 22, 5, 10); //двигатель нижний
|
||||
|
||||
|
@ -32,28 +32,28 @@
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveWarship = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddBattleship = new Button();
|
||||
buttonAddWarship = new Button();
|
||||
comboBoxSelectionCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
maskedTextBox1 = new MaskedTextBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(maskedTextBox1);
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonRemoveWarship);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddBattleship);
|
||||
groupBoxTools.Controls.Add(buttonAddWarship);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectionCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(861, 0);
|
||||
groupBoxTools.Location = new Point(706, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(292, 583);
|
||||
groupBoxTools.Size = new Size(273, 594);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
@ -63,18 +63,18 @@
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(12, 477);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(274, 42);
|
||||
buttonRefresh.Size = new Size(255, 42);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
buttonRefresh.Click += buttonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(12, 381);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(274, 42);
|
||||
buttonGoToCheck.Size = new Size(255, 42);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@ -85,33 +85,41 @@
|
||||
buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveWarship.Location = new Point(12, 283);
|
||||
buttonRemoveWarship.Name = "buttonRemoveWarship";
|
||||
buttonRemoveWarship.Size = new Size(274, 42);
|
||||
buttonRemoveWarship.Size = new Size(255, 42);
|
||||
buttonRemoveWarship.TabIndex = 4;
|
||||
buttonRemoveWarship.Text = "Удалить корабль";
|
||||
buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||
buttonRemoveWarship.Click += buttonRemoveWarship_Click_1;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBox.Location = new Point(12, 238);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(255, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
//
|
||||
// buttonAddBattleship
|
||||
//
|
||||
buttonAddBattleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddBattleship.Location = new Point(12, 143);
|
||||
buttonAddBattleship.Name = "buttonAddBattleship";
|
||||
buttonAddBattleship.Size = new Size(274, 42);
|
||||
buttonAddBattleship.Size = new Size(255, 42);
|
||||
buttonAddBattleship.TabIndex = 2;
|
||||
buttonAddBattleship.Text = "Добавление линкора";
|
||||
buttonAddBattleship.UseVisualStyleBackColor = true;
|
||||
buttonAddBattleship.Click += ButtonAddBattleship_Click;
|
||||
buttonAddBattleship.Click += buttonAddBattleship_Click;
|
||||
//
|
||||
// buttonAddWarship
|
||||
//
|
||||
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddWarship.Location = new Point(12, 95);
|
||||
buttonAddWarship.Name = "buttonAddWarship";
|
||||
buttonAddWarship.Size = new Size(274, 42);
|
||||
buttonAddWarship.Size = new Size(255, 42);
|
||||
buttonAddWarship.TabIndex = 1;
|
||||
buttonAddWarship.Text = "Добавление корабля";
|
||||
buttonAddWarship.UseVisualStyleBackColor = true;
|
||||
buttonAddWarship.Click += ButtonAddWarship_Click;
|
||||
buttonAddWarship.Click += buttonAddWarship_Click;
|
||||
//
|
||||
// comboBoxSelectionCompany
|
||||
//
|
||||
@ -121,7 +129,7 @@
|
||||
comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectionCompany.Location = new Point(12, 26);
|
||||
comboBoxSelectionCompany.Name = "comboBoxSelectionCompany";
|
||||
comboBoxSelectionCompany.Size = new Size(274, 28);
|
||||
comboBoxSelectionCompany.Size = new Size(255, 28);
|
||||
comboBoxSelectionCompany.TabIndex = 0;
|
||||
comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
@ -130,28 +138,20 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(861, 583);
|
||||
pictureBox.Size = new Size(706, 594);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// maskedTextBox1
|
||||
//
|
||||
maskedTextBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBox1.Location = new Point(12, 250);
|
||||
maskedTextBox1.Mask = "00";
|
||||
maskedTextBox1.Name = "maskedTextBox1";
|
||||
maskedTextBox1.Size = new Size(274, 27);
|
||||
maskedTextBox1.TabIndex = 7;
|
||||
//
|
||||
// FormWarshipCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1153, 583);
|
||||
ClientSize = new Size(979, 594);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormWarshipCollection";
|
||||
Text = "Коллекция кораблей";
|
||||
//Load += this.FormWarshipCollection_Load;
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
@ -161,12 +161,13 @@
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectionCompany;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonAddBattleship;
|
||||
private Button buttonAddWarship;
|
||||
private Button buttonRemoveWarship;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
private MaskedTextBox maskedTextBox1;
|
||||
}
|
||||
}
|
@ -55,15 +55,15 @@ public partial class FormWarshipCollection : Form
|
||||
break;
|
||||
case nameof(DrawingBattleship):
|
||||
drawingWarship = new DrawingBattleship(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
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)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawingWarship != -1)
|
||||
if (_company + drawingWarship)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -90,6 +90,55 @@ public partial class FormWarshipCollection : Form
|
||||
return color;
|
||||
}
|
||||
|
||||
/// <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="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 ButtonRemoveCar_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)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передача на тесты
|
||||
/// </summary>
|
||||
@ -103,8 +152,8 @@ public partial class FormWarshipCollection : Form
|
||||
}
|
||||
|
||||
DrawingWarship? warship = null;
|
||||
int counter = 120;
|
||||
while (warship == null)
|
||||
int counter = 100;
|
||||
while (warship == null)
|
||||
{
|
||||
warship = _company.GetRandomObject();
|
||||
counter--;
|
||||
@ -114,69 +163,18 @@ public partial class FormWarshipCollection : Form
|
||||
}
|
||||
}
|
||||
|
||||
FormBattleship form = new()
|
||||
{
|
||||
SetWarship = warship
|
||||
};
|
||||
FormBattleship form = new FormBattleship();
|
||||
form.SetWarship = warship;
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
/// <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="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 buttonRemoveWarship_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox1.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 ButtonRefresh_Click(object sender, EventArgs e)
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
|
@ -1,4 +1,10 @@
|
||||
namespace Battleship.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Battleship.MovementStrategy;
|
||||
|
||||
public interface IMoveableObjectcs
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user