Готовая лабораторная 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(DrawTank);
Controls.Add(panel1); Controls.Add(panel1);
Name = "CollectionsFrame"; Name = "CollectionsFrame";
Text = "Form1"; Text = "CollectionsFrame";
panel1.ResumeLayout(false); panel1.ResumeLayout(false);
panel1.PerformLayout(); panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)DrawTank).EndInit(); ((System.ComponentModel.ISupportInitialize)DrawTank).EndInit();

View File

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

View File

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

View File

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

View File

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