Compare commits

...

2 Commits

Author SHA1 Message Date
platoff aeeee
de5812d86c Готовая 5 лаба 2023-12-05 19:35:57 +04:00
platoff aeeee
d8a1dfa401 правки 5 лаб 2023-11-22 11:02:20 +04:00
7 changed files with 129 additions and 88 deletions

View File

@ -63,11 +63,11 @@ namespace Tank.DrawingObjects
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
private int _pictureWidth; public int _pictureWidth;
/// <summary> /// <summary>
/// Высота окна /// Высота окна
/// </summary> /// </summary>
private int _pictureHeight; public int _pictureHeight;
/// <summary> /// <summary>
/// Левая координата прорисовки автомобиля /// Левая координата прорисовки автомобиля
/// </summary> /// </summary>

View File

@ -27,7 +27,7 @@ namespace Tank.Entites
/// Шаг перемещения автомобиля /// Шаг перемещения автомобиля
/// </summary> /// </summary>
public double Step => (double)Speed * 300 / Weight; public double Step => (double)Speed * 300 / Weight;
public void setBodyColor(Color color) { BodyColor = color; }
/// <summary> /// <summary>
/// Конструктор с параметрами /// Конструктор с параметрами
/// </summary> /// </summary>
@ -40,7 +40,10 @@ namespace Tank.Entites
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
public void setBodyColor(Color color)
{
BodyColor = color;
}
} }
} }

View File

@ -10,7 +10,6 @@ namespace Tank.Entites
public class EntityTank : EntityArmoredCar public class EntityTank : EntityArmoredCar
{ {
public int Speed { get; private set; } public int Speed { get; private set; }
public void setAdditionalColor(Color color) { AdditionalColor = color; }
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
// Признак (опция) наличия обвеса // Признак (опция) наличия обвеса
public bool BodyKit { get; private set; } public bool BodyKit { get; private set; }
@ -35,6 +34,11 @@ namespace Tank.Entites
Trunk = trunk; Trunk = trunk;
Line = line; Line = line;
} }
public void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
} }
} }

View File

@ -72,8 +72,8 @@ namespace Tank
return; return;
} }
FormTankConfig form = new FormTankConfig(); FormTankConfig form = new FormTankConfig();
form.AddEvent(AddArmoredCar);
form.Show(); form.Show();
form.AddEvent(AddArmoredCar);
} }
private void ButtonRemoveArmoredCar_Click(object sender, EventArgs e) private void ButtonRemoveArmoredCar_Click(object sender, EventArgs e)

View File

@ -29,12 +29,6 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxParameters = new System.Windows.Forms.GroupBox(); this.groupBoxParameters = new System.Windows.Forms.GroupBox();
this.button_Cancel = new System.Windows.Forms.Button();
this.button_Add = new System.Windows.Forms.Button();
this.panelColor = new System.Windows.Forms.Panel();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.labelAdditionalColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label();
this.labelComplexObject = new System.Windows.Forms.Label(); this.labelComplexObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label(); this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox(); this.groupBoxColors = new System.Windows.Forms.GroupBox();
@ -53,19 +47,24 @@
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelWeigth = new System.Windows.Forms.Label(); this.labelWeigth = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label(); this.labelSpeed = new System.Windows.Forms.Label();
this.button_Cancel = new System.Windows.Forms.Button();
this.button_Add = new System.Windows.Forms.Button();
this.PanelObject = new System.Windows.Forms.Panel();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelColor = new System.Windows.Forms.Panel();
this.label_Additional_Color = new System.Windows.Forms.Label();
this.label_Color = new System.Windows.Forms.Label();
this.groupBoxParameters.SuspendLayout(); this.groupBoxParameters.SuspendLayout();
this.panelColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.groupBoxColors.SuspendLayout(); this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.PanelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelColor.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxParameters // groupBoxParameters
// //
this.groupBoxParameters.Controls.Add(this.button_Cancel);
this.groupBoxParameters.Controls.Add(this.button_Add);
this.groupBoxParameters.Controls.Add(this.panelColor);
this.groupBoxParameters.Controls.Add(this.labelComplexObject); this.groupBoxParameters.Controls.Add(this.labelComplexObject);
this.groupBoxParameters.Controls.Add(this.labelSimpleObject); this.groupBoxParameters.Controls.Add(this.labelSimpleObject);
this.groupBoxParameters.Controls.Add(this.groupBoxColors); this.groupBoxParameters.Controls.Add(this.groupBoxColors);
@ -78,85 +77,28 @@
this.groupBoxParameters.Controls.Add(this.labelSpeed); this.groupBoxParameters.Controls.Add(this.labelSpeed);
this.groupBoxParameters.Location = new System.Drawing.Point(12, 12); this.groupBoxParameters.Location = new System.Drawing.Point(12, 12);
this.groupBoxParameters.Name = "groupBoxParameters"; this.groupBoxParameters.Name = "groupBoxParameters";
this.groupBoxParameters.Size = new System.Drawing.Size(752, 303); this.groupBoxParameters.Size = new System.Drawing.Size(476, 213);
this.groupBoxParameters.TabIndex = 0; this.groupBoxParameters.TabIndex = 0;
this.groupBoxParameters.TabStop = false; this.groupBoxParameters.TabStop = false;
this.groupBoxParameters.Text = "Параметры"; this.groupBoxParameters.Text = "Параметры";
// //
// button_Cancel
//
this.button_Cancel.Location = new System.Drawing.Point(591, 198);
this.button_Cancel.Name = "button_Cancel";
this.button_Cancel.Size = new System.Drawing.Size(105, 32);
this.button_Cancel.TabIndex = 15;
this.button_Cancel.Text = "Отмена";
this.button_Cancel.UseVisualStyleBackColor = true;
//
// button_Add
//
this.button_Add.Location = new System.Drawing.Point(477, 197);
this.button_Add.Name = "button_Add";
this.button_Add.Size = new System.Drawing.Size(105, 32);
this.button_Add.TabIndex = 14;
this.button_Add.Text = "Добавить";
this.button_Add.UseVisualStyleBackColor = true;
this.button_Add.Click += new System.EventHandler(this.button_Add_Click);
//
// panelColor
//
this.panelColor.AllowDrop = true;
this.panelColor.Controls.Add(this.pictureBoxObject);
this.panelColor.Controls.Add(this.labelAdditionalColor);
this.panelColor.Controls.Add(this.labelColor);
this.panelColor.Location = new System.Drawing.Point(477, 30);
this.panelColor.Name = "panelColor";
this.panelColor.Size = new System.Drawing.Size(219, 153);
this.panelColor.TabIndex = 11;
this.panelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(13, 55);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(196, 84);
this.pictureBoxObject.TabIndex = 10;
this.pictureBoxObject.TabStop = false;
//
// labelAdditionalColor
//
this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdditionalColor.Location = new System.Drawing.Point(114, 10);
this.labelAdditionalColor.Name = "labelAdditionalColor";
this.labelAdditionalColor.Size = new System.Drawing.Size(95, 32);
this.labelAdditionalColor.TabIndex = 13;
this.labelAdditionalColor.Text = "Доп.цвет";
this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelColor
//
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(13, 10);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(95, 32);
this.labelColor.TabIndex = 12;
this.labelColor.Text = "Цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelComplexObject // labelComplexObject
// //
this.labelComplexObject.AllowDrop = true;
this.labelComplexObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelComplexObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelComplexObject.Location = new System.Drawing.Point(346, 195); this.labelComplexObject.Location = new System.Drawing.Point(346, 164);
this.labelComplexObject.Name = "labelComplexObject"; this.labelComplexObject.Name = "labelComplexObject";
this.labelComplexObject.Size = new System.Drawing.Size(109, 34); this.labelComplexObject.Size = new System.Drawing.Size(109, 34);
this.labelComplexObject.TabIndex = 9; this.labelComplexObject.TabIndex = 9;
this.labelComplexObject.Text = "Продвинутый"; this.labelComplexObject.Text = "Продвинутый";
this.labelComplexObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelComplexObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelComplexObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
// //
// labelSimpleObject // labelSimpleObject
// //
this.labelSimpleObject.AllowDrop = true;
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(222, 195); this.labelSimpleObject.Location = new System.Drawing.Point(222, 164);
this.labelSimpleObject.Name = "labelSimpleObject"; this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(109, 34); this.labelSimpleObject.Size = new System.Drawing.Size(109, 34);
this.labelSimpleObject.TabIndex = 8; this.labelSimpleObject.TabIndex = 8;
@ -183,6 +125,7 @@
// //
// panelWhite // panelWhite
// //
this.panelWhite.AllowDrop = true;
this.panelWhite.BackColor = System.Drawing.Color.White; this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(178, 63); this.panelWhite.Location = new System.Drawing.Point(178, 63);
this.panelWhite.Name = "panelWhite"; this.panelWhite.Name = "panelWhite";
@ -220,6 +163,7 @@
this.panelYellow.Name = "panelYellow"; this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(48, 35); this.panelYellow.Size = new System.Drawing.Size(48, 35);
this.panelYellow.TabIndex = 1; this.panelYellow.TabIndex = 1;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
// //
// panelBlue // panelBlue
// //
@ -228,6 +172,7 @@
this.panelBlue.Name = "panelBlue"; this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(48, 35); this.panelBlue.Size = new System.Drawing.Size(48, 35);
this.panelBlue.TabIndex = 1; this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
// //
// panelGreen // panelGreen
// //
@ -236,6 +181,7 @@
this.panelGreen.Name = "panelGreen"; this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(48, 35); this.panelGreen.Size = new System.Drawing.Size(48, 35);
this.panelGreen.TabIndex = 1; this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
// //
// panelRed // panelRed
// //
@ -244,6 +190,9 @@
this.panelRed.Name = "panelRed"; this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(48, 35); this.panelRed.Size = new System.Drawing.Size(48, 35);
this.panelRed.TabIndex = 0; this.panelRed.TabIndex = 0;
this.panelRed.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelRed.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
// //
// checkBoxLine // checkBoxLine
// //
@ -337,21 +286,102 @@
this.labelSpeed.TabIndex = 0; this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость"; this.labelSpeed.Text = "Скорость";
// //
// button_Cancel
//
this.button_Cancel.Location = new System.Drawing.Point(625, 12);
this.button_Cancel.Name = "button_Cancel";
this.button_Cancel.Size = new System.Drawing.Size(105, 32);
this.button_Cancel.TabIndex = 15;
this.button_Cancel.Text = "Отмена";
this.button_Cancel.UseVisualStyleBackColor = true;
//
// button_Add
//
this.button_Add.Location = new System.Drawing.Point(514, 12);
this.button_Add.Name = "button_Add";
this.button_Add.Size = new System.Drawing.Size(105, 32);
this.button_Add.TabIndex = 14;
this.button_Add.Text = "Добавить";
this.button_Add.UseVisualStyleBackColor = true;
this.button_Add.Click += new System.EventHandler(this.button_Add_Click);
//
// PanelObject
//
this.PanelObject.AllowDrop = true;
this.PanelObject.Controls.Add(this.pictureBoxObject);
this.PanelObject.Location = new System.Drawing.Point(494, 137);
this.PanelObject.Name = "PanelObject";
this.PanelObject.Size = new System.Drawing.Size(294, 190);
this.PanelObject.TabIndex = 11;
this.PanelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.PanelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(6, 14);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(270, 157);
this.pictureBoxObject.TabIndex = 10;
this.pictureBoxObject.TabStop = false;
//
// panelColor
//
this.panelColor.AllowDrop = true;
this.panelColor.Controls.Add(this.label_Additional_Color);
this.panelColor.Controls.Add(this.label_Color);
this.panelColor.Location = new System.Drawing.Point(500, 52);
this.panelColor.Name = "panelColor";
this.panelColor.Size = new System.Drawing.Size(288, 65);
this.panelColor.TabIndex = 11;
this.panelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// label_Additional_Color
//
this.label_Additional_Color.AllowDrop = true;
this.label_Additional_Color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_Additional_Color.Location = new System.Drawing.Point(151, 4);
this.label_Additional_Color.Name = "label_Additional_Color";
this.label_Additional_Color.Size = new System.Drawing.Size(111, 47);
this.label_Additional_Color.TabIndex = 13;
this.label_Additional_Color.Text = "Доп.цвет";
this.label_Additional_Color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_Additional_Color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_Additional_Color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter);
//
// label_Color
//
this.label_Color.AllowDrop = true;
this.label_Color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_Color.Location = new System.Drawing.Point(14, 4);
this.label_Color.Name = "label_Color";
this.label_Color.Size = new System.Drawing.Size(115, 47);
this.label_Color.TabIndex = 12;
this.label_Color.Text = "Цвет";
this.label_Color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_Color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_Color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter);
//
// FormTankConfig // FormTankConfig
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button_Add);
this.Controls.Add(this.panelColor);
this.Controls.Add(this.button_Cancel);
this.Controls.Add(this.PanelObject);
this.Controls.Add(this.groupBoxParameters); this.Controls.Add(this.groupBoxParameters);
this.Name = "FormTankConfig"; this.Name = "FormTankConfig";
this.Text = "FormTankConfig"; this.Text = "FormTankConfig";
this.groupBoxParameters.ResumeLayout(false); this.groupBoxParameters.ResumeLayout(false);
this.groupBoxParameters.PerformLayout(); this.groupBoxParameters.PerformLayout();
this.panelColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.groupBoxColors.ResumeLayout(false); this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.PanelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelColor.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -380,8 +410,9 @@
private PictureBox pictureBoxObject; private PictureBox pictureBoxObject;
private Button button_Cancel; private Button button_Cancel;
private Button button_Add; private Button button_Add;
private Label labelAdditionalColor; private Label label_Color;
private Label labelColor; private Panel PanelObject;
private Panel panelColor; private Panel panelColor;
private Label label_Additional_Color;
} }
} }

View File

@ -54,6 +54,7 @@ namespace Tank
EventAddTank += eventAdd; EventAddTank += eventAdd;
} }
} }
private void panelColor_MouseDown(object sender, MouseEventArgs e) private void panelColor_MouseDown(object sender, MouseEventArgs e)
{ {
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
@ -75,13 +76,12 @@ namespace Tank
{ {
return; return;
} }
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
switch (((Label)sender).Name) switch (((Label)sender).Name)
{ {
case "labelColor": case "label_Color":
_Tank.Tank.setBodyColor((Color)e.Data.GetData(typeof(Color))); _Tank.Tank.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break; break;
case "labelAdditionalColor": case "label_Additional_Color":
if (!(_Tank is DrawingTank)) if (!(_Tank is DrawingTank))
return; return;
(_Tank.Tank as EntityTank).setAdditionalColor((Color)e.Data.GetData(typeof(Color))); (_Tank.Tank as EntityTank).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
@ -96,6 +96,7 @@ namespace Tank
DragDropEffects.Move | DragDropEffects.Copy); DragDropEffects.Move | DragDropEffects.Copy);
} }
private void PanelObject_DragEnter(object sender, DragEventArgs e) private void PanelObject_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
@ -106,6 +107,7 @@ namespace Tank
{ {
e.Effect = DragDropEffects.None; e.Effect = DragDropEffects.None;
} }
} }
private void PanelObject_DragDrop(object sender, DragEventArgs e) private void PanelObject_DragDrop(object sender, DragEventArgs e)

View File

@ -133,9 +133,10 @@ namespace Tank.Generics
{ {
if (tank != null) if (tank != null)
{ {
tank._pictureWidth = _pictureWidth;
tank._pictureHeight = _pictureHeight;
tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth,
(i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
tank.DrawTransport(g); tank.DrawTransport(g);
} }
i++; i++;