Лабораторная работа №3
This commit is contained in:
parent
3fa56e548d
commit
3ac1dab1c9
@ -56,7 +56,6 @@ public abstract class AbstractCompany
|
||||
{
|
||||
return company._collection.Insert(warship);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезагрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
@ -108,4 +107,3 @@ public abstract class AbstractCompany
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
||||
|
||||
|
@ -64,23 +64,22 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
{
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int nullIndex = -1;
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
nullIndex = i;
|
||||
break;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Если пустого элемента нет, то выходим
|
||||
if (nullIndex < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
int j = nullIndex - 1;
|
||||
while (j >= position)
|
||||
@ -88,7 +87,6 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection[j + 1] = _collection[j];
|
||||
j--;
|
||||
}
|
||||
position--;
|
||||
}
|
||||
// TODO вставка по позиции
|
||||
_collection[position] = obj;
|
||||
|
@ -54,7 +54,7 @@ public class WarshipSharingService : AbstractCompany
|
||||
posWidth = 0;
|
||||
posHeight--;
|
||||
}
|
||||
if (posHeight < 0)
|
||||
if (posHeight > height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Battleship.Entities;
|
||||
//using System.Drawings;
|
||||
|
||||
namespace Battleship.Drawings;
|
||||
/// <summary>
|
||||
|
@ -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,21 +32,21 @@
|
||||
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);
|
||||
@ -89,15 +89,7 @@
|
||||
buttonRemoveWarship.TabIndex = 4;
|
||||
buttonRemoveWarship.Text = "Удалить корабль";
|
||||
buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// 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(274, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
buttonRemoveWarship.Click += buttonRemoveWarship_Click_1;
|
||||
//
|
||||
// buttonAddBattleship
|
||||
//
|
||||
@ -142,6 +134,15 @@
|
||||
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);
|
||||
@ -151,7 +152,6 @@
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormWarshipCollection";
|
||||
Text = "Коллекция кораблей";
|
||||
//Load += this.FormWarshipCollection_Load;
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
@ -161,13 +161,12 @@
|
||||
|
||||
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,8 +55,8 @@ public partial class FormWarshipCollection : Form
|
||||
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)),
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
@ -149,7 +149,7 @@ public partial class FormWarshipCollection : Form
|
||||
/// <param name="e"></param>
|
||||
private void buttonRemoveWarship_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
||||
if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -159,7 +159,7 @@ public partial class FormWarshipCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
int pos = Convert.ToInt32(maskedTextBox1.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
@ -171,36 +171,6 @@ public partial class FormWarshipCollection : Form
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
FormBattleship form = new FormBattleship();
|
||||
form.SetWarship = warship;
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление
|
||||
/// </summary>
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Battleship.MovementStrategy;
|
||||
namespace Battleship.MovementStrategy;
|
||||
|
||||
public interface IMoveableObjectcs
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user