laba3 is done
This commit is contained in:
parent
29e4a164f8
commit
93d33965fe
@ -84,7 +84,6 @@
|
|||||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39);
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39);
|
||||||
this.maskedTextBoxNumber.TabIndex = 1;
|
this.maskedTextBoxNumber.TabIndex = 1;
|
||||||
this.maskedTextBoxNumber.TextChanged += new System.EventHandler(this.maskedTextBoxNumber_TextChanged);
|
|
||||||
//
|
//
|
||||||
// ButtonAddArmoredTransport
|
// ButtonAddArmoredTransport
|
||||||
//
|
//
|
||||||
|
@ -40,7 +40,7 @@ namespace ProjectTank
|
|||||||
TankForm form = new();
|
TankForm form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_armoredTransports + form.SelectedArmoredTransport)
|
if (_armoredTransports + form.SelectedArmoredTransport != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
|
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
|
||||||
@ -84,10 +84,5 @@ namespace ProjectTank
|
|||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
|
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maskedTextBoxNumber_TextChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@ namespace ProjectTank.Generics
|
|||||||
where T : DrawningArmoredTransport
|
where T : DrawningArmoredTransport
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Коэффициент изменения ширины парковки
|
||||||
|
/// </summary>
|
||||||
|
readonly int koefWidth = 2;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна прорисовки
|
/// Ширина окна прорисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -32,7 +36,7 @@ namespace ProjectTank.Generics
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Размер занимаемого объектом места (высота)
|
/// Размер занимаемого объектом места (высота)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _placeSizeHeight = 80;
|
private readonly int _placeSizeHeight = 90;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -56,13 +60,13 @@ namespace ProjectTank.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <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>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
@ -70,15 +74,14 @@ namespace ProjectTank.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="pos"></param>
|
/// <param name="pos"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T? operator -(ArmoredTransportsGenericCollection<T, U> collect, int
|
public static bool operator -(ArmoredTransportsGenericCollection<T, U> collect, int pos)
|
||||||
pos)
|
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect?._collection.Get(pos);
|
||||||
if (obj != null)
|
if (obj != null && collect != null)
|
||||||
{
|
{
|
||||||
collect._collection.Remove(pos);
|
return collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return obj;
|
return false;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта IMoveableObject
|
/// Получение объекта IMoveableObject
|
||||||
@ -108,17 +111,19 @@ namespace ProjectTank.Generics
|
|||||||
private void DrawBackground(Graphics g)
|
private void DrawBackground(Graphics g)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.Black, 3);
|
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 +
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
1; ++j)
|
|
||||||
{
|
{
|
||||||
//линия рамзетки места
|
//линия рамзетки места
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight,
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight,
|
||||||
i * _placeSizeWidth + _placeSizeWidth / 2, 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,
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||||
_pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
_pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -127,11 +132,18 @@ namespace ProjectTank.Generics
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
|
int width = (_pictureWidth / _placeSizeWidth)/koefWidth; //изменение ширины парковки
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
{
|
{
|
||||||
// TODO получение объекта
|
DrawningArmoredTransport? armoredTransport = _collection.Get(i);
|
||||||
// TODO установка позиции
|
if (armoredTransport != null)
|
||||||
// TODO прорисовка объекта
|
{
|
||||||
|
int row = height - 1 - (i / width);
|
||||||
|
int col = width - 1 - (i % width);
|
||||||
|
armoredTransport.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
|
||||||
|
armoredTransport.DrawTransport(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,18 @@ namespace ProjectTank.Generics
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="car">Добавляемый автомобиль</param>
|
/// <param name="armoredTransport">Добавляемый автомобиль</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T car)
|
public int Insert(T armoredTransport)
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
if (_places[Count - 1] != null)
|
||||||
return true;
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Insert(armoredTransport,0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
@ -45,15 +51,22 @@ namespace ProjectTank.Generics
|
|||||||
/// <param name="car">Добавляемый автомобиль</param>
|
/// <param name="car">Добавляемый автомобиль</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T car, int position)
|
public int Insert(T armoredTransport, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (!(position >= 0 && position < Count))
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
return -1;
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
if (_places[position] != null)
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
{
|
||||||
// TODO вставка по позиции
|
int ind = position;
|
||||||
_places[position] = car;
|
while (ind < Count && _places[ind] != null)
|
||||||
return true;
|
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>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
@ -62,9 +75,12 @@ namespace ProjectTank.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
{
|
||||||
return true;
|
return false;
|
||||||
|
}
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта из набора по позиции
|
/// Получение объекта из набора по позиции
|
||||||
@ -73,7 +89,10 @@ namespace ProjectTank.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (!(position >= 0 && position < Count))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
ProjectTank/ProjectTank/TankForm.Designer.cs
generated
15
ProjectTank/ProjectTank/TankForm.Designer.cs
generated
@ -38,6 +38,7 @@
|
|||||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||||
this.ButtonCreateArmoredTransport = new System.Windows.Forms.Button();
|
this.ButtonCreateArmoredTransport = new System.Windows.Forms.Button();
|
||||||
this.ButtonStep = 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();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -162,11 +163,24 @@
|
|||||||
this.ButtonStep.UseVisualStyleBackColor = true;
|
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||||
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
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
|
// TankForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1445, 881);
|
this.ClientSize = new System.Drawing.Size(1445, 881);
|
||||||
|
this.Controls.Add(this.ButtonSelectArmoredTransport);
|
||||||
this.Controls.Add(this.ButtonStep);
|
this.Controls.Add(this.ButtonStep);
|
||||||
this.Controls.Add(this.ButtonCreateArmoredTransport);
|
this.Controls.Add(this.ButtonCreateArmoredTransport);
|
||||||
this.Controls.Add(this.comboBoxStrategy);
|
this.Controls.Add(this.comboBoxStrategy);
|
||||||
@ -197,5 +211,6 @@
|
|||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button ButtonCreateArmoredTransport;
|
private Button ButtonCreateArmoredTransport;
|
||||||
private Button ButtonStep;
|
private Button ButtonStep;
|
||||||
|
private Button ButtonSelectArmoredTransport;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -53,9 +53,17 @@ namespace ProjectTank
|
|||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
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));
|
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),
|
_drawningArmoredTransport = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
color, dopColor,Convert.ToBoolean(random.Next(0, 2)),
|
color, dopColor,Convert.ToBoolean(random.Next(0, 2)),
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
@ -73,6 +81,11 @@ namespace ProjectTank
|
|||||||
Random random = new();
|
Random random = new();
|
||||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
//TODO âûáîð îñíîâíîãî öâåòà
|
//TODO âûáîð îñíîâíîãî öâåòà
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
_drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), color,
|
_drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), color,
|
||||||
pictureBoxTanks.Width, pictureBoxTanks.Height);
|
pictureBoxTanks.Width, pictureBoxTanks.Height);
|
||||||
_drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100));
|
_drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100));
|
||||||
@ -152,7 +165,7 @@ namespace ProjectTank
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonSelectCar_Click(object sender, EventArgs e)
|
private void ButtonSelectArmoredTransport_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SelectedArmoredTransport = _drawningArmoredTransport;
|
SelectedArmoredTransport = _drawningArmoredTransport;
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user