ISEbd-21 Melnikov I. O. Lab work 02 advanced #3
@ -0,0 +1,67 @@
|
||||
namespace WarmlyLocomotove
|
||||
{
|
||||
internal class DrawningEllipseOrnament : IDrawningAdditionalElements
|
||||
{
|
||||
private WheelsNumber wheelsNumber;
|
||||
|
||||
public int WheelsNum
|
||||
{
|
||||
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 WheelsNumber.Two:
|
||||
g.DrawEllipse(pen, startPosX + 20, startPosY + 40, 20, 15);
|
||||
g.DrawEllipse(pen, startPosX + 120, startPosY + 40, 20, 15);
|
||||
break;
|
||||
case WheelsNumber.Three:
|
||||
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 WheelsNumber.Four:
|
||||
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;
|
||||
}
|
||||
}
|
||||
public void DrawOrnament(Graphics g, float startPosX, float startPosY)
|
||||
{
|
||||
//рисуем круглый орнамент
|
||||
Pen pen = new(Color.Red);
|
||||
switch (wheelsNumber)
|
||||
{
|
||||
case WheelsNumber.Two:
|
||||
g.DrawEllipse(pen, startPosX + 25, startPosY + 45, 10, 7);
|
||||
g.DrawEllipse(pen, startPosX + 125, startPosY + 45, 10, 7);
|
||||
break;
|
||||
case WheelsNumber.Three:
|
||||
g.DrawEllipse(pen, startPosX + 25, startPosY + 45, 10, 7);
|
||||
g.DrawEllipse(pen, startPosX + 95, startPosY + 45, 10, 7);
|
||||
g.DrawEllipse(pen, startPosX + 125, startPosY + 45, 10, 7);
|
||||
break;
|
||||
case WheelsNumber.Four:
|
||||
g.DrawEllipse(pen, startPosX + 25, startPosY + 45, 10, 7);
|
||||
g.DrawEllipse(pen, startPosX + 55, startPosY + 45, 10, 7);
|
||||
g.DrawEllipse(pen, startPosX + 95, startPosY + 45, 10, 7);
|
||||
g.DrawEllipse(pen, startPosX + 125, startPosY + 45, 10, 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
/// <summary>
|
||||
/// Класс отрисовки колёс
|
||||
/// </summary>
|
||||
public DrawningWheels Wheels;
|
||||
public IDrawningAdditionalElements AdditionalElements;
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки локомотива
|
||||
/// </summary>
|
||||
@ -46,7 +46,7 @@
|
||||
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||
Wheels = new DrawningWheels();
|
||||
AdditionalElements = new DrawningWheels();
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для изменения размеров локомотива
|
||||
@ -175,7 +175,8 @@
|
||||
g.FillRectangle(brBodyColor, _startPosX + 60, _startPosY + 10, 15, 25);
|
||||
g.DrawRectangle(pen, _startPosX + 60, _startPosY + 10, 15, 25);
|
||||
//колёса
|
||||
Wheels.DrawWheels(g, _startPosX, _startPosY, Color.Black);
|
||||
AdditionalElements.DrawWheels(g, _startPosX, _startPosY, Color.Black);
|
||||
AdditionalElements.DrawOrnament(g, _startPosX, _startPosY);
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод перерисовки при изменении границ рисунка
|
||||
|
@ -0,0 +1,67 @@
|
||||
namespace WarmlyLocomotove
|
||||
{
|
||||
internal class DrawningRectOrnament : IDrawningAdditionalElements
|
||||
{
|
||||
private WheelsNumber wheelsNumber;
|
||||
|
||||
public int WheelsNum
|
||||
{
|
||||
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 WheelsNumber.Two:
|
||||
g.DrawEllipse(pen, startPosX + 20, startPosY + 40, 20, 15);
|
||||
g.DrawEllipse(pen, startPosX + 120, startPosY + 40, 20, 15);
|
||||
break;
|
||||
case WheelsNumber.Three:
|
||||
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 WheelsNumber.Four:
|
||||
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;
|
||||
}
|
||||
}
|
||||
public void DrawOrnament(Graphics g, float startPosX, float startPosY)
|
||||
{
|
||||
//рисуем прямоугольный орнамент
|
||||
Brush brush = new SolidBrush(Color.Blue);
|
||||
switch (wheelsNumber)
|
||||
{
|
||||
case WheelsNumber.Two:
|
||||
g.FillRectangle(brush, startPosX + 25, startPosY + 45, 10, 7);
|
||||
g.FillRectangle(brush, startPosX + 125, startPosY + 45, 10, 7);
|
||||
break;
|
||||
case WheelsNumber.Three:
|
||||
g.FillRectangle(brush, startPosX + 25, startPosY + 45, 10, 7);
|
||||
g.FillRectangle(brush, startPosX + 95, startPosY + 45, 10, 7);
|
||||
g.FillRectangle(brush, startPosX + 125, startPosY + 45, 10, 7);
|
||||
break;
|
||||
case WheelsNumber.Four:
|
||||
g.FillRectangle(brush, startPosX + 25, startPosY + 45, 10, 7);
|
||||
g.FillRectangle(brush, startPosX + 55, startPosY + 45, 10, 7);
|
||||
g.FillRectangle(brush, startPosX + 95, startPosY + 45, 10, 7);
|
||||
g.FillRectangle(brush, startPosX + 125, startPosY + 45, 10, 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace WarmlyLocomotove
|
||||
{
|
||||
internal class DrawningWheels
|
||||
internal class DrawningWheels : IDrawningAdditionalElements
|
||||
{
|
||||
private WheelsNumber wheelsNumber;
|
||||
|
||||
@ -40,5 +40,9 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawOrnament(Graphics g, float startPosX, float startPosY)
|
||||
{
|
||||
//ничего не рисуем, т.к. орнамента нет
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@
|
||||
_locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||
SetData(_locomotive);
|
||||
_locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
_locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -115,7 +115,7 @@
|
||||
Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData(_locomotive);
|
||||
SetAdditionalData((DrawningWarmlyLocomotive)_locomotive);
|
||||
_locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
_locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,9 @@
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.labelWheelsNumber = new System.Windows.Forms.Label();
|
||||
this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown();
|
||||
this.radioButtonNoOrnament = new System.Windows.Forms.RadioButton();
|
||||
this.radioButtonRectOrnament = new System.Windows.Forms.RadioButton();
|
||||
this.radioButtonEllipseOrnament = new System.Windows.Forms.RadioButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
|
||||
@ -230,11 +233,52 @@
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// radioButtonNoOrnament
|
||||
//
|
||||
this.radioButtonNoOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.radioButtonNoOrnament.AutoSize = true;
|
||||
this.radioButtonNoOrnament.Checked = true;
|
||||
this.radioButtonNoOrnament.Location = new System.Drawing.Point(223, 399);
|
||||
this.radioButtonNoOrnament.Name = "radioButtonNoOrnament";
|
||||
this.radioButtonNoOrnament.Size = new System.Drawing.Size(108, 19);
|
||||
this.radioButtonNoOrnament.TabIndex = 11;
|
||||
this.radioButtonNoOrnament.TabStop = true;
|
||||
this.radioButtonNoOrnament.Text = "Нет орнамента";
|
||||
this.radioButtonNoOrnament.UseVisualStyleBackColor = true;
|
||||
this.radioButtonNoOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged);
|
||||
//
|
||||
// radioButtonRectOrnament
|
||||
//
|
||||
this.radioButtonRectOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.radioButtonRectOrnament.AutoSize = true;
|
||||
this.radioButtonRectOrnament.Location = new System.Drawing.Point(337, 399);
|
||||
this.radioButtonRectOrnament.Name = "radioButtonRectOrnament";
|
||||
this.radioButtonRectOrnament.Size = new System.Drawing.Size(91, 19);
|
||||
this.radioButtonRectOrnament.TabIndex = 12;
|
||||
this.radioButtonRectOrnament.Text = "Квадратный";
|
||||
this.radioButtonRectOrnament.UseVisualStyleBackColor = true;
|
||||
this.radioButtonRectOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged);
|
||||
//
|
||||
// radioButtonEllipseOrnament
|
||||
//
|
||||
this.radioButtonEllipseOrnament.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.radioButtonEllipseOrnament.AutoSize = true;
|
||||
this.radioButtonEllipseOrnament.Location = new System.Drawing.Point(437, 399);
|
||||
this.radioButtonEllipseOrnament.Name = "radioButtonEllipseOrnament";
|
||||
this.radioButtonEllipseOrnament.Size = new System.Drawing.Size(73, 19);
|
||||
this.radioButtonEllipseOrnament.TabIndex = 13;
|
||||
this.radioButtonEllipseOrnament.Text = "Круглый";
|
||||
this.radioButtonEllipseOrnament.UseVisualStyleBackColor = true;
|
||||
this.radioButtonEllipseOrnament.CheckedChanged += new System.EventHandler(this.RadioButtonOrnament_CheckedChanged);
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.radioButtonEllipseOrnament);
|
||||
this.Controls.Add(this.radioButtonRectOrnament);
|
||||
this.Controls.Add(this.radioButtonNoOrnament);
|
||||
this.Controls.Add(this.labelWheelsNumber);
|
||||
this.Controls.Add(this.numericUpDownWheelsNumber);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
@ -276,5 +320,8 @@
|
||||
private ToolStripStatusLabel toolStripStatusLabelHasFuelTank;
|
||||
private Label labelWheelsNumber;
|
||||
private NumericUpDown numericUpDownWheelsNumber;
|
||||
private RadioButton radioButtonNoOrnament;
|
||||
private RadioButton radioButtonRectOrnament;
|
||||
private RadioButton radioButtonEllipseOrnament;
|
||||
}
|
||||
}
|
@ -49,7 +49,8 @@
|
||||
Random rnd = new();
|
||||
var locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
SetOrnament(locomotive);
|
||||
locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
SetData(locomotive);
|
||||
}
|
||||
/// <summary>
|
||||
@ -93,7 +94,8 @@
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
SetOrnament(locomotive);
|
||||
locomotive.AdditionalElements.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||||
SetData(locomotive);
|
||||
SetAdditionalData(locomotive);
|
||||
}
|
||||
@ -119,5 +121,31 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string CurrentOrnament = "";
|
||||
|
||||
private void RadioButtonOrnament_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (((RadioButton)sender).Checked)
|
||||
{
|
||||
CurrentOrnament = ((RadioButton)sender).Name;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetOrnament(DrawningLocomotive locomotive)
|
||||
{
|
||||
switch (CurrentOrnament)
|
||||
{
|
||||
case "radioButtonNoOrnament":
|
||||
locomotive.AdditionalElements = new DrawningWheels();
|
||||
break;
|
||||
case "radioButtonRectOrnament":
|
||||
locomotive.AdditionalElements = new DrawningRectOrnament();
|
||||
break;
|
||||
case "radioButtonEllipseOrnament":
|
||||
locomotive.AdditionalElements = new DrawningEllipseOrnament();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
namespace WarmlyLocomotove
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для прорисовки элементов усложнения
|
||||
/// </summary>
|
||||
internal interface IDrawningAdditionalElements
|
||||
{
|
||||
/// <summary>
|
||||
/// Свойство получения количества колёс
|
||||
/// </summary>
|
||||
public int WheelsNum { set; }
|
||||
/// <summary>
|
||||
/// Отрисовка колёс
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
/// <param name="startPosX"></param>
|
||||
/// <param name="startPosY"></param>
|
||||
/// <param name="wheelsColor"></param>
|
||||
public void DrawWheels(Graphics g, float startPosX, float startPosY, Color wheelsColor);
|
||||
/// <summary>
|
||||
/// Отрисовка орнамента (если есть)
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
/// <param name="startPosX"></param>
|
||||
/// <param name="startPosY"></param>
|
||||
public void DrawOrnament(Graphics g, float startPosX, float startPosY);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user