3 lab
This commit is contained in:
parent
595ba18b4a
commit
3d28f936f9
@ -0,0 +1,119 @@
|
|||||||
|
using ProjectBattleship.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBattleship.CollectionGenericObjects;
|
||||||
|
/// <summary>
|
||||||
|
/// Абстракция компании, хранящий коллекцию кораблей
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeWidth = 210;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (высота)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeHeight = 100;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Коллекция кораблей
|
||||||
|
/// </summary>
|
||||||
|
protected ICollectionGenericObjects<DrawingShip>? _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<DrawingShip> collection)
|
||||||
|
{
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.SetMaxCount = GetMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="car">Добавляемый объект</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(AbstractCompany company, DrawingShip ship)
|
||||||
|
{
|
||||||
|
return company._collection.Insert(ship);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора удаления для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="position">Номер удаляемого объекта</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DrawingShip operator -(AbstractCompany company, int position)
|
||||||
|
{
|
||||||
|
return company._collection?.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение случайного объекта из коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DrawingShip? 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);
|
||||||
|
DrawBackground(graphics);
|
||||||
|
|
||||||
|
SetObjectsPosition();
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||||
|
{
|
||||||
|
DrawingShip? obj = _collection?.Get(i);
|
||||||
|
obj?.DrawTransport(graphics);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод заднего фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
protected abstract void DrawBackground(Graphics g);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Расстановка объектов
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void SetObjectsPosition();
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBattleship.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
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>
|
||||||
|
bool 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,109 @@
|
|||||||
|
using ProjectBattleship.Drawnings;
|
||||||
|
using ProjectBattleship.CollectionGenericObjects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
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;
|
||||||
|
/// <summary>
|
||||||
|
/// Установка максимального кол-ва объектов
|
||||||
|
/// </summary>
|
||||||
|
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?>();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция (индекс)</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _collection.Length)
|
||||||
|
return null;
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
public int Insert(T obj)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Length; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public bool Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _collection.Length) // проверка позиции
|
||||||
|
return false;
|
||||||
|
if (_collection[position] == null) // Попытка вставить на указанную позицию
|
||||||
|
{
|
||||||
|
_collection[position] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (int i = position; i < _collection.Length; i++) // попытка вставить объект на позицию после указанной
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < position; i++) // попытка вставить объект на позицию до указанной
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _collection.Length || _collection[position] == null) // проверка позиции и наличия объекта
|
||||||
|
return null;
|
||||||
|
T? temp = _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
using ProjectBattleship.Drawnings;
|
||||||
|
using ProjectBattleship.CollectionGenericObjects;
|
||||||
|
using ProjectBattleship.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.AccessControl;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBattleship.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация абстрактной компании - доки с кораблями
|
||||||
|
/// </summary>
|
||||||
|
public class ShipDocks : AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="collection"></param>
|
||||||
|
public ShipDocks(int picWidth, int picHeight, ICollectionGenericObjects<DrawingShip> collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new Pen(Color.Brown, 4);
|
||||||
|
int x = 0, y = 0;
|
||||||
|
while (y + _placeSizeHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
while (x + _placeSizeWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, x, y, x + _placeSizeWidth, y);
|
||||||
|
g.DrawLine(pen, x, y, x, y + _placeSizeHeight);
|
||||||
|
g.DrawLine(pen, x, y + _placeSizeHeight, x + _placeSizeWidth, y + _placeSizeHeight);
|
||||||
|
x += _placeSizeWidth + 50;
|
||||||
|
}
|
||||||
|
y += _placeSizeHeight;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetObjectsPosition()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (int iy = _placeSizeHeight * 11 + 5; iy >= 0; iy -= _placeSizeHeight)
|
||||||
|
{
|
||||||
|
for (int ix = 5; ix + _placeSizeWidth + 50 < _pictureWidth; ix += _placeSizeWidth + 50)
|
||||||
|
{
|
||||||
|
_collection?.Get(count)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection?.Get(count)?.SetPosition(ix, iy);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectBattleship
|
namespace ProjectBattleship.Drawnings
|
||||||
{
|
{
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
using ProjectBattleship.Entities;
|
using ProjectBattleship.Entities;
|
||||||
|
|
||||||
namespace ProjectBattleship.Drawning;
|
namespace ProjectBattleship.Drawnings;
|
||||||
public class DrawingBattleship : DrawingShip
|
public class DrawingBattleship : DrawingShip
|
||||||
{
|
{
|
||||||
public DrawingBattleship(int speed, double weight, Color bodyColor, Color additionalColor, bool turret, bool rocketLauncher) : base(150, 50)
|
public DrawingBattleship(int speed, double weight, Color bodyColor, Color additionalColor, bool turret, bool rocketLauncher) : base(150, 50)
|
@ -1,6 +1,6 @@
|
|||||||
using ProjectBattleship.Entities;
|
using ProjectBattleship.Entities;
|
||||||
|
|
||||||
namespace ProjectBattleship.Drawning;
|
namespace ProjectBattleship.Drawnings;
|
||||||
public class DrawingShip
|
public class DrawingShip
|
||||||
{
|
{
|
||||||
public EntityShip? EntityShip { get; protected set; }
|
public EntityShip? EntityShip { get; protected set; }
|
@ -30,12 +30,10 @@
|
|||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBattleship));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBattleship));
|
||||||
pictureBoxBattleship = new PictureBox();
|
pictureBoxBattleship = new PictureBox();
|
||||||
buttonCreate = new Button();
|
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonCreateShip = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonStrategyStep = new Button();
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxBattleship).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxBattleship).BeginInit();
|
||||||
@ -52,17 +50,6 @@
|
|||||||
pictureBoxBattleship.TabIndex = 0;
|
pictureBoxBattleship.TabIndex = 0;
|
||||||
pictureBoxBattleship.TabStop = false;
|
pictureBoxBattleship.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
|
||||||
//
|
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreate.Location = new Point(38, 500);
|
|
||||||
buttonCreate.Name = "buttonCreate";
|
|
||||||
buttonCreate.Size = new Size(121, 62);
|
|
||||||
buttonCreate.TabIndex = 1;
|
|
||||||
buttonCreate.Text = "Создать линкор";
|
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreate.Click += buttonCreate_Click;
|
|
||||||
//
|
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
@ -111,17 +98,6 @@
|
|||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonCreateShip
|
|
||||||
//
|
|
||||||
buttonCreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreateShip.Location = new Point(212, 500);
|
|
||||||
buttonCreateShip.Name = "buttonCreateShip";
|
|
||||||
buttonCreateShip.Size = new Size(121, 62);
|
|
||||||
buttonCreateShip.TabIndex = 6;
|
|
||||||
buttonCreateShip.Text = "Создать корабль";
|
|
||||||
buttonCreateShip.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateShip.Click += buttonCreateShip_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
// comboBoxStrategy
|
||||||
//
|
//
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
@ -149,12 +125,10 @@
|
|||||||
ClientSize = new Size(922, 598);
|
ClientSize = new Size(922, 598);
|
||||||
Controls.Add(buttonStrategyStep);
|
Controls.Add(buttonStrategyStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonCreateShip);
|
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonCreate);
|
|
||||||
Controls.Add(pictureBoxBattleship);
|
Controls.Add(pictureBoxBattleship);
|
||||||
Name = "FormBattleship";
|
Name = "FormBattleship";
|
||||||
Text = "Линкор";
|
Text = "Линкор";
|
||||||
@ -166,12 +140,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxBattleship;
|
private PictureBox pictureBoxBattleship;
|
||||||
private Button buttonCreate;
|
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonCreateShip;
|
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStrategyStep;
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using ProjectBattleship.Drawning;
|
using ProjectBattleship.Drawnings;
|
||||||
using ProjectBattleship.MovementStrategy;
|
using ProjectBattleship.MovementStrategy;
|
||||||
using ProjectBattleship.MovementStrateg;
|
|
||||||
|
|
||||||
namespace ProjectBattleship
|
namespace ProjectBattleship
|
||||||
{
|
{
|
||||||
@ -13,6 +12,17 @@ namespace ProjectBattleship
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_strategy = null;
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
public DrawingShip SetShip
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawingShip = value;
|
||||||
|
_drawingShip.SetPictureSize(pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawingShip == null)
|
if (_drawingShip == null)
|
||||||
@ -24,31 +34,6 @@ namespace ProjectBattleship
|
|||||||
_drawingShip.DrawTransport(gr);
|
_drawingShip.DrawTransport(gr);
|
||||||
pictureBoxBattleship.Image = bmp;
|
pictureBoxBattleship.Image = bmp;
|
||||||
}
|
}
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawingShip):
|
|
||||||
_drawingShip = new DrawingShip(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):
|
|
||||||
_drawingShip = 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;
|
|
||||||
}
|
|
||||||
_drawingShip.SetPictureSize(pictureBoxBattleship.Width, pictureBoxBattleship.Height);
|
|
||||||
_drawingShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
private void buttonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBattleship));
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawingShip == null)
|
if (_drawingShip == null)
|
||||||
@ -81,7 +66,6 @@ namespace ProjectBattleship
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void buttonCreateShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingShip));
|
|
||||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawingShip == null)
|
if (_drawingShip == null)
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAB44AAAOdCAYAAAB6bE8jAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAB44AAAOdCAYAAAB6bE8jAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAAahtJREFUeF7s3V+MnXW99/0JIcYQY2rtXH/X/Ok4ljKdmc4MxhBjjDHGGLNjdnY8
|
vwAADr8BOAVTJAAAahtJREFUeF7s3V+MnXW99/0JIcYQY2rtXH/X/Ok4ljKdmc4MxhBjjDHGGLNjdnY8
|
||||||
eA7u7EMOnoN9SO4z4iGHHvbANO261hQGEbACKmI3GCKGiOE2hJjG26cCIgICYsFSy/VcA617XOsH9M/M
|
eA7u7EMOnoN9SO4z4iGHHvbANO261hQGEbACKmI3GCKGiOE2hJjG26cCIgICYsFSy/VcA617XOsH9M/M
|
||||||
rN+11uudvA7uvRWms9a6muxPvveakCRJktrQ8TSdvX1i4rqL/09JkiRJkiRJkiRJ0jjVy8pvVWnx6sbC
|
rN+11uudvA7uvRWms9a6muxPvveakCRJktrQ8TSdvX1i4rqL/09JkiRJkiRJkiRJ0jjVy8pvVWnx6sbC
|
||||||
wscu/o8kSZIkSZIkSZIkSePQepIkvbS4t0qLepPhWJIkSZIkSZIkSZLGqItXxi9fGo0Nx5IkSZIkSZIk
|
wscu/o8kSZIkSZIkSZIkSePQepIkvbS4t0qLepPhWJIkSZIkSZIkSZLGqItXxi9fGo0Nx5IkSZIkSZIk
|
||||||
@ -580,7 +580,7 @@
|
|||||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAA50AAAeOCAYAAAB3IVJsAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAA50AAAeOCAYAAAB3IVJsAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAAg6NJREFUeF7s/V2MZXWd939XiCGGGINM135Ye9cDbdk0/VBdVZiJMcaYiTHGTIwx
|
vwAADr8BOAVTJAAAg6NJREFUeF7s/V2MZXWd939XiCGGGINM135Ye9cDbdk0/VBdVZiJMcaYiTHGTIwx
|
||||||
HvwPJnPIwX0wh+Q6I3PI4Rz2gSHdu3Y1FCIiAiJiD0yIGCOGvyHEEC//LSIiICA22LTNvtfuXjOjmx9N
|
HvwPJnPIwX0wh+Q6I3PI4Rz2gSHdu3Y1FCIiAiJiD0yIGCOGvyHEEC//LSIiICA22LTNvtfuXjOjmx9N
|
||||||
P6z1++29f6938sqd+3/NKHRX7bU+yffa14IkSbq8RtX/ryRJkiRJtTZoF//Pdqf4/1X/fyVJkiRJqqdj
|
P6z1++29f6938sqd+3/NKHRX7bU+yffa14IkSbq8RtX/ryRJkiRJtTZoF//Pdqf4/1X/fyVJkiRJqqdj
|
||||||
3e7ydrt4rfTWYM9Kp/r/LEmSJEnS1XX7wsI15dh8tDSq3F/9H0mSJEmSdHUNO8VtfzM4zxt2et+o/o8l
|
3e7ydrt4rfTWYM9Kp/r/LEmSJEnS1XX7wsI15dh8tDSq3F/9H0mSJEmSdHUNO8VtfzM4zxt2et+o/o8l
|
||||||
@ -1148,7 +1148,7 @@
|
|||||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAA50AAAeOCAYAAAB3IVJsAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAA50AAAeOCAYAAAB3IVJsAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAAgjRJREFUeF7s3F+MZQWZ7/0KIYYYQ5Dp3n/W3lVdtG3T9J/qqsJMjDHGTIwxZmIm
|
vwAADr8BOAVTJAAAgjRJREFUeF7s3F+MZQWZ7/0KIYYYQ5Dp3n/W3lVdtG3T9J/qqsJMjDHGTIwxZmIm
|
||||||
Ey8n55LLuSTnzswll3PZF4bQu3Y1FiIiAiI6DEyIGiMTX0OMIRyDioiIDSK00Db73dWsmXF2LxvoXms9
|
Ey8n55LLuSTnzswll3PZF4bQu3Y1FiIiAiI6DEyIGiMTX0OMIRyDioiIDSK00Db73dWsmXF2LxvoXms9
|
||||||
u/bz+Safq/e8R4WqtdYv50ktSZIkSZIkaY7b6g7+bqs3+CIAsCh6nytf85IkxbfVKX601S0mAMCiGDxb
|
u/bz+Safq/e8R4WqtdYv50ktSZIkSZIkaY7b6g7+bqs3+CIAsCh6nytf85IkxbfVKX601S0mAMCiGDxb
|
||||||
vuYlSYrP6ASARWN0SpLmKKMTABaN0SlJmqOMTgBYNEanJGmOMjoBYNEYnZKkOcroBIBFY3RKkuYooxMA
|
vuYlSYrP6ASARWN0SpLmKKMTABaN0SlJmqOMTgBYNEanJGmOMjoBYNEYnZKkOcroBIBFY3RKkuYooxMA
|
||||||
@ -1710,7 +1710,7 @@
|
|||||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAB44AAAOdCAYAAAB6bE8jAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAB44AAAOdCAYAAAB6bE8jAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAAZi5JREFUeF7s3V2MnXW99/8JIcQQY7DOrHU9rHnoMLZlHtesmh1jDDHGGGOMMcaD
|
vwAADr8BOAVTJAAAZi5JREFUeF7s3V2MnXW99/8JIcQQY7DOrHU9rHnoMLZlHtesmh1jDDHGGGOMMcaD
|
||||||
/8HOPuTgf+Ah2WfEQw497IFp2jVrClMKQoUKiBUMEUPEcJOGmIbbfwWslYeCpdS2ttd/1vRXQb0KnXZm
|
/8HOPuTgf+Ah2WfEQw497IFp2jVrClMKQoUKiBUMEUPEcJOGmIbbfwWslYeCpdS2ttd/1vRXQb0KnXZm
|
||||||
1u9a6/VOXgf3vd3Qzqxr7WR/8t3XkCRJkiRJkiRJkiRJkiRJkiRJkja4+4aGbtlfr0+E/6ckSZIkSZIk
|
1u9a6/VOXgf3vd3Qzqxr7WR/8t3XkCRJkiRJkiRJkiRJkiRJkiRJkja4+4aGbtlfr0+E/6ckSZIkSZIk
|
||||||
SZIkadBamZ6+bamenesk2b0rQ0O3hP9vSZIkSZIkSZIkSdKgFIbjInh+33C+I/yXJEmSJEmSJEmSJEmD
|
SZIkadBamZ6+bamenesk2b0rQ0O3hP9vSZIkSZIkSZIkSdKgFIbjInh+33C+I/yXJEmSJEmSJEmSJEmD
|
||||||
|
174
ProjectBattleship/ProjectBattleship/FormShipCollection.Designer.cs
generated
Normal file
174
ProjectBattleship/ProjectBattleship/FormShipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
namespace Battleship
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
Tools = new GroupBox();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
buttonGoToTest = new Button();
|
||||||
|
buttonDelShip = new Button();
|
||||||
|
maskedTextBox = new MaskedTextBox();
|
||||||
|
buttonAddBettleship = new Button();
|
||||||
|
buttonAddShip = new Button();
|
||||||
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
Tools.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// Tools
|
||||||
|
//
|
||||||
|
Tools.Controls.Add(buttonRefresh);
|
||||||
|
Tools.Controls.Add(buttonGoToTest);
|
||||||
|
Tools.Controls.Add(buttonDelShip);
|
||||||
|
Tools.Controls.Add(maskedTextBox);
|
||||||
|
Tools.Controls.Add(buttonAddBettleship);
|
||||||
|
Tools.Controls.Add(buttonAddShip);
|
||||||
|
Tools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
Tools.Dock = DockStyle.Right;
|
||||||
|
Tools.Location = new Point(1605, 0);
|
||||||
|
Tools.Name = "Tools";
|
||||||
|
Tools.Size = new Size(488, 1236);
|
||||||
|
Tools.TabIndex = 0;
|
||||||
|
Tools.TabStop = false;
|
||||||
|
Tools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRefresh.Location = new Point(14, 1134);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(468, 90);
|
||||||
|
buttonRefresh.TabIndex = 6;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonGoToTest
|
||||||
|
//
|
||||||
|
buttonGoToTest.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonGoToTest.Location = new Point(6, 768);
|
||||||
|
buttonGoToTest.Name = "buttonGoToTest";
|
||||||
|
buttonGoToTest.Size = new Size(476, 90);
|
||||||
|
buttonGoToTest.TabIndex = 5;
|
||||||
|
buttonGoToTest.Text = "Передать на тест";
|
||||||
|
buttonGoToTest.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToTest.Click += ButtonGoToTest_Click;
|
||||||
|
//
|
||||||
|
// buttonDelShip
|
||||||
|
//
|
||||||
|
buttonDelShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonDelShip.Location = new Point(6, 573);
|
||||||
|
buttonDelShip.Name = "buttonDelShip";
|
||||||
|
buttonDelShip.Size = new Size(476, 90);
|
||||||
|
buttonDelShip.TabIndex = 4;
|
||||||
|
buttonDelShip.Text = "Удалить корабль";
|
||||||
|
buttonDelShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelShip.Click += ButtonDelShip_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBox
|
||||||
|
//
|
||||||
|
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
maskedTextBox.Location = new Point(6, 520);
|
||||||
|
maskedTextBox.Mask = "00";
|
||||||
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
|
maskedTextBox.Size = new Size(476, 39);
|
||||||
|
maskedTextBox.TabIndex = 3;
|
||||||
|
maskedTextBox.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonAddBettleship
|
||||||
|
//
|
||||||
|
buttonAddBettleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddBettleship.Location = new Point(6, 283);
|
||||||
|
buttonAddBettleship.Name = "buttonAddBettleship";
|
||||||
|
buttonAddBettleship.Size = new Size(476, 90);
|
||||||
|
buttonAddBettleship.TabIndex = 2;
|
||||||
|
buttonAddBettleship.Text = "Добавить боевой корабль";
|
||||||
|
buttonAddBettleship.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddBettleship.Click += ButtonAddBattleship_Click;
|
||||||
|
//
|
||||||
|
// buttonAddShip
|
||||||
|
//
|
||||||
|
buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddShip.Location = new Point(6, 172);
|
||||||
|
buttonAddShip.Name = "buttonAddShip";
|
||||||
|
buttonAddShip.Size = new Size(476, 90);
|
||||||
|
buttonAddShip.TabIndex = 1;
|
||||||
|
buttonAddShip.Text = "Добавить корабль";
|
||||||
|
buttonAddShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddShip.Click += buttonAddShip_Click_1;
|
||||||
|
//
|
||||||
|
// 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, 38);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(476, 40);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(1605, 1236);
|
||||||
|
pictureBox.TabIndex = 1;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormShipCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(2093, 1236);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(Tools);
|
||||||
|
Name = "FormShipCollection";
|
||||||
|
Text = "Коллекция кораблей";
|
||||||
|
Tools.ResumeLayout(false);
|
||||||
|
Tools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox Tools;
|
||||||
|
private Button buttonAddBettleship;
|
||||||
|
private Button buttonAddShip;
|
||||||
|
private ComboBox comboBoxSelectorCompany;
|
||||||
|
private Button buttonDelShip;
|
||||||
|
private MaskedTextBox maskedTextBox;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
private Button buttonGoToTest;
|
||||||
|
}
|
||||||
|
}
|
167
ProjectBattleship/ProjectBattleship/FormShipCollection.cs
Normal file
167
ProjectBattleship/ProjectBattleship/FormShipCollection.cs
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
using ProjectBattleship;
|
||||||
|
using ProjectBattleship.CollectionGenericObjects;
|
||||||
|
using ProjectBattleship.Drawnings;
|
||||||
|
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 Battleship;
|
||||||
|
|
||||||
|
public partial class FormShipCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Компания
|
||||||
|
/// </summary>
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormShipCollection()
|
||||||
|
{
|
||||||
|
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 ShipDocks(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingShip>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new();
|
||||||
|
DrawingShip drawningShip;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawingShip):
|
||||||
|
drawningShip = new DrawingShip(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||||
|
break;
|
||||||
|
case nameof(DrawingBattleship):
|
||||||
|
drawningShip = 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 + drawningShip != -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, 255), random.Next(0, 255), random.Next(0, 255));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelShip_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 ButtonGoToTest_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawingShip? ship = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (ship == null)
|
||||||
|
{
|
||||||
|
ship = _company.GetRandomObject();
|
||||||
|
counter--;
|
||||||
|
if (counter <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ship == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormBattleship form = new()
|
||||||
|
{
|
||||||
|
SetShip = ship
|
||||||
|
};
|
||||||
|
form.ShowDialog();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
private void ButtonAddBattleship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBattleship));
|
||||||
|
|
||||||
|
private void buttonAddShip_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawingShip));
|
||||||
|
}
|
120
ProjectBattleship/ProjectBattleship/FormShipCollection.resx
Normal file
120
ProjectBattleship/ProjectBattleship/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>
|
@ -1,6 +1,4 @@
|
|||||||
using ProjectBattleship.MovementStrateg;
|
namespace ProjectBattleship.MovementStrategy;
|
||||||
|
|
||||||
namespace ProjectBattleship.MovementStrategy;
|
|
||||||
public abstract class AbstractStrategy
|
public abstract class AbstractStrategy
|
||||||
{
|
{
|
||||||
private IMoveableObject? _moveableObject;
|
private IMoveableObject? _moveableObject;
|
@ -1,4 +1,4 @@
|
|||||||
using ProjectBattleship.Drawning;
|
using ProjectBattleship.Drawnings;
|
||||||
|
|
||||||
namespace ProjectBattleship.MovementStrategy;
|
namespace ProjectBattleship.MovementStrategy;
|
||||||
public class MoveableShip : IMoveableObject
|
public class MoveableShip : IMoveableObject
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectBattleship.MovementStrateg
|
namespace ProjectBattleship.MovementStrategy
|
||||||
{
|
{
|
||||||
public enum StrategyStatus
|
public enum StrategyStatus
|
||||||
{
|
{
|
@ -1,3 +1,5 @@
|
|||||||
|
using Battleship;
|
||||||
|
|
||||||
namespace ProjectBattleship
|
namespace ProjectBattleship
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -11,7 +13,7 @@ namespace ProjectBattleship
|
|||||||
// 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 FormBattleship());
|
Application.Run(new FormShipCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user