Готовая 3 лаба
This commit is contained in:
parent
28f3d56a17
commit
e8df20e0eb
@ -79,11 +79,11 @@ namespace Tank.DrawingObjects
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _ArmoredcarWidth = 100;
|
||||
protected readonly int _ArmoredcarWidth = 150;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _ArmoredcarHeight = 55;
|
||||
protected readonly int _ArmoredcarHeight = 65;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -203,7 +203,7 @@ namespace Tank.DrawingObjects
|
||||
//кузов
|
||||
Brush br = new SolidBrush(Tank.BodyColor);
|
||||
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
|
||||
g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
|
||||
g.FillRectangle(br, _startPosX + 30, _startPosY + 3, 50, 13);
|
||||
|
||||
// колеса
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
|
22
Tank/Tank/FormArmoredCarCollection.Designer.cs
generated
22
Tank/Tank/FormArmoredCarCollection.Designer.cs
generated
@ -44,25 +44,25 @@
|
||||
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.groupBox1.Controls.Add(this.ButtonRemoveArmoredCar);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddArmoredCar);
|
||||
this.groupBox1.Location = new System.Drawing.Point(546, 12);
|
||||
this.groupBox1.Location = new System.Drawing.Point(579, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(242, 383);
|
||||
this.groupBox1.Size = new System.Drawing.Size(200, 426);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(37, 78);
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(36, 85);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 23);
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(129, 23);
|
||||
this.maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(16, 174);
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(7, 160);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(210, 34);
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(187, 31);
|
||||
this.ButtonRefreshCollection.TabIndex = 2;
|
||||
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
@ -70,9 +70,9 @@
|
||||
//
|
||||
// ButtonRemoveArmoredCar
|
||||
//
|
||||
this.ButtonRemoveArmoredCar.Location = new System.Drawing.Point(17, 131);
|
||||
this.ButtonRemoveArmoredCar.Location = new System.Drawing.Point(7, 114);
|
||||
this.ButtonRemoveArmoredCar.Name = "ButtonRemoveArmoredCar";
|
||||
this.ButtonRemoveArmoredCar.Size = new System.Drawing.Size(210, 34);
|
||||
this.ButtonRemoveArmoredCar.Size = new System.Drawing.Size(187, 40);
|
||||
this.ButtonRemoveArmoredCar.TabIndex = 1;
|
||||
this.ButtonRemoveArmoredCar.Text = "Удалить бронированную машину";
|
||||
this.ButtonRemoveArmoredCar.UseVisualStyleBackColor = true;
|
||||
@ -80,9 +80,9 @@
|
||||
//
|
||||
// ButtonAddArmoredCar
|
||||
//
|
||||
this.ButtonAddArmoredCar.Location = new System.Drawing.Point(17, 22);
|
||||
this.ButtonAddArmoredCar.Location = new System.Drawing.Point(7, 22);
|
||||
this.ButtonAddArmoredCar.Name = "ButtonAddArmoredCar";
|
||||
this.ButtonAddArmoredCar.Size = new System.Drawing.Size(210, 34);
|
||||
this.ButtonAddArmoredCar.Size = new System.Drawing.Size(187, 42);
|
||||
this.ButtonAddArmoredCar.TabIndex = 0;
|
||||
this.ButtonAddArmoredCar.Text = "Добавить бронированную машину";
|
||||
this.ButtonAddArmoredCar.UseVisualStyleBackColor = true;
|
||||
@ -92,7 +92,7 @@
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(1, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(539, 395);
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(572, 438);
|
||||
this.pictureBoxCollection.TabIndex = 1;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
|
@ -20,8 +20,8 @@ namespace Tank
|
||||
public FormArmoredCarCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_tanks = new TanksGenericCollection<DrawingArmoredCar,
|
||||
DrawingObjectArmoredCar>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_tanks = new TanksGenericCollection<DrawingArmoredCar, DrawingObjectArmoredCar>
|
||||
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
|
||||
private void ButtonAddArmoredCar_Click(object sender, EventArgs e)
|
||||
@ -29,7 +29,7 @@ DrawingObjectArmoredCar>(pictureBoxCollection.Width, pictureBoxCollection.Height
|
||||
FormTank form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_tanks + form.SelectedTank)
|
||||
if (_tanks + form.SelectedTank != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _tanks.ShowTanks();
|
||||
@ -39,7 +39,6 @@ DrawingObjectArmoredCar>(pictureBoxCollection.Width, pictureBoxCollection.Height
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonRemoveArmoredCar_Click(object sender, EventArgs e)
|
||||
|
14
Tank/Tank/FormTank.Designer.cs
generated
14
Tank/Tank/FormTank.Designer.cs
generated
@ -37,6 +37,7 @@
|
||||
this.buttonCreateArmoredCar = new System.Windows.Forms.Button();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonSelectTank = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -136,11 +137,22 @@
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboBoxStrategy.TabIndex = 10;
|
||||
//
|
||||
// ButtonSelectTank
|
||||
//
|
||||
this.ButtonSelectTank.Location = new System.Drawing.Point(737, 113);
|
||||
this.ButtonSelectTank.Name = "ButtonSelectTank";
|
||||
this.ButtonSelectTank.Size = new System.Drawing.Size(117, 23);
|
||||
this.ButtonSelectTank.TabIndex = 11;
|
||||
this.ButtonSelectTank.Text = "Выбор машины";
|
||||
this.ButtonSelectTank.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectTank.Click += new System.EventHandler(this.ButtonSelectTank_Click);
|
||||
//
|
||||
// FormTank
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.Controls.Add(this.ButtonSelectTank);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.buttonCreateArmoredCar);
|
||||
@ -153,7 +165,6 @@
|
||||
this.Name = "FormTank";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Tank";
|
||||
|
||||
this.Load += new System.EventHandler(this.FormTank_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
@ -172,5 +183,6 @@
|
||||
private Button buttonCreateArmoredCar;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button ButtonSelectTank;
|
||||
}
|
||||
}
|
@ -9,10 +9,10 @@ namespace Tank
|
||||
public partial class FormTank : Form
|
||||
{
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
private DrawingArmoredCar? _Tank;
|
||||
private DrawingArmoredCar? _Tank; // DrawingArmoredCar DrawingTank
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingArmoredCar? SelectedTank { get; private set; }
|
||||
public DrawingArmoredCar? SelectedTank { get; private set; } // DrawingArmoredCar DrawingTank
|
||||
public FormTank()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -46,12 +46,22 @@ namespace Tank
|
||||
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;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
//TODO âûáîð äîïîëíèòåëüíîãî öâåòà
|
||||
// âûáîð äîïîëíèòåëüíîãî öâåòà
|
||||
ColorDialog dialog2 = new();
|
||||
if (dialog2.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog2.Color;
|
||||
}
|
||||
|
||||
_Tank = new DrawingTank(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color,
|
||||
@ -144,17 +154,18 @@ namespace Tank
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void FormTank_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ButtonSelectTank_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedTank = _Tank;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
private void FormTank_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -33,11 +33,28 @@ namespace Tank.Generics
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T tank)
|
||||
public int Insert(T tank)
|
||||
{
|
||||
// вставка в начало набора
|
||||
|
||||
return true;
|
||||
int index = -1;
|
||||
for (int i = 0; i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int i = index; i > 0; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[0] = tank;
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -45,7 +62,7 @@ namespace Tank.Generics
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T tank, int position)
|
||||
public int Insert(T tank, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
|
||||
@ -54,9 +71,29 @@ namespace Tank.Generics
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
|
||||
// TODO вставка по позиции
|
||||
|
||||
if (position < 0 || position >= Count)
|
||||
return -1;
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = tank;
|
||||
return position;
|
||||
}
|
||||
int index = -1;
|
||||
for (int i = position; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
index = i; break;
|
||||
}
|
||||
}
|
||||
if (index < 0)
|
||||
return -1;
|
||||
for (int i = index; index > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = tank;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
@ -65,9 +102,12 @@ namespace Tank.Generics
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
|
||||
|
||||
// проверка позиции
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -29,11 +29,11 @@ namespace Tank.Generics
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 100;
|
||||
private readonly int _placeSizeWidth = 160;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 55;
|
||||
private readonly int _placeSizeHeight = 65;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
@ -57,15 +57,14 @@ namespace Tank.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(TanksGenericCollection<T, U> collect, T?
|
||||
public static int operator +(TanksGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
@ -73,15 +72,15 @@ namespace Tank.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static T? operator -(TanksGenericCollection<T, U> collect, int
|
||||
public static bool operator -(TanksGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
@ -113,12 +112,11 @@ namespace Tank.Generics
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; 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, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 40, j * _placeSizeHeight);
|
||||
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
@ -134,16 +132,12 @@ namespace Tank.Generics
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// получение объекта
|
||||
DrawingArmoredCar? tank = _collection.Get(i);
|
||||
if (tank == null)
|
||||
if (tank != null)
|
||||
{
|
||||
continue;
|
||||
tank.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
tank.DrawTransport(g);
|
||||
}
|
||||
// установка позиции
|
||||
tank.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
// прорисовка объекта
|
||||
tank.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user