Готовая лабораторная 3

This commit is contained in:
nikbel2004@outlook.com 2023-10-21 16:09:16 +04:00
parent b54059d598
commit c69b8824c6
5 changed files with 40 additions and 34 deletions

View File

@ -115,7 +115,7 @@
Controls.Add(DrawTank);
Controls.Add(panel1);
Name = "CollectionsFrame";
Text = "Form1";
Text = "CollectionsFrame";
panel1.ResumeLayout(false);
panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)DrawTank).EndInit();

View File

@ -28,7 +28,7 @@ namespace Tank
FormTank form = new FormTank();
if (form.ShowDialog() == DialogResult.OK)
{
if (_tanks + form.SelectedCar != -1)
if (_tanks + form.SelectedTank != -1)
{
MessageBox.Show("Объект добавлен");
DrawTank.Image = _tanks.ShowTanks();
@ -67,6 +67,5 @@ namespace Tank
{
DrawTank.Image = _tanks.ShowTanks();
}
}
}

View File

@ -44,16 +44,18 @@
// pictureBoxTank
//
pictureBoxTank.Location = new Point(1, 0);
pictureBoxTank.Margin = new Padding(3, 4, 3, 4);
pictureBoxTank.Name = "pictureBoxTank";
pictureBoxTank.Size = new Size(799, 428);
pictureBoxTank.Size = new Size(913, 571);
pictureBoxTank.TabIndex = 0;
pictureBoxTank.TabStop = false;
//
// ButtonCreate
//
ButtonCreate.Location = new Point(12, 375);
ButtonCreate.Location = new Point(14, 500);
ButtonCreate.Margin = new Padding(3, 4, 3, 4);
ButtonCreate.Name = "ButtonCreate";
ButtonCreate.Size = new Size(127, 40);
ButtonCreate.Size = new Size(145, 53);
ButtonCreate.TabIndex = 1;
ButtonCreate.Text = "Создание танка";
ButtonCreate.UseVisualStyleBackColor = true;
@ -64,9 +66,10 @@
keyDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
keyDown.BackgroundImage = Properties.Resources.KeyDown;
keyDown.BackgroundImageLayout = ImageLayout.Stretch;
keyDown.Location = new Point(718, 386);
keyDown.Location = new Point(821, 515);
keyDown.Margin = new Padding(3, 4, 3, 4);
keyDown.Name = "keyDown";
keyDown.Size = new Size(30, 30);
keyDown.Size = new Size(34, 40);
keyDown.TabIndex = 11;
keyDown.UseVisualStyleBackColor = true;
keyDown.Click += ButtonMove_Click;
@ -76,9 +79,10 @@
keyUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
keyUp.BackgroundImage = Properties.Resources.KeyUp;
keyUp.BackgroundImageLayout = ImageLayout.Stretch;
keyUp.Location = new Point(718, 350);
keyUp.Location = new Point(821, 467);
keyUp.Margin = new Padding(3, 4, 3, 4);
keyUp.Name = "keyUp";
keyUp.Size = new Size(30, 30);
keyUp.Size = new Size(34, 40);
keyUp.TabIndex = 12;
keyUp.UseVisualStyleBackColor = true;
keyUp.Click += ButtonMove_Click;
@ -88,9 +92,10 @@
keyLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
keyLeft.BackgroundImage = Properties.Resources.KeyLeft;
keyLeft.BackgroundImageLayout = ImageLayout.Stretch;
keyLeft.Location = new Point(682, 386);
keyLeft.Location = new Point(779, 515);
keyLeft.Margin = new Padding(3, 4, 3, 4);
keyLeft.Name = "keyLeft";
keyLeft.Size = new Size(30, 30);
keyLeft.Size = new Size(34, 40);
keyLeft.TabIndex = 13;
keyLeft.UseVisualStyleBackColor = true;
keyLeft.Click += ButtonMove_Click;
@ -100,18 +105,20 @@
keyRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
keyRight.BackgroundImage = Properties.Resources.KeyRight;
keyRight.BackgroundImageLayout = ImageLayout.Stretch;
keyRight.Location = new Point(753, 386);
keyRight.Location = new Point(861, 515);
keyRight.Margin = new Padding(3, 4, 3, 4);
keyRight.Name = "keyRight";
keyRight.Size = new Size(30, 30);
keyRight.Size = new Size(34, 40);
keyRight.TabIndex = 14;
keyRight.UseVisualStyleBackColor = true;
keyRight.Click += ButtonMove_Click;
//
// buttonArmVechicle
//
buttonArmVechicle.Location = new Point(154, 376);
buttonArmVechicle.Location = new Point(176, 501);
buttonArmVechicle.Margin = new Padding(3, 4, 3, 4);
buttonArmVechicle.Name = "buttonArmVechicle";
buttonArmVechicle.Size = new Size(127, 40);
buttonArmVechicle.Size = new Size(150, 53);
buttonArmVechicle.TabIndex = 15;
buttonArmVechicle.Text = "Создание бронеавтомобиля";
buttonArmVechicle.UseVisualStyleBackColor = true;
@ -119,9 +126,10 @@
//
// buttonStep
//
buttonStep.Location = new Point(713, 53);
buttonStep.Location = new Point(815, 71);
buttonStep.Margin = new Padding(3, 4, 3, 4);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(75, 23);
buttonStep.Size = new Size(86, 31);
buttonStep.TabIndex = 17;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
@ -131,18 +139,16 @@
//
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
comboBoxStrategy.Location = new Point(655, 18);
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
comboBoxStrategy.Location = new Point(749, 24);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(133, 23);
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 19;
//
// ChooseCar
//
ChooseCar.Location = new Point(706, 90);
ChooseCar.Margin = new Padding(3, 2, 3, 2);
ChooseCar.Location = new Point(807, 120);
ChooseCar.Name = "ChooseCar";
ChooseCar.Size = new Size(82, 39);
ChooseCar.Size = new Size(94, 52);
ChooseCar.TabIndex = 20;
ChooseCar.Text = "Выбрать технику";
ChooseCar.UseVisualStyleBackColor = true;
@ -150,10 +156,10 @@
//
// FormTank
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = SystemColors.ButtonHighlight;
ClientSize = new Size(800, 426);
ClientSize = new Size(914, 568);
Controls.Add(ChooseCar);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonStep);
@ -164,6 +170,7 @@
Controls.Add(keyDown);
Controls.Add(ButtonCreate);
Controls.Add(pictureBoxTank);
Margin = new Padding(3, 4, 3, 4);
Name = "FormTank";
Text = "FormTank";
Load += FormTank_Load;

View File

@ -7,13 +7,13 @@ namespace Tank
{
private DrawArmoVehicle? _Tank;
private AbstractStrategy? _abstractStrategy;
public DrawArmoVehicle? SelectedCar { get; private set; }
public DrawArmoVehicle? SelectedTank { get; private set; }
public FormTank()
{
InitializeComponent();
_abstractStrategy = null;
SelectedCar = null;
SelectedTank = null;
}
private void Draw()
@ -125,7 +125,7 @@ namespace Tank
private void ButtonSelectTank_Click(object sender, EventArgs e)
{
SelectedCar = _Tank;
SelectedTank = _Tank;
DialogResult = DialogResult.OK;
}

View File

@ -21,7 +21,7 @@ namespace Tank
}
//Добавление объекта в набор
public int Insert(T car)
public int Insert(T tank)
{
int index = -1;
for(int i = 0; i < _places.Length; i++)
@ -39,18 +39,18 @@ namespace Tank
{
_places[i] = _places[i - 1];
}
_places[0] = car;
_places[0] = tank;
return 0;
}
// Добавление объекта в набор на конкретную позицию
public int Insert(T car, int position)
public int Insert(T tank, int position)
{
if (position < 0 || position >= Count)
return -1;
if (_places[position] == null)
{
_places[position] = car;
_places[position] = tank;
return position;
}
int index = -1;
@ -67,7 +67,7 @@ namespace Tank
{
_places[i] = _places[i - 1];
}
_places[position] = car;
_places[position] = tank;
return position;
}