Вторая лабораторная работа. Переход на конструкторы. Продвинутый объект.
This commit is contained in:
parent
fc7866c869
commit
9e7872158e
99
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
99
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class DrawingContainerShip : DrawingShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawingContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Ship is not EntityContainerShip containerShip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(containerShip.DopColor);
|
||||
Pen dopPen = new (containerShip.DopColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
if (containerShip.Containers)
|
||||
{
|
||||
Point[] container1 =
|
||||
{
|
||||
new Point((int)(_startPosX + 5), (int)(_startPosY + 15)),
|
||||
new Point((int)(_startPosX + 5), (int)(_startPosY + 5)),
|
||||
new Point((int)(_startPosX + 25), (int)_startPosY + 5),
|
||||
new Point((int)_startPosX + 25, (int)_startPosY + 15)
|
||||
};
|
||||
|
||||
|
||||
Point[] container2 =
|
||||
{
|
||||
new Point((int)_startPosX + 40, (int)_startPosY + 15),
|
||||
new Point((int)_startPosX + 40, (int)_startPosY + 5),
|
||||
new Point((int)_startPosX + 75, (int)_startPosY + 5),
|
||||
new Point((int)_startPosX + 75, (int)_startPosY + 15)
|
||||
};
|
||||
|
||||
Point[] container3 =
|
||||
{
|
||||
new Point((int)_startPosX + 16 * 5, (int)_startPosY + 15),
|
||||
new Point((int)_startPosX + 16 * 5, (int)_startPosY + 5),
|
||||
new Point((int)_startPosX + 22 * 5, (int)_startPosY + 5),
|
||||
new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15)
|
||||
};
|
||||
|
||||
Point[] container4 =
|
||||
{
|
||||
new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15),
|
||||
new Point((int)_startPosX + 22 * 5, (int)_startPosY),
|
||||
new Point((int)_startPosX + 26 * 5, (int)_startPosY),
|
||||
new Point((int)_startPosX + 26 * 5, (int)_startPosY + 15)
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, container1);
|
||||
g.DrawPolygon(pen, container1);
|
||||
g.FillPolygon(dopBrush, container2);
|
||||
g.DrawPolygon(pen, container2);
|
||||
g.FillPolygon(dopBrush, container3);
|
||||
g.DrawPolygon(pen, container3);
|
||||
g.FillPolygon(dopBrush, container4);
|
||||
g.DrawPolygon(pen, container4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (containerShip.Crane)
|
||||
{
|
||||
g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 15, _startPosX + 8 * 5, _startPosY - 30);
|
||||
g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30);
|
||||
g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 25);
|
||||
g.DrawLine(dopPen, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ namespace ContainerShip
|
||||
{
|
||||
internal class DrawingShip
|
||||
{
|
||||
public EntityShip Ship { private set; get; }
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
public EntityShip Ship { protected set; get; }
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
private int? _pictureWidth = null;
|
||||
private int _startPosXInt;
|
||||
private int _startPosYInt;
|
||||
@ -33,10 +33,9 @@ namespace ContainerShip
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawingShip(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Ship = new EntityShip();
|
||||
Ship.Init(speed, weight, bodyColor);
|
||||
Ship = new EntityShip(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <param name="x">Координата X</param>
|
||||
@ -100,7 +99,7 @@ namespace ContainerShip
|
||||
/// Отрисовка
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
|
32
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
32
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class EntityContainerShip : EntityShip
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
public bool Containers { get; private set; }
|
||||
public bool Crane { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public EntityContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Crane = crane;
|
||||
Containers = containers;
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ namespace ContainerShip
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityShip(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
15
ContainerShip/ContainerShip/FormShip.Designer.cs
generated
15
ContainerShip/ContainerShip/FormShip.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
|
||||
this.ButtonCreate = new System.Windows.Forms.Button();
|
||||
this.ButtonCreateModif = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -142,11 +143,24 @@
|
||||
this.ButtonCreate.UseVisualStyleBackColor = false;
|
||||
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// ButtonCreateModif
|
||||
//
|
||||
this.ButtonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreateModif.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.ButtonCreateModif.Location = new System.Drawing.Point(130, 381);
|
||||
this.ButtonCreateModif.Name = "ButtonCreateModif";
|
||||
this.ButtonCreateModif.Size = new System.Drawing.Size(143, 34);
|
||||
this.ButtonCreateModif.TabIndex = 9;
|
||||
this.ButtonCreateModif.Text = "Модификация";
|
||||
this.ButtonCreateModif.UseVisualStyleBackColor = false;
|
||||
this.ButtonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// FormShip
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.ButtonCreateModif);
|
||||
this.Controls.Add(this.ButtonCreate);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -177,5 +191,6 @@
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private PictureBox pictureBoxShip;
|
||||
private Button ButtonCreate;
|
||||
private Button ButtonCreateModif;
|
||||
}
|
||||
}
|
@ -61,16 +61,34 @@ namespace ContainerShip
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||
}
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_ship = new DrawingShip();
|
||||
_ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0,256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
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)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user