laba3 is done

This commit is contained in:
vladimir_zinovev 2023-11-02 20:50:20 +04:00
parent 29e4a164f8
commit 93d33965fe
6 changed files with 97 additions and 44 deletions

View File

@ -84,7 +84,6 @@
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39);
this.maskedTextBoxNumber.TabIndex = 1;
this.maskedTextBoxNumber.TextChanged += new System.EventHandler(this.maskedTextBoxNumber_TextChanged);
//
// ButtonAddArmoredTransport
//

View File

@ -40,7 +40,7 @@ namespace ProjectTank
TankForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_armoredTransports + form.SelectedArmoredTransport)
if (_armoredTransports + form.SelectedArmoredTransport != null)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
@ -84,10 +84,5 @@ namespace ProjectTank
{
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
}
private void maskedTextBoxNumber_TextChanged(object sender, EventArgs e)
{
}
}
}

View File

@ -17,6 +17,10 @@ namespace ProjectTank.Generics
where T : DrawningArmoredTransport
where U : IMoveableObject
{
/// <summary>
/// Коэффициент изменения ширины парковки
/// </summary>
readonly int koefWidth = 2;
/// <summary>
/// Ширина окна прорисовки
/// </summary>
@ -32,7 +36,7 @@ namespace ProjectTank.Generics
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 80;
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
@ -56,13 +60,13 @@ namespace ProjectTank.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(ArmoredTransportsGenericCollection<T, U> collect, T? obj)
public static int operator +(ArmoredTransportsGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
if (obj == null || collect == null)
{
return false;
return -1;
}
return collect?._collection.Insert(obj) ?? false;
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -70,15 +74,14 @@ namespace ProjectTank.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(ArmoredTransportsGenericCollection<T, U> collect, int
pos)
public static bool operator -(ArmoredTransportsGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
T? obj = collect?._collection.Get(pos);
if (obj != null && collect != null)
{
collect._collection.Remove(pos);
return collect._collection.Remove(pos);
}
return obj;
return false;
}
/// <summary>
/// Получение объекта IMoveableObject
@ -108,17 +111,19 @@ namespace ProjectTank.Generics
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
for (int i = 0; i < (_pictureWidth / _placeSizeWidth)/koefWidth; i++) //изменение ширины парковки
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight,
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight,
i * _placeSizeWidth + _placeSizeWidth / 2, j *_placeSizeHeight);
g.DrawString("P", new Font("Courier New", 30.0F), new SolidBrush(Color.Blue),
new Point(i * _placeSizeWidth, (j-1) * _placeSizeHeight));
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
_pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
@ -127,11 +132,18 @@ namespace ProjectTank.Generics
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int width = (_pictureWidth / _placeSizeWidth)/koefWidth; //изменение ширины парковки
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _collection.Count; i++)
{
// TODO получение объекта
// TODO установка позиции
// TODO прорисовка объекта
DrawningArmoredTransport? armoredTransport = _collection.Get(i);
if (armoredTransport != null)
{
int row = height - 1 - (i / width);
int col = width - 1 - (i % width);
armoredTransport.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
armoredTransport.DrawTransport(g);
}
}
}
}

View File

@ -32,12 +32,18 @@ namespace ProjectTank.Generics
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <param name="armoredTransport">Добавляемый автомобиль</param>
/// <returns></returns>
public bool Insert(T car)
public int Insert(T armoredTransport)
{
// TODO вставка в начало набора
return true;
if (_places[Count - 1] != null)
{
return -1;
}
else
{
return Insert(armoredTransport,0);
}
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -45,15 +51,22 @@ namespace ProjectTank.Generics
/// <param name="car">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T car, int position)
public int Insert(T armoredTransport, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
_places[position] = car;
return true;
if (!(position >= 0 && position < Count))
return -1;
if (_places[position] != null)
{
int ind = position;
while (ind < Count && _places[ind] != null)
ind++;
if (ind == Count)
return -1;
for (int i = ind - 1; i >= position; i--)
_places[i + 1] = _places[i];
}
_places[position] = armoredTransport;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
@ -62,9 +75,12 @@ namespace ProjectTank.Generics
/// <returns></returns>
public bool Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
return true;
if (!(position >= 0 && position < Count) || _places[position] == null)
{
return false;
}
_places[position] = null;
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
@ -73,7 +89,10 @@ namespace ProjectTank.Generics
/// <returns></returns>
public T? Get(int position)
{
// TODO проверка позиции
if (!(position >= 0 && position < Count))
{
return null;
}
return _places[position];
}
}

View File

@ -38,6 +38,7 @@
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.ButtonCreateArmoredTransport = new System.Windows.Forms.Button();
this.ButtonStep = new System.Windows.Forms.Button();
this.ButtonSelectArmoredTransport = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit();
this.SuspendLayout();
//
@ -162,11 +163,24 @@
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// ButtonSelectArmoredTransport
//
this.ButtonSelectArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ButtonSelectArmoredTransport.Location = new System.Drawing.Point(664, 806);
this.ButtonSelectArmoredTransport.Margin = new System.Windows.Forms.Padding(6);
this.ButtonSelectArmoredTransport.Name = "ButtonSelectArmoredTransport";
this.ButtonSelectArmoredTransport.Size = new System.Drawing.Size(227, 49);
this.ButtonSelectArmoredTransport.TabIndex = 10;
this.ButtonSelectArmoredTransport.Text = "Выбор";
this.ButtonSelectArmoredTransport.UseVisualStyleBackColor = true;
this.ButtonSelectArmoredTransport.Click += new System.EventHandler(this.ButtonSelectArmoredTransport_Click);
//
// TankForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1445, 881);
this.Controls.Add(this.ButtonSelectArmoredTransport);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.ButtonCreateArmoredTransport);
this.Controls.Add(this.comboBoxStrategy);
@ -197,5 +211,6 @@
private ComboBox comboBoxStrategy;
private Button ButtonCreateArmoredTransport;
private Button ButtonStep;
private Button ButtonSelectArmoredTransport;
}
}

View File

@ -53,9 +53,17 @@ namespace ProjectTank
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO выбор основного цвета
ColorDialog dialogMain = new();
if (dialogMain.ShowDialog() == DialogResult.OK)
{
color = dialogMain.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO выбор дополнительного цвета
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_drawningArmoredTransport = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000),
color, dopColor,Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
@ -73,6 +81,11 @@ namespace ProjectTank
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO âûáîð îñíîâíîãî öâåòà
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), color,
pictureBoxTanks.Width, pictureBoxTanks.Height);
_drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100));
@ -152,7 +165,7 @@ namespace ProjectTank
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectCar_Click(object sender, EventArgs e)
private void ButtonSelectArmoredTransport_Click(object sender, EventArgs e)
{
SelectedArmoredTransport = _drawningArmoredTransport;
DialogResult = DialogResult.OK;