Полная лабораторная.
This commit is contained in:
parent
d93265500a
commit
15eb081a88
@ -10,6 +10,10 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityLocomotive Locomotive { get; private set; }
|
public EntityLocomotive Locomotive { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Класс отрисовки колёс
|
||||||
|
/// </summary>
|
||||||
|
public DrawningWheels Wheels;
|
||||||
|
/// <summary>
|
||||||
/// Левая координата отрисовки локомотива
|
/// Левая координата отрисовки локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
private float _startPosX;
|
||||||
@ -32,7 +36,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота локомотива
|
/// Высота локомотива
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly int _locomotiveHeight = 55;
|
protected readonly int _locomotiveHeight = 80;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств объекта-сущности
|
/// Инициализация свойств объекта-сущности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -43,6 +47,7 @@
|
|||||||
{
|
{
|
||||||
Locomotive = new EntityLocomotive();
|
Locomotive = new EntityLocomotive();
|
||||||
Locomotive.Init(speed, weight, bodyColor);
|
Locomotive.Init(speed, weight, bodyColor);
|
||||||
|
Wheels = new DrawningWheels();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка начальной позиции локомотива
|
/// Установка начальной позиции локомотива
|
||||||
@ -157,10 +162,7 @@
|
|||||||
g.FillRectangle(brBodyColor, _startPosX + 60, _startPosY + 10, 15, 25);
|
g.FillRectangle(brBodyColor, _startPosX + 60, _startPosY + 10, 15, 25);
|
||||||
g.DrawRectangle(pen, _startPosX + 60, _startPosY + 10, 15, 25);
|
g.DrawRectangle(pen, _startPosX + 60, _startPosY + 10, 15, 25);
|
||||||
//колёса
|
//колёса
|
||||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 40, 20, 15);
|
Wheels.DrawWheels(g, _startPosX, _startPosY, Color.Black);
|
||||||
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 40, 20, 15);
|
|
||||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, 15);
|
|
||||||
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 40, 20, 15);
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод перерисовки при изменении границ рисунка
|
/// Метод перерисовки при изменении границ рисунка
|
||||||
|
46
LocomotivesAdvanced/LocomotivesAdvanced/DrawningWheels.cs
Normal file
46
LocomotivesAdvanced/LocomotivesAdvanced/DrawningWheels.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
namespace LocomotivesAdvanced
|
||||||
|
{
|
||||||
|
internal class DrawningWheels
|
||||||
|
{
|
||||||
|
private WheelsNumber wheelsNumber;
|
||||||
|
|
||||||
|
public int _wheelsNumber
|
||||||
|
{
|
||||||
|
get => (int)wheelsNumber;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 2 || value > 4)
|
||||||
|
{
|
||||||
|
wheelsNumber = (WheelsNumber)2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wheelsNumber = (WheelsNumber)value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DrawWheels(Graphics g, float startPosX, float startPosY, Color wheelsColor)
|
||||||
|
{
|
||||||
|
Pen pen = new(wheelsColor);
|
||||||
|
switch (_wheelsNumber)
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
|
g.DrawEllipse(pen, startPosX + 20, startPosY + 40, 20, 15);
|
||||||
|
g.DrawEllipse(pen, startPosX + 120, startPosY + 40, 20, 15);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
g.DrawEllipse(pen, startPosX + 20, startPosY + 40, 20, 15);
|
||||||
|
g.DrawEllipse(pen, startPosX + 90, startPosY + 40, 20, 15);
|
||||||
|
g.DrawEllipse(pen, startPosX + 120, startPosY + 40, 20, 15);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
g.DrawEllipse(pen, startPosX + 20, startPosY + 40, 20, 15);
|
||||||
|
g.DrawEllipse(pen, startPosX + 50, startPosY + 40, 20, 15);
|
||||||
|
g.DrawEllipse(pen, startPosX + 90, startPosY + 40, 20, 15);
|
||||||
|
g.DrawEllipse(pen, startPosX + 120, startPosY + 40, 20, 15);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -38,8 +38,11 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.labelWheelsNumber = new System.Windows.Forms.Label();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxLocomotive
|
// pictureBoxLocomotive
|
||||||
@ -48,7 +51,7 @@
|
|||||||
this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0);
|
this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0);
|
||||||
this.pictureBoxLocomotive.MinimumSize = new System.Drawing.Size(1, 1);
|
this.pictureBoxLocomotive.MinimumSize = new System.Drawing.Size(1, 1);
|
||||||
this.pictureBoxLocomotive.Name = "pictureBoxLocomotive";
|
this.pictureBoxLocomotive.Name = "pictureBoxLocomotive";
|
||||||
this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 428);
|
this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 450);
|
||||||
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxLocomotive.TabIndex = 0;
|
this.pictureBoxLocomotive.TabIndex = 0;
|
||||||
this.pictureBoxLocomotive.TabStop = false;
|
this.pictureBoxLocomotive.TabStop = false;
|
||||||
@ -143,23 +146,60 @@
|
|||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
|
// numericUpDownWheelsNumber
|
||||||
|
//
|
||||||
|
this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(651, 402);
|
||||||
|
this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] {
|
||||||
|
4,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDownWheelsNumber.Minimum = new decimal(new int[] {
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpDownWheelsNumber.Name = "numericUpDownWheelsNumber";
|
||||||
|
this.numericUpDownWheelsNumber.ReadOnly = true;
|
||||||
|
this.numericUpDownWheelsNumber.Size = new System.Drawing.Size(29, 23);
|
||||||
|
this.numericUpDownWheelsNumber.TabIndex = 7;
|
||||||
|
this.numericUpDownWheelsNumber.Value = new decimal(new int[] {
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
//
|
||||||
|
// labelWheelsNumber
|
||||||
|
//
|
||||||
|
this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.labelWheelsNumber.AutoSize = true;
|
||||||
|
this.labelWheelsNumber.Location = new System.Drawing.Point(565, 404);
|
||||||
|
this.labelWheelsNumber.Name = "labelWheelsNumber";
|
||||||
|
this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15);
|
||||||
|
this.labelWheelsNumber.TabIndex = 8;
|
||||||
|
this.labelWheelsNumber.Text = "Число колёс:";
|
||||||
|
//
|
||||||
// FormLocomotive
|
// FormLocomotive
|
||||||
//
|
//
|
||||||
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.labelWheelsNumber);
|
||||||
|
this.Controls.Add(this.numericUpDownWheelsNumber);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonCreate);
|
this.Controls.Add(this.buttonCreate);
|
||||||
this.Controls.Add(this.pictureBoxLocomotive);
|
|
||||||
this.Controls.Add(this.statusStrip);
|
this.Controls.Add(this.statusStrip);
|
||||||
|
this.Controls.Add(this.pictureBoxLocomotive);
|
||||||
this.Name = "FormLocomotive";
|
this.Name = "FormLocomotive";
|
||||||
this.Text = "Локомотив";
|
this.Text = "Локомотив";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
|
||||||
this.statusStrip.ResumeLayout(false);
|
this.statusStrip.ResumeLayout(false);
|
||||||
this.statusStrip.PerformLayout();
|
this.statusStrip.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@ -177,5 +217,7 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private NumericUpDown numericUpDownWheelsNumber;
|
||||||
|
private Label labelWheelsNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,6 +35,7 @@
|
|||||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_locomotive.Locomotive.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Скорость: {_locomotive.Locomotive.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}";
|
toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}";
|
||||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_locomotive.Locomotive.BodyColor.Name}";
|
toolStripStatusLabelBodyColor.Text = $"Цвет: {_locomotive.Locomotive.BodyColor.Name}";
|
||||||
|
_locomotive.Wheels._wheelsNumber = (int)numericUpDownWheelsNumber.Value;
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
12
LocomotivesAdvanced/LocomotivesAdvanced/WheelsNumber.cs
Normal file
12
LocomotivesAdvanced/LocomotivesAdvanced/WheelsNumber.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace LocomotivesAdvanced
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Число колёс
|
||||||
|
/// </summary>
|
||||||
|
internal enum WheelsNumber
|
||||||
|
{
|
||||||
|
Two = 2,
|
||||||
|
Three = 3,
|
||||||
|
Four = 4
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user