diff --git a/Tank/Tank/Drawings/DrawingArmoredCar.cs b/Tank/Tank/Drawings/DrawingArmoredCar.cs index f726b91..96b5092 100644 --- a/Tank/Tank/Drawings/DrawingArmoredCar.cs +++ b/Tank/Tank/Drawings/DrawingArmoredCar.cs @@ -79,11 +79,11 @@ namespace Tank.DrawingObjects /// /// Ширина прорисовки автомобиля /// - protected readonly int _ArmoredcarWidth = 100; + protected readonly int _ArmoredcarWidth = 150; /// /// Высота прорисовки автомобиля /// - protected readonly int _ArmoredcarHeight = 55; + protected readonly int _ArmoredcarHeight = 65; /// /// Конструктор /// @@ -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); diff --git a/Tank/Tank/FormArmoredCarCollection.Designer.cs b/Tank/Tank/FormArmoredCarCollection.Designer.cs index f187d42..5483e9a 100644 --- a/Tank/Tank/FormArmoredCarCollection.Designer.cs +++ b/Tank/Tank/FormArmoredCarCollection.Designer.cs @@ -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; // diff --git a/Tank/Tank/FormArmoredCarCollection.cs b/Tank/Tank/FormArmoredCarCollection.cs index a7ac9e5..766e4be 100644 --- a/Tank/Tank/FormArmoredCarCollection.cs +++ b/Tank/Tank/FormArmoredCarCollection.cs @@ -20,8 +20,8 @@ namespace Tank public FormArmoredCarCollection() { InitializeComponent(); - _tanks = new TanksGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + _tanks = new TanksGenericCollection + (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) diff --git a/Tank/Tank/FormTank.Designer.cs b/Tank/Tank/FormTank.Designer.cs index fcac7cf..6e99147 100644 --- a/Tank/Tank/FormTank.Designer.cs +++ b/Tank/Tank/FormTank.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/Tank/Tank/FormTank.cs b/Tank/Tank/FormTank.cs index d34b74a..2a3c514 100644 --- a/Tank/Tank/FormTank.cs +++ b/Tank/Tank/FormTank.cs @@ -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) - { - - } } } \ No newline at end of file diff --git a/Tank/Tank/Generics/SetGeneric.cs b/Tank/Tank/Generics/SetGeneric.cs index 90fd68a..195e8ad 100644 --- a/Tank/Tank/Generics/SetGeneric.cs +++ b/Tank/Tank/Generics/SetGeneric.cs @@ -33,11 +33,28 @@ namespace Tank.Generics /// /// Добавляемый автомобиль /// - 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; } /// /// Добавление объекта в набор на конкретную позицию @@ -45,7 +62,7 @@ namespace Tank.Generics /// Добавляемый автомобиль /// Позиция /// - 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; } /// /// Удаление объекта из набора с конкретной позиции @@ -65,9 +102,12 @@ namespace Tank.Generics /// public bool Remove(int position) { - // TODO проверка позиции - - + // проверка позиции + if (position < 0 || position >= Count) + { + return false; + } + _places[position] = null; return true; } /// diff --git a/Tank/Tank/Generics/TanksGenericCollection.cs b/Tank/Tank/Generics/TanksGenericCollection.cs index 6b4108f..aa2dc3b 100644 --- a/Tank/Tank/Generics/TanksGenericCollection.cs +++ b/Tank/Tank/Generics/TanksGenericCollection.cs @@ -29,11 +29,11 @@ namespace Tank.Generics /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 100; + private readonly int _placeSizeWidth = 160; /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 55; + private readonly int _placeSizeHeight = 65; /// /// Набор объектов /// @@ -57,15 +57,14 @@ namespace Tank.Generics /// /// /// - public static bool operator +(TanksGenericCollection collect, T? + public static int operator +(TanksGenericCollection collect, T? obj) { if (obj == null) { - return false; + return -1; } - return collect?._collection.Insert(obj) ?? false; - + return collect._collection.Insert(obj); } /// /// Перегрузка оператора вычитания @@ -73,15 +72,15 @@ namespace Tank.Generics /// /// /// - public static T? operator -(TanksGenericCollection collect, int + public static bool operator -(TanksGenericCollection 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; } /// /// Получение объекта 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); } } }