polymorphism
This commit is contained in:
parent
8733297af1
commit
a6ff38c3e4
@ -6,11 +6,11 @@ public class DrawningCruiser : DrawningBase
|
|||||||
{
|
{
|
||||||
// Инициализация свойств (все параметры класса (сущности))
|
// Инициализация свойств (все параметры класса (сущности))
|
||||||
public DrawningCruiser(int speed, double weight, Color bodyColor,
|
public DrawningCruiser(int speed, double weight, Color bodyColor,
|
||||||
Color additionalColor, bool pads, bool hangar) : base(302, 42)
|
Color additionalColor, bool hangars) : base(302, 42)
|
||||||
// all additional featchures 'inside' object, so size remains
|
// all additional featchures 'inside' object, so size remains
|
||||||
{
|
{
|
||||||
EntityTransport = new EntityCruiser(speed, weight,
|
EntityTransport = new EntityCruiser(speed, weight,
|
||||||
bodyColor, additionalColor, pads, hangar);
|
bodyColor, additionalColor, hangars);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
@ -31,24 +31,16 @@ public class DrawningCruiser : DrawningBase
|
|||||||
|
|
||||||
base.DrawTransport(g);
|
base.DrawTransport(g);
|
||||||
|
|
||||||
// вертолетная площадка
|
// вертолетная площадка - default TRUE now
|
||||||
if (ship.HelicopterPads)
|
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||||
{
|
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
|
||||||
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ангар
|
// ангар(ы)
|
||||||
if (ship.Hangar)
|
if (ship.Hangars)
|
||||||
{
|
{
|
||||||
int n = EntityTransport.values[2];
|
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
|
||||||
if (n == 1) g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
|
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@ public class EntityCruiser : EntityBase
|
|||||||
|
|
||||||
// признаки (наличия)
|
// признаки (наличия)
|
||||||
public bool HelicopterPads { get; private set; } // вертолетная площадка
|
public bool HelicopterPads { get; private set; } // вертолетная площадка
|
||||||
public bool Hangar { get; private set; } // ангар
|
public bool Hangars { get; private set; } // ангар
|
||||||
|
|
||||||
public EntityCruiser(int speed, double weight, Color mainc,
|
public EntityCruiser(int speed, double weight, Color mainc,
|
||||||
Color additionalColor, bool pads, bool hangar)
|
Color additionalColor, bool hangars)
|
||||||
: base(speed, weight, mainc)
|
: base(speed, weight, mainc)
|
||||||
{
|
{
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
HelicopterPads = pads;
|
// HelicopterPads = pads; - default TRUE now for Advanced obj
|
||||||
Hangar = hangar;
|
Hangars = hangars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,10 +64,11 @@ namespace ProjectCruiser
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(DrawningCruiser):
|
case nameof(DrawningCruiser):
|
||||||
_drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000),
|
_drawningCruiser = new DrawningCruiser(
|
||||||
|
random.Next(100, 300), random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
Convert.ToBoolean(random.Next(0, 2)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
25
ProjectCruiser/ServiceForm2.Designer.cs
generated
25
ProjectCruiser/ServiceForm2.Designer.cs
generated
@ -45,9 +45,10 @@
|
|||||||
//
|
//
|
||||||
comboBoxArrList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
comboBoxArrList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
comboBoxArrList.FormattingEnabled = true;
|
comboBoxArrList.FormattingEnabled = true;
|
||||||
|
comboBoxArrList.Items.AddRange(new object[] { "Storage" });
|
||||||
comboBoxArrList.Location = new Point(17, 54);
|
comboBoxArrList.Location = new Point(17, 54);
|
||||||
comboBoxArrList.Name = "comboBoxArrList";
|
comboBoxArrList.Name = "comboBoxArrList";
|
||||||
comboBoxArrList.Size = new Size(242, 40);
|
comboBoxArrList.Size = new Size(268, 40);
|
||||||
comboBoxArrList.TabIndex = 0;
|
comboBoxArrList.TabIndex = 0;
|
||||||
comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged;
|
comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
@ -56,7 +57,7 @@
|
|||||||
btnAddBase.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnAddBase.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
btnAddBase.Location = new Point(17, 561);
|
btnAddBase.Location = new Point(17, 561);
|
||||||
btnAddBase.Name = "btnAddBase";
|
btnAddBase.Name = "btnAddBase";
|
||||||
btnAddBase.Size = new Size(242, 46);
|
btnAddBase.Size = new Size(268, 46);
|
||||||
btnAddBase.TabIndex = 1;
|
btnAddBase.TabIndex = 1;
|
||||||
btnAddBase.Text = "Add ship";
|
btnAddBase.Text = "Add ship";
|
||||||
btnAddBase.UseVisualStyleBackColor = true;
|
btnAddBase.UseVisualStyleBackColor = true;
|
||||||
@ -72,9 +73,9 @@
|
|||||||
groupBox.Controls.Add(btnAddCruiser);
|
groupBox.Controls.Add(btnAddCruiser);
|
||||||
groupBox.Controls.Add(btnAddBase);
|
groupBox.Controls.Add(btnAddBase);
|
||||||
groupBox.Controls.Add(comboBoxArrList);
|
groupBox.Controls.Add(comboBoxArrList);
|
||||||
groupBox.Location = new Point(1006, 12);
|
groupBox.Location = new Point(1437, 12);
|
||||||
groupBox.Name = "groupBox";
|
groupBox.Name = "groupBox";
|
||||||
groupBox.Size = new Size(274, 938);
|
groupBox.Size = new Size(300, 938);
|
||||||
groupBox.TabIndex = 2;
|
groupBox.TabIndex = 2;
|
||||||
groupBox.TabStop = false;
|
groupBox.TabStop = false;
|
||||||
groupBox.Text = "Tool panel";
|
groupBox.Text = "Tool panel";
|
||||||
@ -84,7 +85,7 @@
|
|||||||
btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
btnUpdate.Location = new Point(17, 865);
|
btnUpdate.Location = new Point(17, 865);
|
||||||
btnUpdate.Name = "btnUpdate";
|
btnUpdate.Name = "btnUpdate";
|
||||||
btnUpdate.Size = new Size(242, 46);
|
btnUpdate.Size = new Size(268, 46);
|
||||||
btnUpdate.TabIndex = 6;
|
btnUpdate.TabIndex = 6;
|
||||||
btnUpdate.Text = "Update";
|
btnUpdate.Text = "Update";
|
||||||
btnUpdate.UseVisualStyleBackColor = true;
|
btnUpdate.UseVisualStyleBackColor = true;
|
||||||
@ -95,7 +96,7 @@
|
|||||||
btnTest.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnTest.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
btnTest.Location = new Point(17, 795);
|
btnTest.Location = new Point(17, 795);
|
||||||
btnTest.Name = "btnTest";
|
btnTest.Name = "btnTest";
|
||||||
btnTest.Size = new Size(242, 64);
|
btnTest.Size = new Size(268, 64);
|
||||||
btnTest.TabIndex = 5;
|
btnTest.TabIndex = 5;
|
||||||
btnTest.Text = "Choose for testing";
|
btnTest.Text = "Choose for testing";
|
||||||
btnTest.UseVisualStyleBackColor = true;
|
btnTest.UseVisualStyleBackColor = true;
|
||||||
@ -106,19 +107,19 @@
|
|||||||
btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
btnDelete.Location = new Point(17, 732);
|
btnDelete.Location = new Point(17, 732);
|
||||||
btnDelete.Name = "btnDelete";
|
btnDelete.Name = "btnDelete";
|
||||||
btnDelete.Size = new Size(242, 46);
|
btnDelete.Size = new Size(268, 46);
|
||||||
btnDelete.TabIndex = 4;
|
btnDelete.TabIndex = 4;
|
||||||
btnDelete.Text = "Delete";
|
btnDelete.Text = "Delete";
|
||||||
btnDelete.UseVisualStyleBackColor = true;
|
btnDelete.UseVisualStyleBackColor = true;
|
||||||
btnDelete.Click += btnRemoveCar_Click;
|
btnDelete.Click += btnRemoveCar_Click;
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
maskedTextBoxPosition.Location = new Point(17, 682);
|
maskedTextBoxPosition.Location = new Point(17, 682);
|
||||||
maskedTextBoxPosition.Mask = "00";
|
maskedTextBoxPosition.Mask = "00";
|
||||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
maskedTextBoxPosition.Size = new Size(242, 39);
|
maskedTextBoxPosition.Size = new Size(268, 39);
|
||||||
maskedTextBoxPosition.TabIndex = 3;
|
maskedTextBoxPosition.TabIndex = 3;
|
||||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
//
|
//
|
||||||
@ -127,7 +128,7 @@
|
|||||||
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
btnAddCruiser.Location = new Point(17, 613);
|
btnAddCruiser.Location = new Point(17, 613);
|
||||||
btnAddCruiser.Name = "btnAddCruiser";
|
btnAddCruiser.Name = "btnAddCruiser";
|
||||||
btnAddCruiser.Size = new Size(242, 46);
|
btnAddCruiser.Size = new Size(268, 46);
|
||||||
btnAddCruiser.TabIndex = 2;
|
btnAddCruiser.TabIndex = 2;
|
||||||
btnAddCruiser.Text = "Add cruiser";
|
btnAddCruiser.Text = "Add cruiser";
|
||||||
btnAddCruiser.UseVisualStyleBackColor = true;
|
btnAddCruiser.UseVisualStyleBackColor = true;
|
||||||
@ -138,7 +139,7 @@
|
|||||||
pictureBox.Dock = DockStyle.Left;
|
pictureBox.Dock = DockStyle.Left;
|
||||||
pictureBox.Location = new Point(0, 0);
|
pictureBox.Location = new Point(0, 0);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(988, 959);
|
pictureBox.Size = new Size(1417, 959);
|
||||||
pictureBox.TabIndex = 3;
|
pictureBox.TabIndex = 3;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -146,7 +147,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1292, 959);
|
ClientSize = new Size(1749, 959);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBox);
|
Controls.Add(groupBox);
|
||||||
Name = "ServiceForm2";
|
Name = "ServiceForm2";
|
||||||
|
@ -5,10 +5,11 @@ namespace ProjectCruiser;
|
|||||||
public partial class ServiceForm2 : Form
|
public partial class ServiceForm2 : Form
|
||||||
{
|
{
|
||||||
// Компания
|
// Компания
|
||||||
private AbstractCompany? _company = null;
|
private AbstractCompany? _company;
|
||||||
public ServiceForm2()
|
public ServiceForm2()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_company = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Выбор компании
|
// Выбор компании
|
||||||
@ -64,12 +65,12 @@ public partial class ServiceForm2 : Form
|
|||||||
// (TODO) вызов диалогового окна для выбора цвета >>>
|
// (TODO) вызов диалогового окна для выбора цвета >>>
|
||||||
drawningCar = new DrawningCruiser(random.Next(100, 300),
|
drawningCar = new DrawningCruiser(random.Next(100, 300),
|
||||||
random.Next(1000, 3000), pickColor(random), pickColor(random),
|
random.Next(1000, 3000), pickColor(random), pickColor(random),
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
Convert.ToBoolean(random.Next(0, 2)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_company + drawningCar > 0)
|
if (_company + drawningCar != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("> Object was added");
|
MessageBox.Show("> Object was added");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
|
@ -22,17 +22,18 @@ public class ShipSharingService : AbstractCompany
|
|||||||
{
|
{
|
||||||
Pen pen = new(Color.Black, 2);
|
Pen pen = new(Color.Black, 2);
|
||||||
|
|
||||||
int currentH = 10, currentW = 10;
|
int currentH = fromCeiling, currentW = fromBorder;
|
||||||
|
|
||||||
for (int i = 0; i < MaxInRow; i++)
|
for (int i = 0; i < MaxInRow; i++)
|
||||||
{
|
{
|
||||||
currentH = 10;
|
currentH = fromCeiling;
|
||||||
for (int j = 0; j < MaxInColon; j++)
|
for (int j = 0; j < MaxInColon; j++)
|
||||||
{
|
{
|
||||||
g.DrawLine(pen, currentW + _placeSizeWidth, currentH - 1,
|
g.DrawLine(pen, currentW + _placeSizeWidth,
|
||||||
currentW - 1, currentH - 1);
|
currentH, currentW, currentH);
|
||||||
g.DrawLine(pen, currentW - 1, currentH - 1, currentW - 1,
|
|
||||||
currentH + _placeSizeHeight);
|
g.DrawLine(pen, currentW, currentH,
|
||||||
|
currentW, currentH + _placeSizeHeight);
|
||||||
|
|
||||||
currentH += _placeSizeHeight + 1;
|
currentH += _placeSizeHeight + 1;
|
||||||
}
|
}
|
||||||
@ -43,20 +44,20 @@ public class ShipSharingService : AbstractCompany
|
|||||||
protected override void SetObjectsPosition()
|
protected override void SetObjectsPosition()
|
||||||
{
|
{
|
||||||
int index_collection = 0;
|
int index_collection = 0;
|
||||||
int newX = fromBorder, newY = fromCeiling;
|
int newX = fromBorder + 6, newY = fromCeiling + 6;
|
||||||
|
|
||||||
if (_collection != null)
|
if (_collection != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MaxInColon; ++i)
|
for (int i = 0; i < MaxInColon; ++i)
|
||||||
{
|
{
|
||||||
newX = fromBorder;
|
newX = fromBorder + 2;
|
||||||
for (int j = 0; j < MaxInRow; ++j)
|
for (int j = 0; j < MaxInRow; ++j)
|
||||||
{
|
{
|
||||||
if (_collection.GetItem(index_collection) != null)
|
if (_collection.GetItem(index_collection) != null)
|
||||||
{
|
{
|
||||||
_collection.GetItem(index_collection).SetPictureSize(_pictureWidth, _pictureHeight);
|
_collection.GetItem(index_collection).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
_collection.GetItem(index_collection).SetPosition(newX, newY);
|
_collection.GetItem(index_collection).SetPosition(newX, newY);
|
||||||
newX += _placeSizeWidth + between;
|
newX += _placeSizeWidth + between + 2;
|
||||||
index_collection++;
|
index_collection++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user